diff --git a/script/get-rocm-devices/README.md b/script/get-rocm-devices/README.md new file mode 100644 index 000000000..7b1f4474c --- /dev/null +++ b/script/get-rocm-devices/README.md @@ -0,0 +1,4 @@ +Run this script +``` +cm run script --tags=get,rocm-devices +``` diff --git a/script/get-rocm-devices/_cm.yaml b/script/get-rocm-devices/_cm.yaml new file mode 100644 index 000000000..21a91b373 --- /dev/null +++ b/script/get-rocm-devices/_cm.yaml @@ -0,0 +1,29 @@ +alias: get-rocm-devices +uid: c618239543364753 + +automation_alias: script +automation_uid: 5b4e0237da074764 + +tags: +- get +- rocm-devices + +cache: false + +can_force_cache: true + +category: ROCM automation + +clean_files: +- tmp-run.out +docker: + run: false + all_gpus: 'yes' + skip_run_cmd: 'no' + skip_cm_sys_upgrade: 'yes' + cm_repo_flags: '--checkout=dev' + use_host_group_id: 'yes' + image_tag_extra: '-cm-dev' + +print_files_if_script_error: +- tmp-run.out diff --git a/script/get-rocm-devices/customize.py b/script/get-rocm-devices/customize.py new file mode 100644 index 000000000..06020b464 --- /dev/null +++ b/script/get-rocm-devices/customize.py @@ -0,0 +1,62 @@ +from cmind import utils +import os +import subprocess + +def preprocess(i): + + env = i['env'] + + if str(env.get('CM_DETECT_USING_HIP-PYTHON', '')).lower() in [ "1", "yes", "true"]: + i['run_script_input']['script_name'] = 'detect' + + return {'return':0} + +def postprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + r = utils.load_txt(file_name='tmp-run.out', + check_if_exists = True, + split = True) + if r['return']>0: return r + + lst = r['list'] + + # properties + p = {} + gpu = {} + + gpu_id = -1 + + for line in lst: + #print (line) + + j = line.find(':') + + if j>=0: + key = line[:j].strip() + val = line[j+1:].strip() + + if key == "GPU Device ID": + gpu_id+=1 + gpu[gpu_id] = {} + + if gpu_id < 0: + continue + + gpu[gpu_id][key] = val + p[key] = val + + key_env = 'CM_ROCM_DEVICE_PROP_'+key.upper().replace(' ','_') + env[key_env] = val + + state['cm_rocm_num_devices'] = gpu_id + 1 + env['CM_ROCM_NUM_DEVICES'] = gpu_id + 1 + + state['cm_rocm_device_prop'] = p + state['cm_rocm_devices_prop'] = gpu + + return {'return':0} diff --git a/script/get-rocm-devices/detect.py b/script/get-rocm-devices/detect.py new file mode 100644 index 000000000..8029f0444 --- /dev/null +++ b/script/get-rocm-devices/detect.py @@ -0,0 +1,55 @@ +from hip import hip + +# Defining the value for hipDeviceGetAttribute +STRINGLENGTH = 256 +hipDeviceAttributeClockRate = 5 +hipDeviceAttributeMaxBlockDimX = 26 +hipDeviceAttributeMaxBlockDimY = 27 +hipDeviceAttributeMaxBlockDimZ = 28 +hipDeviceAttributeMaxGridDimX = 29 +hipDeviceAttributeMaxGridDimY = 30 +hipDeviceAttributeMaxGridDimZ = 31 +hipDeviceAttributeMaxThreadsPerBlock = 56 +hipDeviceAttributeMaxThreadsPerMultiProcessor = 57 +hipDeviceAttributeMaxRegistersPerBlock = 71 +hipDeviceAttributeMaxSharedMemoryPerBlock = 74 +hipDeviceAttributeWarpSize = 87 + + +def get_gpu_info(): + num_gpus = hip.hipGetDeviceCount()[1] + all_gpu_info = [] + + for i in range(num_gpus): + gpu_info = { + "GPU Device ID": hip.hipDeviceGetPCIBusId(STRINGLENGTH, i)[1], + "GPU Name": i, + "GPU compute capability": f"{hip.hipDeviceComputeCapability(i)[1]}.{hip.hipDeviceComputeCapability(i)[2]}", + "ROCM driver version": f"{hip.hipDriverGetVersion()[1]}", + "ROCM runtime version": hip.hipRuntimeGetVersion()[1], + "Global memory (GiB)": hip.hipDeviceTotalMem(i)[1] / 1_073_741_824, + "Max clock rate": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeClockRate), i)[1] / 1000} MHz", + "Total amount of shared memory per block (Bytes)": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxSharedMemoryPerBlock), i)[1]}", + "Total number of registers available per block (Bytes)": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxRegistersPerBlock), i)[1]}", + "Warp size": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeWarpSize), i)[1]}", + "Maximum number of threads per multiprocessor": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxThreadsPerMultiProcessor), i)[1]}", + "Maximum number of threads per block": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxThreadsPerBlock), i)[1]}", + "Max dimension size of a thread block X": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxBlockDimX), i)[1]}", + "Max dimension size of a thread block Y": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxBlockDimY), i)[1]}", + "Max dimension size of a thread block Z": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxBlockDimZ), i)[1]}", + "Max dimension size of a grid size X": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxGridDimX), i)[1]}", + "Max dimension size of a grid size Y": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxGridDimY), i)[1]}", + "Max dimension size of a grid size Z": f"{hip.hipDeviceGetAttribute(hip.hipDeviceAttribute_t(hipDeviceAttributeMaxGridDimZ), i)[1]}", + } + all_gpu_info.append(gpu_info) + + return all_gpu_info + + +if __name__ == "__main__": + gpu_info_list = get_gpu_info() + with open("tmp-run.out", "w") as f: + for idx, gpu_info in enumerate(gpu_info_list): + print(f"GPU {idx}:") + for key, value in gpu_info.items(): + f.write(f"{key}: {value}\n") diff --git a/script/get-rocm-devices/detect.sh b/script/get-rocm-devices/detect.sh new file mode 100644 index 000000000..8f6b93596 --- /dev/null +++ b/script/get-rocm-devices/detect.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +${CM_PYTHON_BIN_WITH_PATH} ${CM_TMP_CURRENT_SCRIPT_PATH}/detect.py +test $? -eq 0 || exit $? diff --git a/script/get-rocm-devices/run.sh b/script/get-rocm-devices/run.sh new file mode 100644 index 000000000..7b4fa0386 --- /dev/null +++ b/script/get-rocm-devices/run.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Compile + +rm a.out + +# Check if hip-python is installed +echo "" +echo "Checking if hip-python is installed..." +echo "" + +if ! python3 -m pip show hip-python > /dev/null 2>&1; then + echo "hip-python not found. Installing hip-python..." + python3 -m pip install --extra-index-url https://test.pypi.org/simple hip-python + if [ $? -ne 0 ]; then + echo "Failed to install hip-python. Please check your Python environment." + exit 1 + fi +else + echo "hip-python is already installed." +fi + +echo "" +echo "Running program ..." +echo "" + +cd ${CM_TMP_CURRENT_PATH} + +python ${CM_TMP_CURRENT_SCRIPT_PATH}/detect.py > tmp-run.out +cat tmp-run.out +test $? -eq 0 || exit 1 diff --git a/script/get-tensorrt/customize.py b/script/get-tensorrt/customize.py index 25e5a1f58..57b2497ef 100644 --- a/script/get-tensorrt/customize.py +++ b/script/get-tensorrt/customize.py @@ -100,7 +100,7 @@ def preprocess(i): my_tar.close() import re - version_match = re.match(r'TensorRT-(\d+.\d+.\d+.\d+)', folder_name) + version_match = re.match(r'TensorRT-(\d+\.\d+\.\d+\.\d+)', folder_name) if not version_match: return {'return': 1, 'error': 'Extracted TensorRT folder does not seem proper - Version information missing'} version = version_match.group(1)