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

Function main

examples/web/run.cpp:30–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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