opencl_kernels_dnn.cpp
217 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
// This file is auto-generated. Do not edit!
#include "opencv2/core.hpp"
#include "cvconfig.h"
#include "opencl_kernels_dnn.hpp"
#ifdef HAVE_OPENCL
namespace cv
{
namespace ocl
{
namespace dnn
{
static const char* const moduleName = "dnn";
struct cv::ocl::internal::ProgramEntry activations_oclsrc={moduleName, "activations",
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#define KERNEL_ARG_DTYPE float\n"
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void ReLUForward(const int count, __global const T* in, __global T* out\n"
"#ifndef RELU_NO_SLOPE\n"
", KERNEL_ARG_DTYPE negative_slope\n"
"#endif\n"
") {\n"
"int index = get_global_id(0);\n"
"if(index < count)\n"
"#ifndef RELU_NO_SLOPE\n"
"out[index] = in[index] > 0 ? in[index] : in[index] * negative_slope;\n"
"#else\n"
"out[index] = in[index] > 0 ? in[index] : 0;\n"
"#endif\n"
"}\n"
"__kernel void ReLU6Forward(const int count, __global const T* in, __global T* out,\n"
"const KERNEL_ARG_DTYPE minValue, const KERNEL_ARG_DTYPE maxValue)\n"
"{\n"
"int index = get_global_id(0);\n"
"if(index < count)\n"
"{\n"
"T x = in[index];\n"
"out[index] = clamp(x, convert_T(minValue), convert_T(maxValue));\n"
"}\n"
"}\n"
"__kernel void PReLUForward(const int count, const int channels, const int plane_size,\n"
"__global const T* in, __global T* out,\n"
"__global const KERNEL_ARG_DTYPE* slope_data)\n"
"{\n"
"int index = get_global_id(0);\n"
"int c = (index / plane_size) % channels;\n"
"if(index < count)\n"
"out[index] = in[index] > 0 ? in[index] : in[index] * slope_data[c];\n"
"}\n"
"__kernel void TanHForward(const int count, __global T* in, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if(index < count)\n"
"out[index] = tanh(in[index]);\n"
"}\n"
"__kernel void SigmoidForward(const int count, __global const T* in, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if(index < count)\n"
"out[index] = 1.0f / (1.0f + exp(-in[index]));\n"
"}\n"
"__kernel void SwishForward(const int count, __global const T* in, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if(index < count)\n"
"out[index] = in[index] / (1.0f + exp(-in[index]));\n"
"}\n"
"__kernel void MishForward(const int count, __global const T* in, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if(index < count)\n"
"out[index] = in[index] * tanh(log(1.0f + exp(in[index])));\n"
"}\n"
"__kernel void BNLLForward(const int n, __global const T* in, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if (index < n) {\n"
"T x = in[index];\n"
"out[index] = x > 0 ? x + log(1.0f + exp(-x)) : log(1.0f + exp(x));\n"
"}\n"
"}\n"
"__kernel void AbsValForward(const int n, __global const T* in, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if (index < n)\n"
"out[index] = fabs(in[index]);\n"
"}\n"
"__kernel void PowForward(const int n, __global const T* in, __global T* out,\n"
"const KERNEL_ARG_DTYPE power,\n"
"const KERNEL_ARG_DTYPE scale,\n"
"const KERNEL_ARG_DTYPE shift)\n"
"{\n"
"int index = get_global_id(0);\n"
"if (index < n)\n"
"out[index] = pow(shift + scale * in[index], power);\n"
"}\n"
"__kernel void ELUForward(const int n, __global const T* in, __global T* out)\n"
"{\n"
"int index = get_global_id(0);\n"
"if (index < n)\n"
"{\n"
"T src = in[index];\n"
"out[index] = (src >= 0.f) ? src : exp(src) - 1;\n"
"}\n"
"}\n"
"__kernel void ExpForward(const int n, __global const T* in, __global T* out,\n"
"const KERNEL_ARG_DTYPE normScale,\n"
"const KERNEL_ARG_DTYPE normShift)\n"
"{\n"
"int index = get_global_id(0);\n"
"if (index < n)\n"
"{\n"
"out[index] = exp(normShift + normScale * in[index]);\n"
"}\n"
"}\n"
, "69e28bd964980d395339a63e2aabfe86", NULL};
struct cv::ocl::internal::ProgramEntry batchnorm_oclsrc={moduleName, "batchnorm",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#if NUM == 8\n"
"#define load(src, index) vload8(0, src + index)\n"
"#define store(vec, dst, index) vstore8(vec, 0, dst + index)\n"
"#define float_type float8\n"
"#define convert_f convert_float8\n"
"#define BATCH_NORM batch_norm8\n"
"#elif NUM == 4\n"
"#define load(src, index) vload4(0, src + index)\n"
"#define store(vec, dst, index) vstore4(vec, 0, dst + index)\n"
"#define float_type float4\n"
"#define convert_f convert_float4\n"
"#define BATCH_NORM batch_norm4\n"
"#elif NUM == 1\n"
"#define load(src, index) src[index]\n"
"#define store(vec, dst, index) dst[index] = vec\n"
"#define float_type float\n"
"#define convert_f convert_float\n"
"#define BATCH_NORM batch_norm1\n"
"#endif\n"
"__kernel void BATCH_NORM(__global const Dtype* src,\n"
"const int rows,\n"
"const int cols,\n"
"const int channels,\n"
"__global const float* weight,\n"
"__global const float* bias,\n"
"__global Dtype* dst)\n"
"{\n"
"int x = get_global_id(0);\n"
"int y = get_global_id(1) * NUM;\n"
"int index = x * cols + y;\n"
"if (x >= rows || y >= cols)\n"
"return;\n"
"float w = weight[x % channels];\n"
"float b = bias[x % channels];\n"
"float_type src_vec = convert_f(load(src, index));\n"
"float_type dst_vec = src_vec * w + (float_type)b;\n"
"store(convert_T(dst_vec), dst, index);\n"
"}\n"
, "c84913b518980a1dc7a4f1f41f7f95fc", NULL};
struct cv::ocl::internal::ProgramEntry col2im_oclsrc={moduleName, "col2im",
"__kernel void col2im(const int n, __global const T* data_col,\n"
"const int data_col_offset,\n"
"const int channels,\n"
"const int height, const int width,\n"
"const int height_col, const int width_col,\n"
"const int coeff_h, const int coeff_w,\n"
"__global const T* biasvec,\n"
"const int bias_offset,\n"
"__global T* data_im,\n"
"const int data_im_offset)\n"
"{\n"
"data_col = data_col + data_col_offset;\n"
"biasvec = biasvec + bias_offset;\n"
"data_im = data_im + data_im_offset;\n"
"int index = get_global_id(0);\n"
"if(index < n)\n"
"{\n"
"T val = 0.f;\n"
"int w = index % width + PAD_W;\n"
"int h = (index / width) % height + PAD_H;\n"
"int c = index / (width * height);\n"
"int h_col_start = (h < KERNEL_H) ? 0 : (h - KERNEL_H) / STRIDE_H + 1;\n"
"int h_col_end = min(h / STRIDE_H + 1, height_col);\n"
"int plane_size_col = height_col * width_col;\n"
"int offset = (c * KERNEL_H * KERNEL_W + h * KERNEL_W + w) * plane_size_col;\n"
"int w_col_start = (w < KERNEL_W) ? 0 : (w - KERNEL_W) / STRIDE_W + 1;\n"
"int w_col_end = min(w / STRIDE_W + 1, width_col);\n"
"for (int h_col = h_col_start; h_col < h_col_end; ++h_col)\n"
"for (int w_col = w_col_start; w_col < w_col_end; ++w_col)\n"
"val += data_col[offset + h_col * coeff_h + w_col * coeff_w];\n"
"data_im[index] = val + biasvec[c];\n"
"}\n"
"}\n"
, "ce817c6699c25771483253b686f98562", NULL};
struct cv::ocl::internal::ProgramEntry concat_oclsrc={moduleName, "concat",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"__kernel void TEMPLATE(concat, Dtype)(const int nthreads,\n"
"__global const Dtype* in_data,\n"
"const int num_concats,\n"
"const int concat_size,\n"
"const int top_concat_axis,\n"
"const int bottom_concat_axis,\n"
"const int offset_concat_axis,\n"
"__global Dtype* out_data)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))\n"
"{\n"
"const int total_concat_size = concat_size * bottom_concat_axis;\n"
"const int concat_num = index / total_concat_size;\n"
"const int concat_index = index % total_concat_size;\n"
"const int top_index = concat_index +\n"
"(concat_num * top_concat_axis + offset_concat_axis) * concat_size;\n"
"out_data[top_index] = in_data[index];\n"
"}\n"
"}\n"
, "504946fb5e8e715dcede68425e93486a", NULL};
struct cv::ocl::internal::ProgramEntry conv_layer_spatial_oclsrc={moduleName, "conv_layer_spatial",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define KERNEL_ARG_DTYPE float\n"
"#define TYPE_FLOAT 1\n"
"#define TYPE_HALF 2\n"
"#if defined(FUSED_CONV_RELU)\n"
"#define ACTIVATION_RELU_FUNCTION(x, c) ((Dtype)(x) > 0 ? (Dtype)(x) : ((Dtype)(x) * (negative_slope)))\n"
"#define FUSED_ARG KERNEL_ARG_DTYPE negative_slope,\n"
"#elif defined(FUSED_CONV_PRELU)\n"
"#define ACTIVATION_RELU_FUNCTION(x, c) ((Dtype)(x) > 0 ? (Dtype)(x) : ((Dtype)(x) * (negative_slope[c])))\n"
"#define FUSED_ARG __global const KERNEL_ARG_DTYPE* negative_slope,\n"
"#elif defined(FUSED_CONV_POWER)\n"
"#define ACTIVATION_RELU_FUNCTION(x, c) pow(x, (Dtype)power)\n"
"#define FUSED_ARG KERNEL_ARG_DTYPE power,\n"
"#elif defined(FUSED_CONV_TANH)\n"
"#define ACTIVATION_RELU_FUNCTION(x, c) tanh(x)\n"
"#define FUSED_ARG\n"
"#elif defined(FUSED_CONV_RELU6)\n"
"#define ACTIVATION_RELU_FUNCTION(x, c) (clamp((Dtype)(x), (Dtype)min_value, (Dtype)max_value))\n"
"#define FUSED_ARG KERNEL_ARG_DTYPE min_value, KERNEL_ARG_DTYPE max_value,\n"
"#else\n"
"#define ACTIVATION_RELU_FUNCTION(x, c) (x)\n"
"#define FUSED_ARG\n"
"#endif\n"
"#ifdef FUSED_CONV_ELTWISE\n"
"#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { \\\n"
"const Dtype _x_ = eltwise_data[(_offset_)] + (_data_); \\\n"
"(_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \\\n"
"} while(0)\n"
"#define ELTWISE_DATA_ARG __global Dtype* eltwise_data,\n"
"#define ELTWISE_DATA_ARG_WITH_OFFSET __global Dtype* eltwise_ptr, int eltwise_offset,\n"
"#else\n"
"#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { \\\n"
"const Dtype _x_ = (_data_); \\\n"
"(_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \\\n"
"} while(0)\n"
"#define ELTWISE_DATA_ARG\n"
"#define ELTWISE_DATA_ARG_WITH_OFFSET\n"
"#endif\n"
"#if APPLY_BIAS\n"
"#define BIAS_KERNEL_ARG __global Dtype * biases_base,\n"
"#define BIAS_KERNEL_ARG_WITH_OFFSET __global Dtype * biases_base_ptr, int biases_base_offset,\n"
"#else\n"
"#define BIAS_KERNEL_ARG\n"
"#define BIAS_KERNEL_ARG_WITH_OFFSET\n"
"#endif\n"
"#define __CAT(x, y) x##y\n"
"#define CAT(x, y) __CAT(x, y)\n"
"#define LOOP0(VAR, STMT)\n"
"#define LOOP1(VAR, STMT) (STMT); (VAR)++;\n"
"#define LOOP2(VAR, STMT) LOOP1(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP3(VAR, STMT) LOOP2(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP4(VAR, STMT) LOOP3(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP5(VAR, STMT) LOOP4(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP6(VAR, STMT) LOOP5(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP7(VAR, STMT) LOOP6(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP8(VAR, STMT) LOOP7(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP9(VAR, STMT) LOOP8(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP10(VAR, STMT) LOOP9(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP11(VAR, STMT) LOOP10(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP12(VAR, STMT) LOOP11(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP13(VAR, STMT) LOOP12(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP14(VAR, STMT) LOOP13(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP15(VAR, STMT) LOOP14(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP16(VAR, STMT) LOOP15(VAR, STMT); (STMT); (VAR)++;\n"
"#define LOOP(N, VAR, STMT) CAT(LOOP, N)((VAR), (STMT))\n"
"#if defined(convolve_simd) || defined(Conv_Interleaved)\n"
"#if TYPE == TYPE_HALF\n"
"#define INT_TYPE ushort\n"
"#define INT_TYPE2 ushort2\n"
"#define INT_TYPE4 ushort4\n"
"#define INT_TYPE8 ushort8\n"
"#define SUB_GROUP_BLOCK_READ2 intel_sub_group_block_read_us2\n"
"#define SUB_GROUP_BLOCK_READ4 intel_sub_group_block_read_us4\n"
"#define SUB_GROUP_BLOCK_READ8 intel_sub_group_block_read_us8\n"
"#define SUB_GROUP_BLOCK_READ intel_sub_group_block_read_us\n"
"#else\n"
"#define INT_TYPE uint\n"
"#define INT_TYPE2 uint2\n"
"#define INT_TYPE4 uint4\n"
"#define INT_TYPE8 uint8\n"
"#define SUB_GROUP_BLOCK_READ2 intel_sub_group_block_read2\n"
"#define SUB_GROUP_BLOCK_READ4 intel_sub_group_block_read4\n"
"#define SUB_GROUP_BLOCK_READ8 intel_sub_group_block_read8\n"
"#define SUB_GROUP_BLOCK_READ intel_sub_group_block_read\n"
"#endif\n"
"#endif\n"
"#ifdef KERNEL_BASIC\n"
"__kernel void ConvolveBasic(\n"
"ELTWISE_DATA_ARG\n"
"FUSED_ARG\n"
"__global Dtype* image_data,\n"
"int image_offset,\n"
"__global Dtype* kernel_data,\n"
"int kernel_offset,\n"
"__global Dtype* bias,\n"
"const int bias_offset,\n"
"__global Dtype* convolved_image_base,\n"
"const int convolved_image_base_offset,\n"
"const int convolved_image_offset,\n"
"const ushort input_width,\n"
"const ushort input_height,\n"
"const ushort output_width,\n"
"const ushort output_height,\n"
"const ushort pad_w,\n"
"const ushort pad_h\n"
")\n"
"{\n"
"__global Dtype* convolved_image = convolved_image_base + convolved_image_base_offset;\n"
"const int out_idx = get_global_id(0);\n"
"const int plane_size = output_width * output_height;\n"
"const int out_plane_idx = out_idx % plane_size;\n"
"const int outputZ = out_idx / plane_size;\n"
"const int outputY = out_plane_idx / output_width;\n"
"const int outputX = out_plane_idx % output_width;\n"
"if (outputZ < OUTPUT_Z)\n"
"{\n"
"Dtype sum = 0.0f;\n"
"const int org_y = outputY * STRIDE_Y - pad_h;\n"
"const int org_x = outputX * STRIDE_X - pad_w;\n"
"const int currentKernelOffset = kernel_offset + outputZ*KERNEL_HEIGHT*KERNEL_WIDTH*CHANNELS;\n"
"const int local_image_offset = org_y * input_width + org_x;\n"
"const int imageSize = input_width * input_height;\n"
"__global Dtype* image_dataPtr = (image_data + (image_offset + local_image_offset));\n"
"__global Dtype* kernel_dataPtr = (kernel_data + (currentKernelOffset));\n"
"for (int c = 0; c < CHANNELS; c++)\n"
"{\n"
"for (int y = 0; y < KERNEL_HEIGHT; y++)\n"
"{\n"
"int y_ = org_y + y * DILATION_Y;\n"
"for (int x = 0; x < KERNEL_WIDTH; x++)\n"
"{\n"
"int x_ = org_x + x * DILATION_X;\n"
"if (y_ >= 0 && y_ < input_height && x_ >= 0 && x_ < input_width)\n"
"{\n"
"sum = mad(image_dataPtr[x * DILATION_X], kernel_dataPtr[x], sum);\n"
"}\n"
"}\n"
"image_dataPtr += input_width * DILATION_Y;\n"
"kernel_dataPtr += KERNEL_WIDTH;\n"
"}\n"
"image_dataPtr += imageSize - input_width*KERNEL_HEIGHT*DILATION_Y;\n"
"}\n"
"int offset = convolved_image_offset + out_idx;\n"
"#if APPLY_BIAS\n"
"int biasIndex = bias_offset + outputZ;\n"
"ACTIVATION_FUNCTION(convolved_image, offset, sum + bias[biasIndex], biasIndex);\n"
"#else\n"
"ACTIVATION_FUNCTION(convolved_image, offset, sum, outputZ);\n"
"#endif\n"
"}\n"
"}\n"
"#elif defined KERNEL_IDLF\n"
"__attribute__((reqd_work_group_size(1, 1, SIMD_SIZE)))\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE)))\n"
"__kernel void\n"
"convolve_simd(\n"
"ELTWISE_DATA_ARG_WITH_OFFSET\n"
"FUSED_ARG\n"
"__global Dtype* inputs_ptr, const int inputs_offset,\n"
"__global Dtype* weights_ptr, const int weights_offset,\n"
"BIAS_KERNEL_ARG_WITH_OFFSET\n"
"__global Dtype* outputs_base, const int outputs_offset,\n"
"const ushort input_width,\n"
"const ushort input_height,\n"
"const ushort output_width,\n"
"const ushort output_height)\n"
"{\n"
"__global Dtype* inputs = inputs_ptr + inputs_offset;\n"
"__global Dtype* weights = weights_ptr + weights_offset;\n"
"#if APPLY_BIAS\n"
"__global Dtype* biases_base = biases_base_ptr + biases_base_offset;\n"
"#endif\n"
"__global Dtype* outputs = outputs_base + outputs_offset;\n"
"#ifdef FUSED_CONV_ELTWISE\n"
"__global Dtype* eltwise_data = eltwise_ptr + eltwise_offset;\n"
"#endif\n"
"unsigned int oc = get_global_id(0) * OUT_BLOCK_WIDTH;\n"
"unsigned int or = get_global_id(1) * OUT_BLOCK_HEIGHT;\n"
"unsigned int fm = get_global_id(2);\n"
"unsigned int fmg = get_group_id(2);\n"
"unsigned int lid = get_local_id(2);\n"
"Dtype out[OUT_BLOCK_WIDTH * OUT_BLOCK_HEIGHT] = { 0.0f };\n"
"unsigned int weight_addr = (fmg % FILTERS_IN_GROUP) *\n"
"INPUT_DEPTH * KERNEL_WIDTH * KERNEL_HEIGHT * SIMD_SIZE + lid;\n"
"unsigned int num_in_batch = fm / ALIGNED_NUM_FILTERS;\n"
"unsigned int input_batch_offset = num_in_batch * INPUT_PITCH * TOTAL_INPUT_DEPTH_SIZE;\n"
"int curr_y = or * STRIDE_Y;\n"
"int curr_x = oc * STRIDE_X + lid;\n"
"int in_addr = input_batch_offset\n"
"+ (curr_y - INPUT_PAD_H) * INPUT_WIDTH\n"
"+ curr_x - INPUT_PAD_W;\n"
"const int in_limit = (get_global_size(2) / ALIGNED_NUM_FILTERS) * TOTAL_INPUT_DEPTH_SIZE * INPUT_PITCH - 1;\n"
"Dtype in_buf[INVEC_SIZE];\n"
"for(int kd = 0; kd < INPUT_DEPTH; kd++)\n"
"{\n"
"#if INPUT_PAD_W != 0 || INPUT_PAD_H != 0 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"const bool cx_out_of_range = !(curr_x >= INPUT_PAD_W && curr_x < INPUT_WIDTH + INPUT_PAD_W);\n"
"int in_offset = in_addr;\n"
"__attribute__((opencl_unroll_hint(INVEC_SIZE)))\n"
"for (int reg = 0; reg < INVEC_SIZE; reg++, in_offset += INPUT_WIDTH)\n"
"{\n"
"Dtype input = inputs[clamp(in_offset, 0, in_limit)];\n"
"int cy = curr_y + reg;\n"
"in_buf[reg] = (cx_out_of_range || cy < INPUT_PAD_H || cy >= INPUT_HEIGHT + INPUT_PAD_H) ? 0 : input;\n"
"}\n"
"#else\n"
"int in_offset = in_addr;\n"
"__attribute__((opencl_unroll_hint(INVEC_SIZE)))\n"
"for (int reg = 0; reg < INVEC_SIZE; reg++, in_offset += INPUT_WIDTH)\n"
"{\n"
"in_buf[reg] = inputs[min(in_offset, in_limit)];\n"
"}\n"
"#endif\n"
"in_addr += INPUT_PITCH;\n"
"#define BLOCK_IN(n, c) intel_sub_group_shuffle(in_buf[n], (c))\n"
"int kr = 0;\n"
"LOOP(KERNEL_HEIGHT, kr,\n"
"{\n"
"int kc = 0;\n"
"LOOP(KERNEL_WIDTH, kc,\n"
"{\n"
"Dtype weight_value = weights[weight_addr];\n"
"weight_addr += SIMD_SIZE;\n"
"for (int br=0; br < OUT_BLOCK_HEIGHT; br++)\n"
"{\n"
"for(int bc=0; bc < OUT_BLOCK_WIDTH; bc++)\n"
"{\n"
"Dtype input = BLOCK_IN((br * STRIDE_Y + kr * DILATION_Y), bc * STRIDE_X + kc * DILATION_X);\n"
"out[br * OUT_BLOCK_WIDTH + bc] = mad(weight_value, input, out[br * OUT_BLOCK_WIDTH + bc]);\n"
"}\n"
"}\n"
"});\n"
"});\n"
"}\n"
"fm = fm % ALIGNED_NUM_FILTERS;\n"
"#if LEFT_FILTERS > 0\n"
"if (fm < NUM_FILTERS)\n"
"#endif\n"
"{\n"
"unsigned int out_addr = (num_in_batch * TOTAL_OUTPUT_DEPTH + fm) * OUTPUT_PITCH;\n"
"out_addr += or * output_width + oc;\n"
"#if APPLY_BIAS\n"
"Dtype bias = biases_base[fm];\n"
"#else\n"
"Dtype bias = 0;\n"
"#endif\n"
"for(unsigned int r = 0; r < OUT_BLOCK_HEIGHT; r++)\n"
"{\n"
"if (r + or >= output_height) break;\n"
"for(unsigned int c = 0; c < OUT_BLOCK_WIDTH; c++)\n"
"{\n"
"if (c + oc >= output_width) break;\n"
"ACTIVATION_FUNCTION(outputs, out_addr + r * output_width + c, bias + out[r * OUT_BLOCK_WIDTH + c], fm);\n"
"}\n"
"}\n"
"}\n"
"}\n"
"#elif defined KERNEL_GEMM_LIKE\n"
"#if APPLY_BIAS\n"
"#define SUBGROUP_GET_BIAS(k, i) intel_sub_group_shuffle(bias[k], i)\n"
"#else\n"
"#define SUBGROUP_GET_BIAS(k, i) ((Dtype)0)\n"
"#endif\n"
"#ifdef Conv_Interleaved\n"
"typedef struct float1 { float s0; } float1;\n"
"typedef struct float5 { float s0; float s1; float s2; float s3; float s4; } float5;\n"
"typedef struct float6 { float s0; float s1; float s2; float s3; float s4; float s5; } float6;\n"
"typedef struct float7 { float s0; float s1; float s2; float s3; float s4; float s5; float s6; } float7;\n"
"typedef struct float9 { float s0; float s1; float s2; float s3; float s4; float s5; float s6; float s7; float s8; } float9;\n"
"typedef struct float10 { float s0; float s1; float s2; float s3; float s4; float s5;\n"
"float s6; float s7; float s8; float s9;} float10;\n"
"typedef struct float11 { float s0; float s1; float s2; float s3; float s4; float s5;\n"
"float s6; float s7; float s8; float s9; float sa;} float11;\n"
"typedef struct float12 { float s0; float s1; float s2; float s3; float s4; float s5;\n"
"float s6; float s7; float s8; float s9; float sa; float sb; } float12;\n"
"typedef struct float13 { float s0; float s1; float s2; float s3; float s4; float s5;\n"
"float s6; float s7; float s8; float s9; float sa; float sb; float sc;} float13;\n"
"typedef struct float14 { float s0; float s1; float s2; float s3; float s4; float s5;\n"
"float s6; float s7; float s8; float s9; float sa; float sb; float sc; float sd; } float14;\n"
"typedef struct float15 { float s0; float s1; float s2; float s3; float s4; float s5;\n"
"float s6; float s7; float s8; float s9; float sa; float sb; float sc; float sd; float se; } float15;\n"
"typedef struct float0 { float s0; } float0;\n"
"typedef struct half1 { half s0; } half1;\n"
"typedef struct half5 { half s0; half s1; half s2; half s3; half s4; } half5;\n"
"typedef struct half6 { half s0; half s1; half s2; half s3; half s4; half s5; } half6;\n"
"typedef struct half7 { half s0; half s1; half s2; half s3; half s4; half s5; half s6; } half7;\n"
"typedef struct half9 { half s0; half s1; half s2; half s3; half s4; half s5; half s6; half s7; half s8; } half9;\n"
"typedef struct half10 { half s0; half s1; half s2; half s3; half s4; half s5;\n"
"half s6; half s7; half s8; half s9; } half10;\n"
"typedef struct half11 { half s0; half s1; half s2; half s3; half s4; half s5;\n"
"half s6; half s7; half s8; half s9; half sa; } half11;\n"
"typedef struct half12 { half s0; half s1; half s2; half s3; half s4; half s5;\n"
"half s6; half s7; half s8; half s9; half sa; half sb; } half12;\n"
"typedef struct half13 { half s0; half s1; half s2; half s3; half s4; half s5;\n"
"half s6; half s7; half s8; half s9; half sa; half sb; half sc; } half13;\n"
"typedef struct half14 { half s0; half s1; half s2; half s3; half s4; half s5;\n"
"half s6; half s7; half s8; half s9; half sa; half sb; half sc; half sd; } half14;\n"
"typedef struct half15 { half s0; half s1; half s2; half s3; half s4; half s5;\n"
"half s6; half s7; half s8; half s9; half sa; half sb; half sc; half sd; half se; } half15;\n"
"typedef struct half0 { half s0; } half0;\n"
"#define OUT_PITCH_X output_width\n"
"#define ROW_PITCH input_width\n"
"#define GEMM_LIKE_KERNEL_ARGS \\\n"
"ELTWISE_DATA_ARG_WITH_OFFSET \\\n"
"FUSED_ARG \\\n"
"const __global Dtype *src0_ptr, const unsigned int src0_offset, const unsigned int src0_limit, \\\n"
"const __global Dtype *src1_ptr, const unsigned int src1_offset, const unsigned int src1_limit, \\\n"
"BIAS_KERNEL_ARG_WITH_OFFSET \\\n"
"__global Dtype *dst_base, const unsigned int dst_offset, const unsigned int dst_limit, \\\n"
"const ushort input_width, \\\n"
"const ushort input_height, \\\n"
"const ushort output_width, \\\n"
"const ushort output_height, \\\n"
"const int out_pitch_y, \\\n"
"const int out_pitch_z, \\\n"
"const int aligned_input_size, \\\n"
"const int slice_pitch\n"
"#endif\n"
"#ifdef GEMM_LIKE_CONV_32_1\n"
"#define TILE_M 1\n"
"#define TILE_K KERNEL_WIDTH\n"
"#define TILE_N 32\n"
"__attribute__((intel_reqd_sub_group_size(8)))\n"
"__kernel void Conv_Interleaved(GEMM_LIKE_KERNEL_ARGS)\n"
"{\n"
"const __global Dtype *src0 = src0_ptr + src0_offset;\n"
"const __global Dtype *src1 = src1_ptr + src1_offset;\n"
"#if APPLY_BIAS\n"
"__global Dtype* biases_base = biases_base_ptr + biases_base_offset;\n"
"#endif\n"
"__global Dtype *dst = dst_base + dst_offset;\n"
"#ifdef FUSED_CONV_ELTWISE\n"
"__global Dtype* eltwise_data = eltwise_ptr + eltwise_offset;\n"
"#endif\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"const int global_z = get_global_id(2);\n"
"int interleaved_y;\n"
"int kernel_y;\n"
"int kernel_idx;\n"
"#define DOT_PRODUCT_8( _result, _rowA, colB ) \\\n"
"{ \\\n"
"_result.s0 = mad( _rowA, sub_group_broadcast( colB, 0 ), _result.s0 ); \\\n"
"_result.s1 = mad( _rowA, sub_group_broadcast( colB, 1 ), _result.s1 ); \\\n"
"_result.s2 = mad( _rowA, sub_group_broadcast( colB, 2 ), _result.s2 ); \\\n"
"_result.s3 = mad( _rowA, sub_group_broadcast( colB, 3 ), _result.s3 ); \\\n"
"_result.s4 = mad( _rowA, sub_group_broadcast( colB, 4 ), _result.s4 ); \\\n"
"_result.s5 = mad( _rowA, sub_group_broadcast( colB, 5 ), _result.s5 ); \\\n"
"_result.s6 = mad( _rowA, sub_group_broadcast( colB, 6 ), _result.s6 ); \\\n"
"_result.s7 = mad( _rowA, sub_group_broadcast( colB, 7 ), _result.s7 ); \\\n"
"}\n"
"typedef CAT( Dtype, KERNEL_WIDTH ) Dtype_t;\n"
"#if 0\n"
"#define OPTIMIZE_READ 1\n"
"#else\n"
"#define OPTIMIZE_READ 0\n"
"#endif\n"
"if( TILE_N_LAST == 0 || global_x < WIDTH1 / TILE_N )\n"
"{\n"
"Dtype8 blockC00 = 0.f;\n"
"Dtype8 blockC10 = 0.f;\n"
"Dtype8 blockC20 = 0.f;\n"
"Dtype8 blockC30 = 0.f;\n"
"int curr_x = ( global_y % output_width ) * STRIDE_X;\n"
"int curr_y = ( global_y / output_width ) * STRIDE_Y;\n"
"#if !OPTIMIZE_READ\n"
"int saved_y = curr_y;\n"
"#endif\n"
"const __global Dtype *src0_read = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y - INPUT_PAD_H) * ROW_PITCH\n"
"+ (curr_x - INPUT_PAD_W);\n"
"const __global Dtype *src1_read = src1 + ( global_x * TILE_N * 2);\n"
"int patch_depth = 0;\n"
"do\n"
"{\n"
"int patch_row = 0;\n"
"#if !OPTIMIZE_READ\n"
"curr_y = saved_y;\n"
"#endif\n"
"do\n"
"{\n"
"const bool kernel_width_is_odd = KERNEL_WIDTH % 2 == 1;\n"
"#if OPTIMIZE_READ\n"
"#if KERNEL_WIDTH == 3\n"
"Dtype_t blockA00 = vload3(0, src0_read);\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"#else\n"
"#if 0\n"
"if ((int)(src0_read - src0) >= src0_limit - KERNEL_WIDTH)\n"
"{\n"
"printf(\"CATCH: src0_read-src0: %d limit=%d curr_y,curr_x=%d,%d\\n\", (int)(src0_read - src0), src0_limit, curr_y, curr_x);\n"
"}\n"
"#endif\n"
"Dtype_t blockA00 = ( (const __global Dtype_t*)src0_read )[ 0 ];\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"#endif\n"
"#else\n"
"Dtype_t blockA00;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y >= INPUT_PAD_H &&\n"
"curr_y < input_height + INPUT_PAD_H &&\n"
"curr_x + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA00[pos] = src0_read[pos * DILATION_X];\n"
"else\n"
"pblockA00[pos] = 0;\n"
"})\n"
"curr_y += DILATION_Y;\n"
"#endif\n"
"src0_read += (ROW_PITCH * DILATION_Y);\n"
"Dtype blockB00[KERNEL_WIDTH*4];\n"
"Dtype8* p8BlockB00 = (Dtype8*)blockB00;\n"
"Dtype4* p4BlockB00 = (Dtype4*)blockB00;\n"
"Dtype* pBlockB00 = (Dtype* )blockB00;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"p8BlockB00[interleaved_y] = as_Dtype8( SUB_GROUP_BLOCK_READ8( (const __global INT_TYPE *)src1_read ) );\n"
"src1_read += WIDTH1 * 2;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"p4BlockB00[KERNEL_WIDTH - 1] = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE *)src1_read ) );\n"
"src1_read += WIDTH1 * 2;\n"
"}\n"
"kernel_idx = 0;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_8( blockC00, pblockA00[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC00, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC10, pblockA00[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC10, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC20, pblockA00[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC20, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC30, pblockA00[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC30, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"} )\n"
"kernel_y = interleaved_y * 2;\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"DOT_PRODUCT_8( blockC00, pblockA00[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC10, pblockA00[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC20, pblockA00[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC30, pblockA00[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"}\n"
"}\n"
"while( ++patch_row < KERNEL_HEIGHT );\n"
"src0_read += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y);\n"
"}\n"
"while ( ++patch_depth < INPUT_DEPTH );\n"
"int out_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M ) / output_width + OUT_PADDING_HEIGHT) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M ) % output_width ) + OUT_PADDING_LEFT;\n"
"__global Dtype *out = dst + out_offset;\n"
"#if APPLY_BIAS\n"
"Dtype bias[4];\n"
"Dtype4 *bias_vec;\n"
"bias_vec = (Dtype4*)bias;\n"
"*bias_vec = as_Dtype4(SUB_GROUP_BLOCK_READ4((__global INT_TYPE *)biases_base + group_x * TILE_N));\n"
"if (group_x > 0xFFFFFFFEul) {\n"
"dst[0] = bias[0] + bias[1] + bias[2] + bias[3];\n"
"}\n"
"#else\n"
"const Dtype bias[4] = {0, 0, 0, 0};\n"
"#endif\n"
"if (global_y * TILE_M < output_width * output_height )\n"
"{\n"
"for (int i = 0; i < 8; i++)\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out_offset + ( 0 + i ) * out_pitch_y, blockC00[i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i);\n"
"ACTIVATION_FUNCTION(dst, out_offset + ( 8 + i ) * out_pitch_y, blockC10[i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + 8 + i);\n"
"ACTIVATION_FUNCTION(dst, out_offset + ( 16 + i ) * out_pitch_y, blockC20[i] + SUBGROUP_GET_BIAS(2, i), group_x * TILE_N + 16 + i);\n"
"ACTIVATION_FUNCTION(dst, out_offset + ( 24 + i ) * out_pitch_y, blockC30[i] + SUBGROUP_GET_BIAS(3, i), group_x * TILE_N + 24 + i);\n"
"}\n"
"}\n"
"}\n"
"#if TILE_N_LAST > 0\n"
"else\n"
"{\n"
"int i = 0;\n"
"Dtype8 blockC[TILE_N_LAST_DIV8];\n"
"LOOP(TILE_N_LAST_DIV8, i,\n"
"{\n"
"blockC[i] = 0.f;\n"
"} )\n"
"int curr_x = ( global_y % output_width ) * STRIDE_X;\n"
"int curr_y = ( global_y / output_width ) * STRIDE_Y;\n"
"#if !OPTIMIZE_READ\n"
"int saved_y = curr_y;\n"
"#endif\n"
"const __global Dtype *src0_read = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y - INPUT_PAD_H) * ROW_PITCH\n"
"+ (curr_x - INPUT_PAD_W);\n"
"const __global Dtype *src1_read = src1 + ( global_x * TILE_N * 2);\n"
"int patch_depth = 0;\n"
"do\n"
"{\n"
"int patch_row = 0;\n"
"#if !OPTIMIZE_READ\n"
"curr_y = saved_y;\n"
"#endif\n"
"do\n"
"{\n"
"const bool kernel_width_is_odd = KERNEL_WIDTH % 2 == 1;\n"
"#if OPTIMIZE_READ\n"
"Dtype_t blockA00 = ( (const __global Dtype_t*)src0_read )[ 0 ];\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"#else\n"
"Dtype_t blockA00;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y >= INPUT_PAD_H &&\n"
"curr_y < input_height + INPUT_PAD_H &&\n"
"curr_x + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA00[pos] = src0_read[pos * DILATION_X];\n"
"else\n"
"pblockA00[pos] = 0;\n"
"})\n"
"curr_y += DILATION_Y;\n"
"#endif\n"
"src0_read += (ROW_PITCH * DILATION_Y);\n"
"Dtype blockB[KERNEL_WIDTH * TILE_N_LAST_DIV8];\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"#if TILE_N_LAST_DIV8 == 1\n"
"Dtype2* p2BlockB = (Dtype2* )blockB;\n"
"p2BlockB[interleaved_y] = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 2\n"
"Dtype4* p4BlockB = (Dtype4* )blockB;\n"
"p4BlockB[interleaved_y] = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 3\n"
"Dtype6* p6BlockB = (Dtype6* )blockB;\n"
"(*((Dtype8*)(&p6BlockB[interleaved_y]))).s0123 = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read ) );\n"
"(*((Dtype8*)(&p6BlockB[interleaved_y]))).s45 = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)(src1_read + 4 * 8) ) );\n"
"#endif\n"
"src1_read += WIDTH1 * 2;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"#if TILE_N_LAST_DIV8 == 1\n"
"Dtype* pBlockB = (Dtype* )blockB;\n"
"pBlockB[KERNEL_WIDTH - 1] = as_Dtype( SUB_GROUP_BLOCK_READ( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 2\n"
"Dtype2* p2BlockB = (Dtype2* )blockB;\n"
"p2BlockB[KERNEL_WIDTH - 1] = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 3\n"
"Dtype3* p3BlockB = (Dtype3* )blockB;\n"
"p3BlockB[KERNEL_WIDTH - 1].s01 = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"p3BlockB[KERNEL_WIDTH - 1].s2 = as_Dtype( SUB_GROUP_BLOCK_READ( (const __global INT_TYPE*) (src1_read + 2 * 8) ) );\n"
"#endif\n"
"src1_read += WIDTH1 * 2;\n"
"}\n"
"Dtype* pBlockB = (Dtype*)blockB;\n"
"kernel_idx = 0;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_8( blockC[0], pblockA00[kernel_y ], pBlockB[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC[0], pblockA00[kernel_y + 1], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 2\n"
"DOT_PRODUCT_8( blockC[1], pblockA00[kernel_y ], pBlockB[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC[1], pblockA00[kernel_y + 1], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 3\n"
"DOT_PRODUCT_8( blockC[2], pblockA00[kernel_y ], pBlockB[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC[2], pblockA00[kernel_y + 1], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#endif\n"
"#endif\n"
"} )\n"
"kernel_y = interleaved_y * 2;\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"DOT_PRODUCT_8( blockC[0], pblockA00[kernel_y], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 2\n"
"DOT_PRODUCT_8( blockC[1], pblockA00[kernel_y], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 3\n"
"DOT_PRODUCT_8( blockC[2], pblockA00[kernel_y], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#endif\n"
"#endif\n"
"}\n"
"}\n"
"while( ++patch_row < KERNEL_HEIGHT );\n"
"src0_read += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y );\n"
"}\n"
"while ( ++patch_depth < INPUT_DEPTH );\n"
"int out_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M ) / output_width + OUT_PADDING_HEIGHT) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M ) % output_width ) + OUT_PADDING_LEFT;\n"
"__global Dtype *out = dst + out_offset;\n"
"#if APPLY_BIAS\n"
"Dtype bias[4];\n"
"Dtype4 *bias_vec;\n"
"bias_vec = (Dtype4*)bias;\n"
"*bias_vec = as_Dtype4(SUB_GROUP_BLOCK_READ4((__global INT_TYPE *)biases_base + group_x * TILE_N));\n"
"if (group_x > 0xFFFFFFFEul) {\n"
"dst[0] = bias[0] + bias[1] + bias[2] + bias[3];\n"
"}\n"
"#else\n"
"const Dtype bias[4] = {0, 0, 0, 0};\n"
"#endif\n"
"if (global_y * TILE_M < output_width * output_height )\n"
"{\n"
"for (int i = 0; i < 8; i++)\n"
"{\n"
"if ( TILE_N_LAST_DIV8 > 0 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out_offset + ( 0+i) * out_pitch_y, blockC[0][i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 1 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out_offset + ( 8+i) * out_pitch_y, blockC[1][i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 8);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 2 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out_offset + (16+i) * out_pitch_y, blockC[2][i] + SUBGROUP_GET_BIAS(2, i), group_x * TILE_N + i + 16);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 3 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out_offset + (24+i) * out_pitch_y, blockC[3][i] + SUBGROUP_GET_BIAS(3, i), group_x * TILE_N + i + 24);\n"
"}\n"
"}\n"
"}\n"
"}\n"
"#endif\n"
"}\n"
"#endif\n"
"#ifdef GEMM_LIKE_CONV_32_2\n"
"#define TILE_M 2\n"
"#define TILE_K KERNEL_WIDTH\n"
"#define TILE_N 32\n"
"__attribute__((intel_reqd_sub_group_size(8)))\n"
"__kernel void Conv_Interleaved(GEMM_LIKE_KERNEL_ARGS)\n"
"{\n"
"const __global Dtype *src0 = src0_ptr + src0_offset;\n"
"const __global Dtype *src1 = src1_ptr + src1_offset;\n"
"#if APPLY_BIAS\n"
"__global Dtype* biases_base = biases_base_ptr + biases_base_offset;\n"
"#endif\n"
"__global Dtype *dst = dst_base + dst_offset;\n"
"#ifdef FUSED_CONV_ELTWISE\n"
"__global Dtype* eltwise_data = eltwise_ptr + eltwise_offset;\n"
"#endif\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"const int global_z = get_global_id(2);\n"
"int interleaved_y;\n"
"int kernel_y;\n"
"int kernel_idx;\n"
"#define DOT_PRODUCT_8( _result, _rowA, colB ) \\\n"
"{ \\\n"
"_result.s0 = mad( _rowA, sub_group_broadcast( colB, 0 ), _result.s0 ); \\\n"
"_result.s1 = mad( _rowA, sub_group_broadcast( colB, 1 ), _result.s1 ); \\\n"
"_result.s2 = mad( _rowA, sub_group_broadcast( colB, 2 ), _result.s2 ); \\\n"
"_result.s3 = mad( _rowA, sub_group_broadcast( colB, 3 ), _result.s3 ); \\\n"
"_result.s4 = mad( _rowA, sub_group_broadcast( colB, 4 ), _result.s4 ); \\\n"
"_result.s5 = mad( _rowA, sub_group_broadcast( colB, 5 ), _result.s5 ); \\\n"
"_result.s6 = mad( _rowA, sub_group_broadcast( colB, 6 ), _result.s6 ); \\\n"
"_result.s7 = mad( _rowA, sub_group_broadcast( colB, 7 ), _result.s7 ); \\\n"
"}\n"
"typedef CAT( Dtype, KERNEL_WIDTH ) Dtype_t;\n"
"if( TILE_N_LAST == 0 || global_x < WIDTH1 / TILE_N )\n"
"{\n"
"Dtype8 blockC00 = 0.f;\n"
"Dtype8 blockC10 = 0.f;\n"
"Dtype8 blockC20 = 0.f;\n"
"Dtype8 blockC30 = 0.f;\n"
"Dtype8 blockC01 = 0.f;\n"
"Dtype8 blockC11 = 0.f;\n"
"Dtype8 blockC21 = 0.f;\n"
"Dtype8 blockC31 = 0.f;\n"
"int curr_x0 = ( ( global_y * TILE_M + 0 ) % output_width ) * STRIDE_X;\n"
"int curr_x1 = ( ( global_y * TILE_M + 1 ) % output_width ) * STRIDE_X;\n"
"int curr_y0 = ( ( global_y * TILE_M + 0 ) / output_width ) * STRIDE_Y;\n"
"int curr_y1 = ( ( global_y * TILE_M + 1 ) / output_width ) * STRIDE_Y;\n"
"#if INPUT_PAD_H != 0 || INPUT_PAD_W != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"int saved_y0 = curr_y0;\n"
"int saved_y1 = curr_y1;\n"
"#endif\n"
"const __global Dtype *src0_read0 = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y0 - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x0 - INPUT_PAD_W;\n"
"const __global Dtype *src0_read1 = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y1 - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x1 - INPUT_PAD_W;\n"
"const __global Dtype *src1_read = src1 + ( global_x * TILE_N * 2);\n"
"int patch_depth = 0;\n"
"do\n"
"{\n"
"int patch_row = 0;\n"
"do\n"
"{\n"
"const bool kernel_width_is_odd = KERNEL_WIDTH % 2 == 1;\n"
"#if INPUT_PAD_H == 0 && INPUT_PAD_W == 0 && DILATION_X == 1 && DILATION_Y == 1 && INPUT_PAD_BOTTOM == 0 && INPUT_PAD_RIGHT == 0\n"
"#if KERNEL_WIDTH == 3\n"
"Dtype_t blockA00 = vload3(0, src0_read0); src0_read0 += ROW_PITCH;\n"
"Dtype_t blockA01 = vload3(0, src0_read1); src0_read1 += ROW_PITCH;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"#else\n"
"Dtype_t blockA00 = { (Dtype)0.f };\n"
"Dtype_t blockA01 = { (Dtype)0.f };\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_x0 + pos < input_width)\n"
"pblockA00[pos] = src0_read0[pos];\n"
"if (curr_x1 + pos < input_width)\n"
"pblockA01[pos] = src0_read1[pos];\n"
"})\n"
"src0_read0 += ROW_PITCH;\n"
"src0_read1 += ROW_PITCH;\n"
"#endif\n"
"#else\n"
"Dtype_t blockA00;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y0 >= INPUT_PAD_H &&\n"
"curr_y0 < input_height + INPUT_PAD_H &&\n"
"curr_x0 + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x0 + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA00[pos] = src0_read0[pos * DILATION_X];\n"
"else\n"
"pblockA00[pos] = 0;\n"
"})\n"
"curr_y0 += DILATION_Y;\n"
"Dtype_t blockA01;\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y1 >= INPUT_PAD_H &&\n"
"curr_y1 < input_height + INPUT_PAD_H &&\n"
"curr_x1 + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x1 + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA01[pos] = src0_read1[pos * DILATION_X];\n"
"else\n"
"pblockA01[pos] = 0;\n"
"})\n"
"curr_y1 += DILATION_Y;\n"
"src0_read0 += (ROW_PITCH * DILATION_Y);\n"
"src0_read1 += (ROW_PITCH * DILATION_Y);\n"
"#endif\n"
"Dtype blockB00[KERNEL_WIDTH*4];\n"
"Dtype8* p8BlockB00 = (Dtype8*)blockB00;\n"
"Dtype4* p4BlockB00 = (Dtype4*)blockB00;\n"
"Dtype* pBlockB00 = (Dtype* )blockB00;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"p8BlockB00[interleaved_y] = as_Dtype8( SUB_GROUP_BLOCK_READ8( (const __global INT_TYPE*)src1_read ) );\n"
"src1_read += WIDTH1 * 2;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"p4BlockB00[KERNEL_WIDTH - 1] = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read ) );\n"
"src1_read += WIDTH1 * 2;\n"
"}\n"
"kernel_idx = 0;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_8( blockC00, pblockA00[kernel_y ], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC01, pblockA01[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC00, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC01, pblockA01[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC10, pblockA00[kernel_y ], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC11, pblockA01[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC10, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC11, pblockA01[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC20, pblockA00[kernel_y ], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC21, pblockA01[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC20, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC21, pblockA01[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC30, pblockA00[kernel_y ], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC31, pblockA01[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC30, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC31, pblockA01[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_8( blockC00, pblockA00[kernel_y], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC01, pblockA01[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC10, pblockA00[kernel_y], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC11, pblockA01[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC20, pblockA00[kernel_y], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC21, pblockA01[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC30, pblockA00[kernel_y], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC31, pblockA01[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"}\n"
"}\n"
"while( ++patch_row < KERNEL_HEIGHT );\n"
"#if INPUT_PAD_W != 0 || INPUT_PAD_H != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"curr_y0 = saved_y0;\n"
"curr_y1 = saved_y1;\n"
"#endif\n"
"src0_read0 += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y );\n"
"src0_read1 += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y );\n"
"}\n"
"while ( ++patch_depth < INPUT_DEPTH );\n"
"int out0_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M + 0 ) / output_width + OUT_PADDING_HEIGHT ) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M + 0 ) % output_width ) + OUT_PADDING_LEFT;\n"
"int out1_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M + 1 ) / output_width + OUT_PADDING_HEIGHT ) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M + 1 ) % output_width ) + OUT_PADDING_LEFT;\n"
"#if APPLY_BIAS\n"
"Dtype bias[4];\n"
"Dtype4 *bias_vec;\n"
"bias_vec = (Dtype4*)bias;\n"
"*bias_vec = as_Dtype4(SUB_GROUP_BLOCK_READ4((__global INT_TYPE *)biases_base + group_x * TILE_N));\n"
"if (group_x > 0xFFFFFFFEul) {\n"
"dst[0] = bias[0] + bias[1] + bias[2] + bias[3];\n"
"}\n"
"#else\n"
"const Dtype bias[4] = {0, 0, 0, 0};\n"
"#endif\n"
"if( global_y * TILE_M < output_width * output_height )\n"
"{\n"
"for( int i = 0; i < 8; i++ )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out0_offset + ( 0+i) * out_pitch_y, blockC00[i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i);\n"
"ACTIVATION_FUNCTION(dst, out0_offset + ( 8+i) * out_pitch_y, blockC10[i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 8);\n"
"ACTIVATION_FUNCTION(dst, out0_offset + (16+i) * out_pitch_y, blockC20[i] + SUBGROUP_GET_BIAS(2, i), group_x * TILE_N + i + 16);\n"
"ACTIVATION_FUNCTION(dst, out0_offset + (24+i) * out_pitch_y, blockC30[i] + SUBGROUP_GET_BIAS(3, i), group_x * TILE_N + i + 24);\n"
"}\n"
"}\n"
"if( global_y * TILE_M + 1 < output_width * output_height )\n"
"{\n"
"for( int i = 0; i < 8; i++ )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out1_offset + ( 0+i) * out_pitch_y, blockC01[i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i);\n"
"ACTIVATION_FUNCTION(dst, out1_offset + ( 8+i) * out_pitch_y, blockC11[i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 8);\n"
"ACTIVATION_FUNCTION(dst, out1_offset + (16+i) * out_pitch_y, blockC21[i] + SUBGROUP_GET_BIAS(2, i), group_x * TILE_N + i + 16);\n"
"ACTIVATION_FUNCTION(dst, out1_offset + (24+i) * out_pitch_y, blockC31[i] + SUBGROUP_GET_BIAS(3, i), group_x * TILE_N + i + 24);\n"
"}\n"
"}\n"
"}\n"
"#if TILE_N_LAST > 0\n"
"else\n"
"{\n"
"int i = 0;\n"
"Dtype8 blockC0[TILE_N_LAST_DIV8];\n"
"Dtype8 blockC1[TILE_N_LAST_DIV8];\n"
"LOOP(TILE_N_LAST_DIV8, i,\n"
"{\n"
"blockC0[i] = 0.f;\n"
"blockC1[i] = 0.f;\n"
"} )\n"
"int curr_x0 = ( ( global_y * TILE_M + 0 ) % output_width ) * STRIDE_X;\n"
"int curr_x1 = ( ( global_y * TILE_M + 1 ) % output_width ) * STRIDE_X;\n"
"int curr_y0 = ( ( global_y * TILE_M + 0 ) / output_width ) * STRIDE_Y;\n"
"int curr_y1 = ( ( global_y * TILE_M + 1 ) / output_width ) * STRIDE_Y;\n"
"#if INPUT_PAD_H != 0 || INPUT_PAD_W != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"int saved_y0 = curr_y0;\n"
"int saved_y1 = curr_y1;\n"
"#endif\n"
"const __global Dtype *src0_read0 = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y0 - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x0 - INPUT_PAD_W;\n"
"const __global Dtype *src0_read1 = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y1 - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x1 - INPUT_PAD_W;\n"
"const __global Dtype *src1_read = src1 + ( global_x * TILE_N * 2);\n"
"int patch_depth = 0;\n"
"do\n"
"{\n"
"int patch_row = 0;\n"
"do\n"
"{\n"
"const bool kernel_width_is_odd = KERNEL_WIDTH % 2 == 1;\n"
"#if INPUT_PAD_H == 0 && INPUT_PAD_W == 0 && DILATION_X == 1 && DILATION_Y == 1 && INPUT_PAD_BOTTOM == 0 && INPUT_PAD_RIGHT == 0\n"
"Dtype_t blockA00 = ( (const __global Dtype_t*)src0_read0 )[ 0 ]; src0_read0 += ROW_PITCH;\n"
"Dtype_t blockA01 = ( (const __global Dtype_t*)src0_read1 )[ 0 ]; src0_read1 += ROW_PITCH;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"#else\n"
"Dtype_t blockA00;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y0 >= INPUT_PAD_H &&\n"
"curr_y0 < input_height + INPUT_PAD_H &&\n"
"curr_x0 + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x0 + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA00[pos] = src0_read0[pos * DILATION_X];\n"
"else\n"
"pblockA00[pos] = 0;\n"
"})\n"
"curr_y0 += DILATION_Y;\n"
"Dtype_t blockA01;\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y1 >= INPUT_PAD_H &&\n"
"curr_y1 < input_height + INPUT_PAD_H &&\n"
"curr_x1 + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x1 + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA01[pos] = src0_read1[pos * DILATION_X];\n"
"else\n"
"pblockA01[pos] = 0;\n"
"})\n"
"curr_y1 += DILATION_Y;\n"
"src0_read0 += (ROW_PITCH * DILATION_Y);\n"
"src0_read1 += (ROW_PITCH * DILATION_Y);\n"
"#endif\n"
"Dtype blockB[KERNEL_WIDTH * TILE_N_LAST_DIV8];\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"#if TILE_N_LAST_DIV8 == 1\n"
"Dtype2* p2BlockB = (Dtype2* )blockB;\n"
"p2BlockB[interleaved_y] = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 2\n"
"Dtype4* p4BlockB = (Dtype4* )blockB;\n"
"p4BlockB[interleaved_y] = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 3\n"
"Dtype6* p6BlockB = (Dtype6* )blockB;\n"
"(*((Dtype8*)(&p6BlockB[interleaved_y]))).s0123 = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read ) );\n"
"(*((Dtype8*)(&p6BlockB[interleaved_y]))).s45 = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)(src1_read + 4 * 8) ) );\n"
"#endif\n"
"src1_read += WIDTH1 * 2;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"#if TILE_N_LAST_DIV8 == 1\n"
"Dtype* pBlockB = (Dtype* )blockB;\n"
"pBlockB[KERNEL_WIDTH - 1] = as_Dtype( SUB_GROUP_BLOCK_READ( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 2\n"
"Dtype2* p2BlockB = (Dtype2* )blockB;\n"
"p2BlockB[KERNEL_WIDTH - 1] = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"#elif TILE_N_LAST_DIV8 == 3\n"
"Dtype3* p3BlockB = (Dtype3* )blockB;\n"
"p3BlockB[KERNEL_WIDTH - 1].s01 = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"p3BlockB[KERNEL_WIDTH - 1].s2 = as_Dtype( SUB_GROUP_BLOCK_READ( (const __global INT_TYPE*) (src1_read + 8) ) );\n"
"#endif\n"
"src1_read += WIDTH1 * 2;\n"
"}\n"
"Dtype* pBlockB = (Dtype*)blockB;\n"
"kernel_idx = 0;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_8( blockC0[0], pblockA00[kernel_y ], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[0], pblockA01[kernel_y ], pBlockB[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC0[0], pblockA00[kernel_y + 1], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[0], pblockA01[kernel_y + 1], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 2\n"
"DOT_PRODUCT_8( blockC0[1], pblockA00[kernel_y ], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[1], pblockA01[kernel_y ], pBlockB[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC0[1], pblockA00[kernel_y + 1], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[1], pblockA01[kernel_y + 1], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 3\n"
"DOT_PRODUCT_8( blockC0[2], pblockA00[kernel_y ], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[2], pblockA01[kernel_y ], pBlockB[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_8( blockC0[2], pblockA00[kernel_y + 1], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[2], pblockA01[kernel_y + 1], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#endif\n"
"#endif\n"
"} )\n"
"kernel_y = interleaved_y * 2;\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"DOT_PRODUCT_8( blockC0[0], pblockA00[kernel_y], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[0], pblockA01[kernel_y], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 2\n"
"DOT_PRODUCT_8( blockC0[1], pblockA00[kernel_y], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[1], pblockA01[kernel_y], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#if TILE_N_LAST_DIV8 >= 3\n"
"DOT_PRODUCT_8( blockC0[2], pblockA00[kernel_y], pBlockB[kernel_idx] );\n"
"DOT_PRODUCT_8( blockC1[2], pblockA01[kernel_y], pBlockB[kernel_idx] ); kernel_idx++;\n"
"#endif\n"
"#endif\n"
"}\n"
"}\n"
"while( ++patch_row < KERNEL_HEIGHT );\n"
"#if INPUT_PAD_W != 0 || INPUT_PAD_H != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"curr_y0 = saved_y0;\n"
"curr_y1 = saved_y1;\n"
"#endif\n"
"src0_read0 += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y );\n"
"src0_read1 += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y );\n"
"}\n"
"while ( ++patch_depth < INPUT_DEPTH );\n"
"int out0_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M + 0 ) / output_width + OUT_PADDING_HEIGHT ) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M + 0 ) % output_width ) + OUT_PADDING_LEFT;\n"
"int out1_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M + 1 ) / output_width + OUT_PADDING_HEIGHT ) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M + 1 ) % output_width ) + OUT_PADDING_LEFT;\n"
"__global Dtype *out1 = dst + out1_offset;\n"
"#if APPLY_BIAS\n"
"Dtype bias[4];\n"
"Dtype4 *bias_vec;\n"
"bias_vec = (Dtype4*)bias;\n"
"*bias_vec = as_Dtype4(SUB_GROUP_BLOCK_READ4((__global INT_TYPE *)biases_base + group_x * TILE_N));\n"
"if (group_x > 0xFFFFFFFEul) {\n"
"dst[0] = bias[0] + bias[1] + bias[2] + bias[3];\n"
"}\n"
"#else\n"
"const Dtype bias[4] = {0, 0, 0, 0};\n"
"#endif\n"
"if( global_y * TILE_M < output_width * output_height )\n"
"{\n"
"for( int i = 0; i < 8; i++ )\n"
"{\n"
"if ( TILE_N_LAST_DIV8 > 0 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out0_offset + ( 0+i) * out_pitch_y, blockC0[0][i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 1 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out0_offset + ( 8+i) * out_pitch_y, blockC0[1][i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 8);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 2 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out0_offset + (16+i) * out_pitch_y, blockC0[2][i] + SUBGROUP_GET_BIAS(2, i), group_x * TILE_N + i + 16);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 3 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out0_offset + (24+i) * out_pitch_y, blockC0[3][i] + SUBGROUP_GET_BIAS(3, i), group_x * TILE_N + i + 24);\n"
"}\n"
"}\n"
"}\n"
"if( global_y * TILE_M + 1 < output_width * output_height )\n"
"{\n"
"for( int i = 0; i < 8; i++ )\n"
"{\n"
"if ( TILE_N_LAST_DIV8 > 0 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out1_offset + ( 0+i) * out_pitch_y, blockC1[0][i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 1 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out1_offset + ( 8+i) * out_pitch_y, blockC1[1][i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 8);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 2 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out1_offset + (16+i) * out_pitch_y, blockC1[2][i] + SUBGROUP_GET_BIAS(2, i), group_x * TILE_N + i + 16);\n"
"}\n"
"if ( TILE_N_LAST_DIV8 > 3 )\n"
"{\n"
"ACTIVATION_FUNCTION(dst, out1_offset + (24+i) * out_pitch_y, blockC1[3][i] + SUBGROUP_GET_BIAS(3, i), group_x * TILE_N + i + 24);\n"
"}\n"
"}\n"
"}\n"
"}\n"
"#endif\n"
"}\n"
"#endif\n"
"#if defined(GEMM_LIKE_CONV_32_2_SIMD16) || defined(GEMM_LIKE_CONV_32_1_SIMD16)\n"
"#define INTERLEAVED_SIMD16_OUTPUT(_out_, _offset_, _m_) do {\\\n"
"if (global_y * TILE_M < output_width * output_height ) \\\n"
"{ \\\n"
"if ( ( OUT_DEPTH % TILE_N ) == 0 ) {\\\n"
"for (int i = 0; i < 16; i++) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + ( 0+i) * out_pitch_y, blockC0 ##_m_ [i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i); \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + (16+i) * out_pitch_y, blockC1 ##_m_ [i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 16); \\\n"
"} \\\n"
"} \\\n"
"else if( ( OUT_DEPTH % 16 ) == 0 ) { \\\n"
"if ( ( global_x + 1 ) < get_global_size(0) ) { \\\n"
"for ( int i = 0; i < 16; i++ ) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + ( 0+i) * out_pitch_y, blockC0 ##_m_ [i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i); \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + (16+i) * out_pitch_y, blockC1 ##_m_ [i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 16); \\\n"
"} \\\n"
"} \\\n"
"else { \\\n"
"for (int i = 0; i < 16; i++) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + ( 0+i) * out_pitch_y, blockC0 ##_m_ [i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i); \\\n"
"} \\\n"
"} \\\n"
"} \\\n"
"else { \\\n"
"if ( ( global_x + 1 ) < get_global_size(0) ) \\\n"
"{ \\\n"
"for ( int i = 0; i < 16; i++ ) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + ( 0+i) * out_pitch_y, blockC0 ##_m_[i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i); \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + (16+i) * out_pitch_y, blockC1 ##_m_[i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 16); \\\n"
"} \\\n"
"} \\\n"
"else { \\\n"
"if ( (OUT_DEPTH % TILE_N) > 16 ) { \\\n"
"for (int i = 0; i < 16 ; i++) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + ( 0+i) * out_pitch_y, blockC0 ##_m_[i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i); \\\n"
"} \\\n"
"for (int i = 0; i < OUT_DEPTH % 16 ; i++) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + (16+i) * out_pitch_y, blockC1 ##_m_[i] + SUBGROUP_GET_BIAS(1, i), group_x * TILE_N + i + 16); \\\n"
"} \\\n"
"} \\\n"
"else { \\\n"
"for (int i = 0; i < OUT_DEPTH % 16 ; i++) \\\n"
"{ \\\n"
"ACTIVATION_FUNCTION(_out_, _offset_ + ( 0+i) * out_pitch_y, blockC0 ##_m_[i] + SUBGROUP_GET_BIAS(0, i), group_x * TILE_N + i); \\\n"
"} \\\n"
"} \\\n"
"} \\\n"
"} \\\n"
"} \\\n"
"}while(0)\n"
"#endif\n"
"#ifdef GEMM_LIKE_CONV_32_1_SIMD16\n"
"#define TILE_M 1\n"
"#define TILE_K KERNEL_WIDTH\n"
"#define TILE_N 32\n"
"__attribute__((intel_reqd_sub_group_size(16)))\n"
"__kernel void Conv_Interleaved(GEMM_LIKE_KERNEL_ARGS)\n"
"{\n"
"const __global Dtype *src0 = src0_ptr + src0_offset;\n"
"const __global Dtype *src1 = src1_ptr + src1_offset;\n"
"#if APPLY_BIAS\n"
"__global Dtype* biases_base = biases_base_ptr + biases_base_offset;\n"
"#endif\n"
"__global Dtype *dst = dst_base + dst_offset;\n"
"#ifdef FUSED_CONV_ELTWISE\n"
"__global Dtype* eltwise_data = eltwise_ptr + eltwise_offset;\n"
"#endif\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"const int global_z = get_global_id(2);\n"
"int interleaved_y;\n"
"int kernel_y;\n"
"int kernel_idx;\n"
"Dtype16 blockC00 = 0.f;\n"
"Dtype16 blockC10 = 0.f;\n"
"int curr_x = ( global_y % output_width ) * STRIDE_X;\n"
"int curr_y = ( global_y / output_width ) * STRIDE_Y;\n"
"#if INPUT_PAD_H != 0 || INPUT_PAD_W != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"int saved_y = curr_y;\n"
"#endif\n"
"const __global Dtype *src0_read = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x - INPUT_PAD_W;\n"
"const __global Dtype *src0_read_orig = src0_read;\n"
"const __global Dtype *src1_read = src1 + ( global_x * TILE_N * 2 );\n"
"#define DOT_PRODUCT_16( _result, _rowA, colB ) \\\n"
"{ \\\n"
"_result.s0 = mad( _rowA, sub_group_broadcast( colB, 0 ), _result.s0 ); \\\n"
"_result.s1 = mad( _rowA, sub_group_broadcast( colB, 1 ), _result.s1 ); \\\n"
"_result.s2 = mad( _rowA, sub_group_broadcast( colB, 2 ), _result.s2 ); \\\n"
"_result.s3 = mad( _rowA, sub_group_broadcast( colB, 3 ), _result.s3 ); \\\n"
"_result.s4 = mad( _rowA, sub_group_broadcast( colB, 4 ), _result.s4 ); \\\n"
"_result.s5 = mad( _rowA, sub_group_broadcast( colB, 5 ), _result.s5 ); \\\n"
"_result.s6 = mad( _rowA, sub_group_broadcast( colB, 6 ), _result.s6 ); \\\n"
"_result.s7 = mad( _rowA, sub_group_broadcast( colB, 7 ), _result.s7 ); \\\n"
"_result.s8 = mad( _rowA, sub_group_broadcast( colB, 8 ), _result.s8 ); \\\n"
"_result.s9 = mad( _rowA, sub_group_broadcast( colB, 9 ), _result.s9 ); \\\n"
"_result.sa = mad( _rowA, sub_group_broadcast( colB, 10 ), _result.sa ); \\\n"
"_result.sb = mad( _rowA, sub_group_broadcast( colB, 11 ), _result.sb ); \\\n"
"_result.sc = mad( _rowA, sub_group_broadcast( colB, 12 ), _result.sc ); \\\n"
"_result.sd = mad( _rowA, sub_group_broadcast( colB, 13 ), _result.sd ); \\\n"
"_result.se = mad( _rowA, sub_group_broadcast( colB, 14 ), _result.se ); \\\n"
"_result.sf = mad( _rowA, sub_group_broadcast( colB, 15 ), _result.sf ); \\\n"
"}\n"
"typedef CAT( Dtype, KERNEL_WIDTH ) Dtype_t;\n"
"int patch_depth = 0;\n"
"__attribute__((opencl_unroll_hint(1)))\n"
"do\n"
"{\n"
"int patch_row = 0;\n"
"#if INPUT_PAD_H != 0 || INPUT_PAD_W != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"curr_y = saved_y;\n"
"#endif\n"
"__attribute__((opencl_unroll_hint(1)))\n"
"do\n"
"{\n"
"const bool kernel_width_is_odd = KERNEL_WIDTH % 2 == 1;\n"
"#if INPUT_PAD_W == 0 && INPUT_PAD_H == 0 && DILATION_X == 1 && DILATION_Y == 1 && INPUT_PAD_BOTTOM == 0 && INPUT_PAD_RIGHT == 0\n"
"#if KERNEL_WIDTH == 3\n"
"Dtype_t blockA00 = vload3(0, src0_read);\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"#else\n"
"Dtype_t blockA00 = ( (const __global Dtype_t*)src0_read )[ 0 ];\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"#endif\n"
"#else\n"
"Dtype_t blockA00;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y >= INPUT_PAD_H &&\n"
"curr_y < input_height + INPUT_PAD_H &&\n"
"curr_x + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA00[pos] = src0_read[pos * DILATION_X];\n"
"else\n"
"pblockA00[pos] = 0;\n"
"})\n"
"curr_y += DILATION_Y;\n"
"#endif\n"
"src0_read += ROW_PITCH * DILATION_Y;\n"
"INT_TYPE blockB00[KERNEL_WIDTH * 2];\n"
"INT_TYPE4* p4BlockB00 = (INT_TYPE4*)blockB00;\n"
"INT_TYPE2* p2BlockB00 = (INT_TYPE2*)blockB00;\n"
"Dtype* pBlockB00 = (Dtype*)blockB00;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"p4BlockB00[interleaved_y] = SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read );\n"
"src1_read += WIDTH1 * 2;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"p2BlockB00[KERNEL_WIDTH - 1] = SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read );\n"
"src1_read += WIDTH1 * 2;\n"
"}\n"
"kernel_idx = 0;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_16( blockC00, pblockA00[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC00, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC10, pblockA00[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC10, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_16( blockC00, pblockA00[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC10, pblockA00[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"}\n"
"}\n"
"while( ++patch_row < KERNEL_HEIGHT );\n"
"src0_read += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y );\n"
"}\n"
"while ( ++patch_depth < INPUT_DEPTH );\n"
"int out_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M ) / output_width + OUT_PADDING_HEIGHT) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M ) % output_width ) + OUT_PADDING_LEFT;\n"
"__global Dtype *out = dst + out_offset;\n"
"#if APPLY_BIAS\n"
"Dtype bias[2];\n"
"Dtype2 *bias_vec;\n"
"bias_vec = (Dtype2*)bias;\n"
"*bias_vec = as_Dtype2(SUB_GROUP_BLOCK_READ2((__global INT_TYPE *)biases_base + group_x * TILE_N));\n"
"if (group_x > 0xFFFFFFFEul) {\n"
"dst[0] = bias[0] + bias[1];\n"
"}\n"
"#else\n"
"const Dtype bias[2] = {0, 0};\n"
"#endif\n"
"INTERLEAVED_SIMD16_OUTPUT(dst, out_offset, 0);\n"
"}\n"
"#endif\n"
"#ifdef GEMM_LIKE_CONV_32_2_SIMD16\n"
"#define TILE_M 2\n"
"#define TILE_K KERNEL_WIDTH\n"
"#define TILE_N 32\n"
"__attribute__((intel_reqd_sub_group_size(16)))\n"
"__kernel void Conv_Interleaved(GEMM_LIKE_KERNEL_ARGS)\n"
"{\n"
"const __global Dtype *src0 = src0_ptr + src0_offset;\n"
"const __global Dtype *src1 = src1_ptr + src1_offset;\n"
"#if APPLY_BIAS\n"
"__global Dtype* biases_base = biases_base_ptr + biases_base_offset;\n"
"#endif\n"
"__global Dtype *dst = dst_base + dst_offset;\n"
"#ifdef FUSED_CONV_ELTWISE\n"
"__global Dtype* eltwise_data = eltwise_ptr + eltwise_offset;\n"
"#endif\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"const int global_z = get_global_id(2);\n"
"int interleaved_y;\n"
"int kernel_y;\n"
"int kernel_idx;\n"
"#define DOT_PRODUCT_16( _result, _rowA, colB ) \\\n"
"{ \\\n"
"_result.s0 = mad( _rowA, sub_group_broadcast( colB, 0 ), _result.s0 ); \\\n"
"_result.s1 = mad( _rowA, sub_group_broadcast( colB, 1 ), _result.s1 ); \\\n"
"_result.s2 = mad( _rowA, sub_group_broadcast( colB, 2 ), _result.s2 ); \\\n"
"_result.s3 = mad( _rowA, sub_group_broadcast( colB, 3 ), _result.s3 ); \\\n"
"_result.s4 = mad( _rowA, sub_group_broadcast( colB, 4 ), _result.s4 ); \\\n"
"_result.s5 = mad( _rowA, sub_group_broadcast( colB, 5 ), _result.s5 ); \\\n"
"_result.s6 = mad( _rowA, sub_group_broadcast( colB, 6 ), _result.s6 ); \\\n"
"_result.s7 = mad( _rowA, sub_group_broadcast( colB, 7 ), _result.s7 ); \\\n"
"_result.s8 = mad( _rowA, sub_group_broadcast( colB, 8 ), _result.s8 ); \\\n"
"_result.s9 = mad( _rowA, sub_group_broadcast( colB, 9 ), _result.s9 ); \\\n"
"_result.sa = mad( _rowA, sub_group_broadcast( colB, 10 ), _result.sa ); \\\n"
"_result.sb = mad( _rowA, sub_group_broadcast( colB, 11 ), _result.sb ); \\\n"
"_result.sc = mad( _rowA, sub_group_broadcast( colB, 12 ), _result.sc ); \\\n"
"_result.sd = mad( _rowA, sub_group_broadcast( colB, 13 ), _result.sd ); \\\n"
"_result.se = mad( _rowA, sub_group_broadcast( colB, 14 ), _result.se ); \\\n"
"_result.sf = mad( _rowA, sub_group_broadcast( colB, 15 ), _result.sf ); \\\n"
"}\n"
"typedef CAT( Dtype, KERNEL_WIDTH ) Dtype_t;\n"
"{\n"
"Dtype16 blockC00 = 0.f;\n"
"Dtype16 blockC10 = 0.f;\n"
"Dtype16 blockC01 = 0.f;\n"
"Dtype16 blockC11 = 0.f;\n"
"int curr_x0 = ( ( global_y * TILE_M + 0 ) % output_width ) * STRIDE_X;\n"
"int curr_x1 = ( ( global_y * TILE_M + 1 ) % output_width ) * STRIDE_X;\n"
"int curr_y0 = ( ( global_y * TILE_M + 0 ) / output_width ) * STRIDE_Y;\n"
"int curr_y1 = ( ( global_y * TILE_M + 1 ) / output_width ) * STRIDE_Y;\n"
"#if INPUT_PAD_H != 0 || INPUT_PAD_W != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"int saved_y0 = curr_y0;\n"
"int saved_y1 = curr_y1;\n"
"#endif\n"
"const __global Dtype *src0_read0 = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y0 - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x0 - INPUT_PAD_W;\n"
"const __global Dtype *src0_read1 = src0\n"
"+ aligned_input_size * global_z\n"
"+ (curr_y1 - INPUT_PAD_H) * ROW_PITCH\n"
"+ curr_x1 - INPUT_PAD_W;\n"
"const __global Dtype *src1_read = src1 + ( global_x * TILE_N * 2);\n"
"int patch_depth = 0;\n"
"do\n"
"{\n"
"int patch_row = 0;\n"
"do\n"
"{\n"
"const bool kernel_width_is_odd = KERNEL_WIDTH % 2 == 1;\n"
"#if INPUT_PAD_H == 0 && INPUT_PAD_W == 0 && DILATION_X == 1 && DILATION_Y == 1 && INPUT_PAD_BOTTOM == 0 && INPUT_PAD_RIGHT == 0\n"
"Dtype_t blockA00 = ( (const __global Dtype_t*)src0_read0 )[ 0 ]; src0_read0 += ROW_PITCH;\n"
"Dtype_t blockA01 = ( (const __global Dtype_t*)src0_read1 )[ 0 ]; src0_read1 += ROW_PITCH;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"#else\n"
"Dtype_t blockA00;\n"
"Dtype* pblockA00 = (Dtype*)(&blockA00);\n"
"int pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y0 >= INPUT_PAD_H &&\n"
"curr_y0 < input_height + INPUT_PAD_H &&\n"
"curr_x0 + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x0 + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA00[pos] = src0_read0[pos * DILATION_X];\n"
"else\n"
"pblockA00[pos] = 0;\n"
"})\n"
"curr_y0 += DILATION_Y;\n"
"Dtype_t blockA01;\n"
"Dtype* pblockA01 = (Dtype*)(&blockA01);\n"
"pos = 0;\n"
"LOOP(KERNEL_WIDTH, pos,\n"
"{\n"
"if (curr_y1 >= INPUT_PAD_H &&\n"
"curr_y1 < input_height + INPUT_PAD_H &&\n"
"curr_x1 + pos * DILATION_X >= INPUT_PAD_W &&\n"
"curr_x1 + pos * DILATION_X < input_width + INPUT_PAD_W)\n"
"pblockA01[pos] = src0_read1[pos * DILATION_X];\n"
"else\n"
"pblockA01[pos] = 0;\n"
"})\n"
"curr_y1 += DILATION_Y;\n"
"src0_read0 += (ROW_PITCH * DILATION_Y);\n"
"src0_read1 += (ROW_PITCH * DILATION_Y);\n"
"#endif\n"
"Dtype blockB00[KERNEL_WIDTH*2];\n"
"Dtype4* p4BlockB00 = (Dtype4*)blockB00;\n"
"Dtype2* p2BlockB00 = (Dtype2*)blockB00;\n"
"Dtype* pBlockB00 = (Dtype* )blockB00;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"p4BlockB00[interleaved_y] = as_Dtype4( SUB_GROUP_BLOCK_READ4( (const __global INT_TYPE*)src1_read ) );\n"
"src1_read += WIDTH1 * 2;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"p2BlockB00[KERNEL_WIDTH - 1] = as_Dtype2( SUB_GROUP_BLOCK_READ2( (const __global INT_TYPE*)src1_read ) );\n"
"src1_read += WIDTH1 * 2;\n"
"}\n"
"kernel_idx = 0;\n"
"interleaved_y = 0;\n"
"LOOP(KERNEL_WIDTH_DIV2, interleaved_y,\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_16( blockC00, pblockA00[kernel_y ], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_16( blockC01, pblockA01[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC00, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_16( blockC01, pblockA01[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC10, pblockA00[kernel_y ], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_16( blockC11, pblockA01[kernel_y ], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC10, pblockA00[kernel_y + 1], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_16( blockC11, pblockA01[kernel_y + 1], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"} )\n"
"if ( kernel_width_is_odd )\n"
"{\n"
"kernel_y = interleaved_y * 2;\n"
"DOT_PRODUCT_16( blockC00, pblockA00[kernel_y], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_16( blockC01, pblockA01[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"DOT_PRODUCT_16( blockC10, pblockA00[kernel_y], pBlockB00[kernel_idx] );\n"
"DOT_PRODUCT_16( blockC11, pblockA01[kernel_y], pBlockB00[kernel_idx] ); kernel_idx++;\n"
"}\n"
"}\n"
"while( ++patch_row < KERNEL_HEIGHT );\n"
"#if INPUT_PAD_W != 0 || INPUT_PAD_H != 0 || DILATION_X != 1 || DILATION_Y != 1 || INPUT_PAD_BOTTOM != 0 || INPUT_PAD_RIGHT != 0\n"
"curr_y0 = saved_y0;\n"
"curr_y1 = saved_y1;\n"
"#endif\n"
"src0_read0 += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y);\n"
"src0_read1 += slice_pitch - ( KERNEL_HEIGHT * ROW_PITCH * DILATION_Y);\n"
"}\n"
"while ( ++patch_depth < INPUT_DEPTH );\n"
"int out0_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M + 0 ) / output_width + OUT_PADDING_HEIGHT ) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M + 0 ) % output_width ) + OUT_PADDING_LEFT;\n"
"int out1_offset = global_z * out_pitch_z\n"
"+ ( group_x * TILE_N ) * out_pitch_y\n"
"+ ( ( global_y * TILE_M + 1 ) / output_width + OUT_PADDING_HEIGHT ) * OUT_PITCH_X\n"
"+ ( ( global_y * TILE_M + 1 ) % output_width ) + OUT_PADDING_LEFT;\n"
"#if APPLY_BIAS\n"
"Dtype bias[2];\n"
"Dtype2 *bias_vec;\n"
"bias_vec = (Dtype2*)bias;\n"
"*bias_vec = as_Dtype2(SUB_GROUP_BLOCK_READ2((__global INT_TYPE *)biases_base + group_x * TILE_N));\n"
"if (group_x > 0xFFFFFFFEul) {\n"
"dst[0] = bias[0] + bias[1];\n"
"}\n"
"#else\n"
"const Dtype bias[2] = {0, 0};\n"
"#endif\n"
"INTERLEAVED_SIMD16_OUTPUT(dst, out0_offset, 0);\n"
"INTERLEAVED_SIMD16_OUTPUT(dst, out1_offset, 1);\n"
"}\n"
"}\n"
"#endif\n"
"#elif defined KERNEL_DWCONV\n"
"__kernel void DWCONV(\n"
"ELTWISE_DATA_ARG\n"
"FUSED_ARG\n"
"__global Dtype* image_data,\n"
"__global Dtype* kernel_data,\n"
"BIAS_KERNEL_ARG\n"
"__global Dtype* convolved_image_base,\n"
"const int convolved_image_offset,\n"
"const ushort input_width,\n"
"const ushort input_height,\n"
"const ushort output_width,\n"
"const ushort output_height) {\n"
"__global Dtype* convolved_image = convolved_image_base + convolved_image_offset;\n"
"const int out_idx = get_global_id(0);\n"
"const int plane_size = output_width * output_height;\n"
"const int out_plane_idx = out_idx % plane_size;\n"
"const int outputZ = out_idx / plane_size;\n"
"const int outputY = out_plane_idx / output_width;\n"
"const int outputX = out_plane_idx % output_width;\n"
"if (outputZ < OUTPUT_Z)\n"
"{\n"
"Dtype sum = 0.;\n"
"const int org_y = outputY * STRIDE_Y - INPUT_PAD_H;\n"
"const int org_x = outputX * STRIDE_X - INPUT_PAD_W;\n"
"const int currentKernelOffset = KERNEL_SIZE*(outputZ%CHANNELS);\n"
"const int biasIndex=outputZ%CHANNELS;\n"
"const int local_image_offset = org_y*input_width + org_x;\n"
"const int imageSize = input_width*input_height;\n"
"__global Dtype* image_dataPtrFloat = (image_data + (imageSize*outputZ + local_image_offset));\n"
"__global Dtype* kernel_dataPtrFloat = (kernel_data + (currentKernelOffset));\n"
"for(int y = 0; y < KERNEL_H; y++)\n"
"{\n"
"for(int x = 0; x < KERNEL_W; x++)\n"
"{\n"
"if(!(org_y + y * DILATION_Y >= 0 && org_y + y * DILATION_Y < input_height && org_x + x * DILATION_X >= 0 && org_x + x * DILATION_X < input_width))\n"
"{\n"
"continue;\n"
"}\n"
"sum += image_dataPtrFloat[x * DILATION_X] * kernel_dataPtrFloat[x];\n"
"}\n"
"image_dataPtrFloat += input_width * DILATION_Y;\n"
"kernel_dataPtrFloat += KERNEL_W;\n"
"}\n"
"#if APPLY_BIAS\n"
"int offset = outputZ*output_height*output_width + outputY*output_width + outputX;\n"
"ACTIVATION_FUNCTION(convolved_image, offset, sum + biases_base[biasIndex], biasIndex);\n"
"#else\n"
"int offset = outputZ*output_height*output_width + outputY*output_width + outputX;\n"
"ACTIVATION_FUNCTION(convolved_image, offset, sum, biasIndex);\n"
"#endif\n"
"}\n"
"}\n"
"#endif\n"
, "3c78cbca36e239b2dec7831380734a49", NULL};
struct cv::ocl::internal::ProgramEntry conv_spatial_helper_oclsrc={moduleName, "conv_spatial_helper",
"#ifdef HALF_SUPPORT\n"
"#ifdef cl_khr_fp16\n"
"#pragma OPENCL EXTENSION cl_khr_fp16:enable\n"
"#endif\n"
"#endif\n"
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"__kernel void TEMPLATE(copyWeightsSwizzled, Dtype)\n"
"(__global Dtype* weightIn,\n"
"__global Dtype* weightOut,\n"
"const int kernel_w,\n"
"const int kernel_h,\n"
"const int channels,\n"
"const int outputs,\n"
"const int swizzleFactor) {\n"
"unsigned int sX = get_global_id(0);\n"
"int filter = sX / (kernel_w*kernel_h*channels);\n"
"int kernel_X = sX % kernel_w;\n"
"int kernel_Y = (sX / kernel_w) % kernel_h;\n"
"int kernel_C = (sX / (kernel_w * kernel_h)) % channels;\n"
"int FP = filter / swizzleFactor;\n"
"int F1 = filter % swizzleFactor;\n"
"int idxOut = FP*(kernel_w*kernel_h*channels*swizzleFactor) + kernel_C*(kernel_w*kernel_h*swizzleFactor) + kernel_Y*(kernel_w*swizzleFactor) + kernel_X*swizzleFactor + F1;\n"
"int idxIn = filter*(kernel_w*kernel_h*channels) + kernel_C*(kernel_w*kernel_h) + kernel_Y*kernel_w + kernel_X;\n"
"Dtype v = (filter < outputs) ? weightIn[idxIn] : (Dtype)0;\n"
"weightOut[idxOut] = v;\n"
"}\n"
, "e973c981815e5a6c4cc7675de1232b3b", NULL};
struct cv::ocl::internal::ProgramEntry detection_output_oclsrc={moduleName, "detection_output",
"#define Dtype float\n"
"#define Dtype4 float4\n"
"__kernel void DecodeBBoxesCORNER(const int nthreads,\n"
"__global const Dtype* loc_data,\n"
"__global const Dtype* prior_data,\n"
"const int variance_encoded_in_target,\n"
"const int num_priors,\n"
"const int share_location,\n"
"const int num_loc_classes,\n"
"const int background_label_id,\n"
"const int clip_bbox,\n"
"const int locPredTransposed,\n"
"__global Dtype* bbox_data)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))\n"
"{\n"
"Dtype bbox_xmin, bbox_ymin, bbox_xmax, bbox_ymax;\n"
"const int i = index % 4;\n"
"const int p = ((index / 4 / num_loc_classes) % num_priors) * 4;\n"
"const int c = (index / 4) % num_loc_classes;\n"
"int label = share_location ? -1 : c;\n"
"if (label == background_label_id)\n"
"return;\n"
"Dtype4 loc_vec = vload4(0, loc_data + index - i);\n"
"Dtype4 bbox_vec, prior_variance;\n"
"if (variance_encoded_in_target)\n"
"{\n"
"bbox_vec = loc_vec;\n"
"} else {\n"
"const int start_index = num_priors * 4 + p;\n"
"prior_variance = vload4(0, prior_data + start_index);\n"
"bbox_vec = loc_vec * prior_variance;\n"
"}\n"
"if (locPredTransposed)\n"
"{\n"
"bbox_ymin = bbox_vec.x;\n"
"bbox_xmin = bbox_vec.y;\n"
"bbox_ymax = bbox_vec.z;\n"
"bbox_xmax = bbox_vec.w;\n"
"} else {\n"
"bbox_xmin = bbox_vec.x;\n"
"bbox_ymin = bbox_vec.y;\n"
"bbox_xmax = bbox_vec.z;\n"
"bbox_ymax = bbox_vec.w;\n"
"}\n"
"Dtype4 prior_vec = vload4(0, prior_data + p);\n"
"Dtype val;\n"
"switch (i)\n"
"{\n"
"case 0:\n"
"val = prior_vec.x + bbox_xmin;\n"
"break;\n"
"case 1:\n"
"val = prior_vec.y + bbox_ymin;\n"
"break;\n"
"case 2:\n"
"val = prior_vec.z + bbox_xmax;\n"
"break;\n"
"case 3:\n"
"val = prior_vec.w + bbox_ymax;\n"
"break;\n"
"}\n"
"if (clip_bbox)\n"
"val = max(min(val, (Dtype)1.), (Dtype)0.);\n"
"bbox_data[index] = val;\n"
"}\n"
"}\n"
"__kernel void DecodeBBoxesCENTER_SIZE(const int nthreads,\n"
"__global const Dtype* loc_data,\n"
"__global const Dtype* prior_data,\n"
"const int variance_encoded_in_target,\n"
"const int num_priors,\n"
"const int share_location,\n"
"const int num_loc_classes,\n"
"const int background_label_id,\n"
"const int clip_bbox,\n"
"const int locPredTransposed,\n"
"__global Dtype* bbox_data)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))\n"
"{\n"
"Dtype bbox_xmin, bbox_ymin, bbox_xmax, bbox_ymax;\n"
"const int i = index % 4;\n"
"const int p = ((index / 4 / num_loc_classes) % num_priors) * 4;\n"
"const int c = (index / 4) % num_loc_classes;\n"
"int label = share_location ? -1 : c;\n"
"if (label == background_label_id)\n"
"return;\n"
"Dtype4 loc_vec = vload4(0, loc_data + index - i);\n"
"Dtype4 bbox_vec, prior_variance;\n"
"if (variance_encoded_in_target)\n"
"{\n"
"bbox_vec = loc_vec;\n"
"} else {\n"
"const int start_index = num_priors * 4 + p;\n"
"prior_variance = vload4(0, prior_data + start_index);\n"
"bbox_vec = loc_vec * prior_variance;\n"
"}\n"
"if (locPredTransposed)\n"
"{\n"
"bbox_ymin = bbox_vec.x;\n"
"bbox_xmin = bbox_vec.y;\n"
"bbox_ymax = bbox_vec.z;\n"
"bbox_xmax = bbox_vec.w;\n"
"} else {\n"
"bbox_xmin = bbox_vec.x;\n"
"bbox_ymin = bbox_vec.y;\n"
"bbox_xmax = bbox_vec.z;\n"
"bbox_ymax = bbox_vec.w;\n"
"}\n"
"Dtype4 prior_vec = vload4(0, prior_data + p);\n"
"Dtype prior_width = prior_vec.z - prior_vec.x;\n"
"Dtype prior_height = prior_vec.w - prior_vec.y;\n"
"Dtype prior_center_x = (prior_vec.x + prior_vec.z) * .5;\n"
"Dtype prior_center_y = (prior_vec.y + prior_vec.w) * .5;\n"
"Dtype decode_bbox_center_x, decode_bbox_center_y;\n"
"Dtype decode_bbox_width, decode_bbox_height;\n"
"decode_bbox_center_x = bbox_xmin * prior_width + prior_center_x;\n"
"decode_bbox_center_y = bbox_ymin * prior_height + prior_center_y;\n"
"decode_bbox_width = exp(bbox_xmax) * prior_width;\n"
"decode_bbox_height = exp(bbox_ymax) * prior_height;\n"
"Dtype val;\n"
"switch (i)\n"
"{\n"
"case 0:\n"
"val = decode_bbox_center_x - decode_bbox_width * .5;\n"
"break;\n"
"case 1:\n"
"val = decode_bbox_center_y - decode_bbox_height * .5;\n"
"break;\n"
"case 2:\n"
"val = decode_bbox_center_x + decode_bbox_width * .5;\n"
"break;\n"
"case 3:\n"
"val = decode_bbox_center_y + decode_bbox_height * .5;\n"
"break;\n"
"}\n"
"if (clip_bbox)\n"
"val = max(min(val, (Dtype)1.), (Dtype)0.);\n"
"bbox_data[index] = val;\n"
"}\n"
"}\n"
, "0817e73f5a1af5ed94be692d3f7a2ee3", NULL};
struct cv::ocl::internal::ProgramEntry dummy_oclsrc={moduleName, "dummy",
"__kernel void dummy_kernel()\n"
"{\n"
"}\n"
, "697bd1a0f09685d066b8946e159d42bc", NULL};
struct cv::ocl::internal::ProgramEntry eltwise_oclsrc={moduleName, "eltwise",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void op_sum4(__global const Dtype * A,\n"
"__global const Dtype * B,\n"
"unsigned int A_col_size,\n"
"const float coeff1,\n"
"const float coeff2,\n"
"__global Dtype * C)\n"
"{\n"
"unsigned int row_gid = get_group_id(0);\n"
"unsigned int lid = get_local_id(0);\n"
"const __global Dtype *src0_read = A + row_gid * 4 * A_col_size;\n"
"const __global Dtype *src1_read = B + row_gid * 4 * A_col_size;\n"
"__global Dtype *dst0_read = C + row_gid * 4 * A_col_size;\n"
"Dtype4 a0, a1, a2, a3;\n"
"Dtype4 dot0, dot1, dot2, dot3;\n"
"unsigned int i = lid;\n"
"while( i < A_col_size / 4)\n"
"{\n"
"const Dtype4 b0 = vload4(i, src1_read);\n"
"const Dtype4 b1 = vload4(i, src1_read + A_col_size);\n"
"const Dtype4 b2 = vload4(i, src1_read + 2 * A_col_size);\n"
"const Dtype4 b3 = vload4(i, src1_read + 3 * A_col_size);\n"
"#if LOOP == 0\n"
"a0 = vload4(i, src0_read);\n"
"a1 = vload4(i, src0_read + A_col_size);\n"
"a2 = vload4(i, src0_read + 2 * A_col_size);\n"
"a3 = vload4(i, src0_read + 3 * A_col_size);\n"
"dot0 = a0 * (Dtype4)coeff1 + b0 * (Dtype4)coeff2;\n"
"dot1 = a1 * (Dtype4)coeff1 + b1 * (Dtype4)coeff2;\n"
"dot2 = a2 * (Dtype4)coeff1 + b2 * (Dtype4)coeff2;\n"
"dot3 = a3 * (Dtype4)coeff1 + b3 * (Dtype4)coeff2;\n"
"#else\n"
"a0 = vload4(i, dst0_read);\n"
"a1 = vload4(i, dst0_read + A_col_size);\n"
"a2 = vload4(i, dst0_read + 2 * A_col_size);\n"
"a3 = vload4(i, dst0_read + 3 * A_col_size);\n"
"dot0 = a0 + b0 * (Dtype4)coeff2;\n"
"dot1 = a1 + b1 * (Dtype4)coeff2;\n"
"dot2 = a2 + b2 * (Dtype4)coeff2;\n"
"dot3 = a3 + b3 * (Dtype4)coeff2;\n"
"#endif\n"
"vstore4(dot0, i, dst0_read);\n"
"vstore4(dot1, i, dst0_read + A_col_size);\n"
"vstore4(dot2, i, dst0_read + 2 * A_col_size);\n"
"vstore4(dot3, i, dst0_read + 3 * A_col_size);\n"
"i += get_local_size(0);\n"
"}\n"
"}\n"
, "c01078058d3ab56727d0b26c2965434e", NULL};
struct cv::ocl::internal::ProgramEntry gemm_buffer_oclsrc={moduleName, "gemm_buffer",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#define KERNEL_ARG_DTYPE float\n"
"#define TYPE_FLOAT 1\n"
"#define TYPE_HALF 2\n"
"#if TYPE == TYPE_HALF\n"
"#define Dtype half\n"
"#define Dtype2 half2\n"
"#define Dtype4 half4\n"
"#define Dtype8 half8\n"
"#define Dtype16 half16\n"
"#define as_Dtype as_half\n"
"#define as_Dtype2 as_half2\n"
"#define as_Dtype4 as_half4\n"
"#define as_Dtype8 as_half8\n"
"#define as_Dtype16 as_half16\n"
"#else\n"
"#define Dtype float\n"
"#define Dtype2 float2\n"
"#define Dtype4 float4\n"
"#define Dtype8 float8\n"
"#define Dtype16 float16\n"
"#define as_Dtype as_float\n"
"#define as_Dtype2 as_float2\n"
"#define as_Dtype4 as_float4\n"
"#define as_Dtype8 as_float8\n"
"#define as_Dtype16 as_float16\n"
"#endif\n"
"#if TYPE == TYPE_HALF\n"
"#define SHUFFLE_TYPE2(val) as_ushort2(val)\n"
"#define SHUFFLE_TYPE8(val) as_ushort8(val)\n"
"#define SIMD_SIZE_GEMM 16\n"
"#else\n"
"#define SHUFFLE_TYPE2(val) val\n"
"#define SHUFFLE_TYPE8(val) val\n"
"#define SIMD_SIZE_GEMM 8\n"
"#endif\n"
"#if defined(cl_intel_subgroups)\n"
"#pragma OPENCL EXTENSION cl_intel_subgroups : enable\n"
"#endif\n"
"#ifdef ZERO_BETA\n"
"#define BETA_ZERO_CHECK(b0, v) (b0)\n"
"#else\n"
"#define BETA_ZERO_CHECK(b0, v) (v)\n"
"#endif\n"
"#define VEC_SIZE 4\n"
"#define LWG_HEIGHT 4\n"
"#define TILE_M 8\n"
"#if TYPE == TYPE_HALF\n"
"#define TILE_K 32\n"
"#define TILE_N 64\n"
"#else\n"
"#define TILE_K 16\n"
"#define TILE_N 32\n"
"#endif\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, LWG_HEIGHT, 1)))\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM)))\n"
"__kernel void TEMPLATE(gemm_buffer_NN, Dtype)(\n"
"const __global Dtype *src0, int off0,\n"
"const __global Dtype *src1, int off1,\n"
"__global Dtype *dst, int offd,\n"
"int M,\n"
"int N,\n"
"int K,\n"
"KERNEL_ARG_DTYPE alpha_in,\n"
"KERNEL_ARG_DTYPE beta_in,\n"
"int start_index)\n"
"{\n"
"const Dtype alpha = (Dtype)alpha_in;\n"
"const Dtype beta = (Dtype)beta_in;\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int local_x = get_local_id(0);\n"
"const int local_y = get_local_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"Dtype4 brow;\n"
"Dtype2 arow0, arow1, arow2, arow3, arow4, arow5, arow6, arow7;\n"
"__global Dtype *dst_write0 = dst + local_x * VEC_SIZE + (group_x * TILE_N) + (group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M) * N + offd;\n"
"const __global Dtype *src0_read = src0 + local_x * (TILE_K / SIMD_SIZE_GEMM) + (group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M) * K + start_index + off0;\n"
"const __global Dtype *src1_read0 = src1 + local_x * VEC_SIZE + (group_x * TILE_N) + start_index * N + off1;\n"
"int border = -(group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M);\n"
"int row0 = mad24(global_y, TILE_M, 0) < M ? 0 : border;\n"
"int row1 = mad24(global_y, TILE_M, 1) < M ? 1 : border;\n"
"int row2 = mad24(global_y, TILE_M, 2) < M ? 2 : border;\n"
"int row3 = mad24(global_y, TILE_M, 3) < M ? 3 : border;\n"
"int row4 = mad24(global_y, TILE_M, 4) < M ? 4 : border;\n"
"int row5 = mad24(global_y, TILE_M, 5) < M ? 5 : border;\n"
"int row6 = mad24(global_y, TILE_M, 6) < M ? 6 : border;\n"
"int row7 = mad24(global_y, TILE_M, 7) < M ? 7 : border;\n"
"Dtype4 dot00 = (start_index != 0) ? vload4(0, dst_write0) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0));\n"
"Dtype4 dot01 = (start_index != 0) ? vload4(0, dst_write0 + 1 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 1 * N));\n"
"Dtype4 dot02 = (start_index != 0) ? vload4(0, dst_write0 + 2 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 2 * N));\n"
"Dtype4 dot03 = (start_index != 0) ? vload4(0, dst_write0 + 3 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 3 * N));\n"
"Dtype4 dot04 = (start_index != 0) ? vload4(0, dst_write0 + 4 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 4 * N));\n"
"Dtype4 dot05 = (start_index != 0) ? vload4(0, dst_write0 + 5 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 5 * N));\n"
"Dtype4 dot06 = (start_index != 0) ? vload4(0, dst_write0 + 6 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 6 * N));\n"
"Dtype4 dot07 = (start_index != 0) ? vload4(0, dst_write0 + 7 * N) : BETA_ZERO_CHECK((Dtype4)0, beta * vload4(0, dst_write0 + 7 * N));\n"
"int end_index = min(start_index + 256, K);\n"
"int w = start_index;\n"
"while( w + TILE_K <= end_index ) {\n"
"arow0 = alpha * vload2(0, src0_read + row0 * K);\n"
"arow1 = alpha * vload2(0, src0_read + row1 * K);\n"
"arow2 = alpha * vload2(0, src0_read + row2 * K);\n"
"arow3 = alpha * vload2(0, src0_read + row3 * K);\n"
"arow4 = alpha * vload2(0, src0_read + row4 * K);\n"
"arow5 = alpha * vload2(0, src0_read + row5 * K);\n"
"arow6 = alpha * vload2(0, src0_read + row6 * K);\n"
"arow7 = alpha * vload2(0, src0_read + row7 * K);\n"
"#define MM_DOT_PRODUCT( index, suffix ) \\\n"
"brow = vload4(0, src1_read0); src1_read0 += N; \\\n"
"dot00 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow0), index )).s##suffix), brow, dot00 ); \\\n"
"dot01 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow1), index )).s##suffix), brow, dot01 ); \\\n"
"dot02 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow2), index )).s##suffix), brow, dot02 ); \\\n"
"dot03 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow3), index )).s##suffix), brow, dot03 ); \\\n"
"dot04 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow4), index )).s##suffix), brow, dot04 ); \\\n"
"dot05 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow5), index )).s##suffix), brow, dot05 ); \\\n"
"dot06 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow6), index )).s##suffix), brow, dot06 ); \\\n"
"dot07 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow7), index )).s##suffix), brow, dot07 );\n"
"MM_DOT_PRODUCT(0, 0);\n"
"MM_DOT_PRODUCT(0, 1);\n"
"MM_DOT_PRODUCT(1, 0);\n"
"MM_DOT_PRODUCT(1, 1);\n"
"MM_DOT_PRODUCT(2, 0);\n"
"MM_DOT_PRODUCT(2, 1);\n"
"MM_DOT_PRODUCT(3, 0);\n"
"MM_DOT_PRODUCT(3, 1);\n"
"MM_DOT_PRODUCT(4, 0);\n"
"MM_DOT_PRODUCT(4, 1);\n"
"MM_DOT_PRODUCT(5, 0);\n"
"MM_DOT_PRODUCT(5, 1);\n"
"MM_DOT_PRODUCT(6, 0);\n"
"MM_DOT_PRODUCT(6, 1);\n"
"MM_DOT_PRODUCT(7, 0);\n"
"MM_DOT_PRODUCT(7, 1);\n"
"#if TYPE == TYPE_HALF\n"
"MM_DOT_PRODUCT(8, 0);\n"
"MM_DOT_PRODUCT(8, 1);\n"
"MM_DOT_PRODUCT(9, 0);\n"
"MM_DOT_PRODUCT(9, 1);\n"
"MM_DOT_PRODUCT(10, 0);\n"
"MM_DOT_PRODUCT(10, 1);\n"
"MM_DOT_PRODUCT(11, 0);\n"
"MM_DOT_PRODUCT(11, 1);\n"
"MM_DOT_PRODUCT(12, 0);\n"
"MM_DOT_PRODUCT(12, 1);\n"
"MM_DOT_PRODUCT(13, 0);\n"
"MM_DOT_PRODUCT(13, 1);\n"
"MM_DOT_PRODUCT(14, 0);\n"
"MM_DOT_PRODUCT(14, 1);\n"
"MM_DOT_PRODUCT(15, 0);\n"
"MM_DOT_PRODUCT(15, 1);\n"
"#endif\n"
"#undef MM_DOT_PRODUCT\n"
"src0_read += TILE_K;\n"
"w += TILE_K;\n"
"}\n"
"if(w < end_index) {\n"
"arow0.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row0 * K)[0] : 0.0f;\n"
"arow0.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row0 * K)[1] : 0.0f;\n"
"arow1.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row1 * K)[0] : 0.0f;\n"
"arow1.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row1 * K)[1] : 0.0f;\n"
"arow2.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row2 * K)[0] : 0.0f;\n"
"arow2.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row2 * K)[1] : 0.0f;\n"
"arow3.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row3 * K)[0] : 0.0f;\n"
"arow3.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row3 * K)[1] : 0.0f;\n"
"arow4.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row4 * K)[0] : 0.0f;\n"
"arow4.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row4 * K)[1] : 0.0f;\n"
"arow5.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row5 * K)[0] : 0.0f;\n"
"arow5.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row5 * K)[1] : 0.0f;\n"
"arow6.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row6 * K)[0] : 0.0f;\n"
"arow6.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row6 * K)[1] : 0.0f;\n"
"arow7.x = ((w + local_x * 2) < K) ? alpha * (src0_read + row7 * K)[0] : 0.0f;\n"
"arow7.y = ((w + local_x * 2 + 1) < K) ? alpha * (src0_read + row7 * K)[1] : 0.0f;\n"
"#define MM_DOT_PRODUCT( index, suffix ) \\\n"
"brow = (w < K) ? vload4(0, src1_read0) : (Dtype4)0.0f; src1_read0 += N; w++; \\\n"
"dot00 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow0), index )).s##suffix), brow, dot00 ); \\\n"
"dot01 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow1), index )).s##suffix), brow, dot01 ); \\\n"
"dot02 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow2), index )).s##suffix), brow, dot02 ); \\\n"
"dot03 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow3), index )).s##suffix), brow, dot03 ); \\\n"
"dot04 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow4), index )).s##suffix), brow, dot04 ); \\\n"
"dot05 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow5), index )).s##suffix), brow, dot05 ); \\\n"
"dot06 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow6), index )).s##suffix), brow, dot06 ); \\\n"
"dot07 = mad( (Dtype4)(as_Dtype2(intel_sub_group_shuffle( SHUFFLE_TYPE2(arow7), index )).s##suffix), brow, dot07 );\n"
"MM_DOT_PRODUCT(0, 0);\n"
"MM_DOT_PRODUCT(0, 1);\n"
"MM_DOT_PRODUCT(1, 0);\n"
"MM_DOT_PRODUCT(1, 1);\n"
"MM_DOT_PRODUCT(2, 0);\n"
"MM_DOT_PRODUCT(2, 1);\n"
"MM_DOT_PRODUCT(3, 0);\n"
"MM_DOT_PRODUCT(3, 1);\n"
"MM_DOT_PRODUCT(4, 0);\n"
"MM_DOT_PRODUCT(4, 1);\n"
"MM_DOT_PRODUCT(5, 0);\n"
"MM_DOT_PRODUCT(5, 1);\n"
"MM_DOT_PRODUCT(6, 0);\n"
"MM_DOT_PRODUCT(6, 1);\n"
"MM_DOT_PRODUCT(7, 0);\n"
"MM_DOT_PRODUCT(7, 1);\n"
"#if TYPE == TYPE_HALF\n"
"MM_DOT_PRODUCT(8, 0);\n"
"MM_DOT_PRODUCT(8, 1);\n"
"MM_DOT_PRODUCT(9, 0);\n"
"MM_DOT_PRODUCT(9, 1);\n"
"MM_DOT_PRODUCT(10, 0);\n"
"MM_DOT_PRODUCT(10, 1);\n"
"MM_DOT_PRODUCT(11, 0);\n"
"MM_DOT_PRODUCT(11, 1);\n"
"MM_DOT_PRODUCT(12, 0);\n"
"MM_DOT_PRODUCT(12, 1);\n"
"MM_DOT_PRODUCT(13, 0);\n"
"MM_DOT_PRODUCT(13, 1);\n"
"MM_DOT_PRODUCT(14, 0);\n"
"MM_DOT_PRODUCT(14, 1);\n"
"MM_DOT_PRODUCT(15, 0);\n"
"MM_DOT_PRODUCT(15, 1);\n"
"#endif\n"
"#undef MM_DOT_PRODUCT\n"
"}\n"
"if(global_x * 4 < N && global_y * 8 < M) {\n"
"if(mad24(global_x, 4, 3) < N) {\n"
"vstore4(dot00, 0, dst_write0); dst_write0 += N;\n"
"if(mad24(global_y, 8, 1) < M) { vstore4(dot01, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 2) < M) { vstore4(dot02, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 3) < M) { vstore4(dot03, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 4) < M) { vstore4(dot04, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 5) < M) { vstore4(dot05, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 6) < M) { vstore4(dot06, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 7) < M) { vstore4(dot07, 0, dst_write0); }\n"
"} else if(mad24(global_x, 4, 2) < N) {\n"
"vstore2(dot00.xy, 0, dst_write0);\n"
"dst_write0[2] = dot00.z;\n"
"dst_write0 += N;\n"
"if(mad24(global_y, 8, 1) < M) {\n"
"vstore2(dot01.xy, 0, dst_write0);\n"
"dst_write0[2] = dot01.z;\n"
"dst_write0 += N;\n"
"} else\n"
"return;\n"
"if(mad24(global_y, 8, 2) < M) {\n"
"vstore2(dot02.xy, 0, dst_write0);\n"
"dst_write0[2] = dot02.z;\n"
"dst_write0 += N;\n"
"} else\n"
"return;\n"
"if(mad24(global_y, 8, 3) < M) {\n"
"vstore2(dot03.xy, 0, dst_write0);\n"
"dst_write0[2] = dot03.z;\n"
"dst_write0 += N;\n"
"} else\n"
"return;\n"
"if(mad24(global_y, 8, 4) < M) {\n"
"vstore2(dot04.xy, 0, dst_write0);\n"
"dst_write0[2] = dot04.z;\n"
"dst_write0 += N;\n"
"} else\n"
"return;\n"
"if(mad24(global_y, 8, 5) < M) {\n"
"vstore2(dot05.xy, 0, dst_write0);\n"
"dst_write0[2] = dot05.z;\n"
"dst_write0 += N;\n"
"} else\n"
"return;\n"
"if(mad24(global_y, 8, 6) < M) {\n"
"vstore2(dot06.xy, 0, dst_write0);\n"
"dst_write0[2] = dot06.z;\n"
"dst_write0 += N;\n"
"} else\n"
"return;\n"
"if(mad24(global_y, 8, 7) < M) {\n"
"vstore2(dot07.xy, 0, dst_write0);\n"
"dst_write0[2] = dot07.z;\n"
"}\n"
"} else if(mad24(global_x, 4, 1) < N) {\n"
"vstore2(dot00.xy, 0, dst_write0); dst_write0 += N;\n"
"if(mad24(global_y, 8, 1) < M) { vstore2(dot01.xy, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 2) < M) { vstore2(dot02.xy, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 3) < M) { vstore2(dot03.xy, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 4) < M) { vstore2(dot04.xy, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 5) < M) { vstore2(dot05.xy, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 6) < M) { vstore2(dot06.xy, 0, dst_write0); dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 7) < M) { vstore2(dot07.xy, 0, dst_write0); }\n"
"} else {\n"
"dst_write0[0] = dot00.x; dst_write0 += N;\n"
"if(mad24(global_y, 8, 1) < M) { dst_write0[0] = dot01.x; dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 2) < M) { dst_write0[0] = dot02.x; dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 3) < M) { dst_write0[0] = dot03.x; dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 4) < M) { dst_write0[0] = dot04.x; dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 5) < M) { dst_write0[0] = dot05.x; dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 6) < M) { dst_write0[0] = dot06.x; dst_write0 += N; }\n"
"else return;\n"
"if(mad24(global_y, 8, 7) < M) { dst_write0[0] = dot07.x; }\n"
"}\n"
"}\n"
"}\n"
"#undef VEC_SIZE\n"
"#undef LWG_HEIGHT\n"
"#undef TILE_M\n"
"#undef TILE_K\n"
"#undef TILE_N\n"
"#define VEC_SIZE 1\n"
"#define TILE_M 8\n"
"#define TILE_N 8\n"
"#define SLM_BLOCK 128\n"
"#if TYPE == TYPE_HALF\n"
"#define LWG_HEIGHT 2\n"
"#define TILE_K 64\n"
"#else\n"
"#define LWG_HEIGHT 4\n"
"#define TILE_K 32\n"
"#endif\n"
"#if TYPE == TYPE_HALF\n"
"__attribute__((reqd_work_group_size(8, LWG_HEIGHT, 1)))\n"
"__attribute__((intel_reqd_sub_group_size(8)))\n"
"__kernel void TEMPLATE(gemm_buffer_NT, Dtype)(\n"
"const __global Dtype *src0, int off0,\n"
"const __global Dtype *src1, int off1,\n"
"__global Dtype *dst, int offd,\n"
"int M,\n"
"int N,\n"
"int K,\n"
"KERNEL_ARG_DTYPE alpha_in,\n"
"KERNEL_ARG_DTYPE beta_in)\n"
"{\n"
"const Dtype alpha = (Dtype)alpha_in;\n"
"const Dtype beta = (Dtype)beta_in;\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int local_x = get_local_id(0);\n"
"const int local_y = get_local_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"Dtype8 dot00 = 0.f;\n"
"Dtype8 dot01 = 0.f;\n"
"Dtype8 dot02 = 0.f;\n"
"Dtype8 dot03 = 0.f;\n"
"Dtype8 dot04 = 0.f;\n"
"Dtype8 dot05 = 0.f;\n"
"Dtype8 dot06 = 0.f;\n"
"Dtype8 dot07 = 0.f;\n"
"Dtype8 brow0;\n"
"Dtype8 brow1;\n"
"Dtype8 brow2;\n"
"Dtype8 brow3;\n"
"Dtype8 brow4;\n"
"Dtype8 brow5;\n"
"Dtype8 brow6;\n"
"Dtype8 brow7;\n"
"__global Dtype *dst_write0 = dst + local_x * VEC_SIZE + (group_x * TILE_N) + (group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M) * N + offd;\n"
"const __global Dtype *src0_read = src0 + local_x * (TILE_K / 8) + (group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M) * K + off0;\n"
"const __global Dtype *src1_read0 = src1 + (group_x * TILE_N) * K + off1;\n"
"__local Dtype slm_brow[8 * SLM_BLOCK];\n"
"__local Dtype* slm_brow0;\n"
"int local_index = mad24(local_y, 8, local_x) * 8;\n"
"int w;\n"
"for(int b_tile = 0; b_tile < K; b_tile += SLM_BLOCK) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(0, K, local_index))), 0, (__local float *)(slm_brow + mad24(0, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(1, K, local_index))), 0, (__local float *)(slm_brow + mad24(1, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(2, K, local_index))), 0, (__local float *)(slm_brow + mad24(2, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(3, K, local_index))), 0, (__local float *)(slm_brow + mad24(3, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(4, K, local_index))), 0, (__local float *)(slm_brow + mad24(4, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(5, K, local_index))), 0, (__local float *)(slm_brow + mad24(5, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(6, K, local_index))), 0, (__local float *)(slm_brow + mad24(6, SLM_BLOCK, local_index)));\n"
"vstore4(vload4(0, (__global float *)(src1_read0 + mad24(7, K, local_index))), 0, (__local float *)(slm_brow + mad24(7, SLM_BLOCK, local_index)));\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"slm_brow0 = slm_brow + local_x * (TILE_K / 8);\n"
"w = b_tile;\n"
"int end_w = min(b_tile + SLM_BLOCK, K);\n"
"while( w + TILE_K <= end_w ) {\n"
"Dtype8 arow;\n"
"brow0 = as_half8(vload4(0, (__local float *)(slm_brow0 + 0 * SLM_BLOCK)));\n"
"brow1 = as_half8(vload4(0, (__local float *)(slm_brow0 + 1 * SLM_BLOCK)));\n"
"brow2 = as_half8(vload4(0, (__local float *)(slm_brow0 + 2 * SLM_BLOCK)));\n"
"brow3 = as_half8(vload4(0, (__local float *)(slm_brow0 + 3 * SLM_BLOCK)));\n"
"brow4 = as_half8(vload4(0, (__local float *)(slm_brow0 + 4 * SLM_BLOCK)));\n"
"brow5 = as_half8(vload4(0, (__local float *)(slm_brow0 + 5 * SLM_BLOCK)));\n"
"brow6 = as_half8(vload4(0, (__local float *)(slm_brow0 + 6 * SLM_BLOCK)));\n"
"brow7 = as_half8(vload4(0, (__local float *)(slm_brow0 + 7 * SLM_BLOCK)));\n"
"#define MM_DOT_PRODUCT( _row, _dot ) \\\n"
"arow = as_half8(vload4(0, (__global float *)(src0_read + _row * K))); \\\n"
"_dot = mad( (Dtype8)(arow.s0), (Dtype8)(brow0.s0, brow1.s0, brow2.s0, brow3.s0, brow4.s0, brow5.s0, brow6.s0, brow7.s0), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s1), (Dtype8)(brow0.s1, brow1.s1, brow2.s1, brow3.s1, brow4.s1, brow5.s1, brow6.s1, brow7.s1), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s2), (Dtype8)(brow0.s2, brow1.s2, brow2.s2, brow3.s2, brow4.s2, brow5.s2, brow6.s2, brow7.s2), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s3), (Dtype8)(brow0.s3, brow1.s3, brow2.s3, brow3.s3, brow4.s3, brow5.s3, brow6.s3, brow7.s3), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s4), (Dtype8)(brow0.s4, brow1.s4, brow2.s4, brow3.s4, brow4.s4, brow5.s4, brow6.s4, brow7.s4), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s5), (Dtype8)(brow0.s5, brow1.s5, brow2.s5, brow3.s5, brow4.s5, brow5.s5, brow6.s5, brow7.s5), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s6), (Dtype8)(brow0.s6, brow1.s6, brow2.s6, brow3.s6, brow4.s6, brow5.s6, brow6.s6, brow7.s6), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s7), (Dtype8)(brow0.s7, brow1.s7, brow2.s7, brow3.s7, brow4.s7, brow5.s7, brow6.s7, brow7.s7), _dot );\n"
"MM_DOT_PRODUCT( 0, dot00 );\n"
"MM_DOT_PRODUCT( 1, dot01 );\n"
"MM_DOT_PRODUCT( 2, dot02 );\n"
"MM_DOT_PRODUCT( 3, dot03 );\n"
"MM_DOT_PRODUCT( 4, dot04 );\n"
"MM_DOT_PRODUCT( 5, dot05 );\n"
"MM_DOT_PRODUCT( 6, dot06 );\n"
"MM_DOT_PRODUCT( 7, dot07 );\n"
"#undef MM_DOT_PRODUCT\n"
"src0_read += TILE_K;\n"
"slm_brow0 += TILE_K;\n"
"w += TILE_K;\n"
"}\n"
"src1_read0 += SLM_BLOCK;\n"
"}\n"
"if(w < K) {\n"
"Dtype8 arow;\n"
"#define READ_BROW(_brow, _row) \\\n"
"_brow = as_half8(vload4(0, (__local float *)(slm_brow0 + _row * SLM_BLOCK))); \\\n"
"_brow.s0 = (mad24(local_x, 8, w) < K) ? _brow.s0 : 0.0f; \\\n"
"_brow.s1 = (mad24(local_x, 8, w + 1) < K) ? _brow.s1 : 0.0f; \\\n"
"_brow.s2 = (mad24(local_x, 8, w + 2) < K) ? _brow.s2 : 0.0f; \\\n"
"_brow.s3 = (mad24(local_x, 8, w + 3) < K) ? _brow.s3 : 0.0f; \\\n"
"_brow.s4 = (mad24(local_x, 8, w + 4) < K) ? _brow.s4 : 0.0f; \\\n"
"_brow.s5 = (mad24(local_x, 8, w + 5) < K) ? _brow.s5 : 0.0f; \\\n"
"_brow.s6 = (mad24(local_x, 8, w + 6) < K) ? _brow.s6 : 0.0f; \\\n"
"_brow.s7 = (mad24(local_x, 8, w + 7) < K) ? _brow.s7 : 0.0f;\n"
"READ_BROW(brow0, 0);\n"
"READ_BROW(brow1, 1);\n"
"READ_BROW(brow2, 2);\n"
"READ_BROW(brow3, 3);\n"
"READ_BROW(brow4, 4);\n"
"READ_BROW(brow5, 5);\n"
"READ_BROW(brow6, 6);\n"
"READ_BROW(brow7, 7);\n"
"#undef READ_BROW\n"
"#define MM_DOT_PRODUCT( _row, _dot ) \\\n"
"arow = as_half8(vload4(0, (__global float *)(src0_read + _row * K))); \\\n"
"arow.s0 = (mad24(local_x, 8, w) < K) ? arow.s0 : 0.0f; \\\n"
"arow.s1 = (mad24(local_x, 8, w + 1) < K) ? arow.s1 : 0.0f; \\\n"
"arow.s2 = (mad24(local_x, 8, w + 2) < K) ? arow.s2 : 0.0f; \\\n"
"arow.s3 = (mad24(local_x, 8, w + 3) < K) ? arow.s3 : 0.0f; \\\n"
"arow.s4 = (mad24(local_x, 8, w + 4) < K) ? arow.s4 : 0.0f; \\\n"
"arow.s5 = (mad24(local_x, 8, w + 5) < K) ? arow.s5 : 0.0f; \\\n"
"arow.s6 = (mad24(local_x, 8, w + 6) < K) ? arow.s6 : 0.0f; \\\n"
"arow.s7 = (mad24(local_x, 8, w + 7) < K) ? arow.s7 : 0.0f; \\\n"
"_dot = mad( (Dtype8)(arow.s0), (Dtype8)(brow0.s0, brow1.s0, brow2.s0, brow3.s0, brow4.s0, brow5.s0, brow6.s0, brow7.s0), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s1), (Dtype8)(brow0.s1, brow1.s1, brow2.s1, brow3.s1, brow4.s1, brow5.s1, brow6.s1, brow7.s1), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s2), (Dtype8)(brow0.s2, brow1.s2, brow2.s2, brow3.s2, brow4.s2, brow5.s2, brow6.s2, brow7.s2), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s3), (Dtype8)(brow0.s3, brow1.s3, brow2.s3, brow3.s3, brow4.s3, brow5.s3, brow6.s3, brow7.s3), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s4), (Dtype8)(brow0.s4, brow1.s4, brow2.s4, brow3.s4, brow4.s4, brow5.s4, brow6.s4, brow7.s4), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s5), (Dtype8)(brow0.s5, brow1.s5, brow2.s5, brow3.s5, brow4.s5, brow5.s5, brow6.s5, brow7.s5), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s6), (Dtype8)(brow0.s6, brow1.s6, brow2.s6, brow3.s6, brow4.s6, brow5.s6, brow6.s6, brow7.s6), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.s7), (Dtype8)(brow0.s7, brow1.s7, brow2.s7, brow3.s7, brow4.s7, brow5.s7, brow6.s7, brow7.s7), _dot );\n"
"MM_DOT_PRODUCT( 0, dot00 );\n"
"MM_DOT_PRODUCT( 1, dot01 );\n"
"MM_DOT_PRODUCT( 2, dot02 );\n"
"MM_DOT_PRODUCT( 3, dot03 );\n"
"MM_DOT_PRODUCT( 4, dot04 );\n"
"MM_DOT_PRODUCT( 5, dot05 );\n"
"MM_DOT_PRODUCT( 6, dot06 );\n"
"MM_DOT_PRODUCT( 7, dot07 );\n"
"#undef MM_DOT_PRODUCT\n"
"}\n"
"#define REDUCE(_dot) \\\n"
"_dot = as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 0)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 1)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 2)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 3)) + \\\n"
"as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 4)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 5)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 6)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 7));\n"
"REDUCE(dot00);\n"
"REDUCE(dot01);\n"
"REDUCE(dot02);\n"
"REDUCE(dot03);\n"
"REDUCE(dot04);\n"
"REDUCE(dot05);\n"
"REDUCE(dot06);\n"
"REDUCE(dot07);\n"
"#undef REDUCE\n"
"Dtype output = 0.0f;\n"
"#define OUTPUT( _dot) \\\n"
"output = (local_x == 0) ? _dot.s0 : output; \\\n"
"output = (local_x == 1) ? _dot.s1 : output; \\\n"
"output = (local_x == 2) ? _dot.s2 : output; \\\n"
"output = (local_x == 3) ? _dot.s3 : output; \\\n"
"output = (local_x == 4) ? _dot.s4 : output; \\\n"
"output = (local_x == 5) ? _dot.s5 : output; \\\n"
"output = (local_x == 6) ? _dot.s6 : output; \\\n"
"output = (local_x == 7) ? _dot.s7 : output; \\\n"
"dst_write0[0] = BETA_ZERO_CHECK(alpha * output, mad(output, alpha, beta * dst_write0[0])); \\\n"
"dst_write0 += N;\n"
"if(global_x < N && global_y * 8 < M) {\n"
"OUTPUT(dot00);\n"
"if(mad24(global_y, 8, 1) < M) { OUTPUT(dot01); }\n"
"if(mad24(global_y, 8, 2) < M) { OUTPUT(dot02); }\n"
"if(mad24(global_y, 8, 3) < M) { OUTPUT(dot03); }\n"
"if(mad24(global_y, 8, 4) < M) { OUTPUT(dot04); }\n"
"if(mad24(global_y, 8, 5) < M) { OUTPUT(dot05); }\n"
"if(mad24(global_y, 8, 6) < M) { OUTPUT(dot06); }\n"
"if(mad24(global_y, 8, 7) < M) { OUTPUT(dot07); }\n"
"}\n"
"#undef OUTPUT\n"
"}\n"
"#else\n"
"__attribute__((reqd_work_group_size(8, LWG_HEIGHT, 1)))\n"
"__attribute__((intel_reqd_sub_group_size(8)))\n"
"__kernel void TEMPLATE(gemm_buffer_NT, Dtype)(\n"
"const __global Dtype *src0, int off0,\n"
"const __global Dtype *src1, int off1,\n"
"__global Dtype *dst, int offd,\n"
"int M,\n"
"int N,\n"
"int K,\n"
"KERNEL_ARG_DTYPE alpha_in,\n"
"KERNEL_ARG_DTYPE beta_in)\n"
"{\n"
"const Dtype alpha = (Dtype)alpha_in;\n"
"const Dtype beta = (Dtype)beta_in;\n"
"const int group_x = get_group_id(0);\n"
"const int group_y = get_group_id(1);\n"
"const int local_x = get_local_id(0);\n"
"const int local_y = get_local_id(1);\n"
"const int global_x = get_global_id(0);\n"
"const int global_y = get_global_id(1);\n"
"Dtype8 dot00 = 0.f;\n"
"Dtype8 dot01 = 0.f;\n"
"Dtype8 dot02 = 0.f;\n"
"Dtype8 dot03 = 0.f;\n"
"Dtype8 dot04 = 0.f;\n"
"Dtype8 dot05 = 0.f;\n"
"Dtype8 dot06 = 0.f;\n"
"Dtype8 dot07 = 0.f;\n"
"Dtype4 brow0;\n"
"Dtype4 brow1;\n"
"Dtype4 brow2;\n"
"Dtype4 brow3;\n"
"Dtype4 brow4;\n"
"Dtype4 brow5;\n"
"Dtype4 brow6;\n"
"Dtype4 brow7;\n"
"__global Dtype *dst_write0 = dst + local_x * VEC_SIZE + (group_x * TILE_N) + (group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M) * N + offd;\n"
"const __global Dtype *src0_read = src0 + local_x * (TILE_K / 8) + (group_y * LWG_HEIGHT * TILE_M + local_y * TILE_M) * K + off0;\n"
"const __global Dtype *src1_read0 = src1 + (group_x * TILE_N) * K + off1;\n"
"__local Dtype slm_brow[8 * SLM_BLOCK];\n"
"__local Dtype* slm_brow0;\n"
"int local_index = mad24(local_y, 8, local_x) * 4;\n"
"int w;\n"
"for(int b_tile = 0; b_tile < K; b_tile += SLM_BLOCK) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"vstore4(vload4(0, src1_read0 + mad24(0, K, local_index)), 0, slm_brow + mad24(0, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(1, K, local_index)), 0, slm_brow + mad24(1, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(2, K, local_index)), 0, slm_brow + mad24(2, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(3, K, local_index)), 0, slm_brow + mad24(3, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(4, K, local_index)), 0, slm_brow + mad24(4, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(5, K, local_index)), 0, slm_brow + mad24(5, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(6, K, local_index)), 0, slm_brow + mad24(6, SLM_BLOCK, local_index));\n"
"vstore4(vload4(0, src1_read0 + mad24(7, K, local_index)), 0, slm_brow + mad24(7, SLM_BLOCK, local_index));\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"slm_brow0 = slm_brow + local_x * (TILE_K / 8);\n"
"w = b_tile;\n"
"int end_w = min(b_tile + SLM_BLOCK, K);\n"
"while( w + TILE_K <= end_w ) {\n"
"Dtype4 arow;\n"
"brow0 = vload4(0, slm_brow0 + 0 * SLM_BLOCK);\n"
"brow1 = vload4(0, slm_brow0 + 1 * SLM_BLOCK);\n"
"brow2 = vload4(0, slm_brow0 + 2 * SLM_BLOCK);\n"
"brow3 = vload4(0, slm_brow0 + 3 * SLM_BLOCK);\n"
"brow4 = vload4(0, slm_brow0 + 4 * SLM_BLOCK);\n"
"brow5 = vload4(0, slm_brow0 + 5 * SLM_BLOCK);\n"
"brow6 = vload4(0, slm_brow0 + 6 * SLM_BLOCK);\n"
"brow7 = vload4(0, slm_brow0 + 7 * SLM_BLOCK);\n"
"#define MM_DOT_PRODUCT( _row, _dot ) \\\n"
"arow = vload4(0, src0_read + _row * K); \\\n"
"_dot = mad( (Dtype8)(arow.x), (Dtype8)(brow0.x, brow1.x, brow2.x, brow3.x, brow4.x, brow5.x, brow6.x, brow7.x), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.y), (Dtype8)(brow0.y, brow1.y, brow2.y, brow3.y, brow4.y, brow5.y, brow6.y, brow7.y), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.z), (Dtype8)(brow0.z, brow1.z, brow2.z, brow3.z, brow4.z, brow5.z, brow6.z, brow7.z), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.w), (Dtype8)(brow0.w, brow1.w, brow2.w, brow3.w, brow4.w, brow5.w, brow6.w, brow7.w), _dot );\n"
"MM_DOT_PRODUCT( 0, dot00 );\n"
"MM_DOT_PRODUCT( 1, dot01 );\n"
"MM_DOT_PRODUCT( 2, dot02 );\n"
"MM_DOT_PRODUCT( 3, dot03 );\n"
"MM_DOT_PRODUCT( 4, dot04 );\n"
"MM_DOT_PRODUCT( 5, dot05 );\n"
"MM_DOT_PRODUCT( 6, dot06 );\n"
"MM_DOT_PRODUCT( 7, dot07 );\n"
"#undef MM_DOT_PRODUCT\n"
"src0_read += TILE_K;\n"
"slm_brow0 += TILE_K;\n"
"w += TILE_K;\n"
"}\n"
"src1_read0 += SLM_BLOCK;\n"
"}\n"
"if(w < K) {\n"
"Dtype4 arow;\n"
"#define READ_BROW(_brow, _row) \\\n"
"_brow = vload4(0, slm_brow0 + _row * SLM_BLOCK); \\\n"
"_brow.x = (mad24(local_x, 4, w) < K) ? _brow.x : 0.0f; \\\n"
"_brow.y = (mad24(local_x, 4, w + 1) < K) ? _brow.y : 0.0f; \\\n"
"_brow.z = (mad24(local_x, 4, w + 2) < K) ? _brow.z : 0.0f; \\\n"
"_brow.w = (mad24(local_x, 4, w + 3) < K) ? _brow.w : 0.0f;\n"
"READ_BROW(brow0, 0);\n"
"READ_BROW(brow1, 1);\n"
"READ_BROW(brow2, 2);\n"
"READ_BROW(brow3, 3);\n"
"READ_BROW(brow4, 4);\n"
"READ_BROW(brow5, 5);\n"
"READ_BROW(brow6, 6);\n"
"READ_BROW(brow7, 7);\n"
"#undef READ_BROW\n"
"#define MM_DOT_PRODUCT( _row, _dot ) \\\n"
"arow = vload4(0, src0_read + _row * K); \\\n"
"arow.x = (mad24(local_x, 4, w) < K) ? arow.x : 0.0f; \\\n"
"arow.y = (mad24(local_x, 4, w + 1) < K) ? arow.y : 0.0f; \\\n"
"arow.z = (mad24(local_x, 4, w + 2) < K) ? arow.z : 0.0f; \\\n"
"arow.w = (mad24(local_x, 4, w + 3) < K) ? arow.w : 0.0f; \\\n"
"_dot = mad( (Dtype8)(arow.x), (Dtype8)(brow0.x, brow1.x, brow2.x, brow3.x, brow4.x, brow5.x, brow6.x, brow7.x), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.y), (Dtype8)(brow0.y, brow1.y, brow2.y, brow3.y, brow4.y, brow5.y, brow6.y, brow7.y), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.z), (Dtype8)(brow0.z, brow1.z, brow2.z, brow3.z, brow4.z, brow5.z, brow6.z, brow7.z), _dot ); \\\n"
"_dot = mad( (Dtype8)(arow.w), (Dtype8)(brow0.w, brow1.w, brow2.w, brow3.w, brow4.w, brow5.w, brow6.w, brow7.w), _dot );\n"
"MM_DOT_PRODUCT( 0, dot00 );\n"
"MM_DOT_PRODUCT( 1, dot01 );\n"
"MM_DOT_PRODUCT( 2, dot02 );\n"
"MM_DOT_PRODUCT( 3, dot03 );\n"
"MM_DOT_PRODUCT( 4, dot04 );\n"
"MM_DOT_PRODUCT( 5, dot05 );\n"
"MM_DOT_PRODUCT( 6, dot06 );\n"
"MM_DOT_PRODUCT( 7, dot07 );\n"
"#undef MM_DOT_PRODUCT\n"
"}\n"
"#define REDUCE(_dot) \\\n"
"_dot = as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 0)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 1)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 2)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 3)) + \\\n"
"as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 4)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 5)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 6)) + as_Dtype8(intel_sub_group_shuffle(SHUFFLE_TYPE8(_dot), 7));\n"
"REDUCE(dot00);\n"
"REDUCE(dot01);\n"
"REDUCE(dot02);\n"
"REDUCE(dot03);\n"
"REDUCE(dot04);\n"
"REDUCE(dot05);\n"
"REDUCE(dot06);\n"
"REDUCE(dot07);\n"
"#undef REDUCE\n"
"Dtype output = 0.0f;\n"
"#define OUTPUT( _dot) \\\n"
"output = (local_x == 0) ? _dot.s0 : output; \\\n"
"output = (local_x == 1) ? _dot.s1 : output; \\\n"
"output = (local_x == 2) ? _dot.s2 : output; \\\n"
"output = (local_x == 3) ? _dot.s3 : output; \\\n"
"output = (local_x == 4) ? _dot.s4 : output; \\\n"
"output = (local_x == 5) ? _dot.s5 : output; \\\n"
"output = (local_x == 6) ? _dot.s6 : output; \\\n"
"output = (local_x == 7) ? _dot.s7 : output; \\\n"
"dst_write0[0] = BETA_ZERO_CHECK(alpha * output, mad(output, alpha, beta * dst_write0[0])); \\\n"
"dst_write0 += N;\n"
"if(global_x < N && global_y * 8 < M) {\n"
"OUTPUT(dot00);\n"
"if(mad24(global_y, 8, 1) < M) { OUTPUT(dot01); }\n"
"if(mad24(global_y, 8, 2) < M) { OUTPUT(dot02); }\n"
"if(mad24(global_y, 8, 3) < M) { OUTPUT(dot03); }\n"
"if(mad24(global_y, 8, 4) < M) { OUTPUT(dot04); }\n"
"if(mad24(global_y, 8, 5) < M) { OUTPUT(dot05); }\n"
"if(mad24(global_y, 8, 6) < M) { OUTPUT(dot06); }\n"
"if(mad24(global_y, 8, 7) < M) { OUTPUT(dot07); }\n"
"}\n"
"#undef OUTPUT\n"
"}\n"
"#endif\n"
"#undef VEC_SIZE\n"
"#undef LWG_HEIGHT\n"
"#undef TILE_M\n"
"#undef TILE_K\n"
"#undef TILE_N\n"
"#undef SLM_BLOCK\n"
"#define SLM_SIZE 64\n"
"void TEMPLATE(gemm_buffer_NT_M_2_edgerows,Dtype)(\n"
"const __global Dtype* srca_read0,\n"
"const __global Dtype* srca_read1,\n"
"const __global Dtype* srcb_read,\n"
"__local Dtype4* work0,\n"
"__local Dtype4* work1,\n"
"int N,\n"
"int K,\n"
"int x_gid,\n"
"int lid,\n"
"Dtype alpha,\n"
"Dtype beta,\n"
"__global Dtype* dstc0,\n"
"__global Dtype* dstc1)\n"
"{\n"
"__local Dtype* work_each0 = (__local Dtype*)work0;\n"
"__local Dtype* work_each1 = (__local Dtype*)work1;\n"
"int rows = N - x_gid * 4;\n"
"Dtype4 dot0[3] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot1[3] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"int i = lid;\n"
"while( i < K / 4) {\n"
"const Dtype4 b0 = {srca_read0[i*4], srca_read0[(i*4+1)], srca_read0[(i*4+2)], srca_read0[(i*4+3)]};\n"
"const Dtype4 b1 = {srca_read1[i*4], srca_read1[(i*4+1)], srca_read1[(i*4+2)], srca_read1[(i*4+3)]};\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"Dtype4 a = vload4(i, srcb_read + j * K);\n"
"dot0[j] += b0 * a;\n"
"dot1[j] += b1 * a;\n"
"}\n"
"i += get_local_size(0);\n"
"}\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"work_each0[lid * 4 + j] = dot0[j].x + dot0[j].y + dot0[j].z + dot0[j].w;\n"
"work_each1[lid * 4 + j] = dot1[j].x + dot1[j].y + dot1[j].z + dot1[j].w;\n"
"}\n"
"if(i == K / 4) {\n"
"short tail_items = K % 4;\n"
"if(tail_items != 0) {\n"
"const __global Dtype *srcb_tail = srcb_read + i * 4;\n"
"const __global Dtype *srca_tail0 = srca_read0 + i * 4;\n"
"const __global Dtype *srca_tail1 = srca_read1 + i * 4;\n"
"#pragma unroll\n"
"for(short i = 0; i < tail_items; ++i) {\n"
"const Dtype at0 = srca_tail0[i];\n"
"const Dtype at1 = srca_tail1[i];\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"work_each0[lid * 4 + j] += at0 * srcb_tail[i + j * K];\n"
"work_each1[lid * 4 + j] += at1 * srcb_tail[i + j * K];\n"
"}\n"
"}\n"
"}\n"
"}\n"
"for(int stride = get_local_size(0) >> 1; stride > 0 ; stride >>= 1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride) {\n"
"work0[lid] += work0[lid+stride];\n"
"work1[lid] += work1[lid+stride];\n"
"}\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid == 0) {\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"#ifdef ZERO_BETA\n"
"Dtype a0 = alpha * work_each0[j];\n"
"Dtype a1 = alpha * work_each1[j];\n"
"#else\n"
"Dtype a0 = alpha * work_each0[j] + beta * dstc0[(x_gid * 4 + j)];\n"
"Dtype a1 = alpha * work_each1[j] + beta * dstc1[(x_gid * 4 + j)];\n"
"#endif\n"
"dstc0[(x_gid * 4 + j)] = a0;\n"
"dstc1[(x_gid * 4 + j)] = a1;\n"
"}\n"
"}\n"
"}\n"
"__kernel void TEMPLATE(gemm_buffer_NT_M_2,Dtype)(\n"
"__global const Dtype * A,\n"
"int offA,\n"
"__global const Dtype * B,\n"
"int offB,\n"
"__global Dtype * C,\n"
"int offC,\n"
"int M,\n"
"int N,\n"
"int K,\n"
"KERNEL_ARG_DTYPE alpha_f,\n"
"KERNEL_ARG_DTYPE beta_f)\n"
"{\n"
"Dtype alpha = (Dtype)alpha_f;\n"
"Dtype beta = (Dtype)beta_f;\n"
"int x_gid = get_group_id(0);\n"
"int lid = get_local_id(0);\n"
"const __global Dtype *srca_read0 = A + offA;\n"
"const __global Dtype *srca_read1 = srca_read0 + K;\n"
"const __global Dtype *srcb_read = B + x_gid * 4 * K + offB;\n"
"__global Dtype4 *dstc0 = (__global Dtype4*)(C + offC);\n"
"__global Dtype4 *dstc1 = (__global Dtype4*)((__global Dtype*)(dstc0) + N);\n"
"__local Dtype4 work0[SLM_SIZE];\n"
"__local Dtype4 work1[SLM_SIZE];\n"
"__local Dtype* work_each0 = (__local Dtype*)work0;\n"
"__local Dtype* work_each1 = (__local Dtype*)work1;\n"
"if(x_gid == N / 4) {\n"
"TEMPLATE(gemm_buffer_NT_M_2_edgerows,Dtype) \\\n"
"(srca_read0, srca_read1, srcb_read, work0, work1, N, K, x_gid, lid, alpha, beta, (__global Dtype*)dstc0, (__global Dtype*)dstc1);\n"
"} else {\n"
"Dtype4 dot0[4] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot1[4] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"int i = lid;\n"
"while( i < K / 4) {\n"
"const Dtype4 b0 = vload4(i, srca_read0);\n"
"const Dtype4 b1 = vload4(i, srca_read1);\n"
"#pragma unroll\n"
"for(int j = 0; j < 4; ++j) {\n"
"Dtype4 a = vload4(i, srcb_read + j * K);\n"
"dot0[j] += b0 * a;\n"
"dot1[j] += b1 * a;\n"
"}\n"
"i += get_local_size(0);\n"
"}\n"
"#pragma unroll\n"
"for(int j = 0; j < 4; ++j) {\n"
"work_each0[lid * 4 + j] = dot0[j].x + dot0[j].y + dot0[j].z + dot0[j].w;\n"
"work_each1[lid * 4 + j] = dot1[j].x + dot1[j].y + dot1[j].z + dot1[j].w;\n"
"}\n"
"if(i == K / 4) {\n"
"short tail_items = K % 4;\n"
"if(tail_items != 0) {\n"
"const __global Dtype *srcb_tail = srcb_read + i * 4;\n"
"const __global Dtype *srca_tail0 = srca_read0 + i * 4;\n"
"const __global Dtype *srca_tail1 = srca_read1 + i * 4;\n"
"#pragma unroll\n"
"for(short i = 0; i < tail_items; ++i) {\n"
"const Dtype at0 = srca_tail0[i];\n"
"const Dtype at1 = srca_tail1[i];\n"
"#pragma unroll\n"
"for(int j = 0; j < 4; ++j) {\n"
"work_each0[lid * 4 + j] += at0 * srcb_tail[i + j * K];\n"
"work_each1[lid * 4 + j] += at1 * srcb_tail[i + j * K];\n"
"}\n"
"}\n"
"}\n"
"}\n"
"for(int stride = get_local_size(0) >> 1; stride > 0 ; stride >>= 1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride) {\n"
"work0[lid] += work0[lid+stride];\n"
"work1[lid] += work1[lid+stride];\n"
"}\n"
"}\n"
"if(lid == 0)\n"
"{\n"
"#ifdef ZERO_BETA\n"
"dstc0[x_gid] = alpha * work0[0];\n"
"dstc1[x_gid] = alpha * work1[0];\n"
"#else\n"
"dstc0[x_gid] = alpha * work0[0] + beta * dstc0[x_gid];\n"
"dstc1[x_gid] = alpha * work1[0] + beta * dstc1[x_gid];\n"
"#endif\n"
"}\n"
"}\n"
"}\n"
"#undef SLM_SIZE\n"
"#define SLM_SIZE 32\n"
"void TEMPLATE(gemm_buffer_NT_M_4_edgerows,Dtype)(\n"
"const __global Dtype* srca_read0,\n"
"const __global Dtype* srca_read1,\n"
"const __global Dtype* srca_read2,\n"
"const __global Dtype* srca_read3,\n"
"const __global Dtype* srcb_read,\n"
"__local Dtype4* work0,\n"
"__local Dtype4* work1,\n"
"__local Dtype4* work2,\n"
"__local Dtype4* work3,\n"
"int N,\n"
"int K,\n"
"int x_gid,\n"
"int lid,\n"
"Dtype alpha,\n"
"Dtype beta,\n"
"__global Dtype* dstc0,\n"
"__global Dtype* dstc1,\n"
"__global Dtype* dstc2,\n"
"__global Dtype* dstc3)\n"
"{\n"
"__local Dtype* work_each0 = (__local Dtype*)(work0 + lid);\n"
"__local Dtype* work_each1 = (__local Dtype*)(work1 + lid);\n"
"__local Dtype* work_each2 = (__local Dtype*)(work2 + lid);\n"
"__local Dtype* work_each3 = (__local Dtype*)(work3 + lid);\n"
"int rows = N - x_gid * 4;\n"
"Dtype4 dot0[3] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot1[3] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot2[3] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot3[3] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"int i = lid;\n"
"while( i < K / 4) {\n"
"const Dtype4 a0 = {srca_read0[i*4], srca_read0[(i*4+1)], srca_read0[(i*4+2)], srca_read0[(i*4+3)]};\n"
"const Dtype4 a1 = {srca_read1[i*4], srca_read1[(i*4+1)], srca_read1[(i*4+2)], srca_read1[(i*4+3)]};\n"
"const Dtype4 a2 = {srca_read2[i*4], srca_read2[(i*4+1)], srca_read2[(i*4+2)], srca_read2[(i*4+3)]};\n"
"const Dtype4 a3 = {srca_read3[i*4], srca_read3[(i*4+1)], srca_read3[(i*4+2)], srca_read3[(i*4+3)]};\n"
"#pragma unrol\n"
"for(int j = 0; j < rows; ++j) {\n"
"dot0[j] += a0 * vload4(i, srcb_read + j * K);\n"
"dot1[j] += a1 * vload4(i, srcb_read + j * K);\n"
"dot2[j] += a2 * vload4(i, srcb_read + j * K);\n"
"dot3[j] += a3 * vload4(i, srcb_read + j * K);\n"
"}\n"
"i += get_local_size(0);\n"
"}\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"work_each0[j] = dot0[j].x + dot0[j].y + dot0[j].z + dot0[j].w;\n"
"work_each1[j] = dot1[j].x + dot1[j].y + dot1[j].z + dot1[j].w;\n"
"work_each2[j] = dot2[j].x + dot2[j].y + dot2[j].z + dot2[j].w;\n"
"work_each3[j] = dot3[j].x + dot3[j].y + dot3[j].z + dot3[j].w;\n"
"}\n"
"if(i == K / 4) {\n"
"short tail_items = K % 4;\n"
"if(tail_items != 0) {\n"
"const __global Dtype *srcb_tail = srcb_read + i * 4;\n"
"const __global Dtype *srca_tail0 = srca_read0 + i * 4;\n"
"const __global Dtype *srca_tail1 = srca_read1 + i * 4;\n"
"const __global Dtype *srca_tail2 = srca_read2 + i * 4;\n"
"const __global Dtype *srca_tail3 = srca_read3 + i * 4;\n"
"#pragma unroll\n"
"for(short i = 0; i < tail_items; ++i) {\n"
"const Dtype at0 = srca_tail0[i];\n"
"const Dtype at1 = srca_tail1[i];\n"
"const Dtype at2 = srca_tail2[i];\n"
"const Dtype at3 = srca_tail3[i];\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"work_each0[j] += at0 * srcb_tail[i + j * K];\n"
"work_each1[j] += at1 * srcb_tail[i + j * K];\n"
"work_each2[j] += at2 * srcb_tail[i + j * K];\n"
"work_each3[j] += at3 * srcb_tail[i + j * K];\n"
"}\n"
"}\n"
"}\n"
"}\n"
"for(int stride = get_local_size(0) >> 1; stride > 0 ; stride >>= 1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride) {\n"
"work0[lid] += work0[lid+stride];\n"
"work1[lid] += work1[lid+stride];\n"
"work2[lid] += work2[lid+stride];\n"
"work3[lid] += work3[lid+stride];\n"
"}\n"
"}\n"
"if(lid == 0) {\n"
"#pragma unroll\n"
"for(int j = 0; j < rows; ++j) {\n"
"#ifdef ZERO_BETA\n"
"dstc0[(x_gid * 4 + j)] = alpha * work_each0[j];\n"
"dstc1[(x_gid * 4 + j)] = alpha * work_each1[j];\n"
"dstc2[(x_gid * 4 + j)] = alpha * work_each2[j];\n"
"dstc3[(x_gid * 4 + j)] = alpha * work_each3[j];\n"
"#else\n"
"dstc0[(x_gid * 4 + j)] = alpha * work_each0[j] + beta * dstc0[(x_gid * 4 + j)];\n"
"dstc1[(x_gid * 4 + j)] = alpha * work_each1[j] + beta * dstc1[(x_gid * 4 + j)];\n"
"dstc2[(x_gid * 4 + j)] = alpha * work_each2[j] + beta * dstc2[(x_gid * 4 + j)];\n"
"dstc3[(x_gid * 4 + j)] = alpha * work_each3[j] + beta * dstc3[(x_gid * 4 + j)];\n"
"#endif\n"
"}\n"
"}\n"
"}\n"
"__kernel void TEMPLATE(gemm_buffer_NT_M_4,Dtype)(\n"
"__global const Dtype * A,\n"
"int offA,\n"
"__global const Dtype * B,\n"
"int offB,\n"
"__global Dtype * C,\n"
"int offC,\n"
"int M,\n"
"int N,\n"
"int K,\n"
"KERNEL_ARG_DTYPE alpha_f,\n"
"KERNEL_ARG_DTYPE beta_f)\n"
"{\n"
"Dtype alpha = (Dtype)alpha_f;\n"
"Dtype beta = (Dtype)beta_f;\n"
"int x_gid = get_group_id(0);\n"
"int lid = get_local_id(0);\n"
"int lsize = get_local_size(0);\n"
"const __global Dtype *srca_read0 = A + offA;\n"
"const __global Dtype *srca_read1 = srca_read0 + K;\n"
"const __global Dtype *srca_read2 = srca_read1 + K;\n"
"const __global Dtype *srca_read3 = srca_read2 + K;\n"
"const __global Dtype *srcb_read = B + x_gid * 4 * K + offB;\n"
"__global Dtype4 *dstc0 = (__global Dtype4*)(C + offC);\n"
"__global Dtype4 *dstc1 = (__global Dtype4*)((__global Dtype*)(dstc0) + N);\n"
"__global Dtype4 *dstc2 = (__global Dtype4*)((__global Dtype*)(dstc1) + N);\n"
"__global Dtype4 *dstc3 = (__global Dtype4*)((__global Dtype*)(dstc2) + N);\n"
"__local Dtype4 work0[SLM_SIZE];\n"
"__local Dtype4 work1[SLM_SIZE];\n"
"__local Dtype4 work2[SLM_SIZE];\n"
"__local Dtype4 work3[SLM_SIZE];\n"
"__local Dtype* work_each0 = (__local Dtype*)(work0 + lid);\n"
"__local Dtype* work_each1 = (__local Dtype*)(work1 + lid);\n"
"__local Dtype* work_each2 = (__local Dtype*)(work2 + lid);\n"
"__local Dtype* work_each3 = (__local Dtype*)(work3 + lid);\n"
"if(x_gid == N / 4) {\n"
"TEMPLATE(gemm_buffer_NT_M_4_edgerows,Dtype) \\\n"
"(srca_read0, srca_read1, srca_read2, srca_read3, srcb_read, \\\n"
"work0, work1, work2, work3, N, K, x_gid, lid, alpha, beta, \\\n"
"(__global Dtype*)dstc0, (__global Dtype*)dstc1, (__global Dtype*)dstc2, (__global Dtype*)dstc3);\n"
"} else {\n"
"Dtype4 dot0[4] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot1[4] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot2[4] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"Dtype4 dot3[4] = {(Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.), (Dtype4)(0.)};\n"
"int kid = lid;\n"
"while( kid < K / 4) {\n"
"const Dtype4 b0 = vload4(kid, srca_read0);\n"
"const Dtype4 b1 = vload4(kid, srca_read1);\n"
"const Dtype4 b2 = vload4(kid, srca_read2);\n"
"const Dtype4 b3 = vload4(kid, srca_read3);\n"
"#pragma unroll\n"
"for(int j = 0; j < 4; ++j) {\n"
"Dtype4 a = vload4(kid, srcb_read + j * K);\n"
"dot0[j] += b0 * a;\n"
"dot1[j] += b1 * a;\n"
"dot2[j] += b2 * a;\n"
"dot3[j] += b3 * a;\n"
"}\n"
"kid += lsize;\n"
"}\n"
"#pragma unroll\n"
"for(int j = 0; j < 4; ++j) {\n"
"work_each0[j] = dot0[j].x + dot0[j].y + dot0[j].z + dot0[j].w;\n"
"work_each1[j] = dot1[j].x + dot1[j].y + dot1[j].z + dot1[j].w;\n"
"work_each2[j] = dot2[j].x + dot2[j].y + dot2[j].z + dot2[j].w;\n"
"work_each3[j] = dot3[j].x + dot3[j].y + dot3[j].z + dot3[j].w;\n"
"}\n"
"if(kid == (K >> 2)) {\n"
"short tail_items = K % 4;\n"
"if(tail_items != 0) {\n"
"int offset = kid << 2;\n"
"const __global Dtype *srcb_tail = srcb_read + offset;\n"
"const __global Dtype *srca_tail0 = srca_read0 + offset;\n"
"const __global Dtype *srca_tail1 = srca_read1 + offset;\n"
"const __global Dtype *srca_tail2 = srca_read2 + offset;\n"
"const __global Dtype *srca_tail3 = srca_read3 + offset;\n"
"#pragma unroll\n"
"for(short i = 0; i < tail_items; ++i) {\n"
"const Dtype at0 = srca_tail0[i];\n"
"const Dtype at1 = srca_tail1[i];\n"
"const Dtype at2 = srca_tail2[i];\n"
"const Dtype at3 = srca_tail3[i];\n"
"#pragma unroll\n"
"for(int j = 0; j < 4; ++j) {\n"
"work_each0[j] += at0 * srcb_tail[i + j * K];\n"
"work_each1[j] += at1 * srcb_tail[i + j * K];\n"
"work_each2[j] += at2 * srcb_tail[i + j * K];\n"
"work_each3[j] += at3 * srcb_tail[i + j * K];\n"
"}\n"
"}\n"
"}\n"
"}\n"
"for(int stride = get_local_size(0) >> 1; stride > 0 ; stride >>= 1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride) {\n"
"work0[lid] += work0[lid+stride];\n"
"work1[lid] += work1[lid+stride];\n"
"work2[lid] += work2[lid+stride];\n"
"work3[lid] += work3[lid+stride];\n"
"}\n"
"}\n"
"if(lid == 0) {\n"
"#ifdef ZERO_BETA\n"
"dstc0[x_gid] = alpha * work0[0];\n"
"dstc1[x_gid] = alpha * work1[0];\n"
"dstc2[x_gid] = alpha * work2[0];\n"
"dstc3[x_gid] = alpha * work3[0];\n"
"#else\n"
"dstc0[x_gid] = alpha * work0[0] + beta * dstc0[x_gid];\n"
"dstc1[x_gid] = alpha * work1[0] + beta * dstc1[x_gid];\n"
"dstc2[x_gid] = alpha * work2[0] + beta * dstc2[x_gid];\n"
"dstc3[x_gid] = alpha * work3[0] + beta * dstc3[x_gid];\n"
"#endif\n"
"}\n"
"}\n"
"}\n"
"#undef SLM_SIZE\n"
"#define SLM_SIZE 16\n"
"__kernel void TEMPLATE(gemm_buffer_NT_M_8,Dtype)(\n"
"__global const Dtype * A,\n"
"int offA,\n"
"__global const Dtype * B,\n"
"int offB,\n"
"__global Dtype * C,\n"
"int offC,\n"
"int M,\n"
"int N,\n"
"int K,\n"
"KERNEL_ARG_DTYPE alpha_f,\n"
"KERNEL_ARG_DTYPE beta_f)\n"
"{\n"
"Dtype alpha = (Dtype)alpha_f;\n"
"Dtype beta = (Dtype)beta_f;\n"
"int x_gid = get_group_id(0);\n"
"int lid = get_local_id(0);\n"
"int lsize = get_local_size(0);\n"
"const __global Dtype *srca_read0 = A + offA;\n"
"const __global Dtype *srca_read1 = srca_read0 + K;\n"
"const __global Dtype *srca_read2 = srca_read1 + K;\n"
"const __global Dtype *srca_read3 = srca_read2 + K;\n"
"const __global Dtype *srca_read4 = srca_read3 + K;\n"
"const __global Dtype *srca_read5 = srca_read4 + K;\n"
"const __global Dtype *srca_read6 = srca_read5 + K;\n"
"const __global Dtype *srca_read7 = srca_read6 + K;\n"
"const __global Dtype *srcb_read = B + x_gid * K + offB;\n"
"__global Dtype *dstc0 = C + offC;\n"
"__global Dtype *dstc1 = dstc0 + N;\n"
"__global Dtype *dstc2 = dstc1 + N;\n"
"__global Dtype *dstc3 = dstc2 + N;\n"
"__global Dtype *dstc4 = dstc3 + N;\n"
"__global Dtype *dstc5 = dstc4 + N;\n"
"__global Dtype *dstc6 = dstc5 + N;\n"
"__global Dtype *dstc7 = dstc6 + N;\n"
"__local Dtype work0[SLM_SIZE];\n"
"__local Dtype work1[SLM_SIZE];\n"
"__local Dtype work2[SLM_SIZE];\n"
"__local Dtype work3[SLM_SIZE];\n"
"__local Dtype work4[SLM_SIZE];\n"
"__local Dtype work5[SLM_SIZE];\n"
"__local Dtype work6[SLM_SIZE];\n"
"__local Dtype work7[SLM_SIZE];\n"
"Dtype4 dot0 = (Dtype4)(0.);\n"
"Dtype4 dot1 = (Dtype4)(0.);\n"
"Dtype4 dot2 = (Dtype4)(0.);\n"
"Dtype4 dot3 = (Dtype4)(0.);\n"
"Dtype4 dot4 = (Dtype4)(0.);\n"
"Dtype4 dot5 = (Dtype4)(0.);\n"
"Dtype4 dot6 = (Dtype4)(0.);\n"
"Dtype4 dot7 = (Dtype4)(0.);\n"
"int kid = lid;\n"
"while( kid < K / 4) {\n"
"const Dtype4 a0 = vload4(kid, srca_read0);\n"
"const Dtype4 a1 = vload4(kid, srca_read1);\n"
"const Dtype4 a2 = vload4(kid, srca_read2);\n"
"const Dtype4 a3 = vload4(kid, srca_read3);\n"
"const Dtype4 a4 = vload4(kid, srca_read4);\n"
"const Dtype4 a5 = vload4(kid, srca_read5);\n"
"const Dtype4 a6 = vload4(kid, srca_read6);\n"
"const Dtype4 a7 = vload4(kid, srca_read7);\n"
"Dtype4 b = vload4(kid, srcb_read);\n"
"dot0 += a0 * b;\n"
"dot1 += a1 * b;\n"
"dot2 += a2 * b;\n"
"dot3 += a3 * b;\n"
"dot4 += a4 * b;\n"
"dot5 += a5 * b;\n"
"dot6 += a6 * b;\n"
"dot7 += a7 * b;\n"
"kid += lsize;\n"
"}\n"
"work0[lid] = dot0.x + dot0.y + dot0.z + dot0.w;\n"
"work1[lid] = dot1.x + dot1.y + dot1.z + dot1.w;\n"
"work2[lid] = dot2.x + dot2.y + dot2.z + dot2.w;\n"
"work3[lid] = dot3.x + dot3.y + dot3.z + dot3.w;\n"
"work4[lid] = dot4.x + dot4.y + dot4.z + dot4.w;\n"
"work5[lid] = dot5.x + dot5.y + dot5.z + dot5.w;\n"
"work6[lid] = dot6.x + dot6.y + dot6.z + dot6.w;\n"
"work7[lid] = dot7.x + dot7.y + dot7.z + dot7.w;\n"
"if(kid == (K >> 2)) {\n"
"short tail_items = K % 4;\n"
"if(tail_items != 0) {\n"
"int offset = kid << 2;\n"
"const __global Dtype *srcb_tail = srcb_read + offset;\n"
"const __global Dtype *srca_tail0 = srca_read0 + offset;\n"
"const __global Dtype *srca_tail1 = srca_read1 + offset;\n"
"const __global Dtype *srca_tail2 = srca_read2 + offset;\n"
"const __global Dtype *srca_tail3 = srca_read3 + offset;\n"
"const __global Dtype *srca_tail4 = srca_read4 + offset;\n"
"const __global Dtype *srca_tail5 = srca_read5 + offset;\n"
"const __global Dtype *srca_tail6 = srca_read6 + offset;\n"
"const __global Dtype *srca_tail7 = srca_read7 + offset;\n"
"#pragma unroll\n"
"for(short item = 0; item < tail_items; ++item) {\n"
"work0[lid] += srca_tail0[item] * srcb_tail[item];\n"
"work1[lid] += srca_tail1[item] * srcb_tail[item];\n"
"work2[lid] += srca_tail2[item] * srcb_tail[item];\n"
"work3[lid] += srca_tail3[item] * srcb_tail[item];\n"
"work4[lid] += srca_tail4[item] * srcb_tail[item];\n"
"work5[lid] += srca_tail5[item] * srcb_tail[item];\n"
"work6[lid] += srca_tail6[item] * srcb_tail[item];\n"
"work7[lid] += srca_tail7[item] * srcb_tail[item];\n"
"}\n"
"}\n"
"}\n"
"for(int stride = get_local_size(0) >> 1; stride > 0 ; stride >>= 1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride) {\n"
"work0[lid] += work0[lid+stride];\n"
"work1[lid] += work1[lid+stride];\n"
"work2[lid] += work2[lid+stride];\n"
"work3[lid] += work3[lid+stride];\n"
"work4[lid] += work4[lid+stride];\n"
"work5[lid] += work5[lid+stride];\n"
"work6[lid] += work6[lid+stride];\n"
"work7[lid] += work7[lid+stride];\n"
"}\n"
"}\n"
"if(lid == 0) {\n"
"#ifdef ZERO_BETA\n"
"dstc0[x_gid] = alpha * work0[0];\n"
"dstc1[x_gid] = alpha * work1[0];\n"
"dstc2[x_gid] = alpha * work2[0];\n"
"dstc3[x_gid] = alpha * work3[0];\n"
"dstc4[x_gid] = alpha * work4[0];\n"
"dstc5[x_gid] = alpha * work5[0];\n"
"dstc6[x_gid] = alpha * work6[0];\n"
"dstc7[x_gid] = alpha * work7[0];\n"
"#else\n"
"dstc0[x_gid] = alpha * work0[0] + beta * dstc0[x_gid];\n"
"dstc1[x_gid] = alpha * work1[0] + beta * dstc1[x_gid];\n"
"dstc2[x_gid] = alpha * work2[0] + beta * dstc2[x_gid];\n"
"dstc3[x_gid] = alpha * work3[0] + beta * dstc3[x_gid];\n"
"dstc4[x_gid] = alpha * work4[0] + beta * dstc4[x_gid];\n"
"dstc5[x_gid] = alpha * work5[0] + beta * dstc5[x_gid];\n"
"dstc6[x_gid] = alpha * work6[0] + beta * dstc6[x_gid];\n"
"dstc7[x_gid] = alpha * work7[0] + beta * dstc7[x_gid];\n"
"#endif\n"
"}\n"
"}\n"
"#undef SLM_SIZE\n"
"#undef VEC_SIZE\n"
"#undef LWG_HEIGHT\n"
"#undef TILE_M\n"
"#undef TILE_K\n"
"#undef TILE_N\n"
"#undef SIMD_SIZE_GEMM\n"
"#undef SHUFFLE_TYPE2\n"
"#undef SHUFFLE_TYPE8\n"
, "11f94a50f6b8bb41e89301f396ba7921", NULL};
struct cv::ocl::internal::ProgramEntry gemm_image_oclsrc={moduleName, "gemm_image",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#define KERNEL_ARG_DTYPE float\n"
"#define TYPE_FLOAT 1\n"
"#define TYPE_HALF 2\n"
"#if TYPE == TYPE_HALF\n"
"#define Dtype half\n"
"#define Dtype2 half2\n"
"#define Dtype4 half4\n"
"#define Dtype8 half8\n"
"#define Dtype16 half16\n"
"#define as_Dtype as_half\n"
"#define as_Dtype2 as_half2\n"
"#define as_Dtype4 as_half4\n"
"#define as_Dtype8 as_half8\n"
"#define as_Dtype16 as_half16\n"
"#else\n"
"#define Dtype float\n"
"#define Dtype2 float2\n"
"#define Dtype4 float4\n"
"#define Dtype8 float8\n"
"#define Dtype16 float16\n"
"#define as_Dtype as_float\n"
"#define as_Dtype2 as_float2\n"
"#define as_Dtype4 as_float4\n"
"#define as_Dtype8 as_float8\n"
"#define as_Dtype16 as_float16\n"
"#endif\n"
"#if defined(cl_intel_subgroups)\n"
"#pragma OPENCL EXTENSION cl_intel_subgroups : enable\n"
"#endif\n"
"#define TILE_M 32\n"
"#define TILE_K 8\n"
"#if TYPE == TYPE_HALF\n"
"#define SUBGROUP_BLOCK_READ8( __image, __coord ) intel_sub_group_block_read_us8( __image, __coord )\n"
"#define SHUFFLE_TYPE2(val) as_ushort2(val)\n"
"#define SHUFFLE_TYPE8(val) as_ushort8(val)\n"
"#define READ_IMAGE(__image, __coord) read_imageh(__image, sampler, __coord)\n"
"#define SIZE_OF_ELEMENT sizeof(ushort)\n"
"#define SIMD_SIZE_GEMM 16\n"
"#define TILE_N 16\n"
"#else\n"
"#define SUBGROUP_BLOCK_READ8( __image, __coord ) intel_sub_group_block_read8( __image, __coord )\n"
"#define SHUFFLE_TYPE2(val) val\n"
"#define SHUFFLE_TYPE8(val) val\n"
"#define READ_IMAGE(__image, __coord) read_imagef(__image, sampler, __coord)\n"
"#define SIZE_OF_ELEMENT sizeof(uint)\n"
"#define SIMD_SIZE_GEMM 8\n"
"#define TILE_N 8\n"
"#endif\n"
"#ifdef USE_IMAGE_C\n"
"#if TYPE == TYPE_HALF\n"
"#define BLOCKC_READ8( _C, _coordC ) as_Dtype8( intel_sub_group_block_read_us8( _C, _coordC ) )\n"
"#define BLOCKC_WRITE8( _C, _coordC, _val ) intel_sub_group_block_write_us8( _C, _coordC, as_ushort8( _val ) )\n"
"#else\n"
"#define BLOCKC_READ8( _C, _coordC ) as_Dtype8( intel_sub_group_block_read8( _C, _coordC ) )\n"
"#define BLOCKC_WRITE8( _C, _coordC, _val ) intel_sub_group_block_write8( _C, _coordC, as_uint8( _val ) )\n"
"#endif\n"
"#define MATC_PARAMETER __read_only image2d_t C, __write_only image2d_t dst\n"
"#define GEMM_OUTPUT(ALPHA1, BETA_NOT0) GEMM_OUTPUT_EXT(ALPHA1, BETA_NOT0, C, dst, sizeof(uint))\n"
"#else\n"
"#define BLOCKC_READ8( _C, _coordC ) \\\n"
"(Dtype8) ( (_coordC.x + get_local_id(0) < N && _coordC.y < M) ? _C[ _coordC.y * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 1 < M) ? _C[ ( _coordC.y + 1 ) * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 2 < M) ? _C[ ( _coordC.y + 2 ) * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 3 < M) ? _C[ ( _coordC.y + 3 ) * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 4 < M) ? _C[ ( _coordC.y + 4 ) * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 5 < M) ? _C[ ( _coordC.y + 5 ) * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 6 < M) ? _C[ ( _coordC.y + 6 ) * ldc + _coordC.x + get_local_id(0) ] : 0, \\\n"
"(_coordC.x + get_local_id(0) < N && _coordC.y + 7 < M) ? _C[ ( _coordC.y + 7 ) * ldc + _coordC.x + get_local_id(0) ] : 0)\n"
"#define BLOCKC_WRITE8( _C, _coordC, _val) do {\\\n"
"if (_coordC.x + get_local_id(0) < N) { \\\n"
"if (_coordC.y < M) \\\n"
"_C[ _coordC.y * ldc + _coordC.x + get_local_id(0) ] = _val.s0; \\\n"
"if (_coordC.y + 1 < M) \\\n"
"_C[ ( _coordC.y + 1 )* ldc + _coordC.x + get_local_id(0) ] = _val.s1; \\\n"
"if (_coordC.y + 2 < M) \\\n"
"_C[ ( _coordC.y + 2 )* ldc + _coordC.x + get_local_id(0) ] = _val.s2; \\\n"
"if (_coordC.y + 3 < M) \\\n"
"_C[ ( _coordC.y + 3 )* ldc + _coordC.x + get_local_id(0) ] = _val.s3; \\\n"
"if (_coordC.y + 4 < M) \\\n"
"_C[ ( _coordC.y + 4 )* ldc + _coordC.x + get_local_id(0) ] = _val.s4; \\\n"
"if (_coordC.y + 5 < M) \\\n"
"_C[ ( _coordC.y + 5 )* ldc + _coordC.x + get_local_id(0) ] = _val.s5; \\\n"
"if (_coordC.y + 6 < M) \\\n"
"_C[ ( _coordC.y + 6 )* ldc + _coordC.x + get_local_id(0) ] = _val.s6; \\\n"
"if (_coordC.y + 7 < M) \\\n"
"_C[ ( _coordC.y + 7 )* ldc + _coordC.x + get_local_id(0) ] = _val.s7; \\\n"
"}} while(0)\n"
"#define MATC_PARAMETER __global Dtype * C, const int offC, const int M, const int N, const int ldc\n"
"#define GEMM_OUTPUT(ALPHA1, BETA_NOT0) GEMM_OUTPUT_EXT(ALPHA1, BETA_NOT0, (C + offC), (C + offC), 1)\n"
"#endif\n"
"#define GEMM_OUTPUT_EXT(ALPHA1, BETA_NOT0, _C, _dst, _C_step) \\\n"
"int2 coordDst = (int2)( ( group_x * TILE_N ) * _C_step, ( group_y * TILE_M ) ); \\\n"
"int2 coordC = coordDst; \\\n"
"Dtype8 blockC00; \\\n"
"Dtype8 blockC01; \\\n"
"Dtype8 blockC02; \\\n"
"Dtype8 blockC03; \\\n"
"if (BETA_NOT0) { \\\n"
"blockC00 = isFirstColBlock ? BLOCKC_READ8( _C, coordC ) * beta : BLOCKC_READ8( _C, coordC ); coordC.y += 8; \\\n"
"blockC01 = isFirstColBlock ? BLOCKC_READ8( _C, coordC ) * beta : BLOCKC_READ8( _C, coordC ); coordC.y += 8; \\\n"
"blockC02 = isFirstColBlock ? BLOCKC_READ8( _C, coordC ) * beta : BLOCKC_READ8( _C, coordC ); coordC.y += 8; \\\n"
"blockC03 = isFirstColBlock ? BLOCKC_READ8( _C, coordC ) * beta : BLOCKC_READ8( _C, coordC ); \\\n"
"if (!ALPHA1) { \\\n"
"blockC00 = mad(blockAxB00, (Dtype8)alpha, blockC00); \\\n"
"blockC01 = mad(blockAxB01, (Dtype8)alpha, blockC01); \\\n"
"blockC02 = mad(blockAxB02, (Dtype8)alpha, blockC02); \\\n"
"blockC03 = mad(blockAxB03, (Dtype8)alpha, blockC03); \\\n"
"} else { \\\n"
"blockC00 += blockAxB00; \\\n"
"blockC01 += blockAxB01; \\\n"
"blockC02 += blockAxB02; \\\n"
"blockC03 += blockAxB03; \\\n"
"} \\\n"
"} else { \\\n"
"blockC00 = isFirstColBlock ? (Dtype)0. : BLOCKC_READ8( _C, coordC ); coordC.y += 8; \\\n"
"blockC01 = isFirstColBlock ? (Dtype)0. : BLOCKC_READ8( _C, coordC ); coordC.y += 8; \\\n"
"blockC02 = isFirstColBlock ? (Dtype)0. : BLOCKC_READ8( _C, coordC ); coordC.y += 8; \\\n"
"blockC03 = isFirstColBlock ? (Dtype)0. : BLOCKC_READ8( _C, coordC ); \\\n"
"if (!ALPHA1) { \\\n"
"blockC00 = mad(blockAxB00, (Dtype8)alpha, blockC00); \\\n"
"blockC01 = mad(blockAxB01, (Dtype8)alpha, blockC01); \\\n"
"blockC02 = mad(blockAxB02, (Dtype8)alpha, blockC02); \\\n"
"blockC03 = mad(blockAxB03, (Dtype8)alpha, blockC03); \\\n"
"} else { \\\n"
"blockC00 += blockAxB00; \\\n"
"blockC01 += blockAxB01; \\\n"
"blockC02 += blockAxB02; \\\n"
"blockC03 += blockAxB03; \\\n"
"} \\\n"
"} \\\n"
"BLOCKC_WRITE8( _dst, coordDst, blockC00 ); coordDst.y += 8; \\\n"
"BLOCKC_WRITE8( _dst, coordDst, blockC01 ); coordDst.y += 8; \\\n"
"BLOCKC_WRITE8( _dst, coordDst, blockC02 ); coordDst.y += 8; \\\n"
"BLOCKC_WRITE8( _dst, coordDst, blockC03 );\n"
"#define TRANSPOSE_BLOCK_8( _block, _col ) \\\n"
"(Dtype8)( intel_sub_group_shuffle( _block.s0, _col ), \\\n"
"intel_sub_group_shuffle( _block.s1, _col ), \\\n"
"intel_sub_group_shuffle( _block.s2, _col ), \\\n"
"intel_sub_group_shuffle( _block.s3, _col ), \\\n"
"intel_sub_group_shuffle( _block.s4, _col ), \\\n"
"intel_sub_group_shuffle( _block.s5, _col ), \\\n"
"intel_sub_group_shuffle( _block.s6, _col ), \\\n"
"intel_sub_group_shuffle( _block.s7, _col ) );\n"
"#if TYPE == TYPE_HALF\n"
"#define MULTIPLY_BLOCKS_8x8( _result, _blockA, _blockB00, _blockB01 ) \\\n"
"{ \\\n"
"const Dtype8 acol0 = TRANSPOSE_BLOCK_8( _blockA, 0 ); \\\n"
"const Dtype8 acol1 = TRANSPOSE_BLOCK_8( _blockA, 1 ); \\\n"
"const Dtype8 acol2 = TRANSPOSE_BLOCK_8( _blockA, 2 ); \\\n"
"const Dtype8 acol3 = TRANSPOSE_BLOCK_8( _blockA, 3 ); \\\n"
"const Dtype8 acol4 = TRANSPOSE_BLOCK_8( _blockA, 4 ); \\\n"
"const Dtype8 acol5 = TRANSPOSE_BLOCK_8( _blockA, 5 ); \\\n"
"const Dtype8 acol6 = TRANSPOSE_BLOCK_8( _blockA, 6 ); \\\n"
"const Dtype8 acol7 = TRANSPOSE_BLOCK_8( _blockA, 7 ); \\\n"
"const Dtype8 acol8 = TRANSPOSE_BLOCK_8( _blockA, 8 ); \\\n"
"const Dtype8 acol9 = TRANSPOSE_BLOCK_8( _blockA, 9 ); \\\n"
"const Dtype8 acola = TRANSPOSE_BLOCK_8( _blockA, 10 ); \\\n"
"const Dtype8 acolb = TRANSPOSE_BLOCK_8( _blockA, 11 ); \\\n"
"const Dtype8 acolc = TRANSPOSE_BLOCK_8( _blockA, 12 ); \\\n"
"const Dtype8 acold = TRANSPOSE_BLOCK_8( _blockA, 13 ); \\\n"
"const Dtype8 acole = TRANSPOSE_BLOCK_8( _blockA, 14 ); \\\n"
"const Dtype8 acolf = TRANSPOSE_BLOCK_8( _blockA, 15 ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s0), acol0, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s1), acol1, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s2), acol2, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s3), acol3, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s4), acol4, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s5), acol5, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s6), acol6, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB00.s7), acol7, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s0), acol8, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s1), acol9, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s2), acola, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s3), acolb, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s4), acolc, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s5), acold, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s6), acole, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB01.s7), acolf, _result ); \\\n"
"}\n"
"#else\n"
"#define MULTIPLY_BLOCKS_8x8( _result, _blockA, _blockB ) \\\n"
"{ \\\n"
"const Dtype8 acol0 = TRANSPOSE_BLOCK_8( _blockA, 0 ); \\\n"
"const Dtype8 acol1 = TRANSPOSE_BLOCK_8( _blockA, 1 ); \\\n"
"const Dtype8 acol2 = TRANSPOSE_BLOCK_8( _blockA, 2 ); \\\n"
"const Dtype8 acol3 = TRANSPOSE_BLOCK_8( _blockA, 3 ); \\\n"
"const Dtype8 acol4 = TRANSPOSE_BLOCK_8( _blockA, 4 ); \\\n"
"const Dtype8 acol5 = TRANSPOSE_BLOCK_8( _blockA, 5 ); \\\n"
"const Dtype8 acol6 = TRANSPOSE_BLOCK_8( _blockA, 6 ); \\\n"
"const Dtype8 acol7 = TRANSPOSE_BLOCK_8( _blockA, 7 ); \\\n"
"_result = mad( (Dtype8)(_blockB.s0), acol0, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s1), acol1, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s2), acol2, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s3), acol3, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s4), acol4, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s5), acol5, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s6), acol6, _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s7), acol7, _result ); \\\n"
"}\n"
"#endif\n"
"#if TYPE == TYPE_HALF\n"
"#define GEMM_NN(ALPHA1, BETA_NOT0) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_NN_ ##ALPHA1 ##_ ##BETA_NOT0, Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"__read_only image2d_t B, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int width0, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0); \\\n"
"const int group_y = get_group_id(1); \\\n"
"Dtype8 blockAxB00 = 0; \\\n"
"Dtype8 blockAxB01 = 0; \\\n"
"Dtype8 blockAxB02 = 0; \\\n"
"Dtype8 blockAxB03 = 0; \\\n"
"int2 coordA = (int2)( 0, group_y * TILE_M ); \\\n"
"int2 coordB = (int2)( ( group_x * TILE_N ) * SIZE_OF_ELEMENT, 0 ); \\\n"
"do \\\n"
"{ \\\n"
"int2 coordBTemp = coordB; \\\n"
"Dtype8 blockB00 = as_Dtype8( SUBGROUP_BLOCK_READ8( B, coordBTemp ) ); coordB.y += TILE_K; \\\n"
"Dtype8 blockB01 = as_Dtype8( SUBGROUP_BLOCK_READ8( B, coordBTemp ) ); coordB.y += TILE_K; \\\n"
"int2 coordATemp = coordA; \\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA02 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA03 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.x += TILE_K * SIZE_OF_ELEMENT * 2; \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00, blockB01 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA01, blockB00, blockB01 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA02, blockB00, blockB01 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA03, blockB00, blockB01 ); \\\n"
"} \\\n"
"while( coordB.y < width0 ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0); \\\n"
"}\n"
"#else\n"
"#define GEMM_NN(ALPHA1, BETA_NOT0) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_NN_ ##ALPHA1 ##_ ##BETA_NOT0, Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"__read_only image2d_t B, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int width0, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0); \\\n"
"const int group_y = get_group_id(1); \\\n"
"Dtype8 blockAxB00 = 0.0f; \\\n"
"Dtype8 blockAxB01 = 0.0f; \\\n"
"Dtype8 blockAxB02 = 0.0f; \\\n"
"Dtype8 blockAxB03 = 0.0f; \\\n"
"int2 coordA = (int2)( 0, group_y * TILE_M ); \\\n"
"int2 coordB = (int2)( ( group_x * TILE_N ) * SIZE_OF_ELEMENT, 0 ); \\\n"
"do \\\n"
"{ \\\n"
"int2 coordBTemp = coordB; \\\n"
"Dtype8 blockB00 = as_Dtype8( SUBGROUP_BLOCK_READ8( B, coordBTemp ) ); coordB.y += TILE_K; \\\n"
"int2 coordATemp = coordA; \\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA02 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA03 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.x += TILE_K * SIZE_OF_ELEMENT; \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA01, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA02, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA03, blockB00 ); \\\n"
"} \\\n"
"while( coordB.y < width0 ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0); \\\n"
"}\n"
"#endif\n"
"GEMM_NN(1, 0)\n"
"GEMM_NN(1, 1)\n"
"GEMM_NN(0, 0)\n"
"GEMM_NN(0, 1)\n"
"#undef TRANSPOSE_BLOCK_8\n"
"#undef MULTIPLY_BLOCKS_8x8\n"
"#undef GEMM_NN\n"
"#define TRANSPOSE_BLOCK_8(_vec, _col) \\\n"
"(Dtype8)( intel_sub_group_shuffle(_vec, _col + 0), \\\n"
"intel_sub_group_shuffle(_vec, _col + 1), \\\n"
"intel_sub_group_shuffle(_vec, _col + 2), \\\n"
"intel_sub_group_shuffle(_vec, _col + 3), \\\n"
"intel_sub_group_shuffle(_vec, _col + 4), \\\n"
"intel_sub_group_shuffle(_vec, _col + 5), \\\n"
"intel_sub_group_shuffle(_vec, _col + 6), \\\n"
"intel_sub_group_shuffle(_vec, _col + 7) )\n"
"#define MULTIPLY_BLOCKS_8x8( _result, _blockA, _blockB, _col ) \\\n"
"{ \\\n"
"_result = mad( (Dtype8)(_blockB.s0), TRANSPOSE_BLOCK_8(_blockA.s0, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s1), TRANSPOSE_BLOCK_8(_blockA.s1, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s2), TRANSPOSE_BLOCK_8(_blockA.s2, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s3), TRANSPOSE_BLOCK_8(_blockA.s3, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s4), TRANSPOSE_BLOCK_8(_blockA.s4, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s5), TRANSPOSE_BLOCK_8(_blockA.s5, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s6), TRANSPOSE_BLOCK_8(_blockA.s6, _col), _result ); \\\n"
"_result = mad( (Dtype8)(_blockB.s7), TRANSPOSE_BLOCK_8(_blockA.s7, _col), _result ); \\\n"
"}\n"
"#if TYPE == TYPE_HALF\n"
"#define GEMM_TN(ALPHA1, BETA_NOT0) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_TN_ ##ALPHA1 ##_ ##BETA_NOT0,Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"__read_only image2d_t B, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int width0, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0);\\\n"
"const int group_y = get_group_id(1);\\\n"
"Dtype8 blockAxB00 = 0;\\\n"
"Dtype8 blockAxB01 = 0;\\\n"
"Dtype8 blockAxB02 = 0;\\\n"
"Dtype8 blockAxB03 = 0;\\\n"
"int2 coordA = (int2)( group_y * TILE_M * SIZE_OF_ELEMENT, 0 );\\\n"
"int2 coordB = (int2)( ( group_x * TILE_N ) * SIZE_OF_ELEMENT, 0 );\\\n"
"do\\\n"
"{\\\n"
"int2 coordBTemp = coordB;\\\n"
"Dtype8 blockB00 = as_Dtype8( SUBGROUP_BLOCK_READ8( B, coordBTemp ) ); coordB.y += TILE_K;\\\n"
"int2 coordATemp = coordA;\\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 16 * SIZE_OF_ELEMENT;\\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.y += TILE_K;\\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00, 0); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA00, blockB00, 8); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA01, blockB00, 0); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA01, blockB00, 8); \\\n"
"} \\\n"
"while( coordB.y < width0 ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0); \\\n"
"}\n"
"#else\n"
"#define GEMM_TN(ALPHA1, BETA_NOT0) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_TN_ ##ALPHA1 ##_ ##BETA_NOT0,Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"__read_only image2d_t B, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int width0, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0);\\\n"
"const int group_y = get_group_id(1);\\\n"
"Dtype8 blockAxB00 = 0.0f;\\\n"
"Dtype8 blockAxB01 = 0.0f;\\\n"
"Dtype8 blockAxB02 = 0.0f;\\\n"
"Dtype8 blockAxB03 = 0.0f;\\\n"
"int2 coordA = (int2)( group_y * TILE_M * SIZE_OF_ELEMENT, 0 );\\\n"
"int2 coordB = (int2)( ( group_x * TILE_N ) * SIZE_OF_ELEMENT, 0 );\\\n"
"do\\\n"
"{\\\n"
"int2 coordBTemp = coordB;\\\n"
"Dtype8 blockB00 = as_Dtype8( SUBGROUP_BLOCK_READ8( B, coordBTemp ) ); coordB.y += TILE_K;\\\n"
"int2 coordATemp = coordA;\\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 8 * SIZE_OF_ELEMENT;\\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 8 * SIZE_OF_ELEMENT;\\\n"
"Dtype8 blockA02 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 8 * SIZE_OF_ELEMENT;\\\n"
"Dtype8 blockA03 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.y += TILE_K;\\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00, 0 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA01, blockB00, 0 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA02, blockB00, 0 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA03, blockB00, 0 ); \\\n"
"} \\\n"
"while( coordB.y < width0 ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0); \\\n"
"}\n"
"#endif\n"
"GEMM_TN(1, 0)\n"
"GEMM_TN(1, 1)\n"
"GEMM_TN(0, 0)\n"
"GEMM_TN(0, 1)\n"
"#undef MULTIPLY_BLOCKS_8x8\n"
"#undef TRANSPOSE_BLOCK_8\n"
"#undef GEMM_TN\n"
"#define TRANSPOSE_BLOCK_8( _block, _col ) \\\n"
"(Dtype8)( intel_sub_group_shuffle( _block.s0, _col), \\\n"
"intel_sub_group_shuffle( _block.s1, _col), \\\n"
"intel_sub_group_shuffle( _block.s2, _col), \\\n"
"intel_sub_group_shuffle( _block.s3, _col), \\\n"
"intel_sub_group_shuffle( _block.s4, _col), \\\n"
"intel_sub_group_shuffle( _block.s5, _col), \\\n"
"intel_sub_group_shuffle( _block.s6, _col), \\\n"
"intel_sub_group_shuffle( _block.s7, _col) )\n"
"#if TYPE == TYPE_HALF\n"
"#define MULTIPLY_BLOCKS_8x8( _result, _blockA, _blockB ) \\\n"
"{ \\\n"
"const Dtype8 acol0 = TRANSPOSE_BLOCK_8( _blockA, 0 ); \\\n"
"const Dtype8 acol1 = TRANSPOSE_BLOCK_8( _blockA, 1 ); \\\n"
"const Dtype8 acol2 = TRANSPOSE_BLOCK_8( _blockA, 2 ); \\\n"
"const Dtype8 acol3 = TRANSPOSE_BLOCK_8( _blockA, 3 ); \\\n"
"const Dtype8 acol4 = TRANSPOSE_BLOCK_8( _blockA, 4 ); \\\n"
"const Dtype8 acol5 = TRANSPOSE_BLOCK_8( _blockA, 5 ); \\\n"
"const Dtype8 acol6 = TRANSPOSE_BLOCK_8( _blockA, 6 ); \\\n"
"const Dtype8 acol7 = TRANSPOSE_BLOCK_8( _blockA, 7 ); \\\n"
"const Dtype8 acol8 = TRANSPOSE_BLOCK_8( _blockA, 8 ); \\\n"
"const Dtype8 acol9 = TRANSPOSE_BLOCK_8( _blockA, 9 ); \\\n"
"const Dtype8 acola = TRANSPOSE_BLOCK_8( _blockA, 10 ); \\\n"
"const Dtype8 acolb = TRANSPOSE_BLOCK_8( _blockA, 11 ); \\\n"
"const Dtype8 acolc = TRANSPOSE_BLOCK_8( _blockA, 12 ); \\\n"
"const Dtype8 acold = TRANSPOSE_BLOCK_8( _blockA, 13 ); \\\n"
"const Dtype8 acole = TRANSPOSE_BLOCK_8( _blockA, 14 ); \\\n"
"const Dtype8 acolf = TRANSPOSE_BLOCK_8( _blockA, 15 ); \\\n"
"_result = mad( (Dtype8)_blockB.s0, acol0, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s1, acol1, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s2, acol2, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s3, acol3, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s4, acol4, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s5, acol5, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s6, acol6, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s7, acol7, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s8, acol8, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s9, acol9, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.sa, acola, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.sb, acolb, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.sc, acolc, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.sd, acold, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.se, acole, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.sf, acolf, _result ); \\\n"
"}\n"
"#else\n"
"#define MULTIPLY_BLOCKS_8x8( _result, _blockA, _blockB ) \\\n"
"{ \\\n"
"const Dtype8 acol0 = TRANSPOSE_BLOCK_8( _blockA, 0 ); \\\n"
"const Dtype8 acol1 = TRANSPOSE_BLOCK_8( _blockA, 1 ); \\\n"
"const Dtype8 acol2 = TRANSPOSE_BLOCK_8( _blockA, 2 ); \\\n"
"const Dtype8 acol3 = TRANSPOSE_BLOCK_8( _blockA, 3 ); \\\n"
"const Dtype8 acol4 = TRANSPOSE_BLOCK_8( _blockA, 4 ); \\\n"
"const Dtype8 acol5 = TRANSPOSE_BLOCK_8( _blockA, 5 ); \\\n"
"const Dtype8 acol6 = TRANSPOSE_BLOCK_8( _blockA, 6 ); \\\n"
"const Dtype8 acol7 = TRANSPOSE_BLOCK_8( _blockA, 7 ); \\\n"
"_result = mad( (Dtype8)_blockB.s0, acol0, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s1, acol1, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s2, acol2, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s3, acol3, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s4, acol4, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s5, acol5, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s6, acol6, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s7, acol7, _result ); \\\n"
"}\n"
"#endif\n"
"#if TYPE == TYPE_HALF\n"
"#define GEMM_NT(ALPHA1, BETA_NOT0, VECSCALAR, VECSIZE) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_NT_ ##VECSCALAR ##_ ##ALPHA1 ##_ ##BETA_NOT0,Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"MATB_PARAMETER, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int padded_k, \\\n"
"int k, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0); \\\n"
"const int group_y = get_group_id(1); \\\n"
"Dtype8 blockAxB00 = 0; \\\n"
"Dtype8 blockAxB01 = 0; \\\n"
"Dtype8 blockAxB02 = 0; \\\n"
"Dtype8 blockAxB03 = 0; \\\n"
"int2 coordA = (int2)( 0, group_y * TILE_M ); \\\n"
"int2 coordB = (int2)( 0, ( group_x * TILE_N )); \\\n"
"const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \\\n"
"do \\\n"
"{ \\\n"
"Dtype16 blockB00; \\\n"
"BLOCKB_READ8(blockB00, B, coordB); \\\n"
"int2 coordATemp = coordA; \\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA02 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA03 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.x += TILE_K * SIZE_OF_ELEMENT * 2; \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA01, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA02, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA03, blockB00 ); \\\n"
"} \\\n"
"while( coordB.x < padded_k / VECSIZE ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0); \\\n"
"}\n"
"#else\n"
"#define GEMM_NT(ALPHA1, BETA_NOT0, VECSCALAR, VECSIZE) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_NT_ ##VECSCALAR ##_ ##ALPHA1 ##_ ##BETA_NOT0,Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"MATB_PARAMETER, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int padded_k, \\\n"
"int k, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0); \\\n"
"const int group_y = get_group_id(1); \\\n"
"Dtype8 blockAxB00 = 0.0f; \\\n"
"Dtype8 blockAxB01 = 0.0f; \\\n"
"Dtype8 blockAxB02 = 0.0f; \\\n"
"Dtype8 blockAxB03 = 0.0f; \\\n"
"int2 coordA = (int2)( 0, group_y * TILE_M ); \\\n"
"int2 coordB = (int2)( 0, ( group_x * TILE_N )); \\\n"
"const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \\\n"
"do \\\n"
"{ \\\n"
"Dtype8 blockB00; \\\n"
"BLOCKB_READ8(blockB00, B, coordB); \\\n"
"int2 coordATemp = coordA; \\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA02 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.y += 8; \\\n"
"Dtype8 blockA03 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.x += TILE_K * SIZE_OF_ELEMENT; \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA01, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA02, blockB00 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA03, blockB00 ); \\\n"
"} \\\n"
"while( coordB.x < padded_k / VECSIZE ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0); \\\n"
"}\n"
"#endif\n"
"#if TYPE == TYPE_HALF\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"_blockb.s0123 = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s4567 = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s89ab = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.scdef = READ_IMAGE(_B, _coordBTemp); _coordB.x += 4;\n"
"#else\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"_blockb.s0123 = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s4567 = READ_IMAGE(_B, _coordBTemp); _coordB.x += 2;\n"
"#endif\n"
"#define MATB_PARAMETER __read_only image2d_t B\n"
"GEMM_NT(1, 0, VEC4, 4)\n"
"GEMM_NT(1, 1, VEC4, 4)\n"
"GEMM_NT(0, 0, VEC4, 4)\n"
"GEMM_NT(0, 1, VEC4, 4)\n"
"#undef BLOCKB_READ8\n"
"#undef MATB_PARAMETER\n"
"#if TYPE == TYPE_HALF\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"const __global float *B_read = (__global float *)(_B + (_coordBTemp.y * ldb) + _coordBTemp.x + offB); \\\n"
"_blockb = as_Dtype16(as_ushort16(vload8(0, B_read))); \\\n"
"_coordB.x += TILE_K * 2;\n"
"#else\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"const __global Dtype *B_read = (__global Dtype *)(_B + (_coordBTemp.y * ldb) + _coordBTemp.x + offB); \\\n"
"_blockb = vload8(0, B_read); \\\n"
"_coordB.x += TILE_K;\n"
"#endif\n"
"#define MATB_PARAMETER __global Dtype *B, int offB, int ldb\n"
"GEMM_NT(1, 0, BUFFER, 1)\n"
"GEMM_NT(1, 1, BUFFER, 1)\n"
"GEMM_NT(0, 0, BUFFER, 1)\n"
"GEMM_NT(0, 1, BUFFER, 1)\n"
"#undef BLOCKB_READ8\n"
"#undef MATB_PARAMETER\n"
"#if TYPE == TYPE_HALF\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"Dtype4 temp; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s0 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s1 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s2 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s3 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s4 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s5 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s6 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s7 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s8 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s9 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.sa = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.sb = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.sc = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.sd = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.se = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.sf = temp.s0; \\\n"
"_coordB.x += 16;\n"
"#else\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"Dtype4 temp; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s0 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s1 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s2 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s3 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s4 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s5 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s6 = temp.s0; \\\n"
"temp = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s7 = temp.s0; \\\n"
"_coordB.x += 8;\n"
"#endif\n"
"#define MATB_PARAMETER __read_only image2d_t B\n"
"GEMM_NT(1, 0, SCALAR, 1)\n"
"GEMM_NT(1, 1, SCALAR, 1)\n"
"GEMM_NT(0, 0, SCALAR, 1)\n"
"GEMM_NT(0, 1, SCALAR, 1)\n"
"#undef BLOCKB_READ8\n"
"#undef MATB_PARAMETER\n"
"#undef MULTIPLY_BLOCKS_8x8\n"
"#undef TRANSPOSE_BLOCK_8\n"
"#undef GEMM_NT\n"
"#define TRANSPOSE_BLOCK_8(_vec, _col) \\\n"
"(Dtype8)( intel_sub_group_shuffle(_vec, _col + 0), \\\n"
"intel_sub_group_shuffle(_vec, _col + 1), \\\n"
"intel_sub_group_shuffle(_vec, _col + 2), \\\n"
"intel_sub_group_shuffle(_vec, _col + 3), \\\n"
"intel_sub_group_shuffle(_vec, _col + 4), \\\n"
"intel_sub_group_shuffle(_vec, _col + 5), \\\n"
"intel_sub_group_shuffle(_vec, _col + 6), \\\n"
"intel_sub_group_shuffle(_vec, _col + 7) );\n"
"#define MULTIPLY_BLOCKS_8x8( _result, _blockA, _blockB, _col ) \\\n"
"{ \\\n"
"const Dtype8 acol0 = TRANSPOSE_BLOCK_8( _blockA.s0, _col ); \\\n"
"const Dtype8 acol1 = TRANSPOSE_BLOCK_8( _blockA.s1, _col ); \\\n"
"const Dtype8 acol2 = TRANSPOSE_BLOCK_8( _blockA.s2, _col ); \\\n"
"const Dtype8 acol3 = TRANSPOSE_BLOCK_8( _blockA.s3, _col ); \\\n"
"const Dtype8 acol4 = TRANSPOSE_BLOCK_8( _blockA.s4, _col ); \\\n"
"const Dtype8 acol5 = TRANSPOSE_BLOCK_8( _blockA.s5, _col ); \\\n"
"const Dtype8 acol6 = TRANSPOSE_BLOCK_8( _blockA.s6, _col ); \\\n"
"const Dtype8 acol7 = TRANSPOSE_BLOCK_8( _blockA.s7, _col ); \\\n"
"_result = mad( (Dtype8)_blockB.s0, acol0, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s1, acol1, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s2, acol2, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s3, acol3, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s4, acol4, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s5, acol5, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s6, acol6, _result ); \\\n"
"_result = mad( (Dtype8)_blockB.s7, acol7, _result ); \\\n"
"}\n"
"#if TYPE == TYPE_HALF\n"
"#define GEMM_TT(ALPHA1, BETA_NOT0, VECSCALAR, VECSIZE) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_TT_ ##VECSCALAR ##_ ##ALPHA1 ##_ ##BETA_NOT0, Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"MATB_PARAMETER, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int padded_k, \\\n"
"int k, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0); \\\n"
"const int group_y = get_group_id(1); \\\n"
"Dtype8 blockAxB00 = 0; \\\n"
"Dtype8 blockAxB01 = 0; \\\n"
"Dtype8 blockAxB02 = 0; \\\n"
"Dtype8 blockAxB03 = 0; \\\n"
"int2 coordA = (int2)( group_y * TILE_M * SIZE_OF_ELEMENT, 0 ); \\\n"
"int2 coordB = (int2)( 0, ( group_x * TILE_N )); \\\n"
"const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \\\n"
"do \\\n"
"{ \\\n"
"Dtype8 blockB00; \\\n"
"BLOCKB_READ8(blockB00, B, coordB); \\\n"
"int2 coordATemp = coordA; \\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 16 * SIZE_OF_ELEMENT;\\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.y += TILE_K;\\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00, blockB00, 0); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA00, blockB00, 8); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA01, blockB00, 0); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA01, blockB00, 8); \\\n"
"} \\\n"
"while( coordB.x < padded_k / VECSIZE ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0);\\\n"
"}\n"
"#else\n"
"#define GEMM_TT(ALPHA1, BETA_NOT0, VECSCALAR, VECSIZE) \\\n"
"__attribute__((intel_reqd_sub_group_size(SIMD_SIZE_GEMM))) \\\n"
"__attribute__((reqd_work_group_size(SIMD_SIZE_GEMM, 1, 1))) \\\n"
"__kernel void TEMPLATE(gemm_32_1_TT_ ##VECSCALAR ##_ ##ALPHA1 ##_ ##BETA_NOT0, Dtype)( \\\n"
"__read_only image2d_t A, \\\n"
"MATB_PARAMETER, \\\n"
"MATC_PARAMETER, \\\n"
"KERNEL_ARG_DTYPE alpha_in, \\\n"
"KERNEL_ARG_DTYPE beta_in, \\\n"
"int padded_k, \\\n"
"int k, \\\n"
"int isFirstColBlock) \\\n"
"{ \\\n"
"const Dtype alpha = (Dtype)alpha_in; \\\n"
"const Dtype beta = (Dtype)beta_in; \\\n"
"const int group_x = get_group_id(0); \\\n"
"const int group_y = get_group_id(1); \\\n"
"Dtype8 blockAxB00 = 0.0f; \\\n"
"Dtype8 blockAxB01 = 0.0f; \\\n"
"Dtype8 blockAxB02 = 0.0f; \\\n"
"Dtype8 blockAxB03 = 0.0f; \\\n"
"int2 coordA = (int2)( group_y * TILE_M * SIZE_OF_ELEMENT, 0 ); \\\n"
"int2 coordB = (int2)( 0, ( group_x * TILE_N )); \\\n"
"const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \\\n"
"do \\\n"
"{ \\\n"
"Dtype8 blockB00; \\\n"
"BLOCKB_READ8(blockB00, B, coordB); \\\n"
"int2 coordATemp = coordA; \\\n"
"Dtype8 blockA00 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 8 * SIZE_OF_ELEMENT; \\\n"
"Dtype8 blockA01 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 8 * SIZE_OF_ELEMENT; \\\n"
"Dtype8 blockA02 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordATemp.x += 8 * SIZE_OF_ELEMENT; \\\n"
"Dtype8 blockA03 = as_Dtype8( SUBGROUP_BLOCK_READ8( A, coordATemp ) ); coordA.y += TILE_K; \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB00, blockA00 , blockB00, 0 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB01, blockA01 , blockB00, 0 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB02, blockA02 , blockB00, 0 ); \\\n"
"MULTIPLY_BLOCKS_8x8( blockAxB03, blockA03 , blockB00, 0 ); \\\n"
"} \\\n"
"while( coordB.x < padded_k / VECSIZE ); \\\n"
"GEMM_OUTPUT(ALPHA1, BETA_NOT0);\\\n"
"}\n"
"#endif\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"_blockb.s0123 = READ_IMAGE(_B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s4567 = READ_IMAGE(_B, _coordBTemp); _coordB.x += 2;\n"
"#define MATB_PARAMETER __read_only image2d_t B\n"
"GEMM_TT(1, 0, VEC4, 4)\n"
"GEMM_TT(1, 1, VEC4, 4)\n"
"GEMM_TT(0, 0, VEC4, 4)\n"
"GEMM_TT(0, 1, VEC4, 4)\n"
"#undef BLOCKB_READ8\n"
"#undef MATB_PARAMETER\n"
"#if TYPE == TYPE_HALF\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"const __global float *B_read = (__global float *)(_B + (_coordBTemp.y * k) + _coordBTemp.x + offB); \\\n"
"_blockb = as_Dtype8(as_ushort8(vload4(0, B_read))); \\\n"
"_coordB.x += TILE_K;\n"
"#else\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"const __global Dtype *B_read = (__global Dtype *)(_B + (_coordBTemp.y * k) + _coordBTemp.x + offB); \\\n"
"_blockb = vload8(0, B_read); \\\n"
"_coordB.x += TILE_K;\n"
"#endif\n"
"#define MATB_PARAMETER __global Dtype *B, int offB, int ldb\n"
"GEMM_TT(1, 0, BUFFER, 1)\n"
"GEMM_TT(1, 1, BUFFER, 1)\n"
"GEMM_TT(0, 0, BUFFER, 1)\n"
"GEMM_TT(0, 1, BUFFER, 1)\n"
"#undef BLOCKB_READ8\n"
"#undef MATB_PARAMETER\n"
"#define BLOCKB_READ8(_blockb, _B, _coordB) \\\n"
"int2 _coordBTemp = _coordB; \\\n"
"_coordBTemp.y += get_local_id(0); \\\n"
"Dtype4 temp; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s0 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s1 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s2 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s3 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s4 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s5 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s6 = temp.s0; \\\n"
"temp = READ_IMAGE(B, _coordBTemp); _coordBTemp.x += 1; \\\n"
"_blockb.s7 = temp.s0; \\\n"
"_coordB.x += 8;\n"
"#define MATB_PARAMETER __read_only image2d_t B\n"
"GEMM_TT(1, 0, SCALAR, 1)\n"
"GEMM_TT(1, 1, SCALAR, 1)\n"
"GEMM_TT(0, 0, SCALAR, 1)\n"
"GEMM_TT(0, 1, SCALAR, 1)\n"
"#undef BLOCKB_READ8\n"
"#undef MATB_PARAMETER\n"
"#undef MULTIPLY_BLOCKS_8x8\n"
"#undef TRANSPOSE_BLOCK_8\n"
"#undef GEMM_TT\n"
"#undef TILE_M\n"
"#undef TILE_K\n"
"#undef TILE_N\n"
"#undef SUBGROUP_BLOCK_READ8\n"
"#undef READ_IMAGE\n"
"#undef SIZE_OF_ELEMENT\n"
"__kernel void TEMPLATE(gemm_buffer_copy_image_transpose, Dtype)(\n"
"__global Dtype* A,\n"
"__write_only image2d_t ImA,\n"
"int offA,\n"
"int width,\n"
"int height,\n"
"int ldA)\n"
"{\n"
"const int gidx = get_global_id(0);\n"
"const int gidy = get_global_id(1);\n"
"if (gidx >= width || gidy >= height)\n"
"return;\n"
"int2 coord_dst = (int2)(gidx, gidy);\n"
"__global Dtype* A_off = A + offA;\n"
"Dtype srcA = A_off[gidy * ldA + gidx];\n"
"#if TYPE == TYPE_HALF\n"
"write_imageh(ImA, coord_dst, (Dtype4)srcA);\n"
"#else\n"
"write_imagef(ImA, coord_dst, (Dtype4)srcA);\n"
"#endif\n"
"}\n"
"__kernel void TEMPLATE(gemm_buffer_copy_image_no_transpose, Dtype)(\n"
"__global Dtype* A,\n"
"__write_only image2d_t ImA,\n"
"int offA,\n"
"int padded_width,\n"
"int padded_height,\n"
"int width,\n"
"int height,\n"
"int ldA)\n"
"{\n"
"const int gidx = get_global_id(0);\n"
"const int gidy = get_global_id(1);\n"
"if (gidx >= padded_width || gidy >= padded_height)\n"
"return;\n"
"int2 coord_dst = (int2)(gidx, gidy);\n"
"#if TYPE == TYPE_HALF\n"
"if (gidx >= width || gidy >= height) {\n"
"write_imageh(ImA, coord_dst, 0);\n"
"return;\n"
"}\n"
"__global Dtype* A_off = A + offA;\n"
"write_imageh(ImA, coord_dst, A_off[gidy * ldA + gidx]);\n"
"#else\n"
"if (gidx >= width || gidy >= height) {\n"
"write_imageui(ImA, coord_dst, (uint4)0);\n"
"return;\n"
"}\n"
"__global Dtype* A_off = A + offA;\n"
"uint4 srcA = convert_uint4(as_uchar4(A_off[gidy * ldA + gidx]));\n"
"write_imageui(ImA, coord_dst, srcA);\n"
"#endif\n"
"}\n"
, "3b788ad998ad54977a6af81e04e13c15", NULL};
struct cv::ocl::internal::ProgramEntry im2col_oclsrc={moduleName, "im2col",
"__kernel void im2col(__global const T *im_src, int im_src_offset,\n"
"int channels, int height_inp, int width_inp,\n"
"int kernel_h, int kernel_w, int pad_h, int pad_w, int stride_h, int stride_w,\n"
"int height_out, int width_out,\n"
"__global T *im_col, int im_col_offset\n"
")\n"
"{\n"
"int index = get_global_id(0);\n"
"if (index >= height_out * width_out * channels)\n"
"return;\n"
"int j_out = index % width_out;\n"
"int i_out = (index / width_out) % height_out;\n"
"int c_inp = (index / width_out) / height_out;\n"
"int c_out = c_inp * kernel_h * kernel_w;\n"
"int i_inp = i_out * stride_h - pad_h;\n"
"int j_inp = j_out * stride_w - pad_w;\n"
"im_src += (c_inp * height_inp + i_inp) * width_inp + j_inp + im_src_offset;\n"
"im_col += (c_out * height_out + i_out) * width_out + j_out + im_col_offset;\n"
"for (int ki = 0; ki < kernel_h; ++ki)\n"
"for (int kj = 0; kj < kernel_w; ++kj) {\n"
"int i = i_inp + ki;\n"
"int j = j_inp + kj;\n"
"*im_col = (i >= 0 && j >= 0 && i < height_inp && j < width_inp) ?\n"
"im_src[ki * width_inp + kj] : 0;\n"
"im_col += height_out * width_out;\n"
"}\n"
"}\n"
, "609f199a321eef4535e1eff3ab281090", NULL};
struct cv::ocl::internal::ProgramEntry lrn_oclsrc={moduleName, "lrn",
"/*************************************************************************************\n"
"* Copyright (c) 2015, Advanced Micro Devices, Inc.\n"
"* All rights reserved.\n"
"*\n"
"* Redistribution and use in source and binary forms, with or without modification,\n"
"* are permitted provided that the following conditions are met:\n"
"*\n"
"* 1. Redistributions of source code must retain the above copyright notice, this\n"
"* list of conditions and the following disclaimer.\n"
"*\n"
"* 2. Redistributions in binary form must reproduce the above copyright notice,\n"
"* this list of conditions and the following disclaimer in the documentation and/or\n"
"* other materials provided with the distribution.\n"
"*\n"
"* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n"
"* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
"* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n"
"* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
"* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n"
"* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n"
"* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n"
"* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n"
"* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
"* POSSIBILITY OF SUCH DAMAGE.\n"
"**************************************************************************************/\n"
"__kernel void LRNComputeOutput(const int nthreads, __global T* in, __global T* scale, const T negative_beta, __global T* out) {\n"
"int index = get_global_id(0);\n"
"int tmp = get_global_size(0);\n"
"for(index; index < nthreads; index += tmp)\n"
"out[index] = in[index] * pow(scale[index], negative_beta);\n"
"}\n"
"__kernel void LRNFillScale(const int nthreads, __global T* in, const int num, const int channels, const int height, const int width, const int size, const T alpha_over_size, const T k, __global T* scale) {\n"
"int index = get_global_id(0);\n"
"int tmp = get_global_size(0);\n"
"for(index; index < nthreads; index += tmp) {\n"
"const int w = index % width;\n"
"const int h = (index / width) % height;\n"
"const int n = index / width / height;\n"
"const int offset = (n * channels * height + h) * width + w;\n"
"const int step = height * width;\n"
"in = in + offset;\n"
"scale = scale + offset;\n"
"int head = 0;\n"
"const int pre_pad = (size - 1) / 2;\n"
"const int post_pad = size - pre_pad - 1;\n"
"T accum_scale = 0;\n"
"while (head < post_pad && head < channels) {\n"
"accum_scale += in[head * step] * in[head * step];\n"
"++head;\n"
"}\n"
"while (head < channels) {\n"
"accum_scale += in[head * step] * in[head * step];\n"
"if (head - size >= 0) {\n"
"accum_scale -= in[(head - size) * step]\n"
"* in[(head - size) * step];\n"
"}\n"
"scale[(head - post_pad) * step] = k + accum_scale * alpha_over_size;\n"
"++head;\n"
"}\n"
"while (head < channels + post_pad) {\n"
"if (head - size >= 0) {\n"
"accum_scale -= in[(head - size) * step]\n"
"* in[(head - size) * step];\n"
"}\n"
"scale[(head - post_pad) * step] = k + accum_scale * alpha_over_size;\n"
"++head;\n"
"}\n"
"}\n"
"}\n"
, "0c65eb40713b6261f88bfa6731e32733", NULL};
struct cv::ocl::internal::ProgramEntry math_oclsrc={moduleName, "math",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#define KERNEL_ARG_DTYPE float\n"
"__kernel void TEMPLATE(axpy,Dtype)(const int n, const KERNEL_ARG_DTYPE alpha, __global const Dtype* x,\n"
"const int offx, __global Dtype* y,\n"
"const int offy) {\n"
"for (int index = get_global_id(0); index < n; index += get_global_size(0)) {\n"
"Dtype src = x[offx + index];\n"
"Dtype dst = y[offy + index];\n"
"y[offy + index] = convert_Dtype(alpha) * src + dst;\n"
"}\n"
"}\n"
, "a76839299bc739767433b6d55915e1b7", NULL};
struct cv::ocl::internal::ProgramEntry matvec_mul_oclsrc={moduleName, "matvec_mul",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#define KERNEL_ARG_DTYPE float\n"
"__kernel void TEMPLATE(matvec_mul4,Dtype)(\n"
"__global const Dtype * A,\n"
"int offA,\n"
"unsigned int A_col_size,\n"
"unsigned int trail_item,\n"
"__global const Dtype * v,\n"
"int offv,\n"
"KERNEL_ARG_DTYPE alpha,\n"
"KERNEL_ARG_DTYPE beta,\n"
"__global Dtype4* result,\n"
"int offr,\n"
"__local Dtype4* work)\n"
"{\n"
"unsigned int row_gid = get_group_id(0);\n"
"unsigned int lid = get_local_id(0);\n"
"const __global Dtype *src0_read = A + row_gid * 4 * A_col_size + offA;\n"
"const __global Dtype *src1_read = v + offv;\n"
"result = (__global Dtype4*)((__global Dtype*)result + offr);\n"
"Dtype4 dot0 = (Dtype4)(0.f);\n"
"Dtype4 dot1 = (Dtype4)(0.f);\n"
"Dtype4 dot2 = (Dtype4)(0.f);\n"
"Dtype4 dot3 = (Dtype4)(0.f);\n"
"unsigned int i = lid;\n"
"while( i < A_col_size / 4) {\n"
"const Dtype4 a0 = vload4(i, src0_read);\n"
"const Dtype4 a1 = vload4(i, src0_read + A_col_size);\n"
"const Dtype4 a2 = vload4(i, src0_read + 2 * A_col_size);\n"
"const Dtype4 a3 = vload4(i, src0_read + 3 * A_col_size);\n"
"const Dtype4 b0 = vload4(i, src1_read);\n"
"dot0 += a0 * b0;\n"
"dot1 += a1 * b0;\n"
"dot2 += a2 * b0;\n"
"dot3 += a3 * b0;\n"
"i += get_local_size(0);\n"
"}\n"
"work[lid].s0 = dot0.x + dot0.y + dot0.z + dot0.w;\n"
"work[lid].s1 = dot1.x + dot1.y + dot1.z + dot1.w;\n"
"work[lid].s2 = dot2.x + dot2.y + dot2.z + dot2.w;\n"
"work[lid].s3 = dot3.x + dot3.y + dot3.z + dot3.w;\n"
"if(i == A_col_size / 4)\n"
"{\n"
"if(trail_item != 0)\n"
"{\n"
"const __global Dtype *src0_trail = src0_read + i * 4;\n"
"const __global Dtype *src1_trail = src1_read + i * 4;\n"
"for(unsigned int i = 0; i < trail_item; ++i) {\n"
"const Dtype at0 = src0_trail[i];\n"
"const Dtype at1 = src0_trail[i + A_col_size];\n"
"const Dtype at2 = src0_trail[i + 2 * A_col_size];\n"
"const Dtype at3 = src0_trail[i + 3 * A_col_size];\n"
"const Dtype bt = src1_trail[i];\n"
"work[lid].s0 += at0 * bt;\n"
"work[lid].s1 += at1 * bt;\n"
"work[lid].s2 += at2 * bt;\n"
"work[lid].s3 += at3 * bt;\n"
"}\n"
"}\n"
"}\n"
"for(unsigned int stride=get_local_size(0)/2 ; stride>0 ; stride>>=1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride)\n"
"work[lid] += work[lid+stride];\n"
"}\n"
"if(lid == 0) {\n"
"if(beta == (Dtype)0)\n"
"result[row_gid] = convert_Dtype(alpha) * work[0];\n"
"else\n"
"result[row_gid] = convert_Dtype(alpha) * work[0] + convert_Dtype(beta) * result[row_gid];\n"
"}\n"
"}\n"
"__kernel void TEMPLATE(matvec_mul1,Dtype)(\n"
"__global const Dtype * A,\n"
"int offA,\n"
"unsigned int A_col_size,\n"
"unsigned int row_offset,\n"
"unsigned int trail_item,\n"
"__global const Dtype * v,\n"
"int offv,\n"
"KERNEL_ARG_DTYPE alpha,\n"
"KERNEL_ARG_DTYPE beta,\n"
"__global Dtype * result,\n"
"int offr,\n"
"__local Dtype * work)\n"
"{\n"
"unsigned int row_gid = get_group_id(0);\n"
"unsigned int lid = get_local_id(0);\n"
"const __global Dtype *src0_read = A + (row_offset + row_gid) * A_col_size + offA;\n"
"const __global Dtype *src1_read = v + + offv;\n"
"result = result + offr;\n"
"Dtype4 dot0 = (Dtype4)(0.f);\n"
"unsigned int i = lid;\n"
"while( i < A_col_size / 4)\n"
"{\n"
"const Dtype4 a0 = vload4(i, src0_read);\n"
"const Dtype4 b0 = vload4(i, src1_read);\n"
"dot0 += a0 * b0;\n"
"i += get_local_size(0);\n"
"}\n"
"work[lid] = dot0.x + dot0.y + dot0.z + dot0.w;\n"
"if(i == A_col_size / 4)\n"
"{\n"
"if(trail_item != 0)\n"
"{\n"
"const __global Dtype *src0_trail = src0_read + i * 4;\n"
"const __global Dtype *src1_trail = src1_read + i * 4;\n"
"for(unsigned int i = 0; i < trail_item; ++i) {\n"
"const Dtype at0 = src0_trail[i];\n"
"const Dtype bt = src1_trail[i];\n"
"work[lid] += at0 * bt;\n"
"}\n"
"}\n"
"}\n"
"for(unsigned int stride=get_local_size(0)/2 ; stride>0 ; stride>>=1) {\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride)\n"
"work[lid] += work[lid+stride];\n"
"}\n"
"if(lid == 0) {\n"
"if(beta == (Dtype)0) {\n"
"result[row_gid+row_offset] = convert_Dtype(alpha) * work[0];\n"
"} else {\n"
"result[row_gid+row_offset] *= convert_Dtype(beta);\n"
"result[row_gid+row_offset] += convert_Dtype(alpha) * work[0];\n"
"}\n"
"}\n"
"}\n"
, "b1ea7917f8161740ee6102617a54cfe1", NULL};
struct cv::ocl::internal::ProgramEntry mvn_oclsrc={moduleName, "mvn",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#define Dtype float\n"
"#define Dtype4 float4\n"
"#define Dtype8 float8\n"
"#if NUM == 8\n"
"#define load(src, index) vload8(0, src + index)\n"
"#define store(vec, dst, index) vstore8(vec, 0, dst + index)\n"
"#define vec_type Dtype8\n"
"#define CALC_MEAN calc_mean8\n"
"#define MVN mvn8\n"
"#define MEAN_FUSE mean_fuse8\n"
"#define MVN_FUSE mvn_fuse8\n"
"#elif NUM == 4\n"
"#define load(src, index) vload4(0, src + index)\n"
"#define store(vec, dst, index) vstore4(vec, 0, dst + index)\n"
"#define vec_type Dtype4\n"
"#define CALC_MEAN calc_mean4\n"
"#define MVN mvn4\n"
"#define MEAN_FUSE mean_fuse4\n"
"#define MVN_FUSE mvn_fuse4\n"
"#elif NUM == 1\n"
"#define load(src, index) src[index]\n"
"#define store(vec, dst, index) dst[index] = vec\n"
"#define vec_type Dtype\n"
"#define CALC_MEAN calc_mean1\n"
"#define MVN mvn1\n"
"#define MEAN_FUSE mean_fuse1\n"
"#define MVN_FUSE mvn_fuse1\n"
"#endif\n"
"#ifdef KERNEL_MEAN\n"
"__kernel void CALC_MEAN(__global const Dtype* src,\n"
"const int rows,\n"
"const int cols,\n"
"__global Dtype* mean,\n"
"__global Dtype* dst)\n"
"{\n"
"int x = get_global_id(0);\n"
"int y = get_global_id(1) * NUM;\n"
"int index = x * cols + y;\n"
"if (x >= rows || y >= cols)\n"
"return;\n"
"Dtype mean_val = mean[x];\n"
"vec_type src_vec = load(src, index);\n"
"vec_type dst_vec = src_vec - (vec_type)mean_val;\n"
"dst_vec = dst_vec * dst_vec;\n"
"store(dst_vec, dst, index);\n"
"}\n"
"#elif defined KERNEL_MVN\n"
"__kernel void MVN(__global const Dtype* src,\n"
"const int rows,\n"
"const int cols,\n"
"const Dtype eps,\n"
"__global const Dtype* mean,\n"
"__global const Dtype* dev,\n"
"__global const Dtype* bnorm_weight,\n"
"__global const Dtype* bnorm_bias,\n"
"const int channels,\n"
"const float relu_slope,\n"
"__global Dtype* dst)\n"
"{\n"
"int x = get_global_id(0);\n"
"int y = get_global_id(1) * NUM;\n"
"int index = x * cols + y;\n"
"if (x >= rows || y >= cols)\n"
"return;\n"
"Dtype mean_val = mean[x];\n"
"Dtype dev_val = dev[x];\n"
"Dtype alpha;\n"
"#ifdef NORM_VARIANCE\n"
"alpha = 1 / sqrt(eps + dev_val);\n"
"#else\n"
"alpha = 1;\n"
"#endif\n"
"Dtype w = 1.f, b = 0.f;\n"
"#ifdef FUSE_BATCH_NORM\n"
"w = bnorm_weight[x % channels];\n"
"b = bnorm_bias[x % channels];\n"
"#endif\n"
"vec_type src_vec = load(src, index) - (vec_type)mean_val;\n"
"vec_type dst_vec = src_vec * alpha;\n"
"dst_vec = dst_vec * w + (vec_type)b;\n"
"#ifdef FUSE_RELU\n"
"vec_type new_val = dst_vec * relu_slope;\n"
"dst_vec = select(new_val, dst_vec, dst_vec > (vec_type)0.f);\n"
"#endif\n"
"store(dst_vec, dst, index);\n"
"}\n"
"#elif defined KERNEL_MEAN_FUSE\n"
"__kernel void MEAN_FUSE(__global const T * A,\n"
"unsigned int A_col_size,\n"
"float alpha,\n"
"__global T4 * mean,\n"
"__global Dtype * tmp)\n"
"{\n"
"unsigned int row_gid = get_group_id(0);\n"
"unsigned int lid = get_local_id(0);\n"
"const __global T *src0_read = A + row_gid * 4 * A_col_size;\n"
"__global Dtype *dst0_read = tmp + row_gid * 4 * A_col_size;\n"
"Dtype4 dot0, dot1, dot2, dot3;\n"
"dot0 = dot1 = dot2 = dot3 = (Dtype4)(0.f);\n"
"unsigned int i = lid;\n"
"const Dtype4 b0 = (Dtype4)1.f;\n"
"while( i < A_col_size / 4)\n"
"{\n"
"const T4 a0 = vload4(i, src0_read);\n"
"const T4 a1 = vload4(i, src0_read + A_col_size);\n"
"const T4 a2 = vload4(i, src0_read + 2 * A_col_size);\n"
"const T4 a3 = vload4(i, src0_read + 3 * A_col_size);\n"
"dot0 += convert_float4(a0);\n"
"dot1 += convert_float4(a1);\n"
"dot2 += convert_float4(a2);\n"
"dot3 += convert_float4(a3);\n"
"i += LOCAL_SIZE;\n"
"}\n"
"__local Dtype4 work[LOCAL_SIZE];\n"
"work[lid].s0 = dot(dot0, b0);\n"
"work[lid].s1 = dot(dot1, b0);\n"
"work[lid].s2 = dot(dot2, b0);\n"
"work[lid].s3 = dot(dot3, b0);\n"
"for(unsigned int stride=LOCAL_SIZE/2 ; stride>0 ; stride>>=1)\n"
"{\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride)\n"
"work[lid] += work[lid+stride];\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid == 0)\n"
"{\n"
"mean[row_gid] = convert_T(alpha * work[0]);\n"
"}\n"
"Dtype4 sum = work[0] * alpha;\n"
"i = lid;\n"
"while( i < A_col_size / 4)\n"
"{\n"
"const T4 a0 = vload4(i, src0_read);\n"
"const T4 a1 = vload4(i, src0_read + A_col_size);\n"
"const T4 a2 = vload4(i, src0_read + 2 * A_col_size);\n"
"const T4 a3 = vload4(i, src0_read + 3 * A_col_size);\n"
"dot0 = convert_float4(a0) - (Dtype4)sum.x;\n"
"dot1 = convert_float4(a1) - (Dtype4)sum.y;\n"
"dot2 = convert_float4(a2) - (Dtype4)sum.z;\n"
"dot3 = convert_float4(a3) - (Dtype4)sum.w;\n"
"dot0 = dot0 * dot0;\n"
"dot1 = dot1 * dot1;\n"
"dot2 = dot2 * dot2;\n"
"dot3 = dot3 * dot3;\n"
"vstore4(dot0, i, dst0_read);\n"
"vstore4(dot1, i, dst0_read + A_col_size);\n"
"vstore4(dot2, i, dst0_read + 2 * A_col_size);\n"
"vstore4(dot3, i, dst0_read + 3 * A_col_size);\n"
"i += LOCAL_SIZE;\n"
"}\n"
"}\n"
"#elif defined KERNEL_MVN_FUSE\n"
"__kernel void MVN_FUSE(__global const Dtype * tmp,\n"
"__global const T * A,\n"
"__global const T4 * mean,\n"
"unsigned int A_col_size,\n"
"const float alpha_val,\n"
"const float eps,\n"
"const float relu_slope,\n"
"__global const Dtype4 * bnorm_weight,\n"
"__global const Dtype4 * bnorm_bias,\n"
"__global T * B)\n"
"{\n"
"unsigned int row_gid = get_group_id(0);\n"
"unsigned int lid = get_local_id(0);\n"
"const __global Dtype *src0_read = tmp + row_gid * 4 * A_col_size;\n"
"const __global T *src1_read = A + row_gid * 4 * A_col_size;\n"
"__global T *dst0_read = B + row_gid * 4 * A_col_size;\n"
"Dtype4 dot0, dot1, dot2, dot3;\n"
"dot0 = dot1 = dot2 = dot3 = (Dtype4)(0.f);\n"
"unsigned int i = lid;\n"
"const Dtype4 b0 = (Dtype4)1.f;\n"
"while( i < A_col_size / 4)\n"
"{\n"
"const Dtype4 a0 = vload4(i, src0_read);\n"
"const Dtype4 a1 = vload4(i, src0_read + A_col_size);\n"
"const Dtype4 a2 = vload4(i, src0_read + 2 * A_col_size);\n"
"const Dtype4 a3 = vload4(i, src0_read + 3 * A_col_size);\n"
"dot0 += a0;\n"
"dot1 += a1;\n"
"dot2 += a2;\n"
"dot3 += a3;\n"
"i += LOCAL_SIZE;\n"
"}\n"
"__local Dtype4 work[LOCAL_SIZE];\n"
"work[lid].s0 = dot(dot0, b0);\n"
"work[lid].s1 = dot(dot1, b0);\n"
"work[lid].s2 = dot(dot2, b0);\n"
"work[lid].s3 = dot(dot3, b0);\n"
"for(unsigned int stride=LOCAL_SIZE/2 ; stride>0 ; stride>>=1)\n"
"{\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(lid < stride)\n"
"work[lid] += work[lid+stride];\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"Dtype4 mean_val = convert_float4(mean[row_gid]);\n"
"Dtype4 dev_val = sqrt(work[0] * alpha_val + (Dtype4)eps);\n"
"Dtype4 alpha = (Dtype4)1.f / dev_val;\n"
"Dtype4 w = (Dtype4)1.f;\n"
"Dtype4 b = (Dtype4)0.f;\n"
"#ifdef FUSE_BATCH_NORM\n"
"w = bnorm_weight[row_gid];\n"
"b = bnorm_bias[row_gid];\n"
"#endif\n"
"i = lid;\n"
"while( i < A_col_size / 4)\n"
"{\n"
"const T4 a0 = vload4(i, src1_read);\n"
"const T4 a1 = vload4(i, src1_read + A_col_size);\n"
"const T4 a2 = vload4(i, src1_read + 2 * A_col_size);\n"
"const T4 a3 = vload4(i, src1_read + 3 * A_col_size);\n"
"dot0 = (convert_float4(a0) - (Dtype4)mean_val.x) * alpha.x;\n"
"dot1 = (convert_float4(a1) - (Dtype4)mean_val.y) * alpha.y;\n"
"dot2 = (convert_float4(a2) - (Dtype4)mean_val.z) * alpha.z;\n"
"dot3 = (convert_float4(a3) - (Dtype4)mean_val.w) * alpha.w;\n"
"dot0 = dot0 * w.x + (Dtype4)b.x;\n"
"dot1 = dot1 * w.y + (Dtype4)b.y;\n"
"dot2 = dot2 * w.z + (Dtype4)b.z;\n"
"dot3 = dot3 * w.w + (Dtype4)b.w;\n"
"#ifdef FUSE_RELU\n"
"Dtype4 new0 = dot0 * relu_slope;\n"
"dot0 = select(new0, dot0, dot0 > (Dtype4)0.f);\n"
"Dtype4 new1 = dot1 * relu_slope;\n"
"dot1 = select(new1, dot1, dot1 > (Dtype4)0.f);\n"
"Dtype4 new2 = dot2 * relu_slope;\n"
"dot2 = select(new2, dot2, dot2 > (Dtype4)0.f);\n"
"Dtype4 new3 = dot3 * relu_slope;\n"
"dot3 = select(new3, dot3, dot3 > (Dtype4)0.f);\n"
"#endif\n"
"vstore4(convert_T(dot0), i, dst0_read);\n"
"vstore4(convert_T(dot1), i, dst0_read + A_col_size);\n"
"vstore4(convert_T(dot2), i, dst0_read + 2 * A_col_size);\n"
"vstore4(convert_T(dot3), i, dst0_read + 3 * A_col_size);\n"
"i += LOCAL_SIZE;\n"
"}\n"
"}\n"
"#else\n"
"#error \"Configuration error!\"\n"
"#endif\n"
, "d0e6334dcdc9ef67a14d01801722c035", NULL};
struct cv::ocl::internal::ProgramEntry ocl4dnn_lrn_oclsrc={moduleName, "ocl4dnn_lrn",
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#define KERNEL_ARG_DTYPE float\n"
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void TEMPLATE(lrn_full_no_scale,Dtype)(const int nthreads, __global const Dtype* in,\n"
"const int num, const int channels,\n"
"const int height, const int width, const int size,\n"
"const KERNEL_ARG_DTYPE alpha_over_size, const KERNEL_ARG_DTYPE k,\n"
"__global Dtype* const out,\n"
"const KERNEL_ARG_DTYPE negative_beta) {\n"
"for (int index = get_global_id(0); index < nthreads;\n"
"index += get_global_size(0)) {\n"
"const int w = index % width;\n"
"const int h = (index / width) % height;\n"
"const int n = index / width / height;\n"
"const int offset = (n * channels * height + h) * width + w;\n"
"const int step = height * width;\n"
"__global const Dtype* in_off = in + offset;\n"
"__global Dtype* out_off = out + offset;\n"
"KERNEL_ARG_DTYPE scale_val;\n"
"int head = 0;\n"
"const int pre_pad = (size - 1) / 2;\n"
"const int post_pad = size - pre_pad - 1;\n"
"KERNEL_ARG_DTYPE accum_scale = 0;\n"
"while (head < post_pad && head < channels) {\n"
"accum_scale += in_off[head * step] * in_off[head * step];\n"
"++head;\n"
"}\n"
"while (head < channels) {\n"
"accum_scale += in_off[head * step] * in_off[head * step];\n"
"if (head - size >= 0) {\n"
"accum_scale -= in_off[(head - size) * step]\n"
"* in_off[(head - size) * step];\n"
"}\n"
"scale_val = k + accum_scale * alpha_over_size;\n"
"out_off[(head - post_pad) * step] = in_off[(head - post_pad) * step] * (Dtype)native_powr(scale_val, negative_beta);\n"
"++head;\n"
"}\n"
"while (head < channels + post_pad) {\n"
"if (head - size >= 0) {\n"
"accum_scale -= in_off[(head - size) * step]\n"
"* in_off[(head - size) * step];\n"
"}\n"
"scale_val = k + accum_scale * alpha_over_size;\n"
"out_off[(head - post_pad) * step] = in_off[(head - post_pad) * step] * (Dtype)native_powr(scale_val, negative_beta);\n"
"++head;\n"
"}\n"
"}\n"
"}\n"
, "5b3b0615ca2e06228fef74b23250379b", NULL};
struct cv::ocl::internal::ProgramEntry ocl4dnn_pooling_oclsrc={moduleName, "ocl4dnn_pooling",
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"#if defined KERNEL_MAX_POOL\n"
"__kernel void\n"
"#ifdef HAVE_MASK\n"
"TEMPLATE(max_pool_forward_mask, Dtype)\n"
"#else\n"
"TEMPLATE(max_pool_forward, Dtype)\n"
"#endif\n"
"(\n"
"const int nthreads, __global const Dtype* bottom_data,\n"
"const int channels, const int height, const int width,\n"
"const int pooled_height, const int pooled_width,\n"
"__global Dtype* top_data\n"
"#ifdef HAVE_MASK\n"
", __global Dtype* mask\n"
"#endif\n"
")\n"
"{\n"
"int index = get_global_id(0);\n"
"if (index >= nthreads)\n"
"return;\n"
"const int pw = index % pooled_width;\n"
"const int xx = index / pooled_width;\n"
"const int ph = xx % pooled_height;\n"
"const int ch = xx / pooled_height;\n"
"int hstart = ph * STRIDE_H - PAD_T;\n"
"int wstart = pw * STRIDE_W - PAD_L;\n"
"Dtype maxval = -FLT_MAX;\n"
"int maxidx = -1;\n"
"int in_offset = ch * height * width;\n"
"for (int h = 0; h < KERNEL_H; ++h)\n"
"{\n"
"int off_y = hstart + h;\n"
"if (off_y >= 0 && off_y < height)\n"
"{\n"
"for (int w = 0; w < KERNEL_W; ++w)\n"
"{\n"
"int off_x = wstart + w;\n"
"if (off_x >= 0 && off_x < width)\n"
"{\n"
"Dtype val = bottom_data[in_offset + off_y * width + off_x];\n"
"maxidx = (val > maxval) ? (off_y * width + off_x) : maxidx;\n"
"maxval = fmax(val, maxval);\n"
"}\n"
"}\n"
"}\n"
"}\n"
"top_data[index] = maxval;\n"
"#ifdef HAVE_MASK\n"
"mask[index] = maxidx;\n"
"#endif\n"
"}\n"
"#elif defined KERNEL_AVE_POOL\n"
"__kernel void TEMPLATE(ave_pool_forward, Dtype)(\n"
"const int nthreads, __global const Dtype* bottom_data,\n"
"const int channels, const int height, const int width,\n"
"const int pooled_height, const int pooled_width,\n"
"__global Dtype* top_data)\n"
"{\n"
"int index = get_global_id(0);\n"
"if (index >= nthreads)\n"
"return;\n"
"const int pw = index % pooled_width;\n"
"const int xx = index / pooled_width;\n"
"const int ph = xx % pooled_height;\n"
"const int ch = xx / pooled_height;\n"
"int hstart = ph * STRIDE_H - PAD_T;\n"
"int wstart = pw * STRIDE_W - PAD_L;\n"
"int hend = min(hstart + KERNEL_H, height + PAD_B);\n"
"int wend = min(wstart + KERNEL_W, width + PAD_R);\n"
"int pool_size;\n"
"#ifdef AVE_POOL_PADDING_AREA\n"
"pool_size = (hend - hstart) * (wend - wstart);\n"
"hstart = max(hstart, (int)0);\n"
"wstart = max(wstart, (int)0);\n"
"hend = min(hend, height);\n"
"wend = min(wend, width);\n"
"#else\n"
"hstart = max(hstart, (int)0);\n"
"wstart = max(wstart, (int)0);\n"
"hend = min(hend, height);\n"
"wend = min(wend, width);\n"
"pool_size = (hend - hstart) * (wend - wstart);\n"
"#endif\n"
"Dtype aveval = 0;\n"
"int in_offset = ch * height * width;\n"
"for (int h = hstart; h < hend; ++h)\n"
"{\n"
"for (int w = wstart; w < wend; ++w)\n"
"{\n"
"aveval += bottom_data[in_offset + h * width + w];\n"
"}\n"
"}\n"
"top_data[index] = aveval / pool_size;\n"
"}\n"
"#elif defined KERNEL_STO_POOL\n"
"__kernel void TEMPLATE(sto_pool_forward_test,Dtype)(\n"
"const int nthreads, __global const Dtype* bottom_data,\n"
"const int channels, const int height, const int width,\n"
"const int pooled_height, const int pooled_width,\n"
"__global Dtype* top_data)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads;\n"
"index += get_global_size(0))\n"
"{\n"
"const int pw = index % pooled_width;\n"
"const int ph = (index / pooled_width) % pooled_height;\n"
"const int c = (index / pooled_width / pooled_height) % channels;\n"
"const int n = index / pooled_width / pooled_height / channels;\n"
"const int hstart = ph * STRIDE_H;\n"
"const int hend = min(hstart + KERNEL_H, height);\n"
"const int wstart = pw * STRIDE_W;\n"
"const int wend = min(wstart + KERNEL_W, width);\n"
"Dtype cumsum = FLT_MIN;\n"
"Dtype cumvalues = 0.;\n"
"__global const Dtype* bottom_slice = bottom_data\n"
"+ (n * channels + c) * height * width;\n"
"for (int h = hstart; h < hend; ++h) {\n"
"for (int w = wstart; w < wend; ++w) {\n"
"Dtype v = bottom_slice[h * width + w];\n"
"cumsum += v;\n"
"cumvalues += v * v;\n"
"}\n"
"}\n"
"top_data[index] = cumvalues / cumsum;\n"
"}\n"
"}\n"
"#endif\n"
, "323321c5f6f114f2693c552e81e87230", NULL};
struct cv::ocl::internal::ProgramEntry permute_oclsrc={moduleName, "permute",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void permute(const int nthreads,\n"
"__global Dtype* bottom_data,\n"
"global int* permute_order,\n"
"global int* oldStride,\n"
"global int* newStride,\n"
"const int num_axes,\n"
"__global Dtype* top_data)\n"
"{\n"
"for (int i = get_global_id(0); i < nthreads; i += get_global_size(0))\n"
"{\n"
"int oldPosition = 0;\n"
"int newPosition = i;\n"
"for (int j = 0; j < num_axes; ++j)\n"
"{\n"
"int order = permute_order[j];\n"
"oldPosition += (newPosition / newStride[j]) * oldStride[order];\n"
"newPosition %= newStride[j];\n"
"}\n"
"top_data[i] = bottom_data[oldPosition];\n"
"}\n"
"}\n"
, "81803672217de8c6fc01de8a6e7f283a", NULL};
struct cv::ocl::internal::ProgramEntry pooling_oclsrc={moduleName, "pooling",
"/*************************************************************************************\n"
"* Copyright (c) 2015, Advanced Micro Devices, Inc.\n"
"* All rights reserved.\n"
"*\n"
"* Redistribution and use in source and binary forms, with or without modification,\n"
"* are permitted provided that the following conditions are met:\n"
"*\n"
"* 1. Redistributions of source code must retain the above copyright notice, this\n"
"* list of conditions and the following disclaimer.\n"
"*\n"
"* 2. Redistributions in binary form must reproduce the above copyright notice,\n"
"* this list of conditions and the following disclaimer in the documentation and/or\n"
"* other materials provided with the distribution.\n"
"*\n"
"* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n"
"* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
"* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n"
"* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
"* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n"
"* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n"
"* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n"
"* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n"
"* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
"* POSSIBILITY OF SUCH DAMAGE.\n"
"**************************************************************************************/\n"
"__kernel void MaxPoolForward(const int nthreads,\n"
"__global T* bottom_data, const int num, const int channels, const int height, const int width,\n"
"const int pooled_height, const int pooled_width, const int kernel_h, const int kernel_w,\n"
"const int stride_h, const int stride_w, const int pad_t, const int pad_l, const int pad_b, const int pad_r,\n"
"__global T* top_data\n"
"#ifdef MASK\n"
", __global float* mask\n"
"#endif\n"
")\n"
"{\n"
"int index = get_global_id(0);\n"
"int tmp = get_global_size(0);\n"
"for(index; index < nthreads; index += tmp) {\n"
"int pw = index % pooled_width;\n"
"int ph = (index / pooled_width) % pooled_height;\n"
"int c = (index / pooled_width / pooled_height) % channels;\n"
"int n = index / pooled_width / pooled_height / channels;\n"
"int hstart = ph * stride_h - pad_t;\n"
"int wstart = pw * stride_w - pad_l;\n"
"const int hend = min(hstart + kernel_h, height);\n"
"const int wend = min(wstart + kernel_w, width);\n"
"hstart = max(hstart, 0);\n"
"wstart = max(wstart, 0);\n"
"T maxval = -FLT_MAX;\n"
"int maxidx = -1;\n"
"bottom_data =\n"
"bottom_data + (n * channels + c) * height * width;\n"
"for (int h = hstart; h < hend; ++h) {\n"
"for (int w = wstart; w < wend; ++w) {\n"
"if (bottom_data[h * width + w] > maxval) {\n"
"maxidx = h * width + w;\n"
"maxval = bottom_data[maxidx];\n"
"}\n"
"}\n"
"}\n"
"top_data[index] = maxval;\n"
"#ifdef MASK\n"
"mask[index] = maxidx;\n"
"#endif\n"
"}\n"
"}\n"
"__kernel void AvePoolForward(const int nthreads,\n"
"__global T* bottom_data, const int num, const int channels, const int height, const int width,\n"
"const int pooled_height, const int pooled_width, const int kernel_h, const int kernel_w,\n"
"const int stride_h, const int stride_w, const int pad_t, const int pad_l, const int pad_b, const int pad_r,\n"
"__global T* top_data\n"
"#ifdef MASK\n"
", __global float* mask\n"
"#endif\n"
")\n"
"{\n"
"int index = get_global_id(0);\n"
"int tmp = get_global_size(0);\n"
"for(index; index < nthreads; index+=tmp) {\n"
"int pw = index % pooled_width;\n"
"int ph = (index / pooled_width) % pooled_height;\n"
"int c = (index / pooled_width / pooled_height) % channels;\n"
"int n = index / pooled_width / pooled_height / channels; int hstart = ph * stride_h - pad_t; int wstart = pw * stride_w - pad_l;\n"
"int hend = min(hstart + kernel_h, height + pad_b);\n"
"int wend = min(wstart + kernel_w, width + pad_r);\n"
"const int pool_size = (hend - hstart) * (wend - wstart);\n"
"hstart = max(hstart, 0);\n"
"wstart = max(wstart, 0);\n"
"hend = min(hend, height);\n"
"wend = min(wend, width);\n"
"T aveval = 0;\n"
"bottom_data =\n"
"bottom_data + (n * channels + c) * height * width;\n"
"for (int h = hstart; h < hend; ++h) {\n"
"for (int w = wstart; w < wend; ++w) {\n"
"aveval += bottom_data[h * width + w];\n"
"}\n"
"}\n"
"top_data[index] = aveval / pool_size;\n"
"}\n"
"}\n"
, "d2fa86ff9f1a4b51458f3caf054ff85f", NULL};
struct cv::ocl::internal::ProgramEntry prior_box_oclsrc={moduleName, "prior_box",
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void prior_box(const int nthreads,\n"
"const float stepX,\n"
"const float stepY,\n"
"__global const float* _offsetsX,\n"
"__global const float* _offsetsY,\n"
"const int offsetsX_size,\n"
"__global const float* _widths,\n"
"__global const float* _heights,\n"
"const int widths_size,\n"
"__global Dtype* dst,\n"
"const int _layerHeight,\n"
"const int _layerWidth,\n"
"const int imgHeight,\n"
"const int imgWidth)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))\n"
"{\n"
"int w = index % _layerWidth;\n"
"int h = index / _layerWidth;\n"
"__global Dtype* outputPtr;\n"
"outputPtr = dst + index * 4 * offsetsX_size * widths_size;\n"
"float _boxWidth, _boxHeight;\n"
"Dtype4 vec;\n"
"for (int i = 0; i < widths_size; ++i)\n"
"{\n"
"_boxWidth = _widths[i];\n"
"_boxHeight = _heights[i];\n"
"for (int j = 0; j < offsetsX_size; ++j)\n"
"{\n"
"Dtype center_x = (w + _offsetsX[j]) * (Dtype)stepX;\n"
"Dtype center_y = (h + _offsetsY[j]) * (Dtype)stepY;\n"
"vec.x = (center_x - _boxWidth * 0.5f) / imgWidth;\n"
"vec.y = (center_y - _boxHeight * 0.5f) / imgHeight;\n"
"vec.z = (center_x + _boxWidth * 0.5f) / imgWidth;\n"
"vec.w = (center_y + _boxHeight * 0.5f) / imgHeight;\n"
"vstore4(vec, 0, outputPtr);\n"
"outputPtr += 4;\n"
"}\n"
"}\n"
"}\n"
"}\n"
"__kernel void set_variance(const int nthreads,\n"
"const int offset,\n"
"const int variance_size,\n"
"__global const float* variance,\n"
"__global Dtype* dst)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))\n"
"{\n"
"Dtype4 var_vec;\n"
"if (variance_size == 1)\n"
"var_vec = (Dtype4)(variance[0]);\n"
"else\n"
"var_vec = convert_T(vload4(0, variance));\n"
"vstore4(var_vec, 0, dst + offset + index * 4);\n"
"}\n"
"}\n"
"__kernel void clip(const int nthreads,\n"
"__global Dtype* dst)\n"
"{\n"
"for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))\n"
"{\n"
"Dtype4 vec = vload4(index, dst);\n"
"vstore4(clamp(vec, (Dtype)0.0f, (Dtype)1.0f), index, dst);\n"
"}\n"
"}\n"
, "1675591e0cb26d5b10d9a5a7e111007e", NULL};
struct cv::ocl::internal::ProgramEntry region_oclsrc={moduleName, "region",
"#define Dtype float\n"
"__kernel void logistic_activ(const int count,\n"
"__global const Dtype* src,\n"
"const int cell_size,\n"
"__global Dtype* dst)\n"
"{\n"
"for (int i = get_global_id(0); i < count; i += get_global_size(0))\n"
"{\n"
"int index = cell_size * i;\n"
"Dtype x = src[index + 4];\n"
"dst[index + 4] = 1.f / (1.f + exp(-x));\n"
"}\n"
"}\n"
"__kernel void softmax_activ(const int count,\n"
"__global const Dtype* src,\n"
"__global const Dtype* biasData,\n"
"const int cell_size,\n"
"const int classes,\n"
"const int classfix,\n"
"const int rows,\n"
"const int cols,\n"
"const int anchors,\n"
"const float thresh,\n"
"__global Dtype* dst)\n"
"{\n"
"for (int index = get_global_id(0); index < count; index += get_global_size(0))\n"
"{\n"
"int box_index = index * cell_size;\n"
"float largest = -FLT_MAX;\n"
"__global const Dtype *input = src + box_index + 5;\n"
"__global Dtype *output = dst + box_index + 5;\n"
"for (int i = 0; i < classes; ++i)\n"
"largest = fmax(largest, input[i]);\n"
"float sum = 0;\n"
"for (int i = 0; i < classes; ++i)\n"
"{\n"
"float e = exp((input[i] - largest));\n"
"sum += e;\n"
"output[i] = e;\n"
"}\n"
"int y = (index / (anchors * cols)) % rows;\n"
"int x = (index / anchors) % cols;\n"
"int a = index % anchors;\n"
"float scale = dst[box_index + 4];\n"
"if (classfix == -1 && scale < .5) scale = 0;\n"
"float v1 = src[box_index + 0];\n"
"float v2 = src[box_index + 1];\n"
"float l1 = 1.f / (1.f + exp(-v1));\n"
"float l2 = 1.f / (1.f + exp(-v2));\n"
"dst[box_index + 0] = (x + l1) / cols;\n"
"dst[box_index + 1] = (y + l2) / rows;\n"
"dst[box_index + 2] = exp(src[box_index + 2]) * biasData[2 * a] / cols;\n"
"dst[box_index + 3] = exp(src[box_index + 3]) * biasData[2 * a + 1] / rows;\n"
"for (int i = 0; i < classes; ++i)\n"
"{\n"
"float prob = scale * output[i] / sum;\n"
"output[i] = (prob > thresh) ? prob : 0;\n"
"}\n"
"}\n"
"}\n"
, "974d8f1dbe16bfbf98914ab49bd55d11", NULL};
struct cv::ocl::internal::ProgramEntry slice_oclsrc={moduleName, "slice",
"#define CONCAT_(A, B) A##B\n"
"#define CONCAT(A, B) CONCAT_(A, B)\n"
"#define BLOCK_COLS_X4 (BLOCK_COLS / 4)\n"
"#define BLOCK_COLS_X16 (BLOCK_COLS / 16)\n"
"__attribute__((reqd_work_group_size(WSZ, 1, 1)))\n"
"__kernel void\n"
"CONCAT(slice_, SLICE_KERNEL_SUFFIX)(\n"
"__global const uchar* src0,\n"
"__global uchar* dst0\n"
")\n"
"{\n"
"uint block_id = get_global_id(1);\n"
"uint dst_offset0 = block_id * BLOCK_SIZE;\n"
"uint src_offset0 = 0;\n"
"{\n"
"#define CALC_SRC_INDEX(dim) \\\n"
"{ \\\n"
"uint plane_sz = CONCAT(DST_STEP_, dim) / BLOCK_SIZE; \\\n"
"CONCAT(idx_, dim) = block_id / plane_sz; \\\n"
"block_id = block_id - CONCAT(idx_, dim) * plane_sz; \\\n"
"}\n"
"#define UPDATE_SRC_OFFSET(dim) \\\n"
"src_offset0 = mad24((uint)(CONCAT(idx_, dim) + CONCAT(SRC_START_, dim)), (uint)CONCAT(SRC_STEP_, dim), (uint)src_offset0);\n"
"#if DIMS > 5\n"
"#error \"invalid configuration\"\n"
"#endif\n"
"#if DIMS > 4\n"
"uint idx_4 = 0;\n"
"#if BLOCK_DIMS <= 4\n"
"CALC_SRC_INDEX(4)\n"
"#endif\n"
"UPDATE_SRC_OFFSET(4)\n"
"#endif\n"
"#if DIMS > 3\n"
"uint idx_3 = 0;\n"
"#if BLOCK_DIMS <= 3\n"
"CALC_SRC_INDEX(3)\n"
"#endif\n"
"UPDATE_SRC_OFFSET(3)\n"
"#endif\n"
"#if DIMS > 2\n"
"uint idx_2 = 0;\n"
"#if BLOCK_DIMS <= 2\n"
"CALC_SRC_INDEX(2)\n"
"#endif\n"
"UPDATE_SRC_OFFSET(2)\n"
"#endif\n"
"#if DIMS > 1\n"
"uint idx_1 = 0;\n"
"#if BLOCK_DIMS <= 1\n"
"CALC_SRC_INDEX(1)\n"
"#endif\n"
"UPDATE_SRC_OFFSET(1)\n"
"#endif\n"
"#if DIMS > 0\n"
"uint idx_0 = 0;\n"
"UPDATE_SRC_OFFSET(0)\n"
"#endif\n"
"}\n"
"#ifdef USE_COPY_1D\n"
"{\n"
"__global const uchar* src = src0 + src_offset0;\n"
"__global uchar* dst = dst0 + dst_offset0;\n"
"uint processed = 0;\n"
"#if BLOCK_COLS_X16 >= 4\n"
"{\n"
"uint i = get_local_id(0) * 16;\n"
"while (i < BLOCK_COLS_X16 * 16)\n"
"{\n"
"uint4 idx0 = (uint4)i;\n"
"uint4 idx = idx0 + (uint4)(0, 16 * WSZ, 32 * WSZ, 48 * WSZ);\n"
"idx = select(idx0, idx, idx < (BLOCK_COLS_X16 * 16));\n"
"uchar16 a0 = vload16(0, src + idx.s0);\n"
"uchar16 a1 = vload16(0, src + idx.s1);\n"
"uchar16 a2 = vload16(0, src + idx.s2);\n"
"uchar16 a3 = vload16(0, src + idx.s3);\n"
"vstore16(a0, 0, dst + idx.s0);\n"
"vstore16(a1, 0, dst + idx.s1);\n"
"vstore16(a2, 0, dst + idx.s2);\n"
"vstore16(a3, 0, dst + idx.s3);\n"
"i += WSZ * 16 * 4;\n"
"}\n"
"processed = BLOCK_COLS_X16 * 16;\n"
"}\n"
"#else\n"
"#define SKIP_1D_BLOCK_COLS_X16 1\n"
"#endif\n"
"#if BLOCK_COLS_X4 > 0 && (defined(SKIP_1D_BLOCK_COLS_X16) || (BLOCK_COLS_X16 * 16 != BLOCK_COLS_X4 * 4))\n"
"{\n"
"uint i = get_local_id(0) * 4 + processed;\n"
"while (i < BLOCK_COLS_X4 * 4)\n"
"{\n"
"uint4 idx0 = (uint4)i;\n"
"uint4 idx = idx0 + (uint4)(0, 4 * WSZ, 8 * WSZ, 12 * WSZ);\n"
"idx = select(idx0, idx, idx < (BLOCK_COLS_X4 * 4));\n"
"uchar4 a0 = vload4(0, src + idx.s0);\n"
"uchar4 a1 = vload4(0, src + idx.s1);\n"
"uchar4 a2 = vload4(0, src + idx.s2);\n"
"uchar4 a3 = vload4(0, src + idx.s3);\n"
"vstore4(a0, 0, dst + idx.s0);\n"
"vstore4(a1, 0, dst + idx.s1);\n"
"vstore4(a2, 0, dst + idx.s2);\n"
"vstore4(a3, 0, dst + idx.s3);\n"
"i += WSZ * 4 * 4;\n"
"}\n"
"processed = BLOCK_COLS_X4 * 4;\n"
"}\n"
"#else\n"
"#define SKIP_1D_BLOCK_COLS_X4 1\n"
"#endif\n"
"#if (defined(SKIP_1D_BLOCK_COLS_X16) && defined(SKIP_1D_BLOCK_COLS_X4)) || BLOCK_COLS_X4 * 4 != BLOCK_COLS\n"
"{\n"
"uint i = get_local_id(0) + processed;\n"
"while (i < BLOCK_COLS)\n"
"{\n"
"uchar a0 = src[i];\n"
"dst[i] = a0;\n"
"i += WSZ;\n"
"}\n"
"}\n"
"#endif\n"
"}\n"
"#else\n"
"{\n"
"__global const uchar* src = src0 + src_offset0;\n"
"__global uchar* dst = dst0 + dst_offset0;\n"
"uint i = get_local_id(0) * 4;\n"
"#define BLOCK_COLS_FILL_X4 (((BLOCK_COLS + 3) / 4) * 4)\n"
"#define BLOCK_SIZE_FILL_X4 (BLOCK_COLS_FILL_X4 * BLOCK_ROWS)\n"
"while (i < BLOCK_SIZE_FILL_X4)\n"
"{\n"
"int row = i / BLOCK_COLS_FILL_X4;\n"
"int col = i % BLOCK_COLS_FILL_X4;\n"
"uint src_offset = row * BLOCK_SRC_STRIDE + col;\n"
"#if BLOCK_COLS_FILL_X4 == BLOCK_COLS\n"
"uint dst_offset = i;\n"
"#else\n"
"uint dst_offset = row * BLOCK_COLS + col;\n"
"#endif\n"
"#if BLOCK_COLS_FILL_X4 != BLOCK_COLS\n"
"if (col <= BLOCK_COLS - 4)\n"
"#endif\n"
"{\n"
"uchar4 a = vload4(0, src + src_offset);\n"
"vstore4(a, 0, dst + dst_offset);\n"
"}\n"
"#if BLOCK_COLS_FILL_X4 != BLOCK_COLS\n"
"else\n"
"{\n"
"uint4 shift = (uint4)(0, 1, 2, 3);\n"
"shift = select((uint4)0, shift, col + shift < BLOCK_COLS);\n"
"dst[dst_offset + shift.s0] = src[src_offset + shift.s0];\n"
"#if BLOCK_COLS_FILL_X4 - BLOCK_COLS <= 2\n"
"dst[dst_offset + shift.s1] = src[src_offset + shift.s1];\n"
"#endif\n"
"#if BLOCK_COLS_FILL_X4 - BLOCK_COLS <= 1\n"
"dst[dst_offset + shift.s2] = src[src_offset + shift.s2];\n"
"#endif\n"
"}\n"
"#endif\n"
"i += WSZ * 4;\n"
"}\n"
"}\n"
"#endif\n"
"}\n"
, "94dad8ab7b7b1da7fd128d8ba047b152", NULL};
struct cv::ocl::internal::ProgramEntry softmax_oclsrc={moduleName, "softmax",
"/*************************************************************************************\n"
"* Copyright (c) 2015, Advanced Micro Devices, Inc.\n"
"* All rights reserved.\n"
"*\n"
"* Redistribution and use in source and binary forms, with or without modification,\n"
"* are permitted provided that the following conditions are met:\n"
"*\n"
"* 1. Redistributions of source code must retain the above copyright notice, this\n"
"* list of conditions and the following disclaimer.\n"
"*\n"
"* 2. Redistributions in binary form must reproduce the above copyright notice,\n"
"* this list of conditions and the following disclaimer in the documentation and/or\n"
"* other materials provided with the distribution.\n"
"*\n"
"* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n"
"* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
"* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n"
"* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
"* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n"
"* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n"
"* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n"
"* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n"
"* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
"* POSSIBILITY OF SUCH DAMAGE.\n"
"**************************************************************************************/\n"
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void kernel_channel_max(const int num, const int channels,\n"
"const int spatial_dim, __global const T* data, __global T* out) {\n"
"int index = get_global_id(0);\n"
"if(index < num * spatial_dim) {\n"
"int n = index / spatial_dim;\n"
"int s = index % spatial_dim;\n"
"T maxval = -FLT_MAX;\n"
"for (int c = 0; c < channels; ++c) {\n"
"maxval = max(data[(n * channels + c) * spatial_dim + s], maxval);\n"
"}\n"
"out[index] = maxval;\n"
"}\n"
"}\n"
"__kernel void kernel_channel_subtract(const int count,\n"
"const int num, const int channels,\n"
"const int spatial_dim, __global const T* channel_max, __global const T* src, __global T* data) {\n"
"int index = get_global_id(0);\n"
"if(index < count) {\n"
"int n = index / channels / spatial_dim;\n"
"int s = index % spatial_dim;\n"
"data[index] = exp(src[index] - channel_max[n * spatial_dim + s]);\n"
"}\n"
"}\n"
"__kernel void kernel_channel_sum(const int num, const int channels,\n"
"const int spatial_dim, __global const T* data, __global T* channel_sum) {\n"
"int index = get_global_id(0);\n"
"if(index < num * spatial_dim) {\n"
"int n = index / spatial_dim;\n"
"int s = index % spatial_dim;\n"
"T sum = 0;\n"
"for (int c = 0; c < channels; ++c) {\n"
"sum += data[(n * channels + c) * spatial_dim + s];\n"
"}\n"
"channel_sum[index] = sum;\n"
"}\n"
"}\n"
"__kernel void kernel_channel_div(const int count,\n"
"const int num, const int channels,\n"
"const int spatial_dim, __global const T* channel_sum, __global T* data) {\n"
"int index = get_global_id(0);\n"
"if(index < count) {\n"
"int n = index / channels / spatial_dim;\n"
"int s = index % spatial_dim;\n"
"T v = data[index] / channel_sum[n * spatial_dim + s];\n"
"#ifdef LOG_SOFTMAX\n"
"v = log(v);\n"
"#endif\n"
"data[index] = v;\n"
"}\n"
"}\n"
, "db5bfbbe4215a169392800a28b6834c4", NULL};
struct cv::ocl::internal::ProgramEntry softmax_loss_oclsrc={moduleName, "softmax_loss",
"#define CONCAT(A,B) A##_##B\n"
"#define TEMPLATE(name,type) CONCAT(name,type)\n"
"#if defined(cl_intel_subgroups)\n"
"#pragma OPENCL EXTENSION cl_intel_subgroups : enable\n"
"#endif\n"
"#if defined(cl_khr_fp16)\n"
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"#endif\n"
"__kernel void TEMPLATE(softmax_forward_slm,Dtype)(const int num, const int channels,\n"
"const int spatial_dim,\n"
"__global Dtype* scale,\n"
"__global const Dtype* data,\n"
"__global Dtype* out,\n"
"__local Dtype *out_tmp,\n"
"__local Dtype *scale_tmp,\n"
"__local Dtype *group_tmp) {\n"
"int n = get_global_id(1);\n"
"for (int index = get_global_id(0), s = 0; index < spatial_dim * get_local_size(0); index +=\n"
"get_global_size(0), ++s) {\n"
"Dtype maxval = -DTYPE_MAX;\n"
"for (int c = get_global_id(0); c < channels; c += get_global_size(0)) {\n"
"Dtype tmp = data[(n * channels + c) * spatial_dim + s];\n"
"maxval = max((Dtype)tmp, (Dtype)maxval);\n"
"}\n"
"maxval = sub_group_reduce_max(maxval);\n"
"group_tmp[get_sub_group_id() * spatial_dim + s] = maxval;\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < spatial_dim * get_max_sub_group_size(); index +=\n"
"get_global_size(0)) {\n"
"int s = index / get_max_sub_group_size();\n"
"Dtype maxval = sub_group_reduce_max(group_tmp[get_sub_group_local_id() * spatial_dim + s]);\n"
"scale_tmp[s] = maxval;\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < channels * spatial_dim;\n"
"index += get_global_size(0)) {\n"
"int s = index % spatial_dim;\n"
"out_tmp[index] = exp(data[n * channels * spatial_dim + index] - scale_tmp[s]);\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"for (int index = get_global_id(0), s = 0; index < spatial_dim * get_local_size(0); index +=\n"
"get_global_size(0), ++s) {\n"
"Dtype sum = 0;\n"
"for (int c = get_global_id(0); c < channels; c += get_global_size(0)) {\n"
"sum += out_tmp[c * spatial_dim + s];\n"
"}\n"
"sum = sub_group_reduce_add(sum);\n"
"group_tmp[get_sub_group_id() * spatial_dim + s] = sum;\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < spatial_dim * get_max_sub_group_size(); index +=\n"
"get_global_size(0)) {\n"
"int s = index / get_max_sub_group_size();\n"
"Dtype sum = sub_group_reduce_add(group_tmp[get_sub_group_local_id() * spatial_dim + s]);\n"
"scale_tmp[s] = sum;\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < channels * spatial_dim;\n"
"index += get_global_size(0)) {\n"
"int s = index % spatial_dim;\n"
"Dtype v = out_tmp[index] / scale_tmp[s];\n"
"#ifdef LOG_SOFTMAX\n"
"v = log(v);\n"
"#endif\n"
"out[n * channels * spatial_dim + index] = v;\n"
"}\n"
"}\n"
"__kernel void TEMPLATE(softmax_forward,Dtype)(const int num, const int channels,\n"
"const int spatial_dim,\n"
"__global Dtype* scale,\n"
"__global const Dtype* data,\n"
"__global Dtype* out) {\n"
"int n = get_global_id(1);\n"
"__global Dtype *group_tmp = scale + spatial_dim * num + n * get_max_sub_group_size() * spatial_dim;\n"
"for (int index = get_global_id(0), s = 0; index < spatial_dim * get_local_size(0); index +=\n"
"get_global_size(0), ++s) {\n"
"Dtype maxval = -DTYPE_MAX;\n"
"for (int c = get_global_id(0); c < channels; c += get_global_size(0)) {\n"
"Dtype tmp = data[(n * channels + c) * spatial_dim + s];\n"
"maxval = max((Dtype)tmp, (Dtype)maxval);\n"
"}\n"
"maxval = sub_group_reduce_max(maxval);\n"
"group_tmp[get_sub_group_id() * spatial_dim + s] = maxval;\n"
"}\n"
"barrier(CLK_GLOBAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < spatial_dim * get_max_sub_group_size(); index +=\n"
"get_global_size(0)) {\n"
"int s = index / get_max_sub_group_size();\n"
"Dtype maxval = sub_group_reduce_max(group_tmp[get_sub_group_local_id() * spatial_dim + s]);\n"
"scale[n * spatial_dim + s] = maxval;\n"
"}\n"
"barrier(CLK_GLOBAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < channels * spatial_dim;\n"
"index += get_global_size(0)) {\n"
"int s = index % spatial_dim;\n"
"out[n * channels * spatial_dim + index] = exp(data[n * channels * spatial_dim + index] - scale[n * spatial_dim + s]);\n"
"}\n"
"barrier(CLK_GLOBAL_MEM_FENCE);\n"
"for (int index = get_global_id(0), s = 0; index < spatial_dim * get_local_size(0); index +=\n"
"get_global_size(0), ++s) {\n"
"Dtype sum = 0;\n"
"for (int c = get_global_id(0); c < channels; c += get_global_size(0)) {\n"
"sum += out[n * channels * spatial_dim + c * spatial_dim + s];\n"
"}\n"
"sum = sub_group_reduce_add(sum);\n"
"group_tmp[get_sub_group_id() * spatial_dim + s] = sum;\n"
"}\n"
"barrier(CLK_GLOBAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < spatial_dim * get_max_sub_group_size(); index +=\n"
"get_global_size(0)) {\n"
"int s = index / get_max_sub_group_size();\n"
"Dtype sum = sub_group_reduce_add(group_tmp[get_sub_group_local_id() * spatial_dim + s]);\n"
"scale[n * spatial_dim + s] = sum;\n"
"}\n"
"barrier(CLK_GLOBAL_MEM_FENCE);\n"
"for (int index = get_global_id(0); index < channels * spatial_dim;\n"
"index += get_global_size(0)) {\n"
"int s = index % spatial_dim;\n"
"Dtype v = out[n * channels * spatial_dim + index] / scale[n * spatial_dim + s];\n"
"#ifdef LOG_SOFTMAX\n"
"v = log(v);\n"
"#endif\n"
"out[n * channels * spatial_dim + index] = v;\n"
"}\n"
"}\n"
, "9b1ebb425bf1e67c1294d8bf60783216", NULL};
}}}
#endif