@@ -38,6 +38,11 @@ classification/imagenet_inception_v2_classification_5.tflite -i \
3838classification/dog.jpg -l classification/labels.txt -c 1 -b 0 -s 255 -t 1
3939# label: Blenheim spaniel with probability 11.0233 有bug
4040
41+ qemu-riscv64 classification/tflite_classification_arm -m \
42+ classification/imagenet_inception_v3_classification_5.tflite -i \
43+ classification/dog.jpg -l classification/labels.txt -c 1 -b 0 -s 255 -t 1
44+ # label: Blenheim spaniel with probability 22.116
45+
4146qemu-riscv64 classification/tflite_classification -m \
4247classification/imagenet_resnet_v1_50_classification_5.tflite -i \
4348classification/dog.jpg -l classification/labels.txt -c 1 -b 0 -s 255 -t 1
@@ -131,21 +136,27 @@ void DisplayFrames(char *display_win, int input_source, Mat &show_image,
131136void display_usage () {
132137std:
133138 cout << " tflite_classification\n "
134- << " --tflite_model, -m: model_name.tflite\n "
135- << " --input_src, -r: [0|1|2] input source: image 0, video 1, camera 2\n "
139+ << " --frame_cnt, -c: the number of frames to be used\n "
136140 << " --input_path, -i: path of the input image/video or video port for "
137141 " camera, e.g., 1 for /dev/video1\n "
138142 << " --labels, -l: labels for the model\n "
139- << " --frame_cnt, -c: the number of frames to be used\n "
143+ << " --tflite_model, -m: model_name.tflite\n "
144+ << " --profiling, -p: [0|1], profiling or not\n "
145+ << " --input_src, -r: [0|1|2] input source: image 0, video 1, camera 2\n "
140146 << " --input_mean, -b: input mean\n "
141147 << " --input_std, -s: input standard deviation\n "
142- << " --profiling, -p: [0|1], profiling or not\n "
143148 << " --threads, -t: number of threads\n "
149+ << " --feature_copy, -f: feature copy to tcm\n "
150+ << " --weight_copy, -w: weight copy to tcm\n "
151+ << " --profile, -d: profile all layer\n "
152+ << " --conv_profile, -P: profile convlution\n "
153+ << " --freq, -F: cpu freq MHz\n "
154+ << " --affinity, -a: process affinity\n "
155+ << " --only_conv, -C: only run convlution\n "
156+ << " --only_misc, -M: only run other op except convlution\n "
144157 << " \n " ;
145158}
146159
147- #ifdef MEM_PROFILE
148- 149160#ifdef __cplusplus
150161extern " C" {
151162#endif
@@ -154,12 +165,23 @@ extern size_t packed_feature_in_byte;
154165
155166extern size_t packed_weight_access_in_byte;
156167extern size_t packed_feature_access_in_byte;
168+ 169+ extern bool PROFILE;
170+ extern bool CONV_PROFILE;
171+ 172+ extern long FREQ;
173+ 174+ extern bool FEA_CPY2TCM;
175+ extern bool FILTER_CPY2TCM;
176+ 177+ extern bool ONLY_CONV;
178+ extern bool ONLY_MISC;
179+ 180+ extern long ELAPSEDTIME;
157181#ifdef __cplusplus
158182}
159183#endif
160184
161- #endif
162- 163185// (input - mean) / std
164186/*
165187 * Main function
@@ -180,30 +202,35 @@ int main(int argc, char **argv) {
180202 while (1 ) {
181203 static struct option long_options[] = {
182204 {" frame_cnt" , required_argument, nullptr , ' c' },
183- {" input_src" , required_argument, nullptr , ' r' },
184205 {" input_path" , required_argument, nullptr , ' i' },
185206 {" labels" , required_argument, nullptr , ' l' },
186207 {" tflite_model" , required_argument, nullptr , ' m' },
187208 {" profiling" , required_argument, nullptr , ' p' },
188- {" threads " , required_argument, nullptr , ' t ' },
209+ {" input_src " , required_argument, nullptr , ' r ' },
189210 {" input_mean" , required_argument, nullptr , ' b' },
190211 {" input_std" , required_argument, nullptr , ' s' },
212+ {" threads" , required_argument, nullptr , ' t' },
213+ {" feature_copy" , required_argument, nullptr , ' f' },
214+ {" weight_copy" , required_argument, nullptr , ' w' },
215+ {" profile" , required_argument, nullptr , ' d' },
216+ {" conv_profile" , required_argument, nullptr , ' P' },
217+ {" freq" , required_argument, nullptr , ' F' },
218+ {" affinity" , required_argument, nullptr , ' a' },
219+ {" only_conv" , required_argument, nullptr , ' C' },
220+ {" only_misc" , required_argument, nullptr , ' M' },
191221 {nullptr , 0 , nullptr , 0 }};
192222
193223 /* getopt_long stores the option index here. */
194224 int option_index = 0 ;
195225
196- c = getopt_long (argc, argv, " b: c:i:l:m:p:r:s:t:h " , long_options ,
197- &option_index);
226+ c = getopt_long (argc, argv, " c:i:l:m:p:r:b: s:t:f:w:d:P:F:a:C:M:h " ,
227+ long_options, &option_index);
198228
199229 /* Detect the end of the options. */
200230 if (c == -1 )
201231 break ;
202232
203233 switch (c) {
204- case ' b' :
205- input_mean = strtod (optarg, nullptr );
206- break ;
207234 case ' c' :
208235 frame_cnt = strtol (optarg, nullptr , 10 );
209236 break ;
@@ -222,12 +249,57 @@ int main(int argc, char **argv) {
222249 case ' r' :
223250 input_source = (eInputType)strtol (optarg, nullptr , 10 );
224251 break ;
252+ case ' b' :
253+ input_mean = strtod (optarg, nullptr );
254+ break ;
225255 case ' s' :
226256 input_std = strtod (optarg, nullptr );
227257 break ;
228258 case ' t' :
229259 num_threads = strtol (optarg, nullptr , 10 );
230260 break ;
261+ case ' f' :
262+ FEA_CPY2TCM = strtol (optarg, nullptr , 10 );
263+ break ;
264+ case ' w' :
265+ FILTER_CPY2TCM = strtol (optarg, nullptr , 10 );
266+ break ;
267+ case ' d' :
268+ PROFILE = strtol (optarg, nullptr , 10 );
269+ break ;
270+ case ' P' :
271+ CONV_PROFILE = strtol (optarg, nullptr , 10 );
272+ break ;
273+ case ' F' :
274+ FREQ = strtol (optarg, nullptr , 10 );
275+ break ;
276+ case ' a' : {
277+ char *core_id_str = strtok (optarg, " ," );
278+ cpu_set_t mask;
279+ CPU_ZERO (&mask);
280+ while (core_id_str) {
281+ long core_id = strtol (core_id_str, nullptr , 10 );
282+ if (core_id > -1 ) {
283+ CPU_SET (core_id, &mask);
284+ fprintf (stderr, " set affinity to %d!\n " , core_id);
285+ } else {
286+ fprintf (stderr, " noaffinity set!\n " );
287+ }
288+ core_id_str = strtok (NULL , " ," );
289+ }
290+ int result = sched_setaffinity (0 , sizeof (mask), &mask);
291+ if (result == 0 ) {
292+ fprintf (stderr, " set process affinity suc!\n " );
293+ } else {
294+ fprintf (stderr, " set process affinity err %d!\n " , result);
295+ }
296+ } break ;
297+ case ' C' :
298+ ONLY_CONV = strtol (optarg, nullptr , 10 );
299+ break ;
300+ case ' M' :
301+ ONLY_MISC = strtol (optarg, nullptr , 10 );
302+ break ;
231303 case ' h' :
232304 display_usage ();
233305 exit (-1 );
@@ -350,9 +422,10 @@ int main(int argc, char **argv) {
350422
351423 if (profiling) {
352424 std::cout << " Inference time for frame " << frame_index << " : "
353- << inference_time_ms << " ms" << std::endl;
425+ << inference_time_ms << " ms"
426+ << " XNNPACKrun: " << ELAPSEDTIME << " ms" << std::endl;
354427 }
355- 428+ ELAPSEDTIME = 0 ;
356429 // Report the inference output
357430 std::string last_label = " None" ;
358431 int argmax = -1 ;
0 commit comments