* initial commit Signed-off-by: raver119 <raver119@gmail.com> * bunch of tweaks Signed-off-by: raver119 <raver119@gmail.com> * hamming distance nullification Signed-off-by: raver119 <raver119@gmail.com> * Add output array value assignment for testing/debugging Signed-off-by: Alex Black <blacka101@gmail.com> * don't assign empty arrays Signed-off-by: raver119 <raver119@gmail.com> * conv2d/conv3d/depthwise2d nullified Signed-off-by: raver119 <raver119@gmail.com> * conv2d/conv3d/depthwise2d nullified Signed-off-by: raver119 <raver119@gmail.com> * conv2d/conv3d/depthwise2d nullified Signed-off-by: raver119 <raver119@gmail.com> * few more fixes Signed-off-by: raver119 <raver119@gmail.com> * im2col Signed-off-by: raver119 <raver119@gmail.com> * pooling? Signed-off-by: raver119 <raver119@gmail.com> * more nullified Signed-off-by: raver119 <raver119@gmail.com> * ismax nullified Signed-off-by: raver119 <raver119@gmail.com> * rollback ismax nullification Signed-off-by: raver119 <raver119@gmail.com> * synchronized cublas handle use on per-device basis Signed-off-by: raver119 <raver119@gmail.com> * hiding method from jcpp Signed-off-by: raver119 <raver119@gmail.com> * get rid of test assigns in DeclarableOp Signed-off-by: raver119 <raver119@gmail.com> * get rid of assigns Signed-off-by: raver119 <raver119@gmail.com> * proper deviceId is back Signed-off-by: raver119 <raver119@gmail.com> * include fixed Signed-off-by: raver119 <raver119@gmail.com> Co-authored-by: Alex Black <blacka101@gmail.com>
99 lines
3.0 KiB
C++
99 lines
3.0 KiB
C++
/*******************************************************************************
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
|
*
|
|
* This program and the accompanying materials are made available under the
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
* https://www.apache.org/licenses/LICENSE-2.0.
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
******************************************************************************/
|
|
|
|
//
|
|
// Created by raver119 on 30.11.17.
|
|
//
|
|
|
|
#include <execution/LaunchContext.h>
|
|
#include <execution/AffinityManager.h>
|
|
#include <helpers/logger.h>
|
|
#include <exceptions/cuda_exception.h>
|
|
#include <thread>
|
|
|
|
#if defined(SD_IOS_BUILD) || defined(SD_APPLE_BUILD) || defined(SD_ANDROID_BUILD)
|
|
sd::ContextBuffers contextBuffers = sd::ContextBuffers();
|
|
#else
|
|
thread_local sd::ContextBuffers contextBuffers = sd::ContextBuffers();
|
|
#endif
|
|
|
|
#ifdef HAVE_MKLDNN
|
|
#include <dnnl.hpp>
|
|
#endif
|
|
|
|
namespace sd {
|
|
|
|
LaunchContext::~LaunchContext() {
|
|
#ifdef HAVE_MKLDNN
|
|
delete reinterpret_cast<dnnl::engine*>(_engine);
|
|
#endif
|
|
}
|
|
|
|
std::vector<std::shared_ptr<LaunchContext>> LaunchContext::_contexts = std::vector<std::shared_ptr<LaunchContext>>();
|
|
MAP_IMPL<int, std::mutex*> LaunchContext::_deviceMutexes;
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
LaunchContext::LaunchContext() {
|
|
// default constructor, just to make clang/ranlib happy
|
|
_workspace = nullptr;
|
|
_deviceID = 0;
|
|
|
|
_deviceMutexes[_deviceID] = new std::mutex();
|
|
|
|
#ifdef HAVE_MKLDNN
|
|
_engine = new dnnl::engine(dnnl::engine::kind::cpu, 0);
|
|
#endif
|
|
}
|
|
|
|
LaunchContext::LaunchContext(Nd4jPointer cudaStream, Nd4jPointer reductionPointer, Nd4jPointer scalarPointer, Nd4jPointer allocationPointer) {
|
|
|
|
}
|
|
|
|
LaunchContext* LaunchContext::defaultContext() {
|
|
// TODO: we need it to be device-aware, but only once we add NUMA support for cpu
|
|
if (LaunchContext::_contexts.empty()) {
|
|
LaunchContext::_contexts.emplace_back(std::make_shared<LaunchContext>());
|
|
}
|
|
|
|
// return context for current device
|
|
return LaunchContext::_contexts[0].get();
|
|
}
|
|
|
|
std::mutex* LaunchContext::deviceMutex() {
|
|
auto deviceId = AffinityManager::currentDeviceId();
|
|
return _deviceMutexes[deviceId];
|
|
}
|
|
|
|
void LaunchContext::swapContextBuffers(ContextBuffers &buffers) {
|
|
//
|
|
}
|
|
|
|
bool LaunchContext::isInitialized() {
|
|
return true;
|
|
}
|
|
|
|
void LaunchContext::releaseBuffers() {
|
|
//
|
|
}
|
|
|
|
sd::ErrorReference* LaunchContext::errorReference() {
|
|
return contextBuffers.errorReference();
|
|
}
|
|
|
|
void* LaunchContext::engine() {
|
|
return _engine;
|
|
}
|
|
} |