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

Function encoder_backward

experimental/kernels/ops.cpp:51–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void encoder_backward(Context& ctx, float* dwte, float* dwpe,
52 float* dout, int* inp,
53 int B, int T, int C) {
54 unsigned long b = static_cast<unsigned long>(B);
55 unsigned long t = static_cast<unsigned long>(T);
56 unsigned long c = static_cast<unsigned long>(C);
57 unsigned long v = VOCAB_SIZE;
58 struct EncoderParams {
59 uint32_t B;
60 uint32_t T;
61 uint32_t C;
62 };
63 setLogLevel(kError);
64 Tensor dwte_t = createTensor(ctx, Shape{v, c}, kf32, dwte);
65 Tensor dwpe_t = createTensor(ctx, Shape{t, c}, kf32, dwpe);
66 Tensor dout_t = createTensor(ctx, Shape{b * t * c}, kf32, dout);
67 Tensor input = createTensor(ctx, Shape{b * t}, ki32, inp);
68 std::promise<void> promise;
69 std::future<void> future = promise.get_future();
70 Kernel op = createKernel(ctx, {kShaderEncoderBackward, 256, kf32},
71 Bindings{dwte_t, dwpe_t, dout_t, input},
72 /* nWorkgroups */ {cdiv(b * t, 256), 1, 1},
73 /* params */
74 EncoderParams{
75 static_cast<uint32_t>(b),
76 static_cast<uint32_t>(t),
77 static_cast<uint32_t>(c)
78 });
79 dispatchKernel(ctx, op, promise);
80 wait(ctx, future);
81 toCPU(ctx, dwte_t, dwte, v * c * sizeof(float));
82 toCPU(ctx, dwpe_t, dwpe, t * c * sizeof(float));
83}
84
85void layernorm_forward(Context& ctx, float* out, float* mean, float* rstd,
86 float* inp, float* weight, float* bias,

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