-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobilenet_v2.cpp
2155 lines (1712 loc) · 60.4 KB
/
mobilenet_v2.cpp
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <assert.h>
#include "cnntype.h"
#include "dnnsimd.h"
extern "C" {
#include "mobilenet_v2_mdl.h"
};
// #include "openclL2.h"
// #include "kernelcl.h"
// #include "dnnlibcl.h"
#include "tictoc.h"
#ifdef __MATLAB__
#include "mex.h"
#include "mexparams.h"
#endif
#define MOBILENET_1_4 (14)
#define MOBILENET_1_0 (10)
// extern "C" void * _aligned_malloc(size_t s, size_t align)
// {
// return aligned_alloc(align, s);
// }
//
// extern "C" void _aligned_free(void *p)
// {
// free(p);
// }
cnn_type_t zbuf[1024 * 1024] = {0};
cnn_type_t obuf[1024 * 1024] = {0};
class MobileNetV2
{
public:
/* dimension parameters */
int M, N, C;
int M1a;
int N1a;
int C1a;
int M1e;
int N1e;
int C1e;
int M1p;
int N1p;
int C1p;
/////
int M2e;
int N2e;
int C2e;
int M2d;
int N2d;
int C2d;
int M2p;
int N2p;
int C2p;
/////
int M3e;
int N3e;
int C3e;
int M3d;
int N3d;
int C3d;
int M3p;
int N3p;
int C3p;
/////
int M3s;
int N3s;
int C3s;
/////
int M4e;
int N4e;
int C4e;
int M4d;
int N4d;
int C4d;
int M4p;
int N4p;
int C4p;
/////
int M5e;
int N5e;
int C5e;
int M5d;
int N5d;
int C5d;
int M5p;
int N5p;
int C5p;
/////
int M5s;
int N5s;
int C5s;
/////
int M6e;
int N6e;
int C6e;
int M6d;
int N6d;
int C6d;
int M6p;
int N6p;
int C6p;
/////
int M6s;
int N6s;
int C6s;
/////
int M7e;
int N7e;
int C7e;
int M7d;
int N7d;
int C7d;
int M7p;
int N7p;
int C7p;
/////
int M8e;
int N8e;
int C8e;
int M8d;
int N8d;
int C8d;
int M8p;
int N8p;
int C8p;
/////
int M8s;
int N8s;
int C8s;
/////
int M9e;
int N9e;
int C9e;
int M9d;
int N9d;
int C9d;
int M9p;
int N9p;
int C9p;
/////
int M9s;
int N9s;
int C9s;
/////
int M10e;
int N10e;
int C10e;
int M10d;
int N10d;
int C10d;
int M10p;
int N10p;
int C10p;
/////
int M10s;
int N10s;
int C10s;
/////
int M11e;
int N11e;
int C11e;
int M11d;
int N11d;
int C11d;
int M11p;
int N11p;
int C11p;
/////
int M12e;
int N12e;
int C12e;
int M12d;
int N12d;
int C12d;
int M12p;
int N12p;
int C12p;
/////
int M12s;
int N12s;
int C12s;
/////
int M13e;
int N13e;
int C13e;
int M13d;
int N13d;
int C13d;
int M13p;
int N13p;
int C13p;
/////
int M13s;
int N13s;
int C13s;
/////
int M14e;
int N14e;
int C14e;
int M14d;
int N14d;
int C14d;
int M14p;
int N14p;
int C14p;
/////
int M15e;
int N15e;
int C15e;
int M15d;
int N15d;
int C15d;
int M15p;
int N15p;
int C15p;
/////
int M15s;
int N15s;
int C15s;
/////
int M16e;
int N16e;
int C16e;
int M16d;
int N16d;
int C16d;
int M16p;
int N16p;
int C16p;
/////
int M16s;
int N16s;
int C16s;
/////
int M17e;
int N17e;
int C17e;
int M17d;
int N17d;
int C17d;
int M17p;
int N17p;
int C17p;
/////
int M18a;
int N18a;
int C18a;
cnn_type_t * Y1a;
cnn_type_t * Y1e;
cnn_type_t * Y1p;
cnn_type_t * Y2e;
cnn_type_t * Y2d;
cnn_type_t * Y2p;
cnn_type_t * Y3e;
cnn_type_t * Y3d;
cnn_type_t * Y3p;
cnn_type_t * Y3s;
cnn_type_t * Y4e;
cnn_type_t * Y4d;
cnn_type_t * Y4p;
cnn_type_t * Y5e;
cnn_type_t * Y5d;
cnn_type_t * Y5p;
cnn_type_t * Y5s;
cnn_type_t * Y6e;
cnn_type_t * Y6d;
cnn_type_t * Y6p;
cnn_type_t * Y6s;
cnn_type_t * Y7e;
cnn_type_t * Y7d;
cnn_type_t * Y7p;
cnn_type_t * Y8e;
cnn_type_t * Y8d;
cnn_type_t * Y8p;
cnn_type_t * Y8s;
cnn_type_t * Y9e;
cnn_type_t * Y9d;
cnn_type_t * Y9p;
cnn_type_t * Y9s;
cnn_type_t * Y10e;
cnn_type_t * Y10d;
cnn_type_t * Y10p;
cnn_type_t * Y10s;
cnn_type_t * Y11e;
cnn_type_t * Y11d;
cnn_type_t * Y11p;
cnn_type_t * Y12e;
cnn_type_t * Y12d;
cnn_type_t * Y12p;
cnn_type_t * Y12s;
cnn_type_t * Y13e;
cnn_type_t * Y13d;
cnn_type_t * Y13p;
cnn_type_t * Y13s;
cnn_type_t * Y14e;
cnn_type_t * Y14d;
cnn_type_t * Y14p;
cnn_type_t * Y15e;
cnn_type_t * Y15d;
cnn_type_t * Y15p;
cnn_type_t * Y15s;
cnn_type_t * Y16e;
cnn_type_t * Y16d;
cnn_type_t * Y16p;
cnn_type_t * Y16s;
cnn_type_t * Y17e;
cnn_type_t * Y17d;
cnn_type_t * Y17p;
cnn_type_t * Y18a;
cnn_type_t * Y19a;
public:
int Initialize(int M, int N, int C, int mode);
cnn_type_t * Run(const cnn_type_t * pX);
int Deinitialize();
void range(cnn_type_t * pX, int M, int N, int C);
};
int MobileNetV2::Initialize(int M0, int N0, int C0, int depth_mode)
{
/* dimension parameters */
M = M0;
N = N0;
C = C0;
M1a = M / 2;
N1a = N / 2;
C1a = (depth_mode == MOBILENET_1_4) ? ( 48) : ( 32);
M1e = M1a;
N1e = N1a;
C1e = C1a;
M1p = M1e;
N1p = N1e;
C1p = (depth_mode == MOBILENET_1_4) ? ( 24) : ( 16);
/////
M2e = M1p;
N2e = N1p;
C2e = (depth_mode == MOBILENET_1_4) ? (144) : ( 96);
M2d = M2e / 2;
N2d = N2e / 2;
C2d = C2e;
M2p = M2d;
N2p = N2d;
C2p = (depth_mode == MOBILENET_1_4) ? ( 32) : ( 24);
/////
M3e = M2p;
N3e = N2p;
C3e = (depth_mode == MOBILENET_1_4) ? (192) : (144);
M3d = M3e;
N3d = N3e;
C3d = C3e;
M3p = M3d;
N3p = N3d;
C3p = (depth_mode == MOBILENET_1_4) ? ( 32) : ( 24);
/////
M3s = M3p;
N3s = N3p;
C3s = C3p;
/////
M4e = M3p;
N4e = N3p;
C4e = (depth_mode == MOBILENET_1_4) ? (192) : (144);
M4d = M4e / 2;
N4d = N4e / 2;
C4d = C4e;
M4p = M4d;
N4p = N4d;
C4p = (depth_mode == MOBILENET_1_4) ? ( 48) : ( 32);
/////
M5e = M4p;
N5e = N4p;
C5e = (depth_mode == MOBILENET_1_4) ? (288) : (192);
M5d = M5e;
N5d = N5e;
C5d = C5e;
M5p = M5d;
N5p = N5d;
C5p = (depth_mode == MOBILENET_1_4) ? ( 48) : ( 32);
/////
M5s = M5p;
N5s = N5p;
C5s = C5p;
/////
M6e = M5p;
N6e = N5p;
C6e = (depth_mode == MOBILENET_1_4) ? (288) : (192);
M6d = M6e;
N6d = N6e;
C6d = C6e;
M6p = M6d;
N6p = N6d;
C6p = (depth_mode == MOBILENET_1_4) ? ( 48) : ( 32);
/////
M6s = M6p;
N6s = N6p;
C6s = C6p;
/////
M7e = M6s;
N7e = N6s;
C7e = (depth_mode == MOBILENET_1_4) ? (288) : (192);
M7d = M7e / 2;
N7d = N7e / 2;
C7d = C7e;
M7p = M7d;
N7p = N7d;
C7p = (depth_mode == MOBILENET_1_4) ? ( 88) : ( 64);
/////
M8e = M7p;
N8e = N7p;
C8e = (depth_mode == MOBILENET_1_4) ? (528) : (384);
M8d = M8e;
N8d = N8e;
C8d = C8e;
M8p = M8d;
N8p = N8d;
C8p = (depth_mode == MOBILENET_1_4) ? ( 88) : ( 64);
/////
M8s = M8p;
N8s = N8p;
C8s = C8p;
/////
M9e = M8p;
N9e = N8p;
C9e = (depth_mode == MOBILENET_1_4) ? (528) : (384);
M9d = M9e;
N9d = N9e;
C9d = C9e;
M9p = M9d;
N9p = N9d;
C9p = (depth_mode == MOBILENET_1_4) ? ( 88) : ( 64);
/////
M9s = M9p;
N9s = N9p;
C9s = C9p;
/////
M10e = M9p;
N10e = N9p;
C10e = (depth_mode == MOBILENET_1_4) ? (528) : (384);
M10d = M10e;
N10d = N10e;
C10d = C10e;
M10p = M10d;
N10p = N10d;
C10p = (depth_mode == MOBILENET_1_4) ? ( 88) : ( 64);
/////
M10s = M10p;
N10s = N10p;
C10s = C10p;
/////
M11e = M10p;
N11e = N10p;
C11e = (depth_mode == MOBILENET_1_4) ? ( 528) : ( 384);
M11d = M11e;
N11d = N11e;
C11d = C11e;
M11p = M11d;
N11p = N11d;
C11p = (depth_mode == MOBILENET_1_4) ? ( 136) : ( 96);
/////
M12e = M11p;
N12e = N11p;
C12e = (depth_mode == MOBILENET_1_4) ? ( 816) : ( 576);
M12d = M12e;
N12d = N12e;
C12d = C12e;
M12p = M12d;
N12p = N12d;
C12p = (depth_mode == MOBILENET_1_4) ? ( 136) : ( 96);
/////
M12s = M12p;
N12s = N12p;
C12s = C12p;
/////
M13e = M12p;
N13e = N12p;
C13e = (depth_mode == MOBILENET_1_4) ? ( 816) : ( 576);
M13d = M12e;
N13d = N12e;
C13d = C12e;
M13p = M13d;
N13p = N13d;
C13p = (depth_mode == MOBILENET_1_4) ? ( 136) : ( 96);
/////
M13s = M13p;
N13s = N13p;
C13s = C13p;
/////
M14e = M13p;
N14e = N13p;
C14e = (depth_mode == MOBILENET_1_4) ? ( 816) : ( 576);
M14d = M14e / 2;
N14d = N14e / 2;
C14d = C14e;
M14p = M14d;
N14p = N14d;
C14p = (depth_mode == MOBILENET_1_4) ? ( 224) : ( 160);
/////
M15e = M14p;
N15e = N14p;
C15e = (depth_mode == MOBILENET_1_4) ? (1344) : ( 960);
M15d = M15e;
N15d = N15e;
C15d = C15e;
M15p = M15d;
N15p = N15d;
C15p = (depth_mode == MOBILENET_1_4) ? ( 224) : ( 160);
/////
M15s = M15p;
N15s = N15p;
C15s = C15p;
/////
M16e = M15p;
N16e = N15p;
C16e = (depth_mode == MOBILENET_1_4) ? (1344) : ( 960);
M16d = M16e;
N16d = N16e;
C16d = C16e;
M16p = M16d;
N16p = N16d;
C16p = (depth_mode == MOBILENET_1_4) ? ( 224) : ( 160);
/////
M16s = M16p;
N16s = N16p;
C16s = C16p;
/////
M17e = M16p;
N17e = N16p;
C17e = (depth_mode == MOBILENET_1_4) ? (1344) : ( 960);
M17d = M17e;
N17d = N17e;
C17d = C17e;
M17p = M17d;
N17p = N17d;
C17p = (depth_mode == MOBILENET_1_4) ? ( 448) : ( 320);
/////
M18a = M17p;
N18a = N17p;
C18a = (depth_mode == MOBILENET_1_4) ? (1792) : (1280);
Y1a = (cnn_type_t *)_aligned_malloc(M1a * N1a * C1a * sizeof(cnn_type_t), 16);
Y1e = (cnn_type_t *)_aligned_malloc(M1e * N1e * C1e * sizeof(cnn_type_t), 16);
Y1p = (cnn_type_t *)_aligned_malloc(M1p * N1p * C1p * sizeof(cnn_type_t), 16);
Y2e = (cnn_type_t *)_aligned_malloc(M2e * N2e * C2e * sizeof(cnn_type_t), 16);
Y2d = (cnn_type_t *)_aligned_malloc(M2d * N2d * C2d * sizeof(cnn_type_t), 16);
Y2p = (cnn_type_t *)_aligned_malloc(M2p * N2p * C2p * sizeof(cnn_type_t), 16);
Y3e = (cnn_type_t *)_aligned_malloc(M3e * N3e * C3e * sizeof(cnn_type_t), 16);
Y3d = (cnn_type_t *)_aligned_malloc(M3d * N3d * C3d * sizeof(cnn_type_t), 16);
Y3p = (cnn_type_t *)_aligned_malloc(M3p * N3p * C3p * sizeof(cnn_type_t), 16);
Y3s = (cnn_type_t *)_aligned_malloc(M3s * N3s * C3s * sizeof(cnn_type_t), 16);
Y4e = (cnn_type_t *)_aligned_malloc(M4e * N4e * C4e * sizeof(cnn_type_t), 16);
Y4d = (cnn_type_t *)_aligned_malloc(M4d * N4d * C4d * sizeof(cnn_type_t), 16);
Y4p = (cnn_type_t *)_aligned_malloc(M4p * N4p * C4p * sizeof(cnn_type_t), 16);
Y5e = (cnn_type_t *)_aligned_malloc(M5e * N5e * C5e * sizeof(cnn_type_t), 16);
Y5d = (cnn_type_t *)_aligned_malloc(M5d * N5d * C5d * sizeof(cnn_type_t), 16);
Y5p = (cnn_type_t *)_aligned_malloc(M5p * N5p * C5p * sizeof(cnn_type_t), 16);
Y5s = (cnn_type_t *)_aligned_malloc(M5s * N5s * C5s * sizeof(cnn_type_t), 16);
Y6e = (cnn_type_t *)_aligned_malloc(M6e * N6e * C6e * sizeof(cnn_type_t), 16);
Y6d = (cnn_type_t *)_aligned_malloc(M6d * N6d * C6d * sizeof(cnn_type_t), 16);
Y6p = (cnn_type_t *)_aligned_malloc(M6p * N6p * C6p * sizeof(cnn_type_t), 16);
Y6s = (cnn_type_t *)_aligned_malloc(M6s * N6s * C6s * sizeof(cnn_type_t), 16);
Y7e = (cnn_type_t *)_aligned_malloc(M7e * N7e * C7e * sizeof(cnn_type_t), 16);
Y7d = (cnn_type_t *)_aligned_malloc(M7d * N7d * C7d * sizeof(cnn_type_t), 16);
Y7p = (cnn_type_t *)_aligned_malloc(M7p * N7p * C7p * sizeof(cnn_type_t), 16);
Y8e = (cnn_type_t *)_aligned_malloc(M8e * N8e * C8e * sizeof(cnn_type_t), 16);
Y8d = (cnn_type_t *)_aligned_malloc(M8d * N8d * C8d * sizeof(cnn_type_t), 16);
Y8p = (cnn_type_t *)_aligned_malloc(M8p * N8p * C8p * sizeof(cnn_type_t), 16);
Y8s = (cnn_type_t *)_aligned_malloc(M8s * N8s * C8s * sizeof(cnn_type_t), 16);
Y9e = (cnn_type_t *)_aligned_malloc(M9e * N9e * C9e * sizeof(cnn_type_t), 16);
Y9d = (cnn_type_t *)_aligned_malloc(M9d * N9d * C9d * sizeof(cnn_type_t), 16);
Y9p = (cnn_type_t *)_aligned_malloc(M9p * N9p * C9p * sizeof(cnn_type_t), 16);
Y9s = (cnn_type_t *)_aligned_malloc(M9s * N9s * C9s * sizeof(cnn_type_t), 16);
Y10e = (cnn_type_t *)_aligned_malloc(M10e * N10e * C10e * sizeof(cnn_type_t), 16);
Y10d = (cnn_type_t *)_aligned_malloc(M10d * N10d * C10d * sizeof(cnn_type_t), 16);
Y10p = (cnn_type_t *)_aligned_malloc(M10p * N10p * C10p * sizeof(cnn_type_t), 16);
Y10s = (cnn_type_t *)_aligned_malloc(M10s * N10s * C10s * sizeof(cnn_type_t), 16);
Y11e = (cnn_type_t *)_aligned_malloc(M11e * N11e * C11e * sizeof(cnn_type_t), 16);
Y11d = (cnn_type_t *)_aligned_malloc(M11d * N11d * C11d * sizeof(cnn_type_t), 16);
Y11p = (cnn_type_t *)_aligned_malloc(M11p * N11p * C11p * sizeof(cnn_type_t), 16);
Y12e = (cnn_type_t *)_aligned_malloc(M12e * N12e * C12e * sizeof(cnn_type_t), 16);
Y12d = (cnn_type_t *)_aligned_malloc(M12d * N12d * C12d * sizeof(cnn_type_t), 16);
Y12p = (cnn_type_t *)_aligned_malloc(M12p * N12p * C12p * sizeof(cnn_type_t), 16);
Y12s = (cnn_type_t *)_aligned_malloc(M12s * N12s * C12s * sizeof(cnn_type_t), 16);
Y13e = (cnn_type_t *)_aligned_malloc(M13e * N13e * C13e * sizeof(cnn_type_t), 16);
Y13d = (cnn_type_t *)_aligned_malloc(M13d * N13d * C13d * sizeof(cnn_type_t), 16);
Y13p = (cnn_type_t *)_aligned_malloc(M13p * N13p * C13p * sizeof(cnn_type_t), 16);
Y13s = (cnn_type_t *)_aligned_malloc(M13s * N13s * C13s * sizeof(cnn_type_t), 16);
Y14e = (cnn_type_t *)_aligned_malloc(M14e * N14e * C14e * sizeof(cnn_type_t), 16);
Y14d = (cnn_type_t *)_aligned_malloc(M14d * N14d * C14d * sizeof(cnn_type_t), 16);
Y14p = (cnn_type_t *)_aligned_malloc(M14p * N14p * C14p * sizeof(cnn_type_t), 16);
Y15e = (cnn_type_t *)_aligned_malloc(M15e * N15e * C15e * sizeof(cnn_type_t), 16);
Y15d = (cnn_type_t *)_aligned_malloc(M15d * N15d * C15d * sizeof(cnn_type_t), 16);
Y15p = (cnn_type_t *)_aligned_malloc(M15p * N15p * C15p * sizeof(cnn_type_t), 16);
Y15s = (cnn_type_t *)_aligned_malloc(M15s * N15s * C15s * sizeof(cnn_type_t), 16);
Y16e = (cnn_type_t *)_aligned_malloc(M16e * N16e * C16e * sizeof(cnn_type_t), 16);
Y16d = (cnn_type_t *)_aligned_malloc(M16d * N16d * C16d * sizeof(cnn_type_t), 16);
Y16p = (cnn_type_t *)_aligned_malloc(M16p * N16p * C16p * sizeof(cnn_type_t), 16);
Y16s = (cnn_type_t *)_aligned_malloc(M16s * N16s * C16s * sizeof(cnn_type_t), 16);
Y17e = (cnn_type_t *)_aligned_malloc(M17e * N17e * C17e * sizeof(cnn_type_t), 16);
Y17d = (cnn_type_t *)_aligned_malloc(M17d * N17d * C17d * sizeof(cnn_type_t), 16);
Y17p = (cnn_type_t *)_aligned_malloc(M17p * N17p * C17p * sizeof(cnn_type_t), 16);
Y18a = (cnn_type_t *)_aligned_malloc(M18a * N18a * C18a * sizeof(cnn_type_t), 16);
Y19a = (cnn_type_t *)_aligned_malloc( 1 * 1 * C18a * sizeof(cnn_type_t), 16);
return (0);
}
int MobileNetV2::Deinitialize()
{
_aligned_free(Y1a);
_aligned_free(Y1e);
_aligned_free(Y1p);
_aligned_free(Y2e);
_aligned_free(Y2d);
_aligned_free(Y2p);
_aligned_free(Y3e);
_aligned_free(Y3d);
_aligned_free(Y3p);
_aligned_free(Y3s);
_aligned_free(Y4e);
_aligned_free(Y4d);
_aligned_free(Y4p);
_aligned_free(Y5e);
_aligned_free(Y5d);
_aligned_free(Y5p);
_aligned_free(Y5s);
_aligned_free(Y6e);
_aligned_free(Y6d);
_aligned_free(Y6p);
_aligned_free(Y6s);
_aligned_free(Y7e);
_aligned_free(Y7d);
_aligned_free(Y7p);
_aligned_free(Y8e);
_aligned_free(Y8d);
_aligned_free(Y8p);
_aligned_free(Y8s);
_aligned_free(Y9e);
_aligned_free(Y9d);
_aligned_free(Y9p);
_aligned_free(Y9s);
_aligned_free(Y10e);
_aligned_free(Y10d);
_aligned_free(Y10p);
_aligned_free(Y10s);
_aligned_free(Y11e);
_aligned_free(Y11d);
_aligned_free(Y11p);
_aligned_free(Y12e);
_aligned_free(Y12d);
_aligned_free(Y12p);
_aligned_free(Y12s);
_aligned_free(Y13e);
_aligned_free(Y13d);
_aligned_free(Y13p);
_aligned_free(Y13s);
_aligned_free(Y14e);
_aligned_free(Y14d);
_aligned_free(Y14p);
_aligned_free(Y15e);
_aligned_free(Y15d);
_aligned_free(Y15p);
_aligned_free(Y15s);
_aligned_free(Y16e);
_aligned_free(Y16d);
_aligned_free(Y16p);
_aligned_free(Y16s);
_aligned_free(Y17e);
_aligned_free(Y17d);
_aligned_free(Y17p);
_aligned_free(Y18a);
_aligned_free(Y19a);
return (0);
}
void mobilenet_avg7x7(
int C,
cnn_type_t * __px,
cnn_type_t * __py
)
{
cnn_type_t * _px = __px; // builtin_assume_aligned(__px, 16);
cnn_type_t * _py = __py; // builtin_assume_aligned(__py, 16);
/* S - 1 */
addpool(C, _px + C * 0, _px + C * 48, (cnn_type_t *)(_px + C * 0));
addpool(C, _px + C * 1, _px + C * 47, (cnn_type_t *)(_px + C * 1));
addpool(C, _px + C * 2, _px + C * 46, (cnn_type_t *)(_px + C * 2));
addpool(C, _px + C * 3, _px + C * 45, (cnn_type_t *)(_px + C * 3));
addpool(C, _px + C * 4, _px + C * 44, (cnn_type_t *)(_px + C * 4));
addpool(C, _px + C * 5, _px + C * 43, (cnn_type_t *)(_px + C * 5));
addpool(C, _px + C * 6, _px + C * 42, (cnn_type_t *)(_px + C * 6));
addpool(C, _px + C * 7, _px + C * 41, (cnn_type_t *)(_px + C * 7));
addpool(C, _px + C * 8, _px + C * 40, (cnn_type_t *)(_px + C * 8));
addpool(C, _px + C * 9, _px + C * 39, (cnn_type_t *)(_px + C * 9));
addpool(C, _px + C * 10, _px + C * 38, (cnn_type_t *)(_px + C * 10));
addpool(C, _px + C * 11, _px + C * 37, (cnn_type_t *)(_px + C * 11));
addpool(C, _px + C * 12, _px + C * 36, (cnn_type_t *)(_px + C * 12));
addpool(C, _px + C * 13, _px + C * 35, (cnn_type_t *)(_px + C * 13));
addpool(C, _px + C * 14, _px + C * 34, (cnn_type_t *)(_px + C * 14));
addpool(C, _px + C * 15, _px + C * 33, (cnn_type_t *)(_px + C * 15));
addpool(C, _px + C * 16, _px + C * 32, (cnn_type_t *)(_px + C * 16));
addpool(C, _px + C * 17, _px + C * 31, (cnn_type_t *)(_px + C * 17));
addpool(C, _px + C * 18, _px + C * 30, (cnn_type_t *)(_px + C * 18));
addpool(C, _px + C * 19, _px + C * 29, (cnn_type_t *)(_px + C * 19));
addpool(C, _px + C * 20, _px + C * 28, (cnn_type_t *)(_px + C * 20));
addpool(C, _px + C * 21, _px + C * 27, (cnn_type_t *)(_px + C * 21));
addpool(C, _px + C * 22, _px + C * 26, (cnn_type_t *)(_px + C * 22));
addpool(C, _px + C * 23, _px + C * 25, (cnn_type_t *)(_px + C * 23));
/* S - 2 */
addpool(C, _px + C * 0, _px + C * 24, (cnn_type_t *)(_px + C * 0));
addpool(C, _px + C * 1, _px + C * 23, (cnn_type_t *)(_px + C * 1));
addpool(C, _px + C * 2, _px + C * 22, (cnn_type_t *)(_px + C * 2));
addpool(C, _px + C * 3, _px + C * 21, (cnn_type_t *)(_px + C * 3));
addpool(C, _px + C * 4, _px + C * 20, (cnn_type_t *)(_px + C * 4));
addpool(C, _px + C * 5, _px + C * 19, (cnn_type_t *)(_px + C * 5));
addpool(C, _px + C * 6, _px + C * 18, (cnn_type_t *)(_px + C * 6));
addpool(C, _px + C * 7, _px + C * 17, (cnn_type_t *)(_px + C * 7));
addpool(C, _px + C * 8, _px + C * 16, (cnn_type_t *)(_px + C * 8));
addpool(C, _px + C * 9, _px + C * 15, (cnn_type_t *)(_px + C * 9));
addpool(C, _px + C * 10, _px + C * 14, (cnn_type_t *)(_px + C * 10));
addpool(C, _px + C * 11, _px + C * 13, (cnn_type_t *)(_px + C * 11));
/* S - 3 */
addpool(C, _px + C * 0, _px + C * 12, (cnn_type_t *)(_px + C * 0));
addpool(C, _px + C * 1, _px + C * 11, (cnn_type_t *)(_px + C * 1));
addpool(C, _px + C * 2, _px + C * 10, (cnn_type_t *)(_px + C * 2));
addpool(C, _px + C * 3, _px + C * 9, (cnn_type_t *)(_px + C * 3));
addpool(C, _px + C * 4, _px + C * 8, (cnn_type_t *)(_px + C * 4));
addpool(C, _px + C * 5, _px + C * 7, (cnn_type_t *)(_px + C * 5));
/* S - 4 */
addpool(C, _px + C * 0, _px + C * 6, (cnn_type_t *)(_px + C * 0));
addpool(C, _px + C * 1, _px + C * 5, (cnn_type_t *)(_px + C * 1));
addpool(C, _px + C * 2, _px + C * 4, (cnn_type_t *)(_px + C * 2));
/* S - 5 */
addpool(C, _px + C * 0, _px + C * 3, (cnn_type_t *)(_px + C * 0));
addpool(C, _px + C * 1, _px + C * 2, (cnn_type_t *)(_px + C * 1));
/* S - 6 */
addpool(C, _px + C * 0, _px + C * 1, (cnn_type_t *)(_py + C * 0));
}
void MobileNetV2::range(
cnn_type_t * prX,
int M, int N, int C
)
{
cnn_type_t fmin = +999.0;
cnn_type_t fmax = -999.0;
for (int i = 0; i < M * N * C; i++)
{
cnn_type_t f = *prX++;
fmin = (f < fmin) ? (f) : (fmin);
fmax = (f > fmax) ? (f) : (fmax);
}
// printf("(fmin, fmax) = (%9.2f, %9.2f).\n", fmin, fmax);
}
cnn_type_t * MobileNetV2::Run(
const cnn_type_t * prX
)
{
/* ********************************************************************** *
* conv2d_3x3, stride = 2, same *
* ********************************************************************** */
conv3x3_p1s2_bnrelu_inp(
M, N,
4, C1a,
prX,
w1a,
mu_1a,
var_1a,
beta_1a,
6.0,
Y1a
);
/* ********************************************************************** *
* depthwise, conv2d_3x3, stride = 1, same *
* ********************************************************************** */
dw_conv3x3_p1s1_bnrelu(
M1a, N1a,
C1a, C1e,
Y1a,
w1e,
mu_1e,
var_1e,
beta_1e,
6.0,
Y1e
);
/* ********************************************************************** *
* conv2d_1x1, stride = 1, same *
* ********************************************************************** */