MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / residual_forward

Function residual_forward

experimental/kernels/ops.cpp:342–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342void 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
358void residual_backward(Context& ctx, float* dinp1, float* dinp2, float* dout, int N){
359 unsigned long n = static_cast<unsigned long>(N);

Callers 1

gpt2_forwardFunction · 0.85

Calls 7

setLogLevelFunction · 0.85
createTensorFunction · 0.85
createKernelFunction · 0.85
cdivFunction · 0.85
dispatchKernelFunction · 0.85
waitFunction · 0.85
toCPUFunction · 0.85

Tested by

no test coverage detected