|
10 | 10 | import sys |
11 | 11 | import traceback |
12 | 12 |
|
13 | | -try: |
14 | | - from cuda import cuda |
15 | | -except: |
16 | | - from cuda.bindings import driver as cuda |
17 | 13 | from datetime import datetime |
18 | 14 | from pathlib import Path |
19 | 15 |
|
@@ -215,63 +211,44 @@ def save_error_report(errors, filename): |
215 | 211 | with open(filename, "w") as f: |
216 | 212 | json.dump(errors, f, indent=2) |
217 | 213 |
|
| 214 | + |
218 | 215 | def get_sm_version(): |
219 | 216 | """Get CUDA compute capability (SM version)""" |
220 | 217 | try: |
221 | 218 | import torch |
| 219 | + |
222 | 220 | if torch.cuda.is_available(): |
223 | 221 | device = torch.cuda.current_device() |
224 | 222 | capability = torch.cuda.get_device_capability(device) |
225 | 223 | return capability[0] * 10 + capability[1] |
226 | 224 | except Exception: |
227 | 225 | pass |
228 | | - |
| 226 | + |
229 | 227 | # fallback to cuda-python |
230 | 228 | try: |
231 | 229 | from cuda import cuda |
| 230 | + |
232 | 231 | # Init |
233 | 232 | (err,) = cuda.cuInit(0) |
234 | 233 | if err != 0: |
235 | 234 | raise RuntimeError(f"cuInit failed with error code: {err}") |
236 | | - |
| 235 | + |
237 | 236 | # Device |
238 | 237 | err, cu_device = cuda.cuDeviceGet(0) |
239 | 238 | if err != 0: |
240 | 239 | raise RuntimeError(f"cuDeviceGet failed with error code: {err}") |
241 | | - |
| 240 | + |
242 | 241 | # Get target architecture |
243 | 242 | err, sm_major = cuda.cuDeviceGetAttribute( |
244 | | - cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, |
245 | | - cu_device |
| 243 | + cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cu_device |
246 | 244 | ) |
247 | 245 | err, sm_minor = cuda.cuDeviceGetAttribute( |
248 | | - cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, |
249 | | - cu_device |
| 246 | + cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cu_device |
250 | 247 | ) |
251 | | - |
| 248 | + |
252 | 249 | return sm_major * 10 + sm_minor |
253 | 250 | except Exception as e: |
254 | | - raise RuntimeError( |
255 | | - f"Cannot get SM version: both PyTorch and cuda-python failed. " |
256 | | - f"Error: {e}" |
257 | | - ) from e |
258 | | - |
259 | | -# def get_sm_version(): |
260 | | -# # Init |
261 | | -# (err,) = cuda.cuInit(0) |
262 | | - |
263 | | -# # Device |
264 | | -# err, cu_device = cuda.cuDeviceGet(0) |
265 | | - |
266 | | -# # Get target architecture |
267 | | -# err, sm_major = cuda.cuDeviceGetAttribute( |
268 | | -# cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cu_device |
269 | | -# ) |
270 | | -# err, sm_minor = cuda.cuDeviceGetAttribute( |
271 | | -# cuda.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cu_device |
272 | | -# ) |
273 | | - |
274 | | -# return sm_major * 10 + sm_minor |
| 251 | + raise RuntimeError(f"Cannot get SM version: both PyTorch and cuda-python failed. Error: {e}") from e |
275 | 252 |
|
276 | 253 |
|
277 | 254 | def create_test_case_id(test_case, test_type, module_name): |
|
0 commit comments