forked from mlcommons/cm4mlops
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mlperf-inference
- Loading branch information
Showing
7 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Run this script | ||
``` | ||
cm run script --tags=get,rocm-devices | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
${CM_PYTHON_BIN_WITH_PATH} ${CM_TMP_CURRENT_SCRIPT_PATH}/detect.py | ||
test $? -eq 0 || exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters