interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tools / prof / write_fix.c

70 lines · 1909 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Independent writer for the built-in profiler fixture. The Omega `fix` mode
3 * must produce these same 176 bytes. It does not open a device. */
4#define _POSIX_C_SOURCE 200809L
5#include <stdint.h>
6#include <stdio.h>
7#include <string.h>
8#include <fcntl.h>
9#include <unistd.h>
10
11static void put_u32(uint8_t *p, uint32_t v) {
12 p[0] = (uint8_t)v;
13 p[1] = (uint8_t)(v >> 8);
14 p[2] = (uint8_t)(v >> 16);
15 p[3] = (uint8_t)(v >> 24);
16}
17
18static void put_u64(uint8_t *p, uint64_t v) {
19 int i;
20 for (i = 0; i < 8; i++) {
21 p[i] = (uint8_t)(v >> (8 * i));
22 }
23}
24
25static void put_kern(uint8_t *p, uint32_t id, uint64_t bytes, uint64_t flops,
26 uint32_t before, uint32_t after) {
27 put_u32(p, id);
28 put_u32(p + 4, 0);
29 put_u64(p + 8, bytes);
30 put_u64(p + 16, flops);
31 put_u32(p + 24, before);
32 put_u32(p + 28, after);
33}
34
35int main(int argc, char **argv) {
36 uint8_t b[176];
37 FILE *f;
38 if (argc != 2) {
39 return 2;
40 }
41 memset(b, 0, sizeof b);
42 b[0] = 80;
43 b[1] = 82;
44 b[2] = 79;
45 b[3] = 70;
46 put_u32(b + 4, 1);
47 put_u32(b + 8, 3);
48 put_u32(b + 12, 4);
49 put_kern(b + 16, 0, 195100000000ull, 115140000000ull, 0, 1);
50 put_kern(b + 48, 1, 195100000ull, 115140000000000ull, 1, 2);
51 put_kern(b + 80, 2, 97550000000ull, 57570000000000ull, 2, 3);
52 put_u64(b + 112, 1000000000000ull);
53 put_u64(b + 128, 1001000000000ull);
54 put_u64(b + 144, 1002000000000ull);
55 put_u64(b + 160, 1003000000000ull);
56 int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
57 f = fd < 0 ? NULL : fdopen(fd, "wb");
58 if (f == NULL && fd >= 0) close(fd);
59 if (f == NULL) {
60 return 5;
61 }
62 if (fwrite(b, 1, 176, f) != 176) {
63 fclose(f);
64 return 5;
65 }
66 if (fclose(f) != 0) {
67 return 5;
68 }
69 return 0;
70}