62 lines
1.7 KiB
Bash
62 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# bash npu_status_310p.sh . 60 1
|
|
|
|
output_dir=$1
|
|
sleep_time=$2
|
|
is_test=$3
|
|
|
|
output_file_path="${output_dir}/npu_status_$(date +"%Y%m%d%H%M%S").json"
|
|
device_cnt=$(npu-smi info | grep '310P3' | wc -l)
|
|
|
|
chip_id_arr_from_info=(0 1 0 1 0 1 0 1)
|
|
npu_id_arr=(0 96 32768 32896)
|
|
|
|
get_power_dissipation() {
|
|
local npu_id="$1"
|
|
power_dissipation=$(npu-smi info -t power -i ${npu_id} | grep "Power Dissipation(W)" | awk '{print $4}')
|
|
echo "${power_dissipation}"
|
|
}
|
|
|
|
get_mem_usage() {
|
|
local chip="$1"
|
|
local device="$2"
|
|
mem_usage=$(npu-smi info | grep "${chip} ${device}" | awk '{print $8}')
|
|
echo "${mem_usage}"
|
|
}
|
|
|
|
cycle_cnt=1500
|
|
if [ "$is_test" -eq "1" ]; then
|
|
cycle_cnt=5
|
|
sleep_time=10
|
|
fi
|
|
|
|
for ((cnt=1; cnt<=cycle_cnt; cnt++))
|
|
do
|
|
device_mem_usage=""
|
|
for ((i=0; i<device_cnt; i++)); do
|
|
mem_usage=$(get_mem_usage ${chip_id_arr_from_info[i]} ${i})
|
|
device_mem_usage="${device_mem_usage}{\"device_id\": ${i}, \"mem_usage_percent\": ${mem_usage}}, "
|
|
# echo "${device_mem_usage}"
|
|
done
|
|
device_mem_usage="${device_mem_usage%??}"
|
|
# echo "${device_mem_usage}"
|
|
|
|
npu_power_dissipation=""
|
|
for npu_id in "${npu_id_arr[@]}"; do
|
|
power_dissipation=$(get_power_dissipation ${npu_id})
|
|
npu_power_dissipation="${npu_power_dissipation}{\"npu_id\": ${npu_id}, \"power_dissipation\": ${power_dissipation}}, "
|
|
done
|
|
npu_power_dissipation="${npu_power_dissipation%??}"
|
|
|
|
cur_time=$(date +"%Y-%m-%d %H:%M:%S")
|
|
|
|
json="{\"cur_time\": \"${cur_time}\", \"npu_power_dissipation\": [${npu_power_dissipation}], \"device_mem_usage\": [${device_mem_usage}]}"
|
|
echo "$json" >> ${output_file_path}
|
|
sleep "${sleep_time}"
|
|
|
|
if [ "$is_test" -eq "1" ]; then
|
|
echo "$json"
|
|
fi
|
|
done
|