#ifndef ENCODER_FORWARD_KERNEL_CUH #define ENCODER_FORWARD_KERNEL_CUH #include #include "../utils/cuda_utils.cuh" __global__ void encoder_forward_kernel(float* out, const int* inp, const float* wte, const float* wpe, int B, int T, int C) { // Implement this int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; if(x < B && y < T){ int token = inp[x*T + y]; for(int i = 0; i < C; i ++){ out[x*T*C + y*C + i] = wte[token*C+i] + wpe[y*C+i]; } } } // Launch kernel here void encoder_forward(float* out, const int* inp, const float* wte, const float* wpe, int B, int T, int C) { // Implement this dim3 block(16,16,1); dim3 grid((B + block.x -1)/ block.x,(T+block.y-1)/block.y); encoder_forward_kernel<<>>(out, inp, wte, wpe,B,T,C); } #endif // ENCODER_FORWARD_KERNEL_CUH