cavis/libnd4j/include/ops/declarable/OpRegistrator.h
raver119 7783012f39
cuDNN integration (#150)
* initial commit

Signed-off-by: raver119 <raver119@gmail.com>

* one file

Signed-off-by: raver119 <raver119@gmail.com>

* few more includes

Signed-off-by: raver119 <raver119@gmail.com>

* m?

Signed-off-by: raver119 <raver119@gmail.com>

* const

Signed-off-by: raver119 <raver119@gmail.com>

* cudnn linkage in tests

Signed-off-by: raver119 <raver119@gmail.com>

* culibos

Signed-off-by: raver119 <raver119@gmail.com>

* static reminder

Signed-off-by: raver119 <raver119@gmail.com>

* platform engine tag

Signed-off-by: raver119 <raver119@gmail.com>

* HAVE_CUDNN moved to config.h.in

Signed-off-by: raver119 <raver119@gmail.com>

* include

Signed-off-by: raver119 <raver119@gmail.com>

* include

Signed-off-by: raver119 <raver119@gmail.com>

* skip cudnn handle creation if there's not cudnn

Signed-off-by: raver119 <raver119@gmail.com>

* meh

Signed-off-by: raver119 <raver119@gmail.com>

* target device in context

Signed-off-by: raver119 <raver119@gmail.com>

* platform engines

Signed-off-by: raver119 <raver119@gmail.com>

* platform engines

Signed-off-by: raver119 <raver119@gmail.com>

* allow multiple -h args

Signed-off-by: raver119 <raver119@gmail.com>

* allow multiple -h args

Signed-off-by: raver119 <raver119@gmail.com>

* move mkldnn out of CPU block

Signed-off-by: raver119 <raver119@gmail.com>

* link to mkldnn on cuda

Signed-off-by: raver119 <raver119@gmail.com>

* less prints

Signed-off-by: raver119 <raver119@gmail.com>

* minor tweaks

Signed-off-by: raver119 <raver119@gmail.com>

* next step

Signed-off-by: raver119 <raver119@gmail.com>

* conv2d NCHW draft

Signed-off-by: raver119 <raver119@gmail.com>

* conv2d biasAdd

Signed-off-by: raver119 <raver119@gmail.com>

* test for MKL/CUDNN combined use

Signed-off-by: raver119 <raver119@gmail.com>

* - provide additional code for conv2d ff based on cudnn api, not tested yet

Signed-off-by: Yurii <iuriish@yahoo.com>

* - further work on conv2d helper based on using cudnn api

Signed-off-by: Yurii <iuriish@yahoo.com>

* - fixing several cuda bugs which appeared after cudnn lib had been started to use

Signed-off-by: Yurii <iuriish@yahoo.com>

* - implementation of conv2d backprop op based on cudnn api

Signed-off-by: Yurii <iuriish@yahoo.com>

* - implementaion of conv3d and conv3d_bp ops based on cudnn api

Signed-off-by: Yurii <iuriish@yahoo.com>

* - bugs fixing in conv3d/conv3d_bp ops (cudnn in use)

Signed-off-by: Yurii <iuriish@yahoo.com>

* - implementation of depthwiseConv2d (ff/bp) op based on cudnn api

Signed-off-by: Yurii <iuriish@yahoo.com>

* - implementation of batchnorm ff op based on cudnn api

Signed-off-by: Yurii <iuriish@yahoo.com>

* - disable cudnn batchnorm temporary

Signed-off-by: Yurii <iuriish@yahoo.com>

* - add minor change in cmake

Signed-off-by: Yurii <iuriish@yahoo.com>

* engine for depthwise mkldnn

Signed-off-by: raver119 <raver119@gmail.com>

* couple of includes

Signed-off-by: raver119 <raver119@gmail.com>

* - provide permutation to cudnn batchnorm ff when format is NHWC

Signed-off-by: Yurii <iuriish@yahoo.com>

* lgamma fix

Signed-off-by: raver119 <raver119@gmail.com>

* - eliminate memory leak in two tests

Signed-off-by: Yurii <iuriish@yahoo.com>

Co-authored-by: Yurii Shyrma <iuriish@yahoo.com>
2020-01-20 21:32:46 +03:00

133 lines
4.6 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 07.10.2017.
//
#ifndef LIBND4J_OPREGISTRATOR_H
#define LIBND4J_OPREGISTRATOR_H
#include <pointercast.h>
#include <vector>
#include <map>
#include <mutex>
#include <ops/declarable/DeclarableOp.h>
#include <ops/declarable/PlatformHelper.h>
#include <execution/Engine.h>
// handlers part
#include <cstdlib>
#include <csignal>
namespace nd4j {
namespace ops {
/**
* This class provides runtime ops lookup, based on opName or opHash.
* To build lookup directory we use *_OP_IMPL macro, which puts static structs at compile time in .cpp files,
* so once binary is executed, static objects are initialized automatically, and we get list of all ops
* available at runtime via this singleton.
*
*/
class ND4J_EXPORT OpRegistrator {
private:
static OpRegistrator* _INSTANCE;
OpRegistrator() {
nd4j_debug("OpRegistrator started\n","");
#ifndef _RELEASE
std::signal(SIGSEGV, &OpRegistrator::sigSegVHandler);
std::signal(SIGINT, &OpRegistrator::sigIntHandler);
std::signal(SIGABRT, &OpRegistrator::sigIntHandler);
std::signal(SIGFPE, &OpRegistrator::sigIntHandler);
std::signal(SIGILL, &OpRegistrator::sigIntHandler);
std::signal(SIGTERM, &OpRegistrator::sigIntHandler);
atexit(&OpRegistrator::exitHandler);
#endif
};
std::map<Nd4jLong, std::string> _msvc;
// pointers to our operations
std::map<Nd4jLong, nd4j::ops::DeclarableOp*> _declarablesLD;
std::map<std::string, nd4j::ops::DeclarableOp*> _declarablesD;
std::vector<nd4j::ops::DeclarableOp *> _uniqueD;
// pointers to platform-specific helpers
std::map<std::pair<Nd4jLong, samediff::Engine>, nd4j::ops::platforms::PlatformHelper*> _helpersLH;
std::map<std::pair<std::string, samediff::Engine>, nd4j::ops::platforms::PlatformHelper*> _helpersH;
std::vector<nd4j::ops::platforms::PlatformHelper*> _uniqueH;
std::mutex _locker;
std::string _opsList;
bool isInit = false;
public:
~OpRegistrator();
static OpRegistrator* getInstance();
static void exitHandler();
static void sigIntHandler(int sig);
static void sigSegVHandler(int sig);
void updateMSVC(Nd4jLong newHash, std::string& oldName);
template <typename T>
std::string local_to_string(T value);
const char * getAllCustomOperations();
/**
* This method registers operation in our registry, so we can use them later
*
* @param op
*/
bool registerOperation(const char* name, nd4j::ops::DeclarableOp* op);
bool registerOperation(nd4j::ops::DeclarableOp *op);
void registerHelper(nd4j::ops::platforms::PlatformHelper* op);
bool hasHelper(Nd4jLong hash, samediff::Engine engine);
nd4j::ops::DeclarableOp* getOperation(const char *name);
nd4j::ops::DeclarableOp* getOperation(Nd4jLong hash);
nd4j::ops::DeclarableOp* getOperation(std::string &name);
nd4j::ops::platforms::PlatformHelper* getPlatformHelper(Nd4jLong hash, samediff::Engine engine);
std::vector<Nd4jLong> getAllHashes();
int numberOfOperations();
};
/*
* These structs are used to "register" our ops in OpRegistrator.
*/
template <typename OpName>
struct __registrator{
__registrator();
};
template <typename OpName>
struct __registratorSynonym {
__registratorSynonym(const char *name, const char *oname);
};
}
}
#endif //LIBND4J_OPREGISTRATOR_H