| 28 | )"; |
| 29 | |
| 30 | int 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 | } |
nothing calls this directly
no test coverage detected