Sigmoid Linear Unit
84 字
1 分钟
Sigmoid Linear Unit
题面

答案
#include <cuda_runtime.h>
__global__ void silu_kernel(const float* input, float* output, int N) { int idx = blockDim.x * blockIdx.x + threadIdx.x; if (idx > N) return; float sigma = 1.0 / (1.0 + exp(-input[idx])); float ans = input[idx] * sigma; output[idx] = ans;}
// input, output are device pointersextern "C" void solve(const float* input, float* output, int N) { int threadsPerBlock = 256; int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
silu_kernel<<<blocksPerGrid, threadsPerBlock>>>(input, output, N); cudaDeviceSynchronize();}Sigmoid Linear Unit
https://dongyanzhang.com/posts/leetgpu/sigmoid-linear-unit/


