Skip to content

Commit 7f472ec

Browse files
committed
Enhance mocks to cover getting device attributes
1 parent c9ee0eb commit 7f472ec

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test/mock_cuda.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,36 @@ CUresult cuDriverGetVersion(int *driverVersion) {
2929
CUresult cuCtxSynchronize(void) {
3030
return CUDA_SUCCESS;
3131
}
32+
33+
// Mock cuCtxGetDevice — return a fixed device id for the parcagpu
34+
// gpu_config probe path.
35+
CUresult cuCtxGetDevice(CUdevice *device) {
36+
if (device == NULL) {
37+
return CUDA_ERROR_INVALID_VALUE;
38+
}
39+
*device = 0;
40+
return CUDA_SUCCESS;
41+
}
42+
43+
// Mock cuDeviceGetAttribute — return plausible H100-class values for the
44+
// attributes parcagpu queries at context init. Anything not enumerated
45+
// returns 0 (still success), so callers see a non-error but inert value.
46+
CUresult cuDeviceGetAttribute(int *pi, CUdevice_attribute attrib,
47+
CUdevice dev) {
48+
(void)dev;
49+
if (pi == NULL) {
50+
return CUDA_ERROR_INVALID_VALUE;
51+
}
52+
switch (attrib) {
53+
case CU_DEVICE_ATTRIBUTE_CLOCK_RATE:
54+
*pi = 1830000; // 1.83 GHz, H100 boost
55+
break;
56+
case CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT:
57+
*pi = 132; // H100 SXM5
58+
break;
59+
default:
60+
*pi = 0;
61+
break;
62+
}
63+
return CUDA_SUCCESS;
64+
}

0 commit comments

Comments
 (0)