yolo layers
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include "kernels.h"
|
||||
|
||||
__global__ void reorg_kernel(int N, float *x, int w, int h, int c, int batch, int stride, int forward, float *out)
|
||||
{
|
||||
int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
|
||||
if(i >= N) return;
|
||||
int in_index = i;
|
||||
int in_w = i%w;
|
||||
i = i/w;
|
||||
int in_h = i%h;
|
||||
i = i/h;
|
||||
int in_c = i%c;
|
||||
i = i/c;
|
||||
int b = i%batch;
|
||||
|
||||
int out_c = c/(stride*stride);
|
||||
|
||||
int c2 = in_c % out_c;
|
||||
int offset = in_c / out_c;
|
||||
int w2 = in_w*stride + offset % stride;
|
||||
int h2 = in_h*stride + offset / stride;
|
||||
//printf("%d\n", offset);
|
||||
int out_index = w2 + w*stride*(h2 + h*stride*(c2 + out_c*b));
|
||||
|
||||
// printf("%d %d %d\n", w2, h2, c2);
|
||||
//printf("%d %d\n", in_index, out_index);
|
||||
//if(out_index >= N || out_index < 0) printf("bad bad bad \n");
|
||||
|
||||
if(forward) out[out_index] = x[in_index];
|
||||
else out[in_index] = x[out_index];
|
||||
//if(forward) out[1] = x[1];
|
||||
//else out[0] = x[0];
|
||||
}
|
||||
|
||||
/**
|
||||
reorg function function
|
||||
*/
|
||||
void reorgForward(value_type* srcData, value_type* dstData, tkDNN::dataDim_t dim, int stride)
|
||||
{
|
||||
int size = dim.tot();
|
||||
|
||||
int blocks = (size+255)/256;
|
||||
int threads = 256;
|
||||
|
||||
reorg_kernel<<<blocks, threads>>>(size, srcData, dim.w, dim.h, dim.c, dim.n, stride, false, dstData);
|
||||
checkCuda( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user