Skip to content

Commit 3a60122

Browse files
authored
Merge branch 'main' into mlperf-inference
2 parents 8312e33 + 6521889 commit 3a60122

File tree

7 files changed

+186
-1
lines changed

7 files changed

+186
-1
lines changed

Diff for: script/get-rocm-devices/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Run this script
2+
```
3+
cm run script --tags=get,rocm-devices
4+
```

Diff for: script/get-rocm-devices/_cm.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
alias: get-rocm-devices
2+
uid: c618239543364753
3+
4+
automation_alias: script
5+
automation_uid: 5b4e0237da074764
6+
7+
tags:
8+
- get
9+
- rocm-devices
10+
11+
cache: false
12+
13+
can_force_cache: true
14+
15+
category: ROCM automation
16+
17+
clean_files:
18+
- tmp-run.out
19+
docker:
20+
run: false
21+
all_gpus: 'yes'
22+
skip_run_cmd: 'no'
23+
skip_cm_sys_upgrade: 'yes'
24+
cm_repo_flags: '--checkout=dev'
25+
use_host_group_id: 'yes'
26+
image_tag_extra: '-cm-dev'
27+
28+
print_files_if_script_error:
29+
- tmp-run.out

Diff for: script/get-rocm-devices/customize.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from cmind import utils
2+
import os
3+
import subprocess
4+
5+
def preprocess(i):
6+
7+
env = i['env']
8+
9+
if str(env.get('CM_DETECT_USING_HIP-PYTHON', '')).lower() in [ "1", "yes", "true"]:
10+
i['run_script_input']['script_name'] = 'detect'
11+
12+
return {'return':0}
13+
14+
def postprocess(i):
15+
16+
env = i['env']
17+
state = i['state']
18+
19+
os_info = i['os_info']
20+
21+
r = utils.load_txt(file_name='tmp-run.out',
22+
check_if_exists = True,
23+
split = True)
24+
if r['return']>0: return r
25+
26+
lst = r['list']
27+
28+
# properties
29+
p = {}
30+
gpu = {}
31+
32+
gpu_id = -1
33+
34+
for line in lst:
35+
#print (line)
36+
37+
j = line.find(':')
38+
39+
if j>=0:
40+
key = line[:j].strip()
41+
val = line[j+1:].strip()
42+
43+
if key == "GPU Device ID":
44+
gpu_id+=1
45+
gpu[gpu_id] = {}
46+
47+
if gpu_id < 0:
48+
continue
49+
50+
gpu[gpu_id][key] = val
51+
p[key] = val
52+
53+
key_env = 'CM_ROCM_DEVICE_PROP_'+key.upper().replace(' ','_')
54+
env[key_env] = val
55+
56+
state['cm_rocm_num_devices'] = gpu_id + 1
57+
env['CM_ROCM_NUM_DEVICES'] = gpu_id + 1
58+
59+
state['cm_rocm_device_prop'] = p
60+
state['cm_rocm_devices_prop'] = gpu
61+
62+
return {'return':0}

Diff for: script/get-rocm-devices/detect.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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")

Diff for: script/get-rocm-devices/detect.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
${CM_PYTHON_BIN_WITH_PATH} ${CM_TMP_CURRENT_SCRIPT_PATH}/detect.py
4+
test $? -eq 0 || exit $?

Diff for: script/get-rocm-devices/run.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Compile
4+
5+
rm a.out
6+
7+
# Check if hip-python is installed
8+
echo ""
9+
echo "Checking if hip-python is installed..."
10+
echo ""
11+
12+
if ! python3 -m pip show hip-python > /dev/null 2>&1; then
13+
echo "hip-python not found. Installing hip-python..."
14+
python3 -m pip install --extra-index-url https://test.pypi.org/simple hip-python
15+
if [ $? -ne 0 ]; then
16+
echo "Failed to install hip-python. Please check your Python environment."
17+
exit 1
18+
fi
19+
else
20+
echo "hip-python is already installed."
21+
fi
22+
23+
echo ""
24+
echo "Running program ..."
25+
echo ""
26+
27+
cd ${CM_TMP_CURRENT_PATH}
28+
29+
python ${CM_TMP_CURRENT_SCRIPT_PATH}/detect.py > tmp-run.out
30+
cat tmp-run.out
31+
test $? -eq 0 || exit 1

Diff for: script/get-tensorrt/customize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def preprocess(i):
100100
my_tar.close()
101101

102102
import re
103-
version_match = re.match(r'TensorRT-(\d+.\d+.\d+.\d+)', folder_name)
103+
version_match = re.match(r'TensorRT-(\d+\.\d+\.\d+\.\d+)', folder_name)
104104
if not version_match:
105105
return {'return': 1, 'error': 'Extracted TensorRT folder does not seem proper - Version information missing'}
106106
version = version_match.group(1)

0 commit comments

Comments
 (0)