Skip to content

Commit 2385e5e

Browse files
committed
fix: use pytest.skip() for unsupported configs in test examples
The _test.py files in cuda_bindings/examples/ are run under pytest, so sys.exit(1) for unsupported configurations causes SystemExit(1) which pytest treats as a test failure. Use pytest.skip() instead for platform/device/capability checks that indicate unsupported configs. Actual test failures (incorrect results) still use sys.exit(1). Made-with: Cursor
1 parent 64cc6d8 commit 2385e5e

10 files changed

Lines changed: 53 additions & 68 deletions

File tree

cuda_bindings/examples/0_Introduction/clock_nvrtc_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

44
import platform
5-
import sys
65

76
import numpy as np
87
from common import common
@@ -59,9 +58,10 @@ def elems_to_bytes(nelems, dt):
5958

6059

6160
def main():
61+
import pytest
62+
6263
if platform.machine() == "armv7l":
63-
print("clock_nvrtc is not supported on ARMv7 - waiving sample", file=sys.stderr)
64-
sys.exit(1)
64+
pytest.skip("clock_nvrtc is not supported on ARMv7")
6565

6666
timer = np.empty(NUM_BLOCKS * 2, dtype="int64")
6767
hinput = np.empty(NUM_THREADS * 2, dtype="float32")

cuda_bindings/examples/0_Introduction/simpleCubemapTexture_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def main():
9090
f"CUDA device [{deviceProps.name}] has {deviceProps.multiProcessorCount} Multi-Processors SM {deviceProps.major}.{deviceProps.minor}"
9191
)
9292
if deviceProps.major < 2:
93-
print("Test requires SM 2.0 or higher for support of Texture Arrays.", file=sys.stderr)
94-
sys.exit(1)
93+
import pytest
94+
95+
pytest.skip("Test requires SM 2.0 or higher for support of Texture Arrays.")
9596

9697
# Generate input data for layered texture
9798
width = 64

cuda_bindings/examples/0_Introduction/simpleP2P_test.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,27 @@
2424

2525

2626
def main():
27+
import pytest
28+
2729
if platform.system() == "Darwin":
28-
print("simpleP2P is not supported on Mac OSX", file=sys.stderr)
29-
sys.exit(1)
30+
pytest.skip("simpleP2P is not supported on Mac OSX")
3031

3132
if platform.machine() == "armv7l":
32-
print("simpleP2P is not supported on ARMv7", file=sys.stderr)
33-
sys.exit(1)
33+
pytest.skip("simpleP2P is not supported on ARMv7")
3434

3535
if platform.machine() == "aarch64":
36-
print("simpleP2P is not supported on aarch64", file=sys.stderr)
37-
sys.exit(1)
36+
pytest.skip("simpleP2P is not supported on aarch64")
3837

3938
if platform.machine() == "sbsa":
40-
print("simpleP2P is not supported on sbsa", file=sys.stderr)
41-
sys.exit(1)
39+
pytest.skip("simpleP2P is not supported on sbsa")
4240

4341
# Number of GPUs
4442
print("Checking for multiple GPUs...")
4543
gpu_n = checkCudaErrors(cudart.cudaGetDeviceCount())
4644
print(f"CUDA-capable device count: {gpu_n}")
4745

4846
if gpu_n < 2:
49-
print("Two or more GPUs with Peer-to-Peer access capability are required", file=sys.stderr)
50-
sys.exit(1)
47+
pytest.skip("Two or more GPUs with Peer-to-Peer access capability are required")
5148

5249
prop = [checkCudaErrors(cudart.cudaGetDeviceProperties(i)) for i in range(gpu_n)]
5350
# Check possibility for peer access
@@ -78,9 +75,7 @@ def main():
7875
break
7976

8077
if p2pCapableGPUs[0] == -1 or p2pCapableGPUs[1] == -1:
81-
print("Two or more GPUs with Peer-to-Peer access capability are required.", file=sys.stderr)
82-
print("Peer to Peer access is not available amongst GPUs in the system, waiving test.", file=sys.stderr)
83-
sys.exit(1)
78+
pytest.skip("Peer to Peer access is not available amongst GPUs in the system")
8479

8580
# Use first pair of p2p capable GPUs detected
8681
gpuid = [p2pCapableGPUs[0], p2pCapableGPUs[1]]

cuda_bindings/examples/0_Introduction/simpleZeroCopy_test.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@ def main():
3232
idev = 0
3333
bPinGenericMemory = False
3434

35+
import pytest
36+
3537
if platform.system() == "Darwin":
36-
print("simpleZeroCopy is not supported on Mac OSX", file=sys.stderr)
37-
sys.exit(1)
38+
pytest.skip("simpleZeroCopy is not supported on Mac OSX")
3839

3940
if platform.machine() == "armv7l":
40-
print("simpleZeroCopy is not supported on ARMv7", file=sys.stderr)
41-
sys.exit(1)
41+
pytest.skip("simpleZeroCopy is not supported on ARMv7")
4242

4343
if platform.machine() == "aarch64":
44-
print("simpleZeroCopy is not supported on aarch64", file=sys.stderr)
45-
sys.exit(1)
44+
pytest.skip("simpleZeroCopy is not supported on aarch64")
4645

4746
if platform.machine() == "sbsa":
48-
print("simpleZeroCopy is not supported on sbsa", file=sys.stderr)
49-
sys.exit(1)
47+
pytest.skip("simpleZeroCopy is not supported on sbsa")
5048

5149
if checkCmdLineFlag("help"):
5250
print("Usage: simpleZeroCopy [OPTION]\n", file=sys.stderr)
@@ -78,8 +76,7 @@ def main():
7876
deviceProp = checkCudaErrors(cudart.cudaGetDeviceProperties(idev))
7977

8078
if not deviceProp.canMapHostMemory:
81-
print(f"Device {idev} does not support mapping CPU host memory!", file=sys.stderr)
82-
sys.exit(1)
79+
pytest.skip(f"Device {idev} does not support mapping CPU host memory!")
8380

8481
checkCudaErrors(cudart.cudaSetDeviceFlags(cudart.cudaDeviceMapHost))
8582

cuda_bindings/examples/0_Introduction/systemWideAtomics_test.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,24 @@ def verify(testData, length):
165165

166166

167167
def main():
168+
import pytest
169+
168170
if os.name == "nt":
169-
print("Atomics not supported on Windows", file=sys.stderr)
170-
sys.exit(1)
171+
pytest.skip("Atomics not supported on Windows")
171172

172173
# set device
173174
dev_id = findCudaDevice()
174175
device_prop = checkCudaErrors(cudart.cudaGetDeviceProperties(dev_id))
175176

176177
if not device_prop.managedMemory:
177-
print("Unified Memory not supported on this device", file=sys.stderr)
178-
sys.exit(1)
178+
pytest.skip("Unified Memory not supported on this device")
179179

180180
computeMode = checkCudaErrors(cudart.cudaDeviceGetAttribute(cudart.cudaDeviceAttr.cudaDevAttrComputeMode, dev_id))
181181
if computeMode == cudart.cudaComputeMode.cudaComputeModeProhibited:
182-
print("This sample requires a device in either default or process exclusive mode", file=sys.stderr)
183-
sys.exit(1)
182+
pytest.skip("This sample requires a device in either default or process exclusive mode")
184183

185184
if device_prop.major < 6:
186-
print("Requires a minimum CUDA compute 6.0 capability, waiving testing.", file=sys.stderr)
187-
sys.exit(1)
185+
pytest.skip("Requires a minimum CUDA compute 6.0 capability")
188186

189187
numThreads = 256
190188
numBlocks = 64

cuda_bindings/examples/0_Introduction/vectorAddDrv_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def main():
4444
cuda.cuDeviceGetAttribute(cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, cuDevice)
4545
)
4646
if not uvaSupported:
47-
print("Accessing pageable memory directly requires UVA", file=sys.stderr)
48-
sys.exit(1)
47+
import pytest
48+
49+
pytest.skip("Accessing pageable memory directly requires UVA")
4950

5051
kernelHelper = common.KernelHelper(vectorAddDrv, int(cuDevice))
5152
_VecAdd_kernel = kernelHelper.getFunction(b"VecAdd_kernel")

cuda_bindings/examples/0_Introduction/vectorAddMMAP_test.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,19 @@ def simpleFreeMultiDeviceMmap(dptr, size):
189189

190190

191191
def main():
192+
import pytest
193+
192194
if platform.system() == "Darwin":
193-
print("vectorAddMMAP is not supported on Mac OSX", file=sys.stderr)
194-
sys.exit(1)
195+
pytest.skip("vectorAddMMAP is not supported on Mac OSX")
195196

196197
if platform.machine() == "armv7l":
197-
print("vectorAddMMAP is not supported on ARMv7", file=sys.stderr)
198-
sys.exit(1)
198+
pytest.skip("vectorAddMMAP is not supported on ARMv7")
199199

200200
if platform.machine() == "aarch64":
201-
print("vectorAddMMAP is not supported on aarch64", file=sys.stderr)
202-
sys.exit(1)
201+
pytest.skip("vectorAddMMAP is not supported on aarch64")
203202

204203
if platform.machine() == "sbsa":
205-
print("vectorAddMMAP is not supported on sbsa", file=sys.stderr)
206-
sys.exit(1)
204+
pytest.skip("vectorAddMMAP is not supported on sbsa")
207205

208206
N = 50000
209207
size = N * np.dtype(np.float32).itemsize
@@ -222,8 +220,7 @@ def main():
222220
)
223221
print(f"Device {cuDevice} VIRTUAL ADDRESS MANAGEMENT SUPPORTED = {attributeVal}.")
224222
if not attributeVal:
225-
print(f"Device {cuDevice} doesn't support VIRTUAL ADDRESS MANAGEMENT.", file=sys.stderr)
226-
sys.exit(1)
223+
pytest.skip(f"Device {cuDevice} doesn't support VIRTUAL ADDRESS MANAGEMENT.")
227224

228225
# The vector addition happens on cuDevice, so the allocations need to be mapped there.
229226
mappingDevices = [cuDevice]

cuda_bindings/examples/2_Concepts_and_Techniques/streamOrderedAllocation_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ def streamOrderedAllocationPostSync(dev, nelem, a, b, c):
191191

192192

193193
def main():
194+
import pytest
195+
194196
if platform.system() == "Darwin":
195-
print("streamOrderedAllocation is not supported on Mac OSX", file=sys.stderr)
196-
sys.exit(1)
197+
pytest.skip("streamOrderedAllocation is not supported on Mac OSX")
197198

198199
cuda.cuInit(0)
199200
if checkCmdLineFlag("help"):
@@ -212,8 +213,7 @@ def main():
212213
cudart.cudaDeviceGetAttribute(cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEMORY_POOLS_SUPPORTED, dev)
213214
)
214215
if not isMemPoolSupported:
215-
print("Waiving execution as device does not support Memory Pools", file=sys.stderr)
216-
sys.exit(1)
216+
pytest.skip("Waiving execution as device does not support Memory Pools")
217217

218218
global _vectorAddGPU
219219
kernelHelper = common.KernelHelper(streamOrderedAllocation, dev)

cuda_bindings/examples/3_CUDA_Features/globalToShmemAsyncCopy_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,16 +1116,16 @@ def MatrixMultiply(dimsA, dimsB, kernel_number):
11161116

11171117

11181118
def main():
1119+
import pytest
1120+
11191121
common.pytest_skipif_compute_capability_too_low(findCudaDevice(), (7, 0))
11201122

11211123
if platform.machine() == "qnx":
1122-
print("globalToShmemAsyncCopy is not supported on QNX", file=sys.stderr)
1123-
sys.exit(1)
1124+
pytest.skip("globalToShmemAsyncCopy is not supported on QNX")
11241125

11251126
version = checkCudaErrors(cuda.cuDriverGetVersion())
11261127
if version < 11010:
1127-
print("CUDA Toolkit 11.1 or greater is required", file=sys.stderr)
1128-
sys.exit(1)
1128+
pytest.skip("CUDA Toolkit 11.1 or greater is required")
11291129

11301130
if checkCmdLineFlag("help") or checkCmdLineFlag("?"):
11311131
print("Usage device=n (n >= 0 for deviceID)", file=sys.stderr)
@@ -1193,8 +1193,7 @@ def main():
11931193
cudart.cudaDeviceGetAttribute(cudart.cudaDeviceAttr.cudaDevAttrComputeCapabilityMajor, devID)
11941194
)
11951195
if major < 7:
1196-
print("globalToShmemAsyncCopy requires SM 7.0 or higher.", file=sys.stderr)
1197-
sys.exit(1)
1196+
pytest.skip("globalToShmemAsyncCopy requires SM 7.0 or higher.")
11981197

11991198
print(f"MatrixA({dimsA.x},{dimsA.y}), MatrixB({dimsB.x},{dimsB.y})")
12001199

cuda_bindings/examples/4_CUDA_Libraries/conjugateGradientMultiBlockCG_test.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,34 +198,31 @@ def genTridiag(I, J, val, N, nz):
198198
def main():
199199
tol = 1e-5
200200

201+
import pytest
202+
201203
# WAIVE: Due to bug in NVRTC
202204
return
203205

204206
if platform.system() == "Darwin":
205-
print("conjugateGradientMultiBlockCG is not supported on Mac OSX", file=sys.stderr)
206-
sys.exit(1)
207+
pytest.skip("conjugateGradientMultiBlockCG is not supported on Mac OSX")
207208

208209
if platform.machine() == "armv7l":
209-
print("conjugateGradientMultiBlockCG is not supported on ARMv7", file=sys.stderr)
210-
sys.exit(1)
210+
pytest.skip("conjugateGradientMultiBlockCG is not supported on ARMv7")
211211

212212
if platform.machine() == "qnx":
213-
print("conjugateGradientMultiBlockCG is not supported on QNX", file=sys.stderr)
214-
sys.exit(1)
213+
pytest.skip("conjugateGradientMultiBlockCG is not supported on QNX")
215214

216215
# This will pick the best possible CUDA capable device
217216
devID = findCudaDevice()
218217
deviceProp = checkCudaErrors(cudart.cudaGetDeviceProperties(devID))
219218

220219
if not deviceProp.managedMemory:
221-
print("Unified Memory not supported on this device", file=sys.stderr)
222-
sys.exit(1)
220+
pytest.skip("Unified Memory not supported on this device")
223221

224222
# This sample requires being run on a device that supports Cooperative Kernel
225223
# Launch
226224
if not deviceProp.cooperativeLaunch:
227-
print(f"\nSelected GPU {devID} does not support Cooperative Kernel Launch, Waiving the run", file=sys.stderr)
228-
sys.exit(1)
225+
pytest.skip(f"Selected GPU {devID} does not support Cooperative Kernel Launch")
229226

230227
# Statistics about the GPU device
231228
print(

0 commit comments

Comments
 (0)