• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <sys/ioctl.h>
25 
26 #include "sdk.h"
27 #include "securec.h"
28 #include "sample_nnie_main.h"
29 
30 static char **s_ppChCmdArgv = NULL;
31 
32 /* function : to process abnormal case */
33 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
SAMPLE_SVP_HandleSig(int s32Signo)34 static void SAMPLE_SVP_HandleSig(int s32Signo)
35 {
36     if (s32Signo == SIGINT || s32Signo == SIGTERM) {
37         switch (*s_ppChCmdArgv[1]) {
38             case '0':
39                 SAMPLE_SVP_NNIE_Rfcn_HandleSig();
40                 break;
41             case '1':
42                 SAMPLE_SVP_NNIE_Segnet_HandleSig();
43                 break;
44             case '2':
45                 SAMPLE_SVP_NNIE_FasterRcnn_HandleSig();
46                 break;
47             case '3':
48                 SAMPLE_SVP_NNIE_FasterRcnn_HandleSig();
49                 break;
50             case '4':
51                 SAMPLE_SVP_NNIE_Cnn_HandleSig();
52                 break;
53             case '5':
54                 SAMPLE_SVP_NNIE_Ssd_HandleSig();
55                 break;
56             case '6':
57                 SAMPLE_SVP_NNIE_Yolov1_HandleSig();
58                 break;
59             case '7':
60                 SAMPLE_SVP_NNIE_Yolov2_HandleSig();
61                 break;
62             case '8':
63                 SAMPLE_SVP_NNIE_Yolov3_HandleSig();
64                 break;
65             case '9':
66                 SAMPLE_SVP_NNIE_Lstm_HandleSig();
67                 break;
68             case 'a':
69                 SAMPLE_SVP_NNIE_Pvanet_HandleSig();
70                 break;
71             case 'b':
72                 SAMPLE_SVP_NNIE_Rfcn_HandleSig_File();
73                 break;
74             default:
75                 break;
76         }
77     }
78 }
79 #endif
80 
81 /* function : show usage */
SAMPLE_SVP_Usage(const char * pchPrgName)82 static void SAMPLE_SVP_Usage(const char *pchPrgName)
83 {
84     printf("Usage : %s <index> \n", pchPrgName);
85     printf("index:\n");
86     printf("\t 0) RFCN(VI->VPSS->NNIE->VGS->VO).\n");
87     printf("\t 1) Segnet(Read File).\n");
88     printf("\t 2) FasterRcnnAlexnet(Read File).\n");
89     printf("\t 3) FasterRcnnDoubleRoiPooling(Read File).\n");
90     printf("\t 4) Cnn(Read File).\n");
91     printf("\t 5) SSD(Read File).\n");
92     printf("\t 6) Yolov1(Read File).\n");
93     printf("\t 7) Yolov2(Read File).\n");
94     printf("\t 8) Yolov3(Read File).\n");
95     printf("\t 9) LSTM(Read File).\n");
96     printf("\t a) Pvanet(Read File).\n");
97     printf("\t b) Rfcn(Read File).\n");
98 }
99 
100 /* function : nnie sample */
101 #if defined(__HuaweiLite__) && (!defined(__OHOS__))
app_main(int argc,char * argv[])102 int app_main(int argc, char *argv[])
103 #else
104 int main(int argc, char *argv[])
105 #endif
106 {
107     int s32Ret = HI_SUCCESS;
108     sdk_init();
109     s_ppChCmdArgv = argv;
110 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
111     struct sigaction sa;
112     (hi_void)memset_s(&sa, sizeof(struct sigaction), 0, sizeof(struct sigaction));
113     sa.sa_handler = SAMPLE_SVP_HandleSig;
114     sa.sa_flags = 0;
115     sigaction(SIGINT, &sa, NULL);
116     sigaction(SIGTERM, &sa, NULL);
117 #endif
118     if (argc < 2 || argc > 2) { /* only support 2 parameters */
119         SAMPLE_SVP_Usage(argv[0]);
120         s32Ret = HI_FAILURE;
121         goto end;
122     }
123 
124     if (strncmp(argv[1], "-h", 2) == 0) { /* 2: maximum number of characters to compare */
125         SAMPLE_SVP_Usage(argv[0]);
126         s32Ret = HI_SUCCESS;
127         goto end;
128     }
129     switch (*argv[1]) {
130         case '0':
131             SAMPLE_SVP_NNIE_Rfcn();
132             break;
133         case '1':
134             SAMPLE_SVP_NNIE_Segnet();
135             break;
136         case '2':
137             SAMPLE_SVP_NNIE_FasterRcnn();
138             break;
139         case '3':
140             SAMPLE_SVP_NNIE_FasterRcnn_DoubleRoiPooling();
141             break;
142         case '4':
143             SAMPLE_SVP_NNIE_Cnn();
144             break;
145         case '5':
146             SAMPLE_SVP_NNIE_Ssd();
147             break;
148         case '6':
149             SAMPLE_SVP_NNIE_Yolov1();
150             break;
151         case '7':
152             SAMPLE_SVP_NNIE_Yolov2();
153             break;
154         case '8':
155             SAMPLE_SVP_NNIE_Yolov3();
156             break;
157         case '9':
158             SAMPLE_SVP_NNIE_Lstm();
159             break;
160         case 'a':
161             SAMPLE_SVP_NNIE_Pvanet();
162             break;
163         case 'b':
164             SAMPLE_SVP_NNIE_Rfcn_File();
165             break;
166         default:
167             SAMPLE_SVP_Usage(argv[0]);
168             break;
169     }
170 
171 end:
172     sdk_exit();
173     return s32Ret;
174 }
175