| 340 | } |
| 341 | |
| 342 | void residual_forward(Context& ctx, float* out, float* inp1, float* inp2, int N){ |
| 343 | unsigned long n = static_cast<unsigned long>(N); |
| 344 | setLogLevel(kError); |
| 345 | Tensor inp1_i = createTensor(ctx, Shape{n}, kf32, inp1); |
| 346 | Tensor inp2_i = createTensor(ctx, Shape{n}, kf32, inp2); |
| 347 | Tensor out_o = createTensor(ctx, Shape{n}, kf32); |
| 348 | std::promise<void> promise; |
| 349 | std::future<void> future = promise.get_future(); |
| 350 | Kernel op = createKernel(ctx, {kShaderResidual, 256, kf32}, |
| 351 | Bindings{inp1_i, inp2_i, out_o}, |
| 352 | /* nWorkgroups */ {cdiv(n, 256), 1, 1}); |
| 353 | dispatchKernel(ctx, op, promise); |
| 354 | wait(ctx, future); |
| 355 | toCPU(ctx, out_o, out, n * sizeof(float)); |
| 356 | } |
| 357 | |
| 358 | void residual_backward(Context& ctx, float* dinp1, float* dinp2, float* dout, int N){ |
| 359 | unsigned long n = static_cast<unsigned long>(N); |
no test coverage detected