Small MISH optimization

- Small MISH optimization from darknet repo.
This commit is contained in:
Harijs Grinbergs
2021-11-01 22:29:32 +02:00
parent 646c5aa4d1
commit d411af52fa
+11 -1
View File
@@ -35,6 +35,16 @@ float mish_yashas(float x) {
return x - 2 * __fdividef(x, n + 2);
}
__device__ float mish_yashas2(float x)
{
float e = __expf(x);
float n = e * e + 2 * e;
if (x <= -0.6f)
return x * __fdividef(n, n + 2);
return x - 2 * __fdividef(x, n + 2);
}
// https://github.com/digantamisra98/Mish
// https://github.com/AlexeyAB/darknet/blob/master/src/activation_kernels.cu
__global__
@@ -42,7 +52,7 @@ 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));
output[i] = mish_yashas(input[i]);
output[i] = mish_yashas2(input[i]);
}
/**