Support yolov4

Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
Micaela Verucchi
2020-04-28 20:35:30 +02:00
parent a874fad2bd
commit db0f8a4d99
15 changed files with 1979 additions and 9 deletions
+31
View File
@@ -0,0 +1,31 @@
#include "kernels.h"
#include <math.h>
#define MISH_THRESHOLD 20
__device__ float tanh_activate_kernel(float x){return (2/(1 + expf(-2*x)) - 1);}
__device__ float softplus_kernel(float x, float threshold = 20) {
if (x > threshold) return x; // too large
else if (x < -threshold) return expf(x); // too small
return logf(expf(x) + 1);
}
// https://github.com/digantamisra98/Mish
// https://github.com/AlexeyAB/darknet/blob/master/src/activation_kernels.cu
__global__
void activation_mish(dnnType *input, dnnType *output, int size) {
int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
if (i < size)
output[i] = input[i] * tanh_activate_kernel( softplus_kernel(input[i], MISH_THRESHOLD));
}
/**
Mish activation function
*/
void activationMishForward(dnnType* srcData, dnnType* dstData, int size, cudaStream_t stream)
{
int blocks = (size+255)/256;
int threads = 256;
activation_mish<<<blocks, threads, 0, stream>>>(srcData, dstData, size);
}
+16
View File
@@ -0,0 +1,16 @@
#include "kernels.h"
#include <math.h>
__global__ void scal_add_kernel(dnnType* dstData, int size, float alpha, float beta, int inc)
{
int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
if (i < size) dstData[i*inc] = dstData[i*inc] * alpha + beta;
}
void scalAdd(dnnType* dstData, int size, float alpha, float beta, int inc, cudaStream_t stream)
{
int blocks = (size+255)/256;
int threads = 256;
scal_add_kernel<<<blocks, threads, 0, stream>>>(dstData, size, alpha, beta, inc);
}