Fix the inference operation of the deformable convolutional layer.
This commit removes the malloc operation in the inference method and adds the sigmoid kernel. Signed-off-by: Davide Sapienza <sapienza.dav@gmail.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "kernels.h"
|
||||
|
||||
__device__
|
||||
__forceinline__
|
||||
double sigmoid (double a)
|
||||
{
|
||||
return 1.0 / (1.0 + exp (-a));
|
||||
}
|
||||
|
||||
|
||||
__global__
|
||||
void activation_sigmoid(dnnType *input, dnnType *output, int size) {
|
||||
|
||||
int stride = gridDim.x * blockDim.x;
|
||||
int tid = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
for (int i = tid; i < size; i += stride) {
|
||||
output[i] = sigmoid (input[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
ELU activation function
|
||||
*/
|
||||
void activationSIGMOIDForward(dnnType* srcData, dnnType* dstData, int size, cudaStream_t stream)
|
||||
{
|
||||
int blocks = (size+255)/256;
|
||||
int threads = 256;
|
||||
|
||||
activation_sigmoid<<<blocks, threads, 0, stream>>>(srcData, dstData, size);
|
||||
}
|
||||
@@ -149,10 +149,8 @@ void dcn_v2_cuda_forward(float *input, float *weight,
|
||||
const int deformable_group,
|
||||
const int in_n, const int in_c, const int in_h, const int in_w,
|
||||
const int out_n, const int out_c, const int out_h, const int out_w,
|
||||
const int dst_dim, cudaStream_t stream)
|
||||
{
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
cudaError_t cudaStat;
|
||||
const int chunk_dim, cudaStream_t stream)
|
||||
{
|
||||
cublasStatus_t stat;
|
||||
cublasHandle_t handle;
|
||||
stat = cublasCreate(&handle);
|
||||
@@ -160,83 +158,50 @@ void dcn_v2_cuda_forward(float *input, float *weight,
|
||||
printf ("CUBLAS initialization failed\n");
|
||||
return;
|
||||
}
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
const int batch = in_n;
|
||||
|
||||
const int channels = in_c;
|
||||
const int height = in_h;
|
||||
const int width = in_w;
|
||||
|
||||
|
||||
const int channels_out = out_c;
|
||||
const int channels_kernel = in_c;
|
||||
const int kernel_h_ = kernel_h;
|
||||
const int kernel_w_ = kernel_w;
|
||||
|
||||
const int height_out = (height + 2 * pad_h - (dilation_h * (kernel_h - 1) + 1)) / stride_h + 1;
|
||||
const int width_out = (width + 2 * pad_w - (dilation_w * (kernel_w - 1) + 1)) / stride_w + 1;
|
||||
|
||||
float *input_n;
|
||||
cudaMalloc(&input_n, (in_n*in_c*in_h*in_w)*sizeof(float));
|
||||
cudaMemcpy(input_n, input, (in_n*in_c*in_h*in_w)*sizeof(float), cudaMemcpyDeviceToDevice);
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
float *offset_n;
|
||||
cudaMalloc(&offset_n, ((dst_dim/3)*2)*sizeof(float));
|
||||
cudaMemcpy(offset_n, offset, ((dst_dim/3)*2)*sizeof(float), cudaMemcpyDeviceToDevice);
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
float *mask_n;
|
||||
cudaMalloc(&mask_n, (dst_dim/3)*sizeof(float));
|
||||
cudaMemcpy(mask_n, mask, (dst_dim/3)*sizeof(float), cudaMemcpyDeviceToDevice);
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
float *output_n;
|
||||
checkCuda(cudaMalloc(&output_n, (channels_out*height_out*width_out)*sizeof(float)));
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
long m_ = channels_out;
|
||||
long n_ = height_out * width_out;
|
||||
long k_ = 1;
|
||||
long m = channels_out;
|
||||
long n = height_out * width_out;
|
||||
long k = 1;
|
||||
float alpha = 1.0;
|
||||
float beta = 0.0;
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
stat = cublasSgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N,
|
||||
n_, m_, k_, &alpha,
|
||||
ones, k_, bias, k_,
|
||||
&beta, output_n, n_);
|
||||
n, m, k, &alpha,
|
||||
ones, k, bias, k,
|
||||
&beta, output, n);
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf ("CUBLAS initialization failed\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
modulated_deformable_im2col_cuda(stream,
|
||||
input_n, offset_n,
|
||||
mask_n,
|
||||
input, offset,
|
||||
mask,
|
||||
1, channels, height, width,
|
||||
height_out, width_out, kernel_h, kernel_w,
|
||||
pad_h, pad_w, stride_h, stride_w, dilation_h, dilation_w,
|
||||
deformable_group, columns);
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
|
||||
//(k * m) x (m * n)
|
||||
// Y = WC
|
||||
long m = channels_out;
|
||||
long n = height_out * width_out;
|
||||
long k = channels * kernel_h * kernel_w;
|
||||
|
||||
alpha = 1.0;
|
||||
k = channels * kernel_h * kernel_w;
|
||||
beta = 1.0;
|
||||
|
||||
stat = cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N,
|
||||
n, m, k, &alpha,
|
||||
columns, n, weight, k,
|
||||
&beta, output_n, n);
|
||||
&beta, output, n);
|
||||
|
||||
cudaMemcpy(output, output_n, (n*m)*sizeof(float), cudaMemcpyDeviceToDevice);
|
||||
checkCuda(cudaDeviceSynchronize());
|
||||
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf ("CUBLAS initialization failed\n");
|
||||
return ;
|
||||
|
||||
Reference in New Issue
Block a user