|
| 1 | +from hip import hip |
| 2 | + |
| 3 | +# Defining the value for hipDeviceGetAttribute |
| 4 | +STRINGLENGTH = 256 |
| 5 | +hipDeviceAttributeClockRate = 5 |
| 6 | +hipDeviceAttributeMaxBlockDimX = 26 |
| 7 | +hipDeviceAttributeMaxBlockDimY = 27 |
| 8 | +hipDeviceAttributeMaxBlockDimZ = 28 |
| 9 | +hipDeviceAttributeMaxGridDimX = 29 |
| 10 | +hipDeviceAttributeMaxGridDimY = 30 |
| 11 | +hipDeviceAttributeMaxGridDimZ = 31 |
| 12 | +hipDeviceAttributeMaxThreadsPerBlock = 56 |
| 13 | +hipDeviceAttributeMaxThreadsPerMultiProcessor = 57 |
| 14 | +hipDeviceAttributeMaxRegistersPerBlock = 71 |
| 15 | +hipDeviceAttributeMaxSharedMemoryPerBlock = 74 |
| 16 | +hipDeviceAttributeWarpSize = 87 |
| 17 | + |
| 18 | + |
| 19 | +def get_gpu_info(): |
| 20 | + num_gpus = hip.hipGetDeviceCount()[1] |
| 21 | + all_gpu_info = [] |
| 22 | + |
| 23 | + for i in range(num_gpus): |
| 24 | + gpu_info = { |
| 25 | + "GPU Device ID": hip.hipDeviceGetPCIBusId(STRINGLENGTH, i)[1], |
| 26 | + "GPU Name": i, |
| 27 | + "GPU compute capability": f"{hip.hipDeviceComputeCapability(i)[1]}.{hip.hipDeviceComputeCapability(i)[2]}", |
| 28 | + "ROCM driver version": f"{hip.hipDriverGetVersion()[1]}", |
| 29 | + "ROCM runtime version": hip.hipRuntimeGetVersion()[1], |
| 30 | + "Global memory (GiB)": hip.hipDeviceTotalMem(i)[1] / 1_073_741_824, |
| 31 | + "Max clock rate": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeClockRate), i)[1] / 1000} MHz", |
| 32 | + "Total amount of shared memory per block (Bytes)": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxSharedMemoryPerBlock), i)[1]}", |
| 33 | + "Total number of registers available per block (Bytes)": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxRegistersPerBlock), i)[1]}", |
| 34 | + "Warp size": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeWarpSize), i)[1]}", |
| 35 | + "Maximum number of threads per multiprocessor": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxThreadsPerMultiProcessor), i)[1]}", |
| 36 | + "Maximum number of threads per block": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxThreadsPerBlock), i)[1]}", |
| 37 | + "Max dimension size of a thread block X": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxBlockDimX), i)[1]}", |
| 38 | + "Max dimension size of a thread block Y": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxBlockDimY), i)[1]}", |
| 39 | + "Max dimension size of a thread block Z": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxBlockDimZ), i)[1]}", |
| 40 | + "Max dimension size of a grid size X": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxGridDimX), i)[1]}", |
| 41 | + "Max dimension size of a grid size Y": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxGridDimY), i)[1]}", |
| 42 | + "Max dimension size of a grid size Z": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxGridDimZ), i)[1]}", |
| 43 | + } |
| 44 | + all_gpu_info.append(gpu_info) |
| 45 | + |
| 46 | + return all_gpu_info |
| 47 | + |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + gpu_info_list = get_gpu_info() |
| 51 | + with open("tmp-run.out", "w") as f: |
| 52 | + for idx, gpu_info in enumerate(gpu_info_list): |
| 53 | + print(f"GPU {idx}:") |
| 54 | + for key, value in gpu_info.items(): |
| 55 | + f.write(f"{key}: {value}\n") |
0 commit comments