forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpolate.cpp
More file actions
4552 lines (4103 loc) · 198 KB
/
interpolate.cpp
File metadata and controls
4552 lines (4103 loc) · 198 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
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "interpolate.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <common/primitive_attr.hpp>
#include <common/primitive_hashing_utils.hpp>
#include <common/utils.hpp>
#include <cpu/x64/cpu_isa_traits.hpp>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <numeric>
#include <oneapi/dnnl/dnnl.hpp>
#include <oneapi/dnnl/dnnl_common.hpp>
#include <string>
#include <utility>
#include <vector>
#include "common/cpu_memcpy.h"
#include "cpu_types.h"
#include "dnnl_extension_utils.h"
#include "eltwise.h"
#include "fake_quantize.h"
#include "graph_context.h"
#include "memory_desc/cpu_memory_desc.h"
#include "node.h"
#include "nodes/common/blocked_desc_creator.h"
#include "nodes/executors/executor.hpp"
#include "nodes/executors/interpolate.hpp"
#include "nodes/executors/interpolate_list.hpp"
#include "nodes/node_config.h"
#include "onednn/iml_type_mapper.h"
#include "openvino/core/enum_names.hpp"
#include "openvino/core/except.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/parallel.hpp"
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/interpolate.hpp"
#include "shape_inference/shape_inference.hpp"
#include "shape_inference/shape_inference_cpu.hpp"
#include "utils/bfloat16.hpp"
#include "utils/general_utils.h"
#include "utils/ngraph_utils.hpp"
#include "utils/precision_support.h"
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
# include <xbyak/xbyak.h>
# include <common/c_types_map.hpp>
# include <unordered_map>
# include "cpu/x64/injectors/jit_uni_depthwise_injector.hpp"
# include "cpu/x64/injectors/jit_uni_eltwise_injector.hpp"
# include "cpu/x64/injectors/jit_uni_quantization_injector.hpp"
# include "cpu/x64/jit_generator.hpp"
# include "emitters/plugin/x64/jit_emitter.hpp"
# include "emitters/plugin/x64/jit_load_store_emitters.hpp"
# include "utils/cpu_utils.hpp"
#endif
using namespace dnnl;
using namespace dnnl::impl;
using namespace dnnl::impl::cpu;
using namespace dnnl::impl::cpu::x64;
using namespace dnnl::impl::utils;
using namespace Xbyak;
#define GET_OFF(field) offsetof(jit_interpolate_call_args, field)
namespace ov::intel_cpu::node {
static inline bool isFloatCompatible(ov::element::Type prc) {
return any_of(prc, ov::element::f32, ov::element::bf16, ov::element::f16, ov::element::f64);
}
#if defined(OPENVINO_ARCH_X86_64)
template <cpu_isa_t isa>
struct jit_uni_interpolate_kernel_f32 : public jit_uni_interpolate_kernel, public jit_generator_t {
DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_interpolate_kernel_f32)
explicit jit_uni_interpolate_kernel_f32(jit_interpolate_config_params jcp, const dnnl_primitive_attr& attr)
: jit_uni_interpolate_kernel(jcp, attr),
jit_generator_t(jit_name()) {}
void create_ker() override {
jit_generator_t::create_kernel();
ker_ = jit_kernel_cast<decltype(ker_)>(jit_ker());
}
void generate() override {
// dummy second reg_tmp_64 as no fill needed
load_pool_gpr_idxs = {static_cast<size_t>(reg_tmp_64.getIdx()), static_cast<size_t>(reg_tmp_64.getIdx())};
store_pool_gpr_idxs = {static_cast<size_t>(reg_tmp_64.getIdx())};
store_pool_vec_idxs = {static_cast<size_t>(vmm_zero.getIdx())};
const auto& p = attr_.post_ops_;
for (int i = 0; i < p.len(); i++) {
auto& post_op = p.entry_[i];
if (post_op.is_eltwise()) {
eltwise_injectors.push_back(std::make_shared<jit_uni_eltwise_injector_t<isa>>(this,
post_op.eltwise.alg,
post_op.eltwise.alpha,
post_op.eltwise.beta,
1.F,
data_type::f32));
} else if (post_op.is_depthwise()) {
depthwise_injectors.push_back(std::make_shared<jit_uni_depthwise_injector_f32<isa>>(this, post_op));
} else if (post_op.is_quantization()) {
quantization_injectors.push_back(std::make_shared<jit_uni_quantization_injector_f32<isa>>(this,
post_op,
vmm_d_weights,
vmm_d_bias,
reg_d_weights,
reg_d_bias));
}
}
this->preamble();
if (attr_.post_ops_.len() != 0) {
mov(reg_post_ops_data, ptr[reg_params + GET_OFF(post_op_data)]);
mov(reg_oc_off, ptr[reg_params + GET_OFF(oc_off)]);
}
uni_vpxor(vmm_zero, vmm_zero, vmm_zero);
switch (jcp_.mode) {
case InterpolateMode::nearest: {
mov(reg_dst, ptr[reg_params + GET_OFF(dst)]);
mov(reg_src, ptr[reg_params + GET_OFF(src_ptr[0])]);
mov(reg_index, ptr[reg_params + GET_OFF(index)]);
mov(reg_work_amount, ptr[reg_params + GET_OFF(work_amount)]);
switch (jcp_.layout) {
case InterpolateLayoutType::planar: {
nn_planar();
break;
}
case InterpolateLayoutType::block: {
nn_blk();
break;
}
case InterpolateLayoutType::by_channel: {
nn_by_channel();
break;
}
default:
assert(!"unsupported memory layout for interpolate layer with nearest neighbor mode.");
}
break;
}
case InterpolateMode::linear_onnx: {
switch (jcp_.layout) {
case InterpolateLayoutType::planar: {
linear_onnx_planar();
break;
}
case InterpolateLayoutType::block:
case InterpolateLayoutType::by_channel: {
linear_onnx_c_gathered();
break;
}
default:
assert(!"unsupported memory layout for interpolate layer with linear_onnx mode.");
}
break;
}
case InterpolateMode::cubic: {
switch (jcp_.layout) {
case InterpolateLayoutType::planar: {
cubic_planar();
break;
}
case InterpolateLayoutType::block:
case InterpolateLayoutType::by_channel: {
cubic_c_gathered();
break;
}
default:
assert(!"unsupported memory layout for interpolate layer with cubic mode.");
}
break;
}
case InterpolateMode::bilinear_pillow:
case InterpolateMode::bicubic_pillow: {
switch (jcp_.layout) {
case InterpolateLayoutType::by_channel: {
pillow_by_channel();
break;
}
default:
assert(
!"unsupported memory layout for interpolate layer with bilinear_pillow and bicubic_pillow modes.");
}
break;
}
case InterpolateMode::linear: {
assert(!"unsupported mode for interpolate layer with JITTED implimentation.");
break;
}
default: {
assert(!"unsupported mode for interpolate layer.");
}
}
this->postamble();
emit_emitters_data();
for (auto& inj : eltwise_injectors) {
inj->prepare_table();
}
if ((jcp_.mode == InterpolateMode::cubic) && (jcp_.layout == InterpolateLayoutType::planar)) {
prepare_cubic_planar_table();
}
}
private:
using Vmm =
typename conditional3<isa == cpu::x64::sse41, Xbyak::Xmm, isa == cpu::x64::avx2, Xbyak::Ymm, Xbyak::Zmm>::type;
const int vlen = cpu_isa_traits_t<isa>::vlen;
const int vector_step = vlen / sizeof(float);
const int tail_step = jcp_.C % vector_step;
const int scalar_step = 1;
Xbyak::Reg64 reg_src = r8;
Xbyak::Reg64 reg_src_aux = r15;
Xbyak::Reg64 reg_src_aux1 = r11;
Xbyak::Reg64 reg_src_aux2 = r12;
Xbyak::Reg64 reg_dst = r9;
Xbyak::Reg64 reg_work_amount = r13;
Xbyak::Reg64 reg_index = r14;
Xbyak::Reg64 reg_params = abi_param1;
Reg8 reg_tmp_8 = r10b;
Reg32 reg_tmp_32 = r10d;
Reg64 reg_tmp_64 = r10;
Xbyak::Reg64 reg_oc_off = rax;
Xbyak::Reg64 reg_post_ops_data = rbx;
Xbyak::Reg64 reg_d_weights = reg_tmp_64;
Xbyak::Reg64 reg_d_bias = rcx;
Xbyak::Reg32 reg_index_offset = edx;
// for cubic planar
Xbyak::Reg64 reg_tbl_y = rsi;
Xbyak::Reg64 reg_tbl_x = rbp;
Xbyak::Reg64 reg_table = rdx; // do not need reg_index_offset in this mode, so use rdx
Vmm vmm_val = Vmm(1);
Vmm vmm_index = Vmm(0);
Vmm vmm_zero = Vmm(2);
Vmm vmm_mask = Vmm(3);
Vmm vmm_d_weights = Vmm(4);
Vmm vmm_d_bias = Vmm(5);
// for linear
Vmm vmm_weightT = Vmm(15);
Vmm vmm_weightB = Vmm(14);
Vmm vmm_weightL = Vmm(13);
Vmm vmm_weightR = Vmm(12);
Vmm vmm_weightF = Vmm(6);
Vmm vmm_weightE = Vmm(7);
Vmm vmm_valTL = Vmm(11);
Vmm vmm_valTR = vmm_val;
Vmm vmm_valBL = Vmm(9);
Vmm vmm_valBR = Vmm(8);
// for cubic
Vmm vmm_src = Vmm(6);
Xmm xmm_src = Xmm(6);
Vmm vmm_dstX = Vmm(7);
Vmm vmm_weightX0 = vmm_weightT;
Vmm vmm_weightX1 = vmm_weightB;
Vmm vmm_weightX2 = vmm_weightL;
Vmm vmm_weightX3 = vmm_weightR;
Vmm vmm_weightY0 = vmm_valTL;
Vmm vmm_weightY1 = Vmm(10); // vmm_valTR is vmm_val, need reserved
Vmm vmm_weightY2 = vmm_valBL;
Vmm vmm_weightY3 = vmm_valBR;
// cubic planar
Vmm vmm_one = vmm_index;
Vmm vmm_weightY = vmm_weightY0;
Vmm vmm_index_y_itr = vmm_weightY1;
Vmm vmm_index_x_itr = vmm_weightY2;
Vmm vmm_tbl_y = vmm_weightY3;
// temporally used. when post ops, value in vmm_d_weights and vmm_d_bias is re-loaded(init) each time.
Vmm vmm_index_in_y = vmm_d_weights;
Vmm vmm_index_in_x = vmm_d_bias;
// pillow
Vmm vmm_weight = Vmm(15);
Vmm vmm_dst = Vmm(14);
Xbyak::Label l_table_constant;
Opmask k_mask = Xbyak::Opmask(1);
std::unordered_map<size_t, std::unique_ptr<jit_emitter>> emitters;
std::vector<size_t> store_pool_gpr_idxs;
std::vector<size_t> store_pool_vec_idxs;
std::vector<size_t> load_pool_gpr_idxs;
std::vector<std::shared_ptr<jit_uni_eltwise_injector_t<isa>>> eltwise_injectors;
std::vector<std::shared_ptr<jit_uni_depthwise_injector_f32<isa>>> depthwise_injectors;
std::vector<std::shared_ptr<jit_uni_quantization_injector_f32<isa>>> quantization_injectors;
void emit_emitters_data() {
for (const auto& emitter : emitters) {
if (emitter.second) {
emitter.second->emit_data();
}
}
}
void load(Xbyak::Reg64 reg_src, Vmm vmm_src, const int elt_num, const int offset = 0) {
emit_load(reg_src, vmm_src, jcp_.src_prc, ov::element::f32, elt_num, offset);
}
void load_weights(Xbyak::Reg64 reg_src, Vmm vmm_src, const int elt_num, const int offset = 0) {
emit_load(reg_src, vmm_src, ov::element::f32, ov::element::f32, elt_num, offset);
}
void emit_load(Xbyak::Reg64 reg_src,
Vmm vmm_src,
ov::element::Type src_prc,
ov::element::Type dst_prc,
const int elt_num,
const int offset = 0) {
const auto seed = load_emitter_params(src_prc, dst_prc, elt_num).hash();
if (!emitters[seed]) {
emitters[seed] = std::make_unique<jit_load_emitter>(this, isa, src_prc, dst_prc, elt_num);
}
emitters[seed]->emit_code({static_cast<size_t>(reg_src.getIdx()), static_cast<size_t>(offset)},
{static_cast<size_t>(vmm_src.getIdx())},
{},
{load_pool_gpr_idxs});
}
void store(Vmm vmm_dst, Xbyak::Reg64 reg_dst, const int elt_num, const int offset = 0) {
const auto seed = store_emitter_params(ov::element::f32, jcp_.dst_prc, elt_num).hash();
if (!emitters[seed]) {
emitters[seed] = std::make_unique<jit_store_emitter>(this, isa, ov::element::f32, jcp_.dst_prc, elt_num);
}
// for cases when Store emitter need 2 aux vmm we can use vmm_dst as second aux vmm
std::vector<size_t> local_store_pool_vec_idxs = {static_cast<size_t>(vmm_dst.getIdx())};
local_store_pool_vec_idxs.insert(local_store_pool_vec_idxs.begin(),
store_pool_vec_idxs.begin(),
store_pool_vec_idxs.end());
emitters[seed]->emit_code({static_cast<size_t>(vmm_dst.getIdx())},
{static_cast<size_t>(reg_dst.getIdx()), static_cast<size_t>(offset)},
{local_store_pool_vec_idxs},
{store_pool_gpr_idxs});
}
// kernel for OH * OW * C
void pillow_by_channel() {
Xbyak::Reg64 reg_src = r8;
Xbyak::Reg64 reg_src_aux = r9;
Xbyak::Reg64 reg_src_aux1 = rbp;
Xbyak::Reg64 reg_weights = r11;
Xbyak::Reg64 reg_weights_bk = rdx;
Xbyak::Reg64 reg_dst = r12;
Xbyak::Reg64 reg_dst_xpass = r13;
Xbyak::Reg64 reg_src_ypass = r14;
Xbyak::Reg64 reg_dst_aux = r15;
auto reg_params = abi_param1;
mov(reg_src, ptr[reg_params + GET_OFF(src_ptr[0])]);
mov(reg_dst, ptr[reg_params + GET_OFF(dst)]);
mov(reg_weights, ptr[reg_params + GET_OFF(weight_ptr[0])]);
mov(reg_weights_bk, reg_weights);
bool xPass = (jcp_.IW != jcp_.OW);
bool yPass = (jcp_.IH != jcp_.OH);
if (xPass && yPass) {
mov(reg_dst_xpass, ptr[reg_params + GET_OFF(src_ptr[0]) + sizeof(size_t)]);
mov(reg_src_ypass, reg_dst_xpass);
} else if (xPass && !yPass) {
mov(reg_dst_xpass, reg_dst);
} else if (!xPass && yPass) {
mov(reg_src_ypass, reg_src);
} else if (!xPass && !yPass) {
for (int blk = 0; blk < (jcp_.OH * jcp_.OW * jcp_.C) / vector_step; blk++) {
load(reg_src, vmm_val, vector_step);
add(reg_src, vector_step * jcp_.src_data_size);
store(vmm_val, reg_dst, vector_step);
add(reg_dst, vector_step * jcp_.dst_data_size);
}
int tail_num = (jcp_.OH * jcp_.OW * jcp_.C) % vector_step;
if (tail_num) {
load(reg_src, vmm_val, tail_num);
store(vmm_val, reg_dst, tail_num);
}
}
// / / / /
// -------- ----
// | | | | ..... -> .
// | |--> | |
// | | | | .
// | | | | .
// -------- ---- .
// \|/
// \|/
// / /
// ----
// | |
// | | .
// ----
int f = 0;
int filterS = 0;
int filterL = 0;
int tail_num = jcp_.C % vector_step;
// xpass
if (xPass) {
mov(reg_dst_aux, reg_dst_xpass);
for (size_t ih = 0; ih < static_cast<size_t>(jcp_.IH); ih++) {
// reg_dst_xpass: point to start of this dst height
// reset reg_dst_aux to start of this height
mov(reg_weights, reg_weights_bk);
for (size_t ow = 0; ow < static_cast<size_t>(jcp_.OW); ow++) {
// reg_src: point to start of this src height src
// reset reg_src_aux to reg_src
mov(reg_src_aux, reg_src);
filterS = jcp_.bound[ow * 2];
filterL = jcp_.bound[ow * 2 + 1];
for (int blk = 0; blk < jcp_.C / vector_step; blk++) {
uni_vpxor(vmm_dst, vmm_dst, vmm_dst);
for (f = 0; f < filterL; f++) {
mov(reg_src_aux1, reg_src_aux);
add(reg_src_aux1, (f + filterS) * jcp_.C * jcp_.src_data_size);
load(reg_src_aux1, vmm_val, vector_step);
uni_vbroadcastss(vmm_weight, ptr[reg_weights + f * sizeof(float)]);
uni_vfmadd231ps(vmm_dst, vmm_val, vmm_weight);
}
// if int, round
if (!isFloatCompatible(jcp_.src_prc)) {
uni_vroundps(vmm_dst, vmm_dst, 0x0); // Round near
}
// src_prc, dst_prc and buf ov::element::Type is the same, otherwise need another store with
// buf(src) precision
store(vmm_dst, reg_dst_aux, vector_step);
add(reg_dst_aux, vector_step * jcp_.src_data_size);
// advance 8/16 faciliate next block
add(reg_src_aux, vector_step * jcp_.src_data_size);
}
if (tail_num) {
uni_vpxor(vmm_dst, vmm_dst, vmm_dst);
for (f = 0; f < filterL; f++) {
mov(reg_src_aux1, reg_src_aux);
add(reg_src_aux1, (f + filterS) * jcp_.C * jcp_.src_data_size);
load(reg_src_aux1, vmm_val, tail_num);
uni_vbroadcastss(vmm_weight, ptr[reg_weights + f * sizeof(float)]);
uni_vfmadd231ps(vmm_dst, vmm_val, vmm_weight);
}
if (!isFloatCompatible(jcp_.src_prc)) {
uni_vroundps(vmm_dst, vmm_dst, 0x0); // Round near
}
store(vmm_dst, reg_dst_aux, tail_num);
add(reg_dst_aux, tail_num * jcp_.src_data_size);
add(reg_src_aux, tail_num * jcp_.src_data_size); // remove
}
add(reg_weights, jcp_.filterLenX * sizeof(float));
}
// reg_src: point to start of this height
add(reg_src, jcp_.IW * jcp_.C * jcp_.src_data_size);
}
}
if (yPass) {
add(reg_weights_bk, jcp_.OW * jcp_.filterLenX * sizeof(float));
mov(reg_weights, reg_weights_bk);
size_t bound_offset_y = jcp_.OW * 2;
for (size_t oh = 0; oh < static_cast<size_t>(jcp_.OH); oh++) {
filterS = jcp_.bound[bound_offset_y + oh * 2];
filterL = jcp_.bound[bound_offset_y + oh * 2 + 1];
for (size_t ow = 0; ow < static_cast<size_t>(jcp_.OW); ow++) {
mov(reg_src_aux, reg_src_ypass); // reg_src_aux to advance block
for (int blk = 0; blk < jcp_.C / vector_step; blk++) {
uni_vpxor(vmm_dst, vmm_dst, vmm_dst);
for (f = 0; f < filterL; f++) {
// shared weight
uni_vbroadcastss(vmm_weight, ptr[reg_weights + f * sizeof(float)]);
mov(reg_src_aux1, reg_src_aux);
add(reg_src_aux1, ((f + filterS) * jcp_.OW + ow) * jcp_.C * jcp_.src_data_size);
load(reg_src_aux1, vmm_val, vector_step);
uni_vfmadd231ps(vmm_dst, vmm_val, vmm_weight);
}
if (!isFloatCompatible(jcp_.src_prc)) {
uni_vroundps(vmm_dst, vmm_dst, 0x0); // Round near
}
store(vmm_dst, reg_dst, vector_step);
add(reg_dst, vector_step * jcp_.dst_data_size);
add(reg_src_aux, vector_step * jcp_.src_data_size);
}
if (tail_num) {
uni_vpxor(vmm_dst, vmm_dst, vmm_dst);
for (f = 0; f < filterL; f++) {
uni_vbroadcastss(vmm_weight, ptr[reg_weights + f * sizeof(float)]);
mov(reg_src_aux1, reg_src_aux);
add(reg_src_aux1, ((f + filterS) * jcp_.OW + ow) * jcp_.C * jcp_.src_data_size);
load(reg_src_aux1, vmm_val, tail_num);
uni_vfmadd231ps(vmm_dst, vmm_val, vmm_weight);
}
if (!isFloatCompatible(jcp_.src_prc)) {
uni_vroundps(vmm_dst, vmm_dst, 0x0); // Round near
}
store(vmm_dst, reg_dst, tail_num);
add(reg_dst, tail_num * jcp_.dst_data_size);
add(reg_src_aux, tail_num * jcp_.src_data_size);
}
}
add(reg_weights, jcp_.filterLenY * sizeof(float));
}
}
}
void nn_planar() {
Xbyak::Reg64 reg_index_h = reg_src_aux1;
Xbyak::Reg64 reg_index_w = reg_src_aux2;
mov(reg_index_h, reg_index);
// reg_index represent reg_index_w
add(reg_index, jcp_.OH * jcp_.indices_size);
// bk for reset to reg_index_w
mov(reg_index_w, reg_index);
Xbyak::Label out_loop_label;
Xbyak::Label out_loop_end;
Xbyak::Reg64 reg_work_amount_oh = rdi;
mov(reg_work_amount_oh, jcp_.OH);
L(out_loop_label);
{
// outloop status
cmp(reg_work_amount_oh, 1);
jl(out_loop_end, T_NEAR);
// reset work_amount to OW
mov(reg_work_amount, jcp_.OW);
Xbyak::Reg64 reg_src_h = rsi;
mov(reg_src_h, reg_src);
// index_h * IW * dataSize done when built to avoid redundent compute
mov(reg_index_offset, dword[reg_index_h]);
add(reg_src_h, Xbyak::Reg64(reg_index_offset.getIdx())); // reg_src_h now point to begin of row
// reset index_w, index_w * dataSize done when built to avoid redundent compute
mov(reg_index, reg_index_w);
Xbyak::Label nn_loop_label;
Xbyak::Label nn_loop_end_label;
Xbyak::Label nn_tail_loop_label;
Xbyak::Label nn_tail_loop_end_label;
L(nn_loop_label); // inner loop
{
cmp(reg_work_amount, vector_step);
jl(nn_loop_end_label, T_NEAR);
uni_vmovdqu(vmm_index, ptr[reg_index]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_val, ptr[reg_src_h + vmm_index], vmm_mask);
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, 1);
}
store(vmm_val, reg_dst, vector_step);
add(reg_dst, vector_step * jcp_.dst_data_size);
add(reg_index, vector_step * jcp_.indices_size);
sub(reg_work_amount, vector_step);
jmp(nn_loop_label, T_NEAR);
}
L(nn_loop_end_label);
L(nn_tail_loop_label);
{
cmp(reg_work_amount, 1);
jl(nn_tail_loop_end_label, T_NEAR);
mov(reg_src_aux, reg_src_h);
mov(reg_index_offset, dword[reg_index]);
add(reg_src_aux, Xbyak::Reg64(reg_index_offset.getIdx()));
load(reg_src_aux, vmm_val, scalar_step);
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, 1);
}
store(vmm_val, reg_dst, scalar_step);
add(reg_dst, scalar_step * jcp_.dst_data_size);
add(reg_index, scalar_step * jcp_.indices_size);
sub(reg_work_amount, scalar_step);
jmp(nn_tail_loop_label, T_NEAR);
}
L(nn_tail_loop_end_label); // inner loop end
// increment index_h to next row
add(reg_index_h, jcp_.indices_size);
sub(reg_work_amount_oh, 1);
jmp(out_loop_label, T_NEAR);
}
L(out_loop_end);
}
void nn_blk() {
Xbyak::Label nn_loop_label;
Xbyak::Label nn_loop_end_label;
L(nn_loop_label);
{
cmp(reg_work_amount, 0);
jle(nn_loop_end_label, T_NEAR);
mov(reg_src_aux, reg_src);
mov(reg_index_offset, dword[reg_index]);
add(reg_src_aux, Xbyak::Reg64(reg_index_offset.getIdx()));
load(reg_src_aux, vmm_val, vector_step);
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, 0);
}
store(vmm_val, reg_dst, vector_step);
add(reg_dst, vector_step * jcp_.dst_data_size);
if (isa == cpu::x64::sse41) {
add(reg_src_aux, vector_step * jcp_.src_data_size);
load(reg_src_aux, vmm_val, vector_step);
if (attr_.post_ops_.len() != 0) {
add(reg_oc_off, vector_step * sizeof(float));
apply_post_ops(jcp_.dst_prc, 0);
sub(reg_oc_off, vector_step * sizeof(float));
}
store(vmm_val, reg_dst, vector_step);
add(reg_dst, vector_step * jcp_.dst_data_size);
}
add(reg_index, jcp_.indices_size);
sub(reg_work_amount, 1);
jmp(nn_loop_label, T_NEAR);
}
L(nn_loop_end_label);
}
void nn_by_channel() {
// kernel for C * OW
Xbyak::Label out_loop_label;
Xbyak::Label out_loop_end;
Xbyak::Reg64 reg_work_amount_bk = reg_src_aux2;
Xbyak::Reg64 reg_oc_off_bk = rsi;
mov(reg_work_amount_bk, ptr[reg_params + GET_OFF(work_amount)]);
if (attr_.post_ops_.len() != 0) {
mov(reg_oc_off_bk, ptr[reg_params + GET_OFF(oc_off)]);
}
Xbyak::Reg64 reg_work_amount_out = reg_src_aux1;
mov(reg_work_amount_out, jcp_.OW);
L(out_loop_label);
{
cmp(reg_work_amount_out, 1);
jl(out_loop_end, T_NEAR);
// inner loop for C
Xbyak::Label nn_loop_label;
Xbyak::Label nn_loop_end_label;
Xbyak::Label nn_tail_loop_label;
Xbyak::Label nn_tail_loop_end_label;
// inner loop for C
// get current loop address reg_src_aux, from reg_src which is unchange, point this C * OW.
// reset offset and work_amount.
// dst and index address is continous, advanced each interator.
mov(reg_src_aux, reg_src);
// index*C*dataSize done when built to avoid redundent compute
mov(reg_index_offset, dword[reg_index]);
// opRR need same bit length input
add(reg_src_aux, Xbyak::Reg64(reg_index_offset.getIdx()));
mov(reg_work_amount, reg_work_amount_bk);
if (attr_.post_ops_.len() != 0) {
mov(reg_oc_off, reg_oc_off_bk);
}
L(nn_loop_label);
{
cmp(reg_work_amount, vector_step);
jl(nn_loop_end_label, T_NEAR);
load(reg_src_aux, vmm_val, vector_step);
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, 0);
}
store(vmm_val, reg_dst, vector_step);
add(reg_dst, vector_step * jcp_.dst_data_size);
add(reg_src_aux, vector_step * jcp_.src_data_size);
add(reg_oc_off, vector_step * sizeof(float));
sub(reg_work_amount, vector_step);
jmp(nn_loop_label, T_NEAR);
}
L(nn_loop_end_label);
if (tail_step != 0) {
load(reg_src_aux, vmm_val, tail_step);
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, 0);
}
store(vmm_val, reg_dst, tail_step);
// check to remove below
add(reg_dst, tail_step * jcp_.dst_data_size);
add(reg_src_aux, tail_step * jcp_.src_data_size);
add(reg_oc_off, tail_step * sizeof(float));
sub(reg_work_amount, tail_step);
}
add(reg_index, jcp_.indices_size);
sub(reg_work_amount_out, 1);
jmp(out_loop_label, T_NEAR);
}
L(out_loop_end);
}
void linear_onnx_c_gathered() {
mov(reg_dst, ptr[reg_params + GET_OFF(dst)]);
// load weight
mov(reg_src, ptr[reg_params + GET_OFF(weight_ptr[0])]);
mov(reg_src_aux, ptr[reg_params + GET_OFF(weight_ptr[0]) + sizeof(size_t)]);
uni_vbroadcastss(vmm_weightL, ptr[reg_src]);
uni_vbroadcastss(vmm_weightR, ptr[reg_src_aux]);
if (jcp_.spatial_dim_size > 1) {
mov(reg_src_aux1, ptr[reg_params + GET_OFF(weight_ptr[0]) + 2 * sizeof(size_t)]);
mov(reg_src_aux2, ptr[reg_params + GET_OFF(weight_ptr[0]) + 3 * sizeof(size_t)]);
uni_vbroadcastss(vmm_weightT, ptr[reg_src_aux1]);
uni_vbroadcastss(vmm_weightB, ptr[reg_src_aux2]);
}
if (jcp_.spatial_dim_size > 2) {
mov(reg_src, ptr[reg_params + GET_OFF(weight_ptr[0]) + 4 * sizeof(size_t)]);
mov(reg_src_aux, ptr[reg_params + GET_OFF(weight_ptr[0]) + 5 * sizeof(size_t)]);
uni_vbroadcastss(vmm_weightF, ptr[reg_src]);
uni_vbroadcastss(vmm_weightE, ptr[reg_src_aux]);
}
// load src
mov(reg_src, ptr[reg_params + GET_OFF(src_ptr[0])]);
mov(reg_src_aux, ptr[reg_params + GET_OFF(src_ptr[0]) + sizeof(size_t)]);
if (jcp_.spatial_dim_size > 1) {
mov(reg_src_aux1, ptr[reg_params + GET_OFF(src_ptr[0]) + 2 * sizeof(size_t)]);
mov(reg_src_aux2, ptr[reg_params + GET_OFF(src_ptr[0]) + 3 * sizeof(size_t)]);
}
Xbyak::Reg64 reg_src_aux4 = r14;
Xbyak::Reg64 reg_src_aux5 = rdx;
Xbyak::Reg64 reg_src_aux6 = rsi;
Xbyak::Reg64 reg_src_aux7 = rbp;
if (jcp_.spatial_dim_size > 2) {
mov(reg_src_aux4, ptr[reg_params + GET_OFF(src_ptr[0]) + 4 * sizeof(size_t)]);
mov(reg_src_aux5, ptr[reg_params + GET_OFF(src_ptr[0]) + 5 * sizeof(size_t)]);
mov(reg_src_aux6, ptr[reg_params + GET_OFF(src_ptr[0]) + 6 * sizeof(size_t)]);
mov(reg_src_aux7, ptr[reg_params + GET_OFF(src_ptr[0]) + 7 * sizeof(size_t)]);
}
mov(reg_work_amount, ptr[reg_params + GET_OFF(work_amount)]);
int blk = (isa == cpu::x64::sse41) ? (2 * vector_step) : vector_step;
int dst_stride = (jcp_.layout == InterpolateLayoutType::by_channel)
? (vector_step * jcp_.dst_data_size)
: (blk * jcp_.OW * jcp_.OH * jcp_.OD * jcp_.dst_data_size);
int src_stride = (jcp_.layout == InterpolateLayoutType::by_channel)
? (vector_step * jcp_.src_data_size)
: (blk * jcp_.IW * jcp_.IH * jcp_.ID * jcp_.src_data_size);
Xbyak::Label main_loop_label;
Xbyak::Label main_loop_end_label;
Xbyak::Label blk_tail_loop_label;
Xbyak::Label blk_tail_loop_end_label;
Xbyak::Label tail_loop_label;
Xbyak::Label tail_loop_end_label;
L(main_loop_label);
{
if (jcp_.layout == InterpolateLayoutType::by_channel) {
cmp(reg_work_amount, vector_step);
jl(main_loop_end_label, T_NEAR);
} else {
cmp(reg_work_amount, 1);
jl(main_loop_end_label, T_NEAR);
}
// progressive manner
load(reg_src, vmm_valTL, vector_step);
load(reg_src_aux, vmm_valTR, vector_step);
if (jcp_.spatial_dim_size == 1) {
linear_onnx_worker_1d();
}
if (jcp_.spatial_dim_size > 1) {
load(reg_src_aux1, vmm_valBL, vector_step);
load(reg_src_aux2, vmm_valBR, vector_step);
linear_onnx_worker_2d();
}
if (jcp_.spatial_dim_size > 2) {
uni_vmovups(vmm_d_bias, vmm_valTR); // temporally save front result to temp_vmm
load(reg_src_aux4, vmm_valTL, vector_step);
load(reg_src_aux5, vmm_valTR, vector_step);
load(reg_src_aux6, vmm_valBL, vector_step);
load(reg_src_aux7, vmm_valBR, vector_step);
// 2d for end depth
linear_onnx_worker_2d();
// 3th dimension
uni_vmulps(vmm_valTR, vmm_valTR, vmm_weightE); // end_value * end_weight
uni_vfmadd231ps(vmm_valTR,
vmm_d_bias,
vmm_weightF); // start_value * start_weight + end_value * end_weight
}
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, false); // vmm_val is vmm_valTR
add(reg_oc_off, vector_step * sizeof(float));
}
store(vmm_valTR, reg_dst, vector_step);
if ((isa == cpu::x64::sse41) && (jcp_.layout == InterpolateLayoutType::block)) {
int offset_src = vector_step * jcp_.src_data_size;
load(reg_src, vmm_valTL, vector_step, offset_src);
load(reg_src_aux, vmm_valTR, vector_step, offset_src);
if (jcp_.spatial_dim_size == 1) {
linear_onnx_worker_1d();
}
if (jcp_.spatial_dim_size > 1) {
load(reg_src_aux1, vmm_valBL, vector_step, offset_src);
load(reg_src_aux2, vmm_valBR, vector_step, offset_src);
linear_onnx_worker_2d();
}
if (jcp_.spatial_dim_size > 2) {
uni_vmovups(vmm_d_bias, vmm_valTR); // temporally save front result to temp_vmm
load(reg_src_aux4, vmm_valTL, vector_step, offset_src);
load(reg_src_aux5, vmm_valTR, vector_step, offset_src);
load(reg_src_aux6, vmm_valBL, vector_step, offset_src);
load(reg_src_aux7, vmm_valBR, vector_step, offset_src);
// 2d for end depth
linear_onnx_worker_2d();
// 3th dimension
uni_vmulps(vmm_valTR, vmm_valTR, vmm_weightE); // end_value * end_weight
uni_vfmadd231ps(vmm_valTR,
vmm_d_bias,
vmm_weightF); // start_value * start_weight + end_value * end_weight
}
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, false);
add(reg_oc_off, vector_step * sizeof(float));
}
int offset_dst = vector_step * jcp_.dst_data_size;
store(vmm_valTR, reg_dst, vector_step, offset_dst);
}
add(reg_dst, dst_stride);
add(reg_src, src_stride);
add(reg_src_aux, src_stride);
if (jcp_.spatial_dim_size > 1) {
add(reg_src_aux1, src_stride);
add(reg_src_aux2, src_stride);
}
if (jcp_.spatial_dim_size > 2) {
add(reg_src_aux4, src_stride);
add(reg_src_aux5, src_stride);
add(reg_src_aux6, src_stride);
add(reg_src_aux7, src_stride);
}
if (jcp_.layout == InterpolateLayoutType::by_channel) {
sub(reg_work_amount, vector_step); // work_amount is c
} else {
sub(reg_work_amount, 1); // work_amount = div_up(c, blk), no tails
}
jmp(main_loop_label, T_NEAR);
}
L(main_loop_end_label);
if ((jcp_.layout == InterpolateLayoutType::by_channel) && (tail_step != 0)) {
load(reg_src, vmm_valTL, tail_step);
load(reg_src_aux, vmm_valTR, tail_step);
if (jcp_.spatial_dim_size == 1) {
linear_onnx_worker_1d();
}
if (jcp_.spatial_dim_size > 1) {
load(reg_src_aux1, vmm_valBL, tail_step);
load(reg_src_aux2, vmm_valBR, tail_step);
linear_onnx_worker_2d();
}
if (jcp_.spatial_dim_size > 2) {
uni_vmovups(vmm_d_bias, vmm_valTR); // temporally save front result to temp_vmm
load(reg_src_aux4, vmm_valTL, tail_step);
load(reg_src_aux5, vmm_valTR, tail_step);
load(reg_src_aux6, vmm_valBL, tail_step);
load(reg_src_aux7, vmm_valBR, tail_step);
// 2d for end depth
linear_onnx_worker_2d();
// 3th dimension
uni_vmulps(vmm_valTR, vmm_valTR, vmm_weightE); // end_value * end_weight
uni_vfmadd231ps(vmm_valTR,
vmm_d_bias,
vmm_weightF); // start_value * start_weight + end_value * end_weight
}
if (attr_.post_ops_.len() != 0) {
apply_post_ops(jcp_.dst_prc, false); // vmm_val is vmm_valTR
add(reg_oc_off, tail_step * sizeof(float));
}
store(vmm_valTR, reg_dst, tail_step);
}
}
void linear_onnx_planar() {
mov(reg_dst, ptr[reg_params + GET_OFF(dst)]);
mov(reg_src, ptr[reg_params + GET_OFF(src_ptr[0])]);
mov(reg_index, ptr[reg_params + GET_OFF(index)]);
mov(reg_src_aux, ptr[reg_params + GET_OFF(weight_ptr[0])]);
mov(reg_work_amount, ptr[reg_params + GET_OFF(work_amount)]);
int index_stride = jcp_.OW * jcp_.OH * jcp_.OD * jcp_.indices_size;
int weight_stride = jcp_.OW * jcp_.OH * jcp_.OD * sizeof(float);
Xbyak::Label main_loop_label;
Xbyak::Label main_loop_end_label;
Xbyak::Label tail_loop_label;
Xbyak::Label tail_loop_end_label;
L(main_loop_label);
{
cmp(reg_work_amount, vector_step);
jl(main_loop_end_label, T_NEAR);
uni_vmovdqu(vmm_index, ptr[reg_index]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valTL, ptr[reg_src + vmm_index], vmm_mask);
uni_vmovdqu(vmm_index, ptr[reg_index + index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valTR, ptr[reg_src + vmm_index], vmm_mask);
load_weights(reg_src_aux, vmm_weightL, vector_step);
load_weights(reg_src_aux, vmm_weightR, vector_step, weight_stride);
// progressive manner
if (jcp_.spatial_dim_size == 1) {
linear_onnx_worker_1d();
}
if (jcp_.spatial_dim_size > 1) {
uni_vmovdqu(vmm_index, ptr[reg_index + 2 * index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valBL, ptr[reg_src + vmm_index], vmm_mask);
uni_vmovdqu(vmm_index, ptr[reg_index + 3 * index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valBR, ptr[reg_src + vmm_index], vmm_mask);
load_weights(reg_src_aux, vmm_weightT, vector_step, 2 * weight_stride);
load_weights(reg_src_aux, vmm_weightB, vector_step, 3 * weight_stride);
linear_onnx_worker_2d();
}
if (jcp_.spatial_dim_size > 2) {
uni_vmovups(vmm_d_bias, vmm_valTR); // temporally save front result to temp_vmm
// for end depth
uni_vmovdqu(vmm_index, ptr[reg_index + 4 * index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valTL, ptr[reg_src + vmm_index], vmm_mask);
uni_vmovdqu(vmm_index, ptr[reg_index + 5 * index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valTR, ptr[reg_src + vmm_index], vmm_mask);
uni_vmovdqu(vmm_index, ptr[reg_index + 6 * index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valBL, ptr[reg_src + vmm_index], vmm_mask);
uni_vmovdqu(vmm_index, ptr[reg_index + 7 * index_stride]);
uni_vpcmpeqd(vmm_mask, vmm_mask, vmm_mask);
vgatherdps(vmm_valBR, ptr[reg_src + vmm_index], vmm_mask);
linear_onnx_worker_2d();
load_weights(reg_src_aux, vmm_weightE, vector_step, 5 * weight_stride);
load_weights(reg_src_aux, vmm_weightF, vector_step, 4 * weight_stride);
uni_vmulps(vmm_valTR, vmm_valTR, vmm_weightE); // end_value * end_weight
uni_vfmadd231ps(vmm_valTR,