hcu_info.sh 2.45 KB
Newer Older
liumg's avatar
liumg committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash

# Define the command variable
cmd="/opt/hyhal/bin/hy-smi"

# Function to display usage
usage() {
    echo "Usage: $0 [-d device_id]"
    echo "  -d device_id : Get information for specific HCU (integer), default: 0"
    exit 1
}

# Check if hy-smi command is available and working
if ! $cmd >/dev/null 2>&1; then
    echo "no driver online"
    exit 1
fi

# Initialize variables
device_id="0"

# Parse command line options
while getopts "d:h" opt; do
    case $opt in
        d)
            if [[ $OPTARG =~ [0-7] ]]; then
                device_id=$OPTARG
            else
                echo "Error: Device ID must be an integer"
                usage
            fi
            ;;
        h)
            usage
            ;;
        \?)
            usage
            ;;
    esac
done


# Function to get PCI bus number for a specific device
get_pci_bus() {
    local dev_id=$1
    local bus_output
    bus_output=$($cmd --showbus -d $dev_id 2>/dev/null)
    
    # Extract PCI Bus number from the output
    if [[ -n "$bus_output" ]]; then
	pci_bus=$(echo "$bus_output"  --showbus -d 0 | grep 'PCI Bus:' | awk -F ' ' '{print $5}')
    else
        pci_bus="N/A"
    fi
    
    echo "$pci_bus"
}

# Function to parse and format GPU info from hy-smi output
format_gpu_info() {
    local dev_id=$1

    pci_bus=$(get_pci_bus $dev_id)
    
    # Extract values using awk or grep
    model=$($cmd --showproductname -d $device_id | grep  'Card Series' | sed 's/.*Card Series:[[:space:]]*//')
    irq=$(more /sys/bus/pci/devices/$pci_bus/irq)
    hcu_sn=$($cmd --showuniqueid -d $device_id | grep  'Unique ID' | sed 's/.*Unique ID:[[:space:]]*//')
    hcu_uuid=$($cmd --showserial -d $device_id | grep  'Serial Number' | sed 's/.*Serial Number:[[:space:]]*//')
    vbios=$($cmd -v -d $device_id | grep  'VBIOS version' | sed 's/.*VBIOS version:[[:space:]]*//')
    dma_size=$(more  /sys/bus/pci/devices/$pci_bus/dma_mask_bits)
    bus_location=$pci_bus
    gpu_mem=$(more /sys/bus/pci/devices/$pci_bus/mem_info_vram_vendor)
    
    # Format output
    printf "%-15s: %s\n" "Model" "$model"
    printf "%-15s: %s\n" "IRQ" "$irq"
    printf "%-15s: %s\n" "HCU_SN" "$hcu_sn"
    printf "%-15s: %s\n" "HCU_UUID" "$hcu_uuid"
    printf "%-15s: %s\n" "VBIOS" "$vbios"
    printf "%-15s: %s\n" "DMA_Size" "$dma_size"
    printf "%-15s: %s\n" "Bus_Location" "$bus_location"
    printf "%-15s: %s\n" "HCU_Firmware" "$vbios"
    printf "%-15s: %s\n" "HCU_Mem_Vendor" "$gpu_mem"
}


format_gpu_info $device_id