diff --git a/CMakeLists.txt b/CMakeLists.txt index c29e987..1242b61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,6 @@ if(WIN32) set(CMAKE_CXX_FLAGS "/Od /FS /EHsc /MDd") set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32 -G -g) endif() -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) endif(WIN32) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/tkDNN) @@ -82,7 +81,13 @@ endif() #------------------------------------------------------------------------------- # CUDA #------------------------------------------------------------------------------- +if(UNIX) set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --compiler-options '-fPIC') +endif(UNIX) + +if(WIN32) +set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --compiler-options) +endif(WIN32) find_package(CUDNN REQUIRED) diff --git a/cmake/cuda_script.exe b/cmake/cuda_script.exe new file mode 100644 index 0000000..642a83a Binary files /dev/null and b/cmake/cuda_script.exe differ diff --git a/cmake/cuda_script.exp b/cmake/cuda_script.exp new file mode 100644 index 0000000..8314526 Binary files /dev/null and b/cmake/cuda_script.exp differ diff --git a/cmake/cuda_script.lib b/cmake/cuda_script.lib new file mode 100644 index 0000000..39219f2 Binary files /dev/null and b/cmake/cuda_script.lib differ diff --git a/demo/demoConfig.yaml b/demo/demoConfig.yaml index 5785852..01f36a2 100644 --- a/demo/demoConfig.yaml +++ b/demo/demoConfig.yaml @@ -1,9 +1,9 @@ # video input input : "../demo/yolo_test.mp4" -win_input : "..\\..\\..\\demo\\yolo_test.mp4" +win_input : "..\\demo\\yolo_test.mp4" # network config -net : "yolo4_berkeley_fp32.rt" +net : "yolo4tiny_fp32.rt" ntype : 'y' n_classes : 80 n_batch : 1 diff --git a/include/tkDNN/CenterTrack.h b/include/tkDNN/CenterTrack.h index aa573fa..802929a 100644 --- a/include/tkDNN/CenterTrack.h +++ b/include/tkDNN/CenterTrack.h @@ -170,12 +170,12 @@ public: tk::dnn::Network *pre_phase_net = nullptr; CenterTrack() {}; ~CenterTrack() {}; - bool init(const std::string& tensor_path, const int n_classes=3, const int n_batches=1, + TKDNN_LIB_EXPORT_API bool init(const std::string& tensor_path, const int n_classes=3, const int n_batches=1, const float conf_thresh=0.3, const bool mode_3d=true, const std::vector& k_calibs=std::vector()); - void preprocess(cv::Mat &frame, const int bi=0); - void postprocess(const int bi=0,const bool mAP=false); - void draw(std::vector& frames); + TKDNN_LIB_EXPORT_API void preprocess(cv::Mat &frame, const int bi=0); + TKDNN_LIB_EXPORT_API void postprocess(const int bi=0,const bool mAP=false); + TKDNN_LIB_EXPORT_API void draw(std::vector& frames); }; diff --git a/include/tkDNN/CenternetDetection.h b/include/tkDNN/CenternetDetection.h index 3c8cfbb..1a18e84 100644 --- a/include/tkDNN/CenternetDetection.h +++ b/include/tkDNN/CenternetDetection.h @@ -73,9 +73,9 @@ public: CenternetDetection() {}; ~CenternetDetection() {}; - bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3); - void preprocess(cv::Mat &frame, const int bi=0); - void postprocess(const int bi=0,const bool mAP=false); + TKDNN_LIB_EXPORT_API bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3); + TKDNN_LIB_EXPORT_API void preprocess(cv::Mat &frame, const int bi=0); + TKDNN_LIB_EXPORT_API void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/CenternetDetection3D.h b/include/tkDNN/CenternetDetection3D.h index 9f2b214..b8fa42c 100644 --- a/include/tkDNN/CenternetDetection3D.h +++ b/include/tkDNN/CenternetDetection3D.h @@ -92,10 +92,10 @@ public: CenternetDetection3D() {}; ~CenternetDetection3D() {}; - bool init(const std::string& tensor_path, const int n_classes=3, const int n_batches=1, const float conf_thresh=0.3, const std::vector& k_calibs=std::vector()); - void preprocess(cv::Mat &frame, const int bi=0); - void postprocess(const int bi=0,const bool mAP=false); - void draw(std::vector& frames); + TKDNN_LIB_EXPORT_API bool init(const std::string& tensor_path, const int n_classes=3, const int n_batches=1, const float conf_thresh=0.3, const std::vector& k_calibs=std::vector()); + TKDNN_LIB_EXPORT_API void preprocess(cv::Mat &frame, const int bi=0); + TKDNN_LIB_EXPORT_API void postprocess(const int bi=0,const bool mAP=false); + TKDNN_LIB_EXPORT_API void draw(std::vector& frames); }; diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index c6d2472..af63e94 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -46,7 +46,7 @@ namespace tk { namespace dnn { void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, std::vector &netLayers, const std::vector& names); std::vector darknetReadNames(const std::string& names_file); - tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file); + TKDNN_LIB_EXPORT_API tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file); void loadYoloInfo(const std::string &cfg_file,int lineNo,std::vector &mask,std::vector &anchors,int &num,int &classes,float &nms_thresh,int &nms_kind,int &coords); void loadYoloInitInfo(int &channels,int &width,int &height,const std::string &cfg_file); std::vector noYolosLine(const std::string &cfg_file); diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index daa27e5..667a951 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -43,8 +43,8 @@ enum layerType_t { class Layer { public: - Layer(Network *net); - virtual ~Layer(); + TKDNN_LIB_EXPORT_API Layer(Network *net); + TKDNN_LIB_EXPORT_API virtual ~Layer(); virtual layerType_t getLayerType() = 0; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData) { @@ -208,8 +208,8 @@ public: class Dense : public LayerWgs { public: - Dense(Network *net, int out_ch, std::string fname_weights); - virtual ~Dense(); + TKDNN_LIB_EXPORT_API Dense(Network *net, int out_ch, std::string fname_weights); + TKDNN_LIB_EXPORT_API virtual ~Dense(); virtual layerType_t getLayerType() { return LAYER_DENSE; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -236,8 +236,8 @@ public: float ceiling; float slope; - Activation(Network *net, int act_mode, const float ceiling=0.0, const float slope=0.1); - virtual ~Activation(); + TKDNN_LIB_EXPORT_API Activation(Network *net, int act_mode, const float ceiling=0.0, const float slope=0.1); + TKDNN_LIB_EXPORT_API virtual ~Activation(); virtual layerType_t getLayerType() { if(act_mode == CUDNN_ACTIVATION_CLIPPED_RELU) return LAYER_ACTIVATION_CRELU; @@ -272,10 +272,10 @@ protected: class Conv2d : public LayerWgs { public: - Conv2d( Network *net, int out_ch, int kernelH, int kernelW, + TKDNN_LIB_EXPORT_API Conv2d( Network *net, int out_ch, int kernelH, int kernelW, int strideH, int strideW, int paddingH, int paddingW, std::string fname_weights, bool batchnorm = false, bool deConv = false, int groups = 1, bool additional_bias=false); - virtual ~Conv2d(); + TKDNN_LIB_EXPORT_API virtual ~Conv2d(); virtual layerType_t getLayerType() { return LAYER_CONV2D; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -325,8 +325,8 @@ protected: class LSTM : public Layer { public: - LSTM(Network *net, int hiddensize, bool returnSeq, std::string fname_weights); - virtual ~LSTM(); + TKDNN_LIB_EXPORT_API LSTM(Network *net, int hiddensize, bool returnSeq, std::string fname_weights); + TKDNN_LIB_EXPORT_API virtual ~LSTM(); virtual layerType_t getLayerType() { return LAYER_LSTM; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -376,7 +376,7 @@ public: virtual ~DeConv2d() {} virtual layerType_t getLayerType() { return LAYER_DECONV2D; }; - virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); + TKDNN_LIB_EXPORT_API virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); }; @@ -386,10 +386,10 @@ public: class DeformConv2d : public LayerWgs { public: - DeformConv2d( Network *net, int out_ch, int deformable_group, int kernelH, int kernelW, + TKDNN_LIB_EXPORT_API DeformConv2d( Network *net, int out_ch, int deformable_group, int kernelH, int kernelW, int strideH, int strideW, int paddingH, int paddingW, std::string d_fname_weights, std::string fname_weights, bool batchnorm); - virtual ~DeformConv2d(); + TKDNN_LIB_EXPORT_API virtual ~DeformConv2d(); virtual layerType_t getLayerType() { return LAYER_DEFORMCONV2D; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -420,8 +420,8 @@ protected: class Flatten : public Layer { public: - Flatten(Network *net); - virtual ~Flatten(); + TKDNN_LIB_EXPORT_API Flatten(Network *net); + TKDNN_LIB_EXPORT_API virtual ~Flatten(); virtual layerType_t getLayerType() { return LAYER_FLATTEN; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -435,8 +435,8 @@ public: class Reshape : public Layer { public: - Reshape(Network *net, dataDim_t new_dim); - virtual ~Reshape(); + TKDNN_LIB_EXPORT_API Reshape(Network *net, dataDim_t new_dim); + TKDNN_LIB_EXPORT_API virtual ~Reshape(); virtual layerType_t getLayerType() { return LAYER_RESHAPE; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -453,7 +453,7 @@ enum ResizeMode_t { NEAREST= 0, class Resize : public Layer { public: - Resize(Network *net, int scale_c, int scale_h, int scale_w, bool fixed=false, ResizeMode_t mode=NEAREST); + TKDNN_LIB_EXPORT_API Resize(Network *net, int scale_c, int scale_h, int scale_w, bool fixed=false, ResizeMode_t mode=NEAREST); virtual ~Resize(); virtual layerType_t getLayerType() { return LAYER_RESIZE; }; @@ -469,7 +469,7 @@ public: class MulAdd : public Layer { public: - MulAdd(Network *net, dnnType mul, dnnType add); + TKDNN_LIB_EXPORT_API MulAdd(Network *net, dnnType mul, dnnType add); virtual ~MulAdd(); virtual layerType_t getLayerType() { return LAYER_MULADD; }; @@ -505,11 +505,11 @@ public: bool size; tkdnnPoolingMode_t pool_mode; - Pooling(Network *net, int winH, int winW, + TKDNN_LIB_EXPORT_API Pooling(Network *net, int winH, int winW, int strideH, int strideW, int paddingH, int paddingW, tkdnnPoolingMode_t pool_mode); - virtual ~Pooling(); + TKDNN_LIB_EXPORT_API virtual ~Pooling(); virtual layerType_t getLayerType() { return LAYER_POOLING; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -534,7 +534,7 @@ typedef enum { class Padding : public Layer { public: - Padding(Network *net,int32_t pad_h,int32_t pad_w,tkdnnPaddingMode_t padding_mode,float constant = 0.0); + TKDNN_LIB_EXPORT_API Padding(Network *net,int32_t pad_h,int32_t pad_w,tkdnnPaddingMode_t padding_mode,float constant = 0.0); virtual ~Padding(); virtual layerType_t getLayerType(){return LAYER_PADDING ;}; virtual dnnType* infer(dataDim_t& dim,dnnType* srcData); @@ -553,8 +553,8 @@ public: class Softmax : public Layer { public: - Softmax(Network *net, const tk::dnn::dataDim_t* dim=nullptr, const cudnnSoftmaxMode_t mode=CUDNN_SOFTMAX_MODE_CHANNEL); - virtual ~Softmax(); + TKDNN_LIB_EXPORT_API Softmax(Network *net, const tk::dnn::dataDim_t* dim=nullptr, const cudnnSoftmaxMode_t mode=CUDNN_SOFTMAX_MODE_CHANNEL); + TKDNN_LIB_EXPORT_API virtual ~Softmax(); virtual layerType_t getLayerType() { return LAYER_SOFTMAX; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -569,8 +569,8 @@ public: class Route : public Layer { public: - Route(Network *net, Layer **layers, int layers_n, int groups = 1, int group_id = 0); - virtual ~Route(); + TKDNN_LIB_EXPORT_API Route(Network *net, Layer **layers, int layers_n, int groups = 1, int group_id = 0); + TKDNN_LIB_EXPORT_API virtual ~Route(); virtual layerType_t getLayerType() { return LAYER_ROUTE; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -607,8 +607,8 @@ public: class Shortcut : public Layer { public: - Shortcut(Network *net, Layer *backLayer, bool mul=false); - virtual ~Shortcut(); + TKDNN_LIB_EXPORT_API Shortcut(Network *net, Layer *backLayer, bool mul=false); + TKDNN_LIB_EXPORT_API virtual ~Shortcut(); virtual layerType_t getLayerType() { return LAYER_SHORTCUT; }; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); @@ -627,7 +627,7 @@ public: class Upsample : public Layer { public: - Upsample(Network *net, int stride); + TKDNN_LIB_EXPORT_API Upsample(Network *net, int stride); virtual ~Upsample(); virtual layerType_t getLayerType() { return LAYER_UPSAMPLE; }; diff --git a/include/tkDNN/MobilenetDetection.h b/include/tkDNN/MobilenetDetection.h index 58512d5..40a6ec6 100644 --- a/include/tkDNN/MobilenetDetection.h +++ b/include/tkDNN/MobilenetDetection.h @@ -65,9 +65,9 @@ public: MobilenetDetection() {}; ~MobilenetDetection() {}; - bool init(const std::string& tensor_path,const int n_classes, const int n_batches=1, const float conf_thresh=0.3); - void preprocess(cv::Mat &frame, const int bi=0); - void postprocess(const int bi=0,const bool mAP=false); + TKDNN_LIB_EXPORT_API bool init(const std::string& tensor_path,const int n_classes, const int n_batches=1, const float conf_thresh=0.3); + TKDNN_LIB_EXPORT_API void preprocess(cv::Mat &frame, const int bi=0); + TKDNN_LIB_EXPORT_API void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/Network.h b/include/tkDNN/Network.h index 6edf248..a78036d 100644 --- a/include/tkDNN/Network.h +++ b/include/tkDNN/Network.h @@ -38,18 +38,18 @@ const int MAX_LAYERS = 512; class Network { public: - Network(dataDim_t input_dim); - virtual ~Network(); - void releaseLayers(); + TKDNN_LIB_EXPORT_API Network(dataDim_t input_dim); + TKDNN_LIB_EXPORT_API virtual ~Network(); + TKDNN_LIB_EXPORT_API void releaseLayers(); /** Do inference for every added layer */ - dnnType* infer(dataDim_t &dim, dnnType* data); + TKDNN_LIB_EXPORT_API dnnType* infer(dataDim_t &dim, dnnType* data); bool addLayer(Layer *l); - void print(); - const char *getNetworkRTName(const char *network_name); + TKDNN_LIB_EXPORT_API void print(); + TKDNN_LIB_EXPORT_API const char *getNetworkRTName(const char *network_name); void adjustFeatureMapSizeWithShortcuts(); cudnnDataType_t dataType; @@ -61,7 +61,7 @@ public: int num_layers; //current number of layers dataDim_t input_dim; - dataDim_t getOutputDim(); + TKDNN_LIB_EXPORT_API dataDim_t getOutputDim(); bool fp16, dla, int8; int maxBatchSize; diff --git a/include/tkDNN/NetworkRT.h b/include/tkDNN/NetworkRT.h index a422134..5a2e67a 100644 --- a/include/tkDNN/NetworkRT.h +++ b/include/tkDNN/NetworkRT.h @@ -55,8 +55,8 @@ public: std::vector yolo_plugins; // yolo layers in network - NetworkRT(Network *net, const char *name); - virtual ~NetworkRT(); + TKDNN_LIB_EXPORT_API NetworkRT(Network *net, const char *name); + TKDNN_LIB_EXPORT_API virtual ~NetworkRT(); int getMaxBatchSize() { if(engineRT != nullptr) @@ -75,7 +75,7 @@ public: /** Do inference */ - dnnType* infer(dataDim_t &dim, dnnType* data); + TKDNN_LIB_EXPORT_API dnnType* infer(dataDim_t &dim, dnnType* data); void enqueue(int batchSize = 1); nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Layer *l); @@ -104,7 +104,7 @@ public: #endif bool deserialize(const char *filename); - void destroy(); + TKDNN_LIB_EXPORT_API void destroy(); diff --git a/include/tkDNN/NetworkViz.h b/include/tkDNN/NetworkViz.h index ffdf361..0a85b11 100644 --- a/include/tkDNN/NetworkViz.h +++ b/include/tkDNN/NetworkViz.h @@ -6,7 +6,7 @@ namespace tk { namespace dnn { cv::Mat vizFloat2colorMap(cv::Mat map, double min=0, double max=0, int classes=19); -cv::Mat vizData2Mat(dnnType *dataInput, tk::dnn::dataDim_t dim, int img_h, int img_w, double min=0, double max=0, int classes=0); -cv::Mat vizLayer2Mat(tk::dnn::Network *net, int layer, int imgdim = 1000); +TKDNN_LIB_EXPORT_API cv::Mat vizData2Mat(dnnType *dataInput, tk::dnn::dataDim_t dim, int img_h, int img_w, double min=0, double max=0, int classes=0); +TKDNN_LIB_EXPORT_API cv::Mat vizLayer2Mat(tk::dnn::Network *net, int layer, int imgdim = 1000); }} diff --git a/include/tkDNN/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index b49915a..47f9c1d 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -24,9 +24,9 @@ public: Yolo3Detection() {}; ~Yolo3Detection() {}; - bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3); - void preprocess(cv::Mat &frame, const int bi=0); - void postprocess(const int bi=0,const bool mAP=false); + TKDNN_LIB_EXPORT_API bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3); + TKDNN_LIB_EXPORT_API void preprocess(cv::Mat &frame, const int bi=0); + TKDNN_LIB_EXPORT_API void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/demo_utils.h b/include/tkDNN/demo_utils.h index c39e704..6794c95 100644 --- a/include/tkDNN/demo_utils.h +++ b/include/tkDNN/demo_utils.h @@ -6,6 +6,7 @@ #include #include #include +#include "utils.h" #ifdef __linux__ #include @@ -18,6 +19,6 @@ #include -void readCalibrationMatrix(const std::string& path, cv::Mat& calib_mat); +TKDNN_LIB_EXPORT_API void readCalibrationMatrix(const std::string& path, cv::Mat& calib_mat); #endif //DEMO_UTILS_H \ No newline at end of file diff --git a/include/tkDNN/evaluation.h b/include/tkDNN/evaluation.h index 4b4cea7..dca4b7d 100644 --- a/include/tkDNN/evaluation.h +++ b/include/tkDNN/evaluation.h @@ -33,7 +33,7 @@ struct PR void print(); }; -void readmAPParams( const char* config_filename, int& classes, int& map_points, +TKDNN_LIB_EXPORT_API void readmAPParams( const char* config_filename, int& classes, int& map_points, int& map_levels, float& map_step, float& IoU_thresh, float& conf_thresh, bool& verbose); @@ -85,7 +85,7 @@ double computeMap( std::vector &images,const int classes, * @return mAP IoU_tresh:IoU_tresh+map_step*map_levels (e.g. mAP 0.5:0.95 when * map_step=0.05 and map_levels=10) */ -double computeMapNIoULevels(std::vector &images,const int classes, +TKDNN_LIB_EXPORT_API double computeMapNIoULevels(std::vector &images,const int classes, const float i_IoU_thresh=0.5, const float conf_thresh=0.3, const int map_points=101, const float map_step=0.05, const int map_levels=10, const bool verbose=false, @@ -105,7 +105,7 @@ double computeMapNIoULevels(std::vector &images,const int classes, * are written on file * @param net name of the considered neural network */ -void computeTPFPFN( std::vector &images,const int classes, +TKDNN_LIB_EXPORT_API void computeTPFPFN( std::vector &images,const int classes, const float IoU_thresh=0.5, const float conf_thresh=0.3, bool verbose=false, const bool write_on_file=false, std::string net=""); diff --git a/include/tkDNN/kernels.h b/include/tkDNN/kernels.h index 4d5474b..998eeb9 100644 --- a/include/tkDNN/kernels.h +++ b/include/tkDNN/kernels.h @@ -3,37 +3,37 @@ #include "utils.h" -void activationELUForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0)); -void activationLEAKYForward(dnnType *srcData, dnnType *dstData, int size, float slope, cudaStream_t stream = cudaStream_t(0)); -void activationReLUCeilingForward(dnnType *srcData, dnnType *dstData, int size, const float ceiling, cudaStream_t stream = cudaStream_t(0)); -void activationLOGISTICForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0)); -void activationSIGMOIDForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0)); -void activationMishForward(dnnType* srcData, dnnType* dstData, int size, cudaStream_t stream= cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void activationELUForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void activationLEAKYForward(dnnType *srcData, dnnType *dstData, int size, float slope, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void activationReLUCeilingForward(dnnType *srcData, dnnType *dstData, int size, const float ceiling, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void activationLOGISTICForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void activationSIGMOIDForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void activationMishForward(dnnType* srcData, dnnType* dstData, int size, cudaStream_t stream= cudaStream_t(0)); -void fill(dnnType *data, int size, dnnType val, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void fill(dnnType *data, int size, dnnType val, cudaStream_t stream = cudaStream_t(0)); -void resizeForward(dnnType *srcData, dnnType *dstData, int n, int i_c, int i_h, int i_w, +TKDNN_LIB_EXPORT_API void resizeForward(dnnType *srcData, dnnType *dstData, int n, int i_c, int i_h, int i_w, int o_c, int o_h, int o_w, cudaStream_t stream = cudaStream_t(0)); -void reorgForward(dnnType *srcData, dnnType *dstData, +TKDNN_LIB_EXPORT_API void reorgForward(dnnType *srcData, dnnType *dstData, int n, int c, int h, int w, int stride, cudaStream_t stream = cudaStream_t(0)); -void MaxPoolingForward(dnnType *srcData, dnnType *dstData, int n, int c, int h, int w, int stride_x, int stride_y, int size, int padding, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void MaxPoolingForward(dnnType *srcData, dnnType *dstData, int n, int c, int h, int w, int stride_x, int stride_y, int size, int padding, cudaStream_t stream = cudaStream_t(0)); -void softmaxForward(float *input, int n, int batch, int batch_offset, +TKDNN_LIB_EXPORT_API void softmaxForward(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output, cudaStream_t stream = cudaStream_t(0)); -void shortcutForward(dnnType *srcData, dnnType *dstData, int n1, int c1, int h1, int w1, int s1, +TKDNN_LIB_EXPORT_API void shortcutForward(dnnType *srcData, dnnType *dstData, int n1, int c1, int h1, int w1, int s1, int n2, int c2, int h2, int w2, int s2, bool mul, cudaStream_t stream = cudaStream_t(0)); -void upsampleForward(dnnType *srcData, dnnType *dstData, +TKDNN_LIB_EXPORT_API void upsampleForward(dnnType *srcData, dnnType *dstData, int n, int c, int h, int w, int s, int forward, float scale, cudaStream_t stream = cudaStream_t(0)); -void float2half(float *srcData, __half *dstData, int size, const cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void float2half(float *srcData, __half *dstData, int size, const cudaStream_t stream = cudaStream_t(0)); -void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle, +TKDNN_LIB_EXPORT_API void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle, float *input, float *weight, float *bias, float *ones, float *offset, float *mask, @@ -47,11 +47,11 @@ void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle, const int out_n, const int out_c, const int out_h, const int out_w, const int dst_dim, cudaStream_t stream = cudaStream_t(0)); -void scalAdd(dnnType* dstData, int size, float alpha, float beta, int inc, cudaStream_t stream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void scalAdd(dnnType* dstData, int size, float alpha, float beta, int inc, cudaStream_t stream = cudaStream_t(0)); -void reflection_pad2d_out_forward(int32_t pad_h,int32_t pad_w,float *srcData,float *dstData,int32_t input_h,int32_t input_w,int32_t plane_dim,int32_t n_batch,cudaStream_t cudaStream = cudaStream_t(0)); +TKDNN_LIB_EXPORT_API void reflection_pad2d_out_forward(int32_t pad_h,int32_t pad_w,float *srcData,float *dstData,int32_t input_h,int32_t input_w,int32_t plane_dim,int32_t n_batch,cudaStream_t cudaStream = cudaStream_t(0)); -void constant_pad2d_forward(dnnType *srcData,dnnType *dstData,int32_t input_h,int32_t input_w,int32_t output_h, +TKDNN_LIB_EXPORT_API void constant_pad2d_forward(dnnType *srcData,dnnType *dstData,int32_t input_h,int32_t input_w,int32_t output_h, int32_t output_w,int32_t c,int32_t n,int32_t padT,int32_t padL,dnnType constant,cudaStream_t cudaStream = cudaStream_t(0)); diff --git a/include/tkDNN/kernelsThrust.h b/include/tkDNN/kernelsThrust.h index ab2fd90..74200b9 100644 --- a/include/tkDNN/kernelsThrust.h +++ b/include/tkDNN/kernelsThrust.h @@ -27,20 +27,20 @@ struct threshold : public thrust::binary_function } }; -void sort(dnnType *src_begin, dnnType *src_end, int *idsrc); -void topk(dnnType *src_begin, int *idsrc, int K, float *topk_scores, +TKDNN_LIB_EXPORT_API void sort(dnnType *src_begin, dnnType *src_end, int *idsrc); +TKDNN_LIB_EXPORT_API void topk(dnnType *src_begin, int *idsrc, int K, float *topk_scores, int *topk_inds, float *topk_ys, float *topk_xs); // void sortAndTopKonDevice(dnnType *src_begin, int *idsrc, float *topk_scores, int *topk_inds, float *topk_ys, float *topk_xs, const int size, const int K, const int n_classes); -void normalize(float *bgr, const int ch, const int h, const int w, const float *mean, const float *stddev); -void transformDep(float *src_begin, float *src_end, float *dst_begin, float *dst_end); -void subtractWithThreshold(dnnType *src_begin, dnnType *src_end, dnnType *src2_begin, dnnType *src_out, struct threshold op); -void topKxyclasses(int *ids_begin, int *ids_end, const int K, const int size, const int wh, int *clses, int *xs, int *ys); -void topKxyAddOffset(int * ids_begin, const int K, const int size, int *intxs_begin, int *intys_begin, +TKDNN_LIB_EXPORT_API void normalize(float *bgr, const int ch, const int h, const int w, const float *mean, const float *stddev); +TKDNN_LIB_EXPORT_API void transformDep(float *src_begin, float *src_end, float *dst_begin, float *dst_end); +TKDNN_LIB_EXPORT_API void subtractWithThreshold(dnnType *src_begin, dnnType *src_end, dnnType *src2_begin, dnnType *src_out, struct threshold op); +TKDNN_LIB_EXPORT_API void topKxyclasses(int *ids_begin, int *ids_end, const int K, const int size, const int wh, int *clses, int *xs, int *ys); +TKDNN_LIB_EXPORT_API void topKxyAddOffset(int * ids_begin, const int K, const int size, int *intxs_begin, int *intys_begin, float *xs_begin, float *ys_begin, dnnType *src_begin, float *src_out, int *ids_out); -void bboxes(int * ids_begin, const int K, const int size, float *xs_begin, float *ys_begin, +TKDNN_LIB_EXPORT_API void bboxes(int * ids_begin, const int K, const int size, float *xs_begin, float *ys_begin, dnnType *src_begin, float *bbx0, float *bbx1, float *bby0, float *bby1, float *src_out, int *ids_out); -void getRecordsFromTopKId(int * ids_begin, const int K, const int ch, const int size, dnnType *src_begin, float *src_out, int *ids_out); +TKDNN_LIB_EXPORT_API void getRecordsFromTopKId(int * ids_begin, const int K, const int ch, const int size, dnnType *src_begin, float *src_out, int *ids_out); -void maxElem(dnnType *src_begin, dnnType *dst_begin, const int c, const int h, const int w); +TKDNN_LIB_EXPORT_API void maxElem(dnnType *src_begin, dnnType *dst_begin, const int c, const int h, const int w); #endif //KERNELSTHRUST_H \ No newline at end of file diff --git a/include/tkDNN/pluginsRT/ActivationLeakyRT.h b/include/tkDNN/pluginsRT/ActivationLeakyRT.h index 1d98a59..d5589ae 100644 --- a/include/tkDNN/pluginsRT/ActivationLeakyRT.h +++ b/include/tkDNN/pluginsRT/ActivationLeakyRT.h @@ -61,7 +61,7 @@ namespace nvinfer1 { class ActivationLeakyRTPluginCreator : public IPluginCreator { public: - ActivationLeakyRTPluginCreator(); + TKDNN_LIB_EXPORT_API ActivationLeakyRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override; diff --git a/include/tkDNN/pluginsRT/ActivationLogisticRT.h b/include/tkDNN/pluginsRT/ActivationLogisticRT.h index d972752..da2f853 100644 --- a/include/tkDNN/pluginsRT/ActivationLogisticRT.h +++ b/include/tkDNN/pluginsRT/ActivationLogisticRT.h @@ -62,7 +62,7 @@ namespace nvinfer1 { class ActivationLogisticRTPluginCreator : public IPluginCreator { public: - ActivationLogisticRTPluginCreator() ; + TKDNN_LIB_EXPORT_API ActivationLogisticRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ActivationMishRT.h b/include/tkDNN/pluginsRT/ActivationMishRT.h index 5b966cd..14f10fa 100644 --- a/include/tkDNN/pluginsRT/ActivationMishRT.h +++ b/include/tkDNN/pluginsRT/ActivationMishRT.h @@ -57,7 +57,7 @@ namespace nvinfer1 { class ActivationMishRTPluginCreator : public IPluginCreator { public: - ActivationMishRTPluginCreator() ; + TKDNN_LIB_EXPORT_API ActivationMishRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; const char *getPluginNamespace() const NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h b/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h index 1830945..a71944f 100644 --- a/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h +++ b/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h @@ -56,7 +56,7 @@ namespace nvinfer1 { class ActivationReLUCeilingPluginCreator : public IPluginCreator { public: - ActivationReLUCeilingPluginCreator() ; + TKDNN_LIB_EXPORT_API ActivationReLUCeilingPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ConstantPaddingRT.h b/include/tkDNN/pluginsRT/ConstantPaddingRT.h index 15f4c0d..3926141 100644 --- a/include/tkDNN/pluginsRT/ConstantPaddingRT.h +++ b/include/tkDNN/pluginsRT/ConstantPaddingRT.h @@ -79,7 +79,7 @@ namespace nvinfer1{ class ConstantPaddingRTPluginCreator : public IPluginCreator { public: - ConstantPaddingRTPluginCreator(); + TKDNN_LIB_EXPORT_API ConstantPaddingRTPluginCreator(); void setPluginNamespace(const char* pluginNamespace) NOEXCEPT override; diff --git a/include/tkDNN/pluginsRT/DeformableConvRT.h b/include/tkDNN/pluginsRT/DeformableConvRT.h index 9170e15..2949af2 100644 --- a/include/tkDNN/pluginsRT/DeformableConvRT.h +++ b/include/tkDNN/pluginsRT/DeformableConvRT.h @@ -112,7 +112,7 @@ namespace nvinfer1 { class DeformableConvRTPluginCreator : public IPluginCreator { public: - DeformableConvRTPluginCreator(); + TKDNN_LIB_EXPORT_API DeformableConvRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/FlattenConcatRT.h b/include/tkDNN/pluginsRT/FlattenConcatRT.h index f7ec495..ecb8215 100644 --- a/include/tkDNN/pluginsRT/FlattenConcatRT.h +++ b/include/tkDNN/pluginsRT/FlattenConcatRT.h @@ -73,7 +73,7 @@ namespace nvinfer1 { class FlattenConcatRTPluginCreator : public IPluginCreator { public: - FlattenConcatRTPluginCreator() ; + TKDNN_LIB_EXPORT_API FlattenConcatRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h b/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h index 95e15f4..0c88f77 100644 --- a/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h +++ b/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h @@ -78,7 +78,7 @@ namespace nvinfer1 { class MaxPoolFixedSizeRTPluginCreator : public IPluginCreator { public: - MaxPoolFixedSizeRTPluginCreator() ; + TKDNN_LIB_EXPORT_API MaxPoolFixedSizeRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ReflectionPadding.h b/include/tkDNN/pluginsRT/ReflectionPadding.h index 7b13710..0ff0e0c 100644 --- a/include/tkDNN/pluginsRT/ReflectionPadding.h +++ b/include/tkDNN/pluginsRT/ReflectionPadding.h @@ -73,7 +73,7 @@ namespace nvinfer1{ class ReflectionPaddingRTPluginCreator : public IPluginCreator { public: - ReflectionPaddingRTPluginCreator(); + TKDNN_LIB_EXPORT_API ReflectionPaddingRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/RegionRT.h b/include/tkDNN/pluginsRT/RegionRT.h index 7f7157c..4b7e68a 100644 --- a/include/tkDNN/pluginsRT/RegionRT.h +++ b/include/tkDNN/pluginsRT/RegionRT.h @@ -82,7 +82,7 @@ namespace nvinfer1 { class RegionRTPluginCreator : public IPluginCreator { public: - RegionRTPluginCreator(); + TKDNN_LIB_EXPORT_API RegionRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ReorgRT.h b/include/tkDNN/pluginsRT/ReorgRT.h index be163a5..df52922 100644 --- a/include/tkDNN/pluginsRT/ReorgRT.h +++ b/include/tkDNN/pluginsRT/ReorgRT.h @@ -71,7 +71,7 @@ namespace nvinfer1 { class ReorgRTPluginCreator : public IPluginCreator { public: - ReorgRTPluginCreator(); + TKDNN_LIB_EXPORT_API ReorgRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override; diff --git a/include/tkDNN/pluginsRT/ReshapeRT.h b/include/tkDNN/pluginsRT/ReshapeRT.h index 65d577d..b473567 100644 --- a/include/tkDNN/pluginsRT/ReshapeRT.h +++ b/include/tkDNN/pluginsRT/ReshapeRT.h @@ -74,7 +74,7 @@ namespace nvinfer1 { class ReshapeRTPluginCreator : public IPluginCreator { public: - ReshapeRTPluginCreator() ; + TKDNN_LIB_EXPORT_API ReshapeRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ResizeLayerRT.h b/include/tkDNN/pluginsRT/ResizeLayerRT.h index 750057e..1cdccef 100644 --- a/include/tkDNN/pluginsRT/ResizeLayerRT.h +++ b/include/tkDNN/pluginsRT/ResizeLayerRT.h @@ -73,7 +73,7 @@ namespace nvinfer1 { class ResizeLayerRTPluginCreator : public IPluginCreator { public: - ResizeLayerRTPluginCreator() ; + TKDNN_LIB_EXPORT_API ResizeLayerRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/RouteRT.h b/include/tkDNN/pluginsRT/RouteRT.h index 499b9da..e15390d 100644 --- a/include/tkDNN/pluginsRT/RouteRT.h +++ b/include/tkDNN/pluginsRT/RouteRT.h @@ -11,7 +11,7 @@ namespace nvinfer1 { */ public: - RouteRT(int groups, int group_id) ; + TKDNN_LIB_EXPORT_API RouteRT(int groups, int group_id) ; ~RouteRT() ; @@ -64,7 +64,7 @@ namespace nvinfer1 { class RouteRTPluginCreator : public IPluginCreator { public: - RouteRTPluginCreator() ; + TKDNN_LIB_EXPORT_API RouteRTPluginCreator() ; void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override ; diff --git a/include/tkDNN/pluginsRT/ShortcutRT.h b/include/tkDNN/pluginsRT/ShortcutRT.h index 0c01b9d..2f1242d 100644 --- a/include/tkDNN/pluginsRT/ShortcutRT.h +++ b/include/tkDNN/pluginsRT/ShortcutRT.h @@ -80,7 +80,7 @@ namespace nvinfer1 { class ShortcutRTPluginCreator : public IPluginCreator { public: - ShortcutRTPluginCreator(); + TKDNN_LIB_EXPORT_API ShortcutRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override; diff --git a/include/tkDNN/pluginsRT/UpsampleRT.h b/include/tkDNN/pluginsRT/UpsampleRT.h index 4379ee7..3fca1d0 100644 --- a/include/tkDNN/pluginsRT/UpsampleRT.h +++ b/include/tkDNN/pluginsRT/UpsampleRT.h @@ -75,7 +75,7 @@ namespace nvinfer1 { class UpsampleRTPluginCreator : public IPluginCreator { public: - UpsampleRTPluginCreator(); + TKDNN_LIB_EXPORT_API UpsampleRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override; diff --git a/include/tkDNN/pluginsRT/YoloRT.h b/include/tkDNN/pluginsRT/YoloRT.h index f0e5733..f2cf826 100644 --- a/include/tkDNN/pluginsRT/YoloRT.h +++ b/include/tkDNN/pluginsRT/YoloRT.h @@ -98,7 +98,7 @@ namespace nvinfer1 { class YoloRTPluginCreator : public IPluginCreator { public: - YoloRTPluginCreator(); + TKDNN_LIB_EXPORT_API YoloRTPluginCreator(); void setPluginNamespace(const char *pluginNamespace) NOEXCEPT override; diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index 607697a..58a0bc6 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -35,6 +35,15 @@ #endif #endif +#ifdef _WIN32 +#define TKDNN_LIB_EXPORT_API __declspec(dllexport) +#define TKDNN_LIB_IMPORT_API __declspec(dllimport) +#elif __linux__ +#define TKDNN_LIB_EXPORT_API __attribute__((visibility("default"))) +#define TKDNN_LIB_IMPORT_API +#endif + + #define dnnType float @@ -143,23 +152,23 @@ typedef enum { ERROR_CUDNNvsTENSORRT = 8 } resultError_t; -void printCenteredTitle(const char *title, char fill, int dim = 30); -bool fileExist(const char *fname); -void downloadWeightsifDoNotExist(const std::string& input_bin, const std::string& test_folder, const std::string& weights_url); -void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0); -int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true, int limit = 10, bool verbose=true); -void printDeviceVector(int size, dnnType* vec_d, bool device = true); +TKDNN_LIB_EXPORT_API void printCenteredTitle(const char *title, char fill, int dim = 30); +TKDNN_LIB_EXPORT_API bool fileExist(const char *fname); +TKDNN_LIB_EXPORT_API void downloadWeightsifDoNotExist(const std::string& input_bin, const std::string& test_folder, const std::string& weights_url); +TKDNN_LIB_EXPORT_API void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0); +TKDNN_LIB_EXPORT_API int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true, int limit = 10, bool verbose=true); +TKDNN_LIB_EXPORT_API void printDeviceVector(int size, dnnType* vec_d, bool device = true); float getColor(const int c, const int x, const int max); void resize(int size, dnnType **data); -void matrixTranspose(cublasHandle_t handle, dnnType* srcData, dnnType* dstData, int rows, int cols); +TKDNN_LIB_EXPORT_API void matrixTranspose(cublasHandle_t handle, dnnType* srcData, dnnType* dstData, int rows, int cols); void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData, dnnType* add_vector, int dim, dnnType mul); -void getMemUsage(double& vm_usage_kb, double& resident_set_kb); +TKDNN_LIB_EXPORT_API void getMemUsage(double& vm_usage_kb, double& resident_set_kb); void printCudaMemUsage(); -void removePathAndExtension(const std::string &full_string, std::string &name); +TKDNN_LIB_EXPORT_API void removePathAndExtension(const std::string &full_string, std::string &name); static inline bool isCudaPointer(void *data) { cudaPointerAttributes attr; return cudaPointerGetAttributes(&attr, data) == 0; diff --git a/src/NetworkRT.cpp b/src/NetworkRT.cpp index 26489bf..2f01626 100644 --- a/src/NetworkRT.cpp +++ b/src/NetworkRT.cpp @@ -15,8 +15,8 @@ using namespace nvinfer1; -extern std::mutex gYoloPlugins_mutex; -extern std::vector gYoloPlugins; +TKDNN_LIB_IMPORT_API extern std::mutex gYoloPlugins_mutex; +TKDNN_LIB_IMPORT_API extern std::vector gYoloPlugins; // Logger for info/warning/errors class Logger : public ILogger { diff --git a/src/pluginsRT/YoloRT.cpp b/src/pluginsRT/YoloRT.cpp index 590acb3..0c36827 100644 --- a/src/pluginsRT/YoloRT.cpp +++ b/src/pluginsRT/YoloRT.cpp @@ -5,8 +5,8 @@ using namespace nvinfer1; // used to retrive Yolo plugin during network deserialization -std::mutex gYoloPlugins_mutex; -std::vector gYoloPlugins; +TKDNN_LIB_EXPORT_API std::mutex gYoloPlugins_mutex; +TKDNN_LIB_EXPORT_API std::vector gYoloPlugins; std::vector YoloRTPluginCreator::mPluginAttributes; PluginFieldCollection YoloRTPluginCreator::mFC{};