|
| 1 | +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE |
| 4 | + |
| 5 | +import sys |
| 6 | + |
| 7 | +from cuda.core.experimental import Device, system |
| 8 | + |
| 9 | + |
| 10 | +# Convert boolean to YES or NO string |
| 11 | +def _yes_no(value: bool) -> str: |
| 12 | + return "YES" if value else "NO" |
| 13 | + |
| 14 | + |
| 15 | +# Convert value in bytes to MB or GB string |
| 16 | +BYTES_TO_MBYTES = 1 / (1024 * 1024) |
| 17 | +BYTES_TO_GBYTES = BYTES_TO_MBYTES / 1024 |
| 18 | + |
| 19 | + |
| 20 | +def _bytes_to_mbytes(value): |
| 21 | + return f"{value * BYTES_TO_MBYTES:.2f}MB" |
| 22 | + |
| 23 | + |
| 24 | +def _bytes_to_gbytes(value): |
| 25 | + return f"{value * BYTES_TO_GBYTES:.2f}GB" |
| 26 | + |
| 27 | + |
| 28 | +# Convert value in KHz to GHz string |
| 29 | +KHZ_TO_GHZ = 1e-6 |
| 30 | + |
| 31 | + |
| 32 | +def _khz_to_ghz(value): |
| 33 | + return f"{value * KHZ_TO_GHZ:.2f}GHz" |
| 34 | + |
| 35 | + |
| 36 | +# Print device properties to stdout |
| 37 | +def print_device_properties(properties): |
| 38 | + print("Properties:\n------------") |
| 39 | + print(f"- Can map host memory into the CUDA address space: {_yes_no(properties.can_map_host_memory)}") |
| 40 | + print( |
| 41 | + "- Can access host registered memory at the same virtual address as the CPU: " |
| 42 | + + f"{_yes_no(properties.can_use_host_pointer_for_registered_mem)}" |
| 43 | + ) |
| 44 | + print(f"- Clock rate: {_khz_to_ghz(properties.clock_rate)}") |
| 45 | + print(f"- Peak memory clock frequency: {_khz_to_ghz(properties.memory_clock_rate)}") |
| 46 | + print( |
| 47 | + "- Performance ratio (single precision)/(double precision): " |
| 48 | + + f"{properties.single_to_double_precision_perf_ratio}" |
| 49 | + ) |
| 50 | + print( |
| 51 | + f"- Compute capability: major={properties.compute_capability_major}, " |
| 52 | + + f"minor={properties.compute_capability_minor}" |
| 53 | + ) |
| 54 | + print(f"- Compute mode: {properties.compute_mode} (0 - default, 2 - prohibited, 3 - exclusive process)") |
| 55 | + print(f"- Support for Compute Preemption: {_yes_no(properties.compute_preemption_supported)}") |
| 56 | + print( |
| 57 | + "- Support for concurrent kernels execution within the same context: " |
| 58 | + + f"{_yes_no(properties.concurrent_kernels)}" |
| 59 | + ) |
| 60 | + print( |
| 61 | + "- Support for coherent access to managed memory concurrently with CPU: " |
| 62 | + + f"{_yes_no(properties.concurrent_managed_access)}" |
| 63 | + ) |
| 64 | + print( |
| 65 | + "- Support for deferred mapping in CUDA arrays and CUDA mipmapped arrays: " |
| 66 | + + f"{_yes_no(properties.deferred_mapping_cuda_array_supported)}" |
| 67 | + ) |
| 68 | + print( |
| 69 | + "- Support for direct access of managed memory on device without migration: " |
| 70 | + + f"{_yes_no(properties.direct_managed_mem_access_from_host)}" |
| 71 | + ) |
| 72 | + print(f"- ECC enabled: {_yes_no(properties.ecc_enabled)}") |
| 73 | + print(f"- Support for generic compression: {_yes_no(properties.generic_compression_supported)}") |
| 74 | + print(f"- Support for caching globals in L1 cache: {_yes_no(properties.global_l1_cache_supported)}") |
| 75 | + print(f"- Support for caching locals in L1 cache: {_yes_no(properties.local_l1_cache_supported)}") |
| 76 | + print(f"- Global memory bus widths: {properties.global_memory_bus_width} bits") |
| 77 | + print(f"- Support for GPUDirect RDMA: {_yes_no(properties.gpu_direct_rdma_supported)}") |
| 78 | + print(f"- GPUDirect RDMA flush-writes options bitmask: 0b{properties.gpu_direct_rdma_flush_writes_options:032b}") |
| 79 | + print( |
| 80 | + f"- GPUDirect RDMA writes ordering: {properties.gpu_direct_rdma_writes_ordering} " |
| 81 | + + "(0 - none, 100 - this device can consume remote writes, " |
| 82 | + + "200 - any CUDA device can consume remote writes to this device)" |
| 83 | + ) |
| 84 | + print( |
| 85 | + "- Can concurrently copy memory between host and device while executing kernel: " |
| 86 | + + f"{_yes_no(properties.gpu_overlap)}" |
| 87 | + ) |
| 88 | + print( |
| 89 | + "- Support for exporting memory to a posix file descriptor: " |
| 90 | + + f"{_yes_no(properties.handle_type_posix_file_descriptor_supported)}" |
| 91 | + ) |
| 92 | + print( |
| 93 | + "- Support for exporting memory to a Win32 NT handle: " |
| 94 | + + f"{_yes_no(properties.handle_type_win32_handle_supported)}" |
| 95 | + ) |
| 96 | + print( |
| 97 | + "- Support for exporting memory to a Win32 KMT handle: " |
| 98 | + + f"{_yes_no(properties.handle_type_win32_kmt_handle_supported)}" |
| 99 | + ) |
| 100 | + print( |
| 101 | + "- Link between device and host supports native atomic operations: " |
| 102 | + + f"{_yes_no(properties.host_native_atomic_supported)}" |
| 103 | + ) |
| 104 | + print(f"- Device is integrated with memory subsystem: {_yes_no(properties.integrated)}") |
| 105 | + print(f"- Kernel execution timeout: {_yes_no(properties.kernel_exec_timeout)}") |
| 106 | + print(f"- L2 cache size: {_bytes_to_mbytes(properties.l2_cache_size)}") |
| 107 | + print(f"- Max L2 persisting lines capacity: {_bytes_to_mbytes(properties.max_persisting_l2_cache_size)}") |
| 108 | + print(f"- Support for managed memory allocation: {_yes_no(properties.managed_memory)}") |
| 109 | + print(f"- Max access policy window size: {_bytes_to_mbytes(properties.max_access_policy_window_size)}") |
| 110 | + print(f"- Max x-dimension of a block: {properties.max_block_dim_x}") |
| 111 | + print(f"- Max y-dimension of a block: {properties.max_block_dim_y}") |
| 112 | + print(f"- Max z-dimension of a block: {properties.max_block_dim_z}") |
| 113 | + print(f"- Max blocks in a multiprocessor: {properties.max_blocks_per_multiprocessor}") |
| 114 | + print(f"- Max x-dimension of a grid: {properties.max_grid_dim_x}") |
| 115 | + print(f"- Max y-dimension of a grid: {properties.max_grid_dim_y}") |
| 116 | + print(f"- Max z-dimension of a grid: {properties.max_grid_dim_z}") |
| 117 | + print(f"- Max pitch allowed by the memory copy functions: {_bytes_to_gbytes(properties.max_pitch)}") |
| 118 | + print(f"- Max number of 32-bit registers per block: {properties.max_registers_per_block}") |
| 119 | + print(f"- Max number of 32-bit registers in a multiprocessor: {properties.max_registers_per_multiprocessor}") |
| 120 | + print(f"- Max shared memory per block: {properties.max_shared_memory_per_block}B") |
| 121 | + print(f"- Max optin shared memory per block: {properties.max_shared_memory_per_block_optin}B") |
| 122 | + print(f"- Max shared memory available to a multiprocessor: {properties.max_shared_memory_per_multiprocessor}B") |
| 123 | + print(f"- Max threads per block: {properties.max_threads_per_block}") |
| 124 | + print(f"- Max threads per multiprocessor: {properties.max_threads_per_multiprocessor}") |
| 125 | + print(f"- Warp size: {properties.warp_size}") |
| 126 | + print(f"- Max 1D surface width: {properties.maximum_surface1d_width}") |
| 127 | + print(f"- Max layers in 1D layered surface: {properties.maximum_surface1d_layered_layers}") |
| 128 | + print(f"- Max 1D layered surface width: {properties.maximum_surface1d_layered_width}") |
| 129 | + print(f"- Max 2D surface width: {properties.maximum_surface2d_width}") |
| 130 | + print(f"- Max 2D surface height: {properties.maximum_surface2d_height}") |
| 131 | + print(f"- Max layers in 2D layered surface: {properties.maximum_surface2d_layered_layers}") |
| 132 | + print(f"- Max 2D layered surface width: {properties.maximum_surface2d_layered_width}") |
| 133 | + print(f"- Max 2D layered surface height: {properties.maximum_surface2d_layered_height}") |
| 134 | + print(f"- Max 3D surface width: {properties.maximum_surface3d_width}") |
| 135 | + print(f"- Max 3D surface height: {properties.maximum_surface3d_height}") |
| 136 | + print(f"- Max 3D surface depth: {properties.maximum_surface3d_depth}") |
| 137 | + print(f"- Max cubemap surface width: {properties.maximum_surfacecubemap_width}") |
| 138 | + print(f"- Max layers in a cubemap layered surface: {properties.maximum_surfacecubemap_layered_layers}") |
| 139 | + print(f"- Max cubemap layered surface width: {properties.maximum_surfacecubemap_layered_width}") |
| 140 | + print(f"- Max 1D texture width: {properties.maximum_texture1d_width}") |
| 141 | + print(f"- Max width for a 1D texture bound to linear memory: {properties.maximum_texture1d_linear_width}") |
| 142 | + print(f"- Max layers in 1D layered texture: {properties.maximum_texture1d_layered_layers}") |
| 143 | + print(f"- Max 1D layered texture width: {properties.maximum_texture1d_layered_width}") |
| 144 | + print(f"- Max mipmapped 1D texture width: {properties.maximum_texture1d_mipmapped_width}") |
| 145 | + print(f"- Max 2D texture width: {properties.maximum_texture2d_width}") |
| 146 | + print(f"- Max 2D texture height: {properties.maximum_texture2d_height}") |
| 147 | + print(f"- Max width for a 2D texture bound to linear memory: {properties.maximum_texture2d_linear_width}") |
| 148 | + print(f"- Max height for a 2D texture bound to linear memory: {properties.maximum_texture2d_linear_height}") |
| 149 | + print( |
| 150 | + "- Max pitch for a 2D texture bound to linear memory: " |
| 151 | + + f"{_bytes_to_mbytes(properties.maximum_texture2d_linear_pitch)}" |
| 152 | + ) |
| 153 | + print(f"- Max layers in 2D layered texture: {properties.maximum_texture2d_layered_layers}") |
| 154 | + print(f"- Max 2D layered texture width: {properties.maximum_texture2d_layered_width}") |
| 155 | + print(f"- Max 2D layered texture height: {properties.maximum_texture2d_layered_height}") |
| 156 | + print(f"- Max mipmapped 2D texture width: {properties.maximum_texture2d_mipmapped_width}") |
| 157 | + print(f"- Max mipmapped 2D texture height: {properties.maximum_texture2d_mipmapped_height}") |
| 158 | + print(f"- Max 3D texture width: {properties.maximum_texture3d_width}") |
| 159 | + print(f"- Max 3D texture height: {properties.maximum_texture3d_height}") |
| 160 | + print(f"- Max 3D texture depth: {properties.maximum_texture3d_depth}") |
| 161 | + print(f"- Alternate max 3D texture width: {properties.maximum_texture3d_width_alternate}") |
| 162 | + print(f"- Alternate max 3D texture height: {properties.maximum_texture3d_height_alternate}") |
| 163 | + print(f"- Alternate max 3D texture depth: {properties.maximum_texture3d_depth_alternate}") |
| 164 | + print(f"- Max cubemap texture width or height: {properties.maximum_texturecubemap_width}") |
| 165 | + print(f"- Max layers in a cubemap layered texture: {properties.maximum_texturecubemap_layered_layers}") |
| 166 | + print(f"- Max cubemap layered texture width or height: {properties.maximum_texturecubemap_layered_width}") |
| 167 | + print(f"- Texture base address alignment requirement: {properties.texture_alignment}B") |
| 168 | + print( |
| 169 | + "- Pitch alignment requirement for 2D texture references bound to pitched memory: " |
| 170 | + + f"{properties.texture_pitch_alignment}B" |
| 171 | + ) |
| 172 | + print(f"- Support for memory pools: {_yes_no(properties.memory_pools_supported)}") |
| 173 | + print( |
| 174 | + "- Bitmask of handle types supported with memory pool-based IPC: " |
| 175 | + + f"0b{properties.mempool_supported_handle_types:032b}" |
| 176 | + ) |
| 177 | + print(f"- Multi-GPU board: {_yes_no(properties.multi_gpu_board)}") |
| 178 | + print(f"- Multi-GPU board group ID: {properties.multi_gpu_board_group_id}") |
| 179 | + print(f"- Support for switch multicast and reduction operations: {_yes_no(properties.multicast_supported)}") |
| 180 | + print(f"- Number of multiprocessors: {properties.multiprocessor_count}") |
| 181 | + print(f"- NUMA configuration: {properties.numa_config}") |
| 182 | + print(f"- NUMA node ID of GPU memory: {properties.numa_id}") |
| 183 | + print(f"- Support for coherently accessing pageable memory: {_yes_no(properties.pageable_memory_access)}") |
| 184 | + print( |
| 185 | + "- Access pageable memory via host's page tables: " |
| 186 | + + f"{_yes_no(properties.pageable_memory_access_uses_host_page_tables)}" |
| 187 | + ) |
| 188 | + print(f"- PCI bus ID: {properties.pci_bus_id}") |
| 189 | + print(f"- PCI device (slot) ID: {properties.pci_device_id}") |
| 190 | + print(f"- PCI domain ID: {properties.pci_domain_id}") |
| 191 | + print( |
| 192 | + "- Support for registering memory that must be mapped to GPU as read-only: " |
| 193 | + + f"{_yes_no(properties.read_only_host_register_supported)}" |
| 194 | + ) |
| 195 | + print( |
| 196 | + "- Amount of shared memory per block reserved by CUDA driver: " |
| 197 | + + f"{properties.reserved_shared_memory_per_block}B" |
| 198 | + ) |
| 199 | + print( |
| 200 | + "- Support for sparse CUDA arrays and sparse CUDA mipmapped arrays: " |
| 201 | + + f"{_yes_no(properties.sparse_cuda_array_supported)}" |
| 202 | + ) |
| 203 | + print(f"- Using TCC driver: {_yes_no(properties.tcc_driver)}") |
| 204 | + print(f"- Constant memory available: {properties.total_constant_memory}B") |
| 205 | + print(f"- Support for unified address space with host: {_yes_no(properties.unified_addressing)}") |
| 206 | + print(f"- Support for virtual memory management: {_yes_no(properties.virtual_memory_management_supported)}") |
| 207 | + |
| 208 | + |
| 209 | +# Print info about all CUDA devices in the system |
| 210 | +def show_device_properties(): |
| 211 | + ndev = system.num_devices |
| 212 | + print(f"Number of GPUs: {ndev}") |
| 213 | + |
| 214 | + for device_id in range(ndev): |
| 215 | + device = Device(device_id) |
| 216 | + print(f"DEVICE {device.name} (id={device_id})") |
| 217 | + |
| 218 | + device.set_current() |
| 219 | + # Extend example to show device context information after #189 is resolved. |
| 220 | + # ctx = device.context |
| 221 | + |
| 222 | + cc = device.compute_capability |
| 223 | + prop = device.properties |
| 224 | + |
| 225 | + print(f"Device compute capability: major={cc[0]}, minor={cc[1]}") |
| 226 | + print(f"Architecture: sm_{cc[0]}{cc[1]}") |
| 227 | + print(f"PCI bus id={device.pci_bus_id}") |
| 228 | + print_device_properties(prop) |
| 229 | + print("*****************************************************\n\n") |
| 230 | + |
| 231 | + |
| 232 | +if __name__ == "__main__": |
| 233 | + assert len(sys.argv) == 1, "no command-line arguments expected" |
| 234 | + show_device_properties() |
0 commit comments