Files
gpt-2-inference-engine/kernels/residual.cuh
T
2026-06-07 13:43:20 -05:00

25 lines
622 B
Plaintext

#ifndef RESIDUAL_KERNEL_CUH_
#define RESIDUAL_KERNEL_CUH_
#include <cuda_runtime.h>
#include "../utils/cuda_utils.cuh"
__global__ void residual_forward_kernel(float* out, float* inp1, float* inp2, int N) {
// Implement this
int x = blockDim.x * blockIdx.x + threadIdx.x;
if(x < N){
out[x] = inp1[x] + inp2[x];
}
}
// Launch kernel here
void residual_forward(float* out, float* inp1, float* inp2, int N) {
// Implement this
dim3 block(32,1,1);
dim3 grid((N + block.x - 1)/ block.x);
residual_forward_kernel<<<grid, block>>>(out, inp1, inp2, N);
}
#endif // RESIDUAL_KERNEL_CUH_