Merge branch 'cnet' of https://github.com/ceccocats/tkDNN into cnet
This commit is contained in:
@@ -229,6 +229,9 @@ public:
|
|||||||
dnnType *offset, *mask;
|
dnnType *offset, *mask;
|
||||||
dnnType *output_conv;
|
dnnType *output_conv;
|
||||||
|
|
||||||
|
cublasStatus_t stat;
|
||||||
|
cublasHandle_t handle;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
cudnnTensorDescriptor_t biasTensorDesc;
|
cudnnTensorDescriptor_t biasTensorDesc;
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ void modulated_deformable_im2col_cuda(cudaStream_t stream,
|
|||||||
const int dilation_h, const int dilation_w,
|
const int dilation_h, const int dilation_w,
|
||||||
const int deformable_group, float *data_col);
|
const int deformable_group, float *data_col);
|
||||||
|
|
||||||
void dcn_v2_cuda_forward(float *input, float *weight,
|
void dcn_v2_cuda_forward(cublasStatus_t stat, cublasHandle_t handle,
|
||||||
|
float *input, float *weight,
|
||||||
float *bias, float *ones,
|
float *bias, float *ones,
|
||||||
float *offset, float *mask,
|
float *offset, float *mask,
|
||||||
float *output, float *columns,
|
float *output, float *columns,
|
||||||
|
|||||||
@@ -52,10 +52,21 @@ public:
|
|||||||
checkCuda( cudaMemcpy(mask, deformable->mask, sizeof(dnnType)*chunk_dim, cudaMemcpyDeviceToDevice) );
|
checkCuda( cudaMemcpy(mask, deformable->mask, sizeof(dnnType)*chunk_dim, cudaMemcpyDeviceToDevice) );
|
||||||
checkCuda( cudaMemcpy(ones_d2, deformable->ones_d2, sizeof(dnnType)*dim_ones, cudaMemcpyDeviceToDevice) );
|
checkCuda( cudaMemcpy(ones_d2, deformable->ones_d2, sizeof(dnnType)*dim_ones, cudaMemcpyDeviceToDevice) );
|
||||||
}
|
}
|
||||||
|
stat = cublasCreate(&handle);
|
||||||
|
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||||
|
printf ("CUBLAS initialization failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~DeformableConvRT(){
|
~DeformableConvRT(){
|
||||||
|
checkCuda( cudaFree(data_d) );
|
||||||
|
checkCuda( cudaFree(bias2_d) );
|
||||||
|
checkCuda( cudaFree(ones_d1) );
|
||||||
|
checkCuda( cudaFree(offset) );
|
||||||
|
checkCuda( cudaFree(mask) );
|
||||||
|
checkCuda( cudaFree(ones_d2) );
|
||||||
|
cublasDestroy(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNbOutputs() const override {
|
int getNbOutputs() const override {
|
||||||
@@ -100,7 +111,8 @@ public:
|
|||||||
activationSIGMOIDForward(mask, mask, chunk_dim);
|
activationSIGMOIDForward(mask, mask, chunk_dim);
|
||||||
|
|
||||||
// deformable convolution
|
// deformable convolution
|
||||||
dcn_v2_cuda_forward(srcData, data_d,
|
dcn_v2_cuda_forward(stat, handle,
|
||||||
|
srcData, data_d,
|
||||||
bias2_d, ones_d1,
|
bias2_d, ones_d1,
|
||||||
offset, mask,
|
offset, mask,
|
||||||
reinterpret_cast<dnnType*>(outputs[0]), ones_d2,
|
reinterpret_cast<dnnType*>(outputs[0]), ones_d2,
|
||||||
@@ -172,6 +184,8 @@ public:
|
|||||||
free(aus);
|
free(aus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cublasStatus_t stat;
|
||||||
|
cublasHandle_t handle;
|
||||||
int i_n, i_c, i_h, i_w;
|
int i_n, i_c, i_h, i_w;
|
||||||
int o_n, o_c, o_h, o_w;
|
int o_n, o_c, o_h, o_w;
|
||||||
int size;
|
int size;
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ namespace tk { namespace dnn {
|
|||||||
|
|
||||||
void DeformConv2d::initCUDNN() {
|
void DeformConv2d::initCUDNN() {
|
||||||
|
|
||||||
|
stat = cublasCreate(&handle);
|
||||||
|
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||||
|
printf ("CUBLAS initialization failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkCUDNN( cudnnCreateTensorDescriptor(&biasTensorDesc) );
|
checkCUDNN( cudnnCreateTensorDescriptor(&biasTensorDesc) );
|
||||||
checkCUDNN( cudnnSetTensor4dDescriptor(biasTensorDesc,
|
checkCUDNN( cudnnSetTensor4dDescriptor(biasTensorDesc,
|
||||||
net->tensorFormat, net->dataType,
|
net->tensorFormat, net->dataType,
|
||||||
@@ -84,6 +89,7 @@ DeformConv2d::~DeformConv2d() {
|
|||||||
checkCuda( cudaFree(offset) );
|
checkCuda( cudaFree(offset) );
|
||||||
checkCuda( cudaFree(mask) );
|
checkCuda( cudaFree(mask) );
|
||||||
checkCuda( cudaFree(output_conv) );
|
checkCuda( cudaFree(output_conv) );
|
||||||
|
cublasDestroy(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
||||||
@@ -97,7 +103,8 @@ dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
|||||||
activationSIGMOIDForward(mask, mask, chunk_dim);
|
activationSIGMOIDForward(mask, mask, chunk_dim);
|
||||||
|
|
||||||
// deformable convolution
|
// deformable convolution
|
||||||
dcn_v2_cuda_forward(srcData, this->data_d,
|
dcn_v2_cuda_forward(stat, handle,
|
||||||
|
srcData, this->data_d,
|
||||||
this->bias2_d, ones_d1,
|
this->bias2_d, ones_d1,
|
||||||
offset, mask,
|
offset, mask,
|
||||||
dstData, ones_d2,
|
dstData, ones_d2,
|
||||||
|
|||||||
+1
-1
@@ -453,7 +453,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) {
|
|||||||
IPluginLayer *lRT = networkRT->addPlugin(inputs, 2, *plugin);
|
IPluginLayer *lRT = networkRT->addPlugin(inputs, 2, *plugin);
|
||||||
checkNULL(lRT);
|
checkNULL(lRT);
|
||||||
lRT->setName( ("Deformable" + std::to_string(l->id)).c_str() );
|
lRT->setName( ("Deformable" + std::to_string(l->id)).c_str() );
|
||||||
|
delete(inputs);
|
||||||
// batchnorm
|
// batchnorm
|
||||||
void *bias_b, *power_b, *mean_b, *variance_b, *scales_b;
|
void *bias_b, *power_b, *mean_b, *variance_b, *scales_b;
|
||||||
if(dtRT == DataType::kHALF) {
|
if(dtRT == DataType::kHALF) {
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ void modulated_deformable_im2col_cuda(cudaStream_t stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void dcn_v2_cuda_forward(float *input, float *weight,
|
void dcn_v2_cuda_forward(cublasStatus_t stat, cublasHandle_t handle,
|
||||||
|
float *input, float *weight,
|
||||||
float *bias, float *ones,
|
float *bias, float *ones,
|
||||||
float *offset, float *mask,
|
float *offset, float *mask,
|
||||||
float *output, float *columns,
|
float *output, float *columns,
|
||||||
@@ -151,14 +152,7 @@ void dcn_v2_cuda_forward(float *input, float *weight,
|
|||||||
const int out_n, const int out_c, const int out_h, const int out_w,
|
const int out_n, const int out_c, const int out_h, const int out_w,
|
||||||
const int chunk_dim, cudaStream_t stream)
|
const int chunk_dim, cudaStream_t stream)
|
||||||
{
|
{
|
||||||
cublasStatus_t stat;
|
// stat and handle have be moved out to preserve 2 - 6 milliseconds every 100.
|
||||||
cublasHandle_t handle;
|
|
||||||
stat = cublasCreate(&handle);
|
|
||||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
|
||||||
printf ("CUBLAS initialization failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int channels = in_c;
|
const int channels = in_c;
|
||||||
const int height = in_h;
|
const int height = in_h;
|
||||||
const int width = in_w;
|
const int width = in_w;
|
||||||
|
|||||||
Reference in New Issue
Block a user