| 309 | } |
| 310 | |
| 311 | void gelu_forward(Context& ctx, float* out, float* inp, int n) { |
| 312 | unsigned long N = static_cast<unsigned long>(n); |
| 313 | setLogLevel(kError); |
| 314 | Tensor input = createTensor(ctx, Shape{N}, kf32, inp); |
| 315 | Tensor output = createTensor(ctx, Shape{N}, kf32); |
| 316 | std::promise<void> promise; |
| 317 | std::future<void> future = promise.get_future(); |
| 318 | Kernel op = createKernel(ctx, {kShaderGelu, 256, kf32}, |
| 319 | Bindings{input, output}, |
| 320 | /* nWorkgroups */ {cdiv(N, 256), 1, 1}); |
| 321 | dispatchKernel(ctx, op, promise); |
| 322 | wait(ctx, future); |
| 323 | toCPU(ctx, output, out, N * sizeof(float)); |
| 324 | } |
| 325 | |
| 326 | void gelu_backward(Context& ctx, float* dinp, float* inp, float* dout, int N){ |
| 327 | unsigned long n = static_cast<unsigned long>(N); |
no test coverage detected