2024-09-06 14:03:54 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
output_dir=$1
|
|
|
|
sleep_time=$2
|
|
|
|
print_to_screen=$3
|
|
|
|
|
2024-09-18 17:14:01 +08:00
|
|
|
output_file_path="${output_dir}/npu_status_$(date +"%Y%m%d%H%M%S").json"
|
|
|
|
device_cnt=$(npu-smi info | grep '910B1' | wc -l)
|
2024-09-06 14:03:54 +08:00
|
|
|
|
2024-09-11 10:02:59 +08:00
|
|
|
|
|
|
|
get_power_dissipation() {
|
|
|
|
local npu_id="$1"
|
2024-09-18 17:14:01 +08:00
|
|
|
power_dissipation=$(npu-smi info -t power -i ${npu_id} | grep "NPU Real-time Power(W)" | awk '{print $5}')
|
2024-09-11 10:02:59 +08:00
|
|
|
echo "${power_dissipation}"
|
|
|
|
}
|
|
|
|
|
|
|
|
get_mem_usage() {
|
2024-09-18 17:14:01 +08:00
|
|
|
local npu_id="$1"
|
|
|
|
mem_usage=$(npu-smi info -t usages -i ${npu_id} | grep "HBM Usage Rate(%)" | awk '{print $5}')
|
2024-09-11 10:02:59 +08:00
|
|
|
echo "${mem_usage}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-06 14:03:54 +08:00
|
|
|
|
2024-09-13 14:46:38 +08:00
|
|
|
|
|
|
|
for i in {1..1500}
|
|
|
|
do
|
2024-09-06 14:03:54 +08:00
|
|
|
device_mem_usage=""
|
|
|
|
for ((i=0; i<device_cnt; i++)); do
|
2024-09-18 17:14:01 +08:00
|
|
|
mem_usage=$(get_mem_usage ${i})
|
2024-09-18 17:31:11 +08:00
|
|
|
# echo "${mem_usage}"
|
2024-09-18 17:14:01 +08:00
|
|
|
device_mem_usage="${device_mem_usage}{\"npu_id\": ${i}, \"mem_usage_percent\": ${mem_usage}}, "
|
2024-09-18 17:31:11 +08:00
|
|
|
# echo "${device_mem_usage}"
|
2024-09-06 14:03:54 +08:00
|
|
|
done
|
|
|
|
device_mem_usage="${device_mem_usage%??}"
|
2024-09-18 17:31:11 +08:00
|
|
|
# echo "${device_mem_usage}"
|
|
|
|
|
2024-09-06 14:03:54 +08:00
|
|
|
npu_power_dissipation=""
|
2024-09-18 17:14:01 +08:00
|
|
|
for ((i=0; i<device_cnt; i++)); do
|
|
|
|
power_dissipation=$(get_power_dissipation ${i})
|
|
|
|
npu_power_dissipation="${npu_power_dissipation}{\"npu_id\": ${i}, \"power_dissipation\": ${power_dissipation}}, "
|
2024-09-06 14:03:54 +08:00
|
|
|
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}]}"
|
2024-09-11 11:20:31 +08:00
|
|
|
echo "$json" >> ${output_file_path}
|
2024-09-11 10:02:59 +08:00
|
|
|
sleep "${sleep_time}"
|
2024-09-06 14:03:54 +08:00
|
|
|
|
|
|
|
if [ "$print_to_screen" -eq "1" ]; then
|
|
|
|
echo "$json"
|
|
|
|
fi
|
|
|
|
done
|