25 lines
673 B
Plaintext
25 lines
673 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* __restrict__ out, const float* __restrict__ inp1, const float* __restrict__ 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_ |