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

Function main

examples/hello_world/run.cpp:27–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25)";
26
27int main(int argc, char **argv) {
28 printf("\033[2J\033[1;1H");
29 printf("\nHello gpu.cpp!\n");
30 printf("--------------\n\n");
31
32 Context ctx = createContext();
33 static constexpr size_t N = 10000;
34 std::array<float, N> inputArr, outputArr;
35 for (int i = 0; i < N; ++i) {
36 inputArr[i] = static_cast<float>(i) / 10.0; // dummy input data
37 }
38 Tensor input = createTensor(ctx, Shape{N}, kf32, inputArr.data());
39 Tensor output = createTensor(ctx, Shape{N}, kf32);
40 std::promise<void> promise;
41 std::future<void> future = promise.get_future();
42 Kernel op = createKernel(ctx, {kGelu, 256, kf32},
43 Bindings{input, output},
44 /* nWorkgroups */ {cdiv(N, 256), 1, 1});
45 dispatchKernel(ctx, op, promise);
46 wait(ctx, future);
47 toCPU(ctx, output, outputArr.data(), sizeof(outputArr));
48 for (int i = 0; i < 12; ++i) {
49 printf(" gelu(%.2f) = %.2f\n", inputArr[i], outputArr[i]);
50 }
51 printf(" ...\n\n");
52 printf("Computed %zu values of GELU(x)\n\n", N);
53 return 0;
54}

Callers

nothing calls this directly

Calls 7

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