| 25 | )"; |
| 26 | |
| 27 | int 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 | } |
nothing calls this directly
no test coverage detected