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 / tests / nvml / transport.c

78 lines · 2701 bytes Raw Blame History
1/* ORACLE: foreign C caller of the generated ABI; not shipped */
2/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
3/* Test transport for the CUDA++ NVML shell: the three omega2_nvrm_* entry points of
4 * native/nvrm/transport.om (aien-dev/CUDApp#281), answered by the Omega RM fake
5 * tests/nvml/rmfake.om instead of /dev/nvidia*. Each call copies the request into the fake's
6 * views, runs one omega_nvml_fake step and copies the reply back. No device file is opened. */
7#include <stdint.h>
8#include <string.h>
9
10#include "transport.h"
11
12enum { FAKE_HN = 4608, FAKE_PN = 55888 };
13
14uint32_t omega_nvml_fake(uint64_t *result, void *p0, uint64_t p0_n, void *p1, uint64_t p1_n,
15 void *p2, uint64_t p2_n);
16
17static uint64_t fake_st[64];
18static uint8_t fake_h[FAKE_HN];
19static uint8_t fake_p[FAKE_PN];
20static uint64_t fake_traps;
21
22void fake_reset(int fault) {
23 memset(fake_st, 0, sizeof fake_st);
24 fake_st[5] = (uint64_t)(unsigned char)fault;
25 fake_traps = 0;
26}
27
28uint64_t fake_get(unsigned i) { return i < 64 ? fake_st[i] : UINT64_MAX; }
29
30uint64_t fake_trapped(void) { return fake_traps; }
31
32/* One fake step; a trap or refusal counts as a violation and reads as transport status 1. */
33static uint32_t fake_step(uint64_t *result) {
34 uint64_t r = 1;
35 if (omega_nvml_fake(&r, fake_st, 64, fake_h, FAKE_HN, fake_p, FAKE_PN) != 0 || r != 0) {
36 fake_traps++;
37 fake_st[13]++;
38 return 1;
39 }
40 *result = fake_st[6];
41 return 0;
42}
43
44uint32_t omega2_nvrm_open_file(uint64_t *result, void *o_path, uint64_t o_path_len) {
45 if (o_path_len == 0 || o_path_len > FAKE_PN) return 32;
46 memcpy(fake_p, o_path, o_path_len);
47 fake_st[0] = 2;
48 fake_st[7] = o_path_len;
49 return fake_step(result);
50}
51
52uint32_t omega2_nvrm_close_file(uint64_t *result, uint64_t o_fd) {
53 fake_st[0] = 3;
54 fake_st[1] = o_fd;
55 return fake_step(result);
56}
57
58uint32_t omega2_nvrm_ioctl(uint64_t *result, uint64_t o_fd, uint64_t o_nr, void *o_h,
59 uint64_t o_h_len, void *o_p, uint64_t o_p_len) {
60 if (o_h_len > FAKE_HN || o_p_len > FAKE_PN) return 32;
61 /* Fault S: the transport itself refuses the GPU name control (omega2 status 1). */
62 if (fake_st[5] == 'S' && o_nr == 42 && o_h_len >= 12) {
63 uint32_t cmd;
64 memcpy(&cmd, (const uint8_t *)o_h + 8, 4);
65 if (cmd == 0x20800110u) return 1;
66 }
67 memcpy(fake_h, o_h, o_h_len);
68 memcpy(fake_p, o_p, o_p_len);
69 fake_st[0] = 1;
70 fake_st[1] = o_fd;
71 fake_st[2] = o_nr;
72 fake_st[3] = o_h_len;
73 fake_st[4] = o_p_len;
74 uint32_t st = fake_step(result);
75 memcpy(o_h, fake_h, o_h_len);
76 memcpy(o_p, fake_p, o_p_len);
77 return st;
78}