Leaky ReLU
92 字
1 分钟
Leaky ReLU
题面

和 ReLU 大同小异。
答案
#include <cuda_runtime.h>
__global__ void leaky_relu_kernel(const float* input, float* output, int N) { int idx = blockDim.x * blockIdx.x + threadIdx.x; if (idx < N) { output[idx] = input[idx] > 0 ? input[idx] : 0.01 * input[idx]; }}
// input, output are device pointers (i.e. pointers to memory on the GPU)extern "C" void solve(const float* input, float* output, int N) { int threadsPerBlock = 256; int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
leaky_relu_kernel<<<blocksPerGrid, threadsPerBlock>>>(input, output, N); cudaDeviceSynchronize();}


