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

Function residual_backward

experimental/kernels/ops.cpp:358–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358void residual_backward(Context& ctx, float* dinp1, float* dinp2, float* dout, int N){
359 unsigned long n = static_cast<unsigned long>(N);
360 setLogLevel(kError);
361 Tensor dout_i = createTensor(ctx, Shape{n}, kf32, dout);
362 Tensor dinp1_o = createTensor(ctx, Shape{n}, kf32, dinp1);
363 Tensor dinp2_o = createTensor(ctx, Shape{n}, kf32, dinp2);
364 std::promise<void> promise;
365 std::future<void> future = promise.get_future();
366 Kernel op = createKernel(ctx, {kShaderResidualBackward, 256, kf32},
367 Bindings{dout_i, dinp1_o, dinp2_o},
368 /* nWorkgroups */ {cdiv(n, 256), 1, 1});
369 dispatchKernel(ctx, op, promise);
370 wait(ctx, future);
371 toCPU(ctx, dinp1_o, dinp1, n * sizeof(float));
372 toCPU(ctx, dinp2_o, dinp2, n * sizeof(float));
373}
374
375void softmax_forward(Context& ctx, float* probs, float* logits, int B, int T, int V, int Vp) {
376 struct SoftmaxParam {

Callers 1

gpt2_backwardFunction · 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