Query and display information about all CUDA devices. Parameters ---------- show_p2p : bool Whether to show peer-to-peer access information (default: True) Returns ------- bool True if successful, False otherwise
(show_p2p=True)
| 315 | |
| 316 | |
| 317 | def query_devices(show_p2p=True): |
| 318 | """ |
| 319 | Query and display information about all CUDA devices. |
| 320 | |
| 321 | Parameters |
| 322 | ---------- |
| 323 | show_p2p : bool |
| 324 | Whether to show peer-to-peer access information (default: True) |
| 325 | |
| 326 | Returns |
| 327 | ------- |
| 328 | bool |
| 329 | True if successful, False otherwise |
| 330 | """ |
| 331 | try: |
| 332 | print("[CUDA Device Query using CUDA Core API]") |
| 333 | devices = Device.get_all_devices() |
| 334 | except Exception as e: |
| 335 | print(f"Error: Failed to get devices: {e}") |
| 336 | import traceback |
| 337 | |
| 338 | traceback.print_exc() |
| 339 | return False |
| 340 | |
| 341 | if len(devices) == 0: |
| 342 | print("There are no available device(s) that support CUDA") |
| 343 | return True |
| 344 | |
| 345 | print(f"Detected {len(devices)} CUDA Capable device(s)") |
| 346 | |
| 347 | for dev_id, device in enumerate(devices): |
| 348 | try: |
| 349 | print_device_info(dev_id, device) |
| 350 | except Exception as e: |
| 351 | print(f"Error: Failed to get information for device {dev_id}: {e}") |
| 352 | import traceback |
| 353 | |
| 354 | traceback.print_exc() |
| 355 | return False |
| 356 | |
| 357 | if show_p2p and len(devices) >= 2: |
| 358 | print_p2p_access_info(devices) |
| 359 | |
| 360 | return True |
| 361 | |
| 362 | |
| 363 | def main(): |
no test coverage detected