forked from open-edge-platform/edge-ai-suites
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_start.sh
More file actions
executable file
·167 lines (153 loc) · 4.08 KB
/
sample_start.sh
File metadata and controls
executable file
·167 lines (153 loc) · 4.08 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
DLSPS_NODE_IP="localhost"
function run_sample() {
pipelines=$1
device=$2
interval=10
if [ $device == "GPU" ]; then
pipeline_name="yolov11s_gpu"
elif [ $device == "NPU" ]; then
pipeline_name="yolov11s_npu"
else
pipeline_name="yolov11s"
fi
pipeline_list=()
echo
echo -n ">>>>>Initialization..."
for x in $(seq 1 $pipelines); do
payload=$(cat <<EOF
{
"source": {
"uri": "file:///home/pipeline-server/videos/new_video_$x.mp4",
"type": "uri"
},
"destination": {
"metadata": {
"type": "mqtt",
"topic": "object_detection_$x",
"publish_frame":false
},
"frame": {
"type": "webrtc",
"peer-id": "object_detection_$x"
}
}
}
EOF
)
response=$(curl -k -s "https://$DLSPS_NODE_IP/api/pipelines/user_defined_pipelines/${pipeline_name}" -X POST -H "Content-Type: application/json" -d "$payload")
if [ $? -ne 0 ]; then
echo -e "\nError: curl -k command failed. Check the deployment status."
return 1
fi
sleep 2
pipeline_list+=("$response")
done
running=false
while [ "$running" != true ]; do
status=$(curl -k -s --location -X GET "https://$DLSPS_NODE_IP/api/pipelines/status" | grep state | awk ' { print $2 } ' | tr -d \")
if [[ "$status" == *"QUEUED"* ]]; then
running=false
echo -n "."
sleep 1
else
running=true
echo -n "Pipelines initialized."
echo
fi
done
}
function stop_all_pipelines() {
echo
echo -n ">>>>>Stopping all running pipelines."
status=$(curl -k -s -X GET "https://$DLSPS_NODE_IP/api/pipelines/status" -H "accept: application/json")
if [ $? -ne 0 ]; then
echo -e "\nError: curl -k command failed. Check the deployment status."
return 1
fi
pipelines=$(echo $status | grep -o '"id": "[^"]*"' | awk ' { print $2 } ' | tr -d \" | paste -sd ',' - )
IFS=','
for pipeline in $pipelines; do
response=$(curl -k -s --location -X DELETE "https://$DLSPS_NODE_IP/api/pipelines/${pipeline}")
sleep 2
done
unset IFS
running=true
while [ "$running" == true ]; do
echo -n "."
status=$(curl -k -s --location -X GET "https://$DLSPS_NODE_IP/api/pipelines/status" | grep state | awk ' { print $2 } ' | tr -d \")
if [[ "$status" == *"RUNNING"* ]]; then
running=true
sleep 2
else
running=false
fi
done
echo -n " done."
echo
return 0
}
forcedCPU=false
forcedGPU=false
forcedNPU=false
for arg in "$@"; do
if [ "$arg" == "cpu" ]; then
forcedCPU=true
forcedGPU=false
forcedNPU=false
elif [ "$arg" == "gpu" ]; then
forcedCPU=false
forcedGPU=true
forcedNPU=false
elif [ "$arg" == "npu" ]; then
forcedCPU=false
forcedGPU=false
forcedNPU=true
else
echo "Unknown argument '$arg', defaulting to CPU"
forcedCPU=true
forcedGPU=false
forcedNPU=false
fi
done
# If no arguments provided, default to CPU
if [ $# -eq 0 ]; then
echo "No device selected, defaulting to CPU"
forcedCPU=true
fi
stop_all_pipelines
if [ $? -ne 0 ]; then
exit 1
fi
# Check if any render device exists
if $forcedGPU; then
if ls /dev/dri/renderD* 1> /dev/null 2>&1; then
echo -e "\n>>>>>GPU device selected."
run_sample 4 GPU
if [ $? -ne 0 ]; then
exit 1
fi
else
echo -e "\n>>>>>No GPU device found. Please check your GPU driver installation or use CPU."
exit 0
fi
elif $forcedNPU; then
if ls /dev/accel/accel* 1> /dev/null 2>&1; then
echo -e "\n>>>>>NPU device selected."
run_sample 4 NPU
if [ $? -ne 0 ]; then
exit 1
fi
else
echo -e "\n>>>>>No NPU device found. Please check your NPU driver installation or use CPU."
exit 0
fi
elif $forcedCPU; then
echo -e "\n>>>>>CPU device selected."
run_sample 4 CPU
if [ $? -ne 0 ]; then
exit 1
fi
fi
echo -e "\n>>>>>Results are visualized in Grafana at 'https://localhost/grafana' "
echo -e "\n>>>>>Pipelines status can be checked with 'curl -k --location -X GET https://localhost/api/pipelines/status' or using script 'sample_status.sh'. \n"