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

Function gelu_forward

experimental/kernels/ops.cpp:311–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309}
310
311void 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
326void gelu_backward(Context& ctx, float* dinp, float* inp, float* dout, int N){
327 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