-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_jacobi_solver.cpp
2890 lines (2403 loc) · 162 KB
/
test_jacobi_solver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <Accelerate/Accelerate.h>
#include "test_case_with_time_measurements.h"
#include "test_pattern_generation.h"
#include "thread_synchronizer.h"
#include "jacobi_solver_metal_cpp.h"
template< class T, bool IS_COL_MAJOR >
class TestCaseJacobiSolver : public TestCaseWithTimeMeasurements {
protected:
const int m_dim;
const int m_iteration;
T* m_A;
T* m_D;
T* m_b;
T* m_x1;
T* m_x2;
bool m_updating_x1;
vector<double> m_diff_x1_x2;
public:
TestCaseJacobiSolver( const int dim, const int iteration )
:m_dim ( dim )
,m_iteration ( iteration )
,m_A ( nullptr )
,m_D ( nullptr )
,m_b ( nullptr )
,m_x1 ( nullptr )
,m_x2 ( nullptr )
,m_updating_x1 ( false )
{
static_assert( is_same< float,T >::value || is_same< double,T >::value );
if constexpr ( is_same<float, T>::value ) {
setDataElementType( FLOAT );
}
else if constexpr ( is_same<double, T>::value ) {
setDataElementType( DOUBLE );
}
else {
assert(true);
}
if constexpr (IS_COL_MAJOR) {
setMatrixColMajor( dim, dim );
}
else {
setMatrixRowMajor( dim, dim );
}
setVerificationType( RMS );
}
virtual ~TestCaseJacobiSolver(){;}
virtual void compareTruth( const T* const baseline )
{
auto rms = getRMSDiffTwoVectors( getActiveX(), baseline, m_dim );
this->setRMS( rms );
}
virtual void setInitialStates( T* A, T* D, T* b , T* x1, T* x2 )
{
m_A = A;
m_D = D;
m_b = b;
m_x1 = x1;
m_x2 = x2;
m_updating_x1 = false;
}
virtual void run() = 0;
virtual T* getActiveX() {
return m_updating_x1 ? m_x1 : m_x2 ;
}
};
template< class T, bool IS_COL_MAJOR >
class TestCaseJacobiSolver_baseline : public TestCaseJacobiSolver< T, IS_COL_MAJOR > {
T* m_Dinv;
public:
TestCaseJacobiSolver_baseline( const int dim, const int solver_iteration )
:TestCaseJacobiSolver< T, IS_COL_MAJOR >( dim, solver_iteration )
,m_Dinv( new T[dim] )
{
this->setCPPBlock( 1, 1 );
}
virtual ~TestCaseJacobiSolver_baseline() {
delete[] m_Dinv;
}
virtual void run() {
this->m_diff_x1_x2.clear();
for ( int i = 0; i < this->m_dim; i++ ) {
m_Dinv[i] = 1.0 / this->m_D[i];
}
for ( int i = 0; i < this->m_iteration; i++ ) {
if ( this->m_updating_x1 ) {
calcX1();
}
else {
calcX2();
}
//T err = getRMSDiffTwoVectors( this->m_x1, this->m_x2, this->m_dim );
T err = getDistTwoVectors( this->m_x1, this->m_x2, this->m_dim );
this->m_diff_x1_x2.push_back( err );
this->m_updating_x1 = ! this->m_updating_x1;
}
}
void calcX1() {
for ( int i = 0; i < this->m_dim; i++ ) {
T sum = 0.0;
for ( int j = 0; j < this->m_dim; j++ ) {
sum += ( this->m_A[ linear_index_mat<IS_COL_MAJOR>(i, j, this->m_dim, this->m_dim) ] * this->m_x2[j] );
}
this->m_x1[i] = (this->m_b[i] - sum) * m_Dinv[ i ];
}
}
void calcX2() {
for ( int i = 0; i < this->m_dim; i++ ) {
T sum = 0.0;
for ( int j = 0; j < this->m_dim; j++ ) {
sum += ( this->m_A[ linear_index_mat<IS_COL_MAJOR>(i, j, this->m_dim, this->m_dim) ] * this->m_x1[j] );
}
this->m_x2[i] = (this->m_b[i] - sum) * m_Dinv[ i ];
}
}
};
template< class T, bool IS_COL_MAJOR >
class TestCaseJacobiSolver_NEON : public TestCaseJacobiSolver< T, IS_COL_MAJOR > {
protected:
T* m_Dinv;
int m_factor_loop_unrolling;
public:
TestCaseJacobiSolver_NEON( const int dim, const int solver_iteration, const int factor_loop_unrolling )
:TestCaseJacobiSolver< T, IS_COL_MAJOR >( dim, solver_iteration )
,m_Dinv( new T[ dim ] )
,m_factor_loop_unrolling( factor_loop_unrolling )
{
static_assert( is_same< float,T >::value || is_same< double,T >::value );
this->setNEON( 1, m_factor_loop_unrolling );
}
virtual ~TestCaseJacobiSolver_NEON() {
delete[] m_Dinv;
}
virtual void run() {
this->m_diff_x1_x2.clear();
if constexpr ( is_same< float,T >::value ) {
if ( m_factor_loop_unrolling == 1 ) {
for (int i = 0; i < this->m_dim; i += 4 ) {
const float32x4_t qw_d1 = { this->m_D[i ], this->m_D[i+1], this->m_D[i+2], this->m_D[i+3] };
const float32x4_t qw_d_inv1_1 = vrecpeq_f32( qw_d1 );
const float32x4_t qw_d_inv2_1 = vmulq_f32( vrecpsq_f32( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
memcpy(&(m_Dinv[i ]), &qw_d_inv2_1, sizeof(float)*4);
}
}
else if ( m_factor_loop_unrolling == 2 ) {
for (int i = 0; i < this->m_dim; i+=8 ) {
const float32x4_t qw_d1 = { this->m_D[i ], this->m_D[i+1], this->m_D[i+2], this->m_D[i+3] };
const float32x4_t qw_d2 = { this->m_D[i+4], this->m_D[i+5], this->m_D[i+6], this->m_D[i+7] };
const float32x4_t qw_d_inv1_1 = vrecpeq_f32( qw_d1 );
const float32x4_t qw_d_inv1_2 = vrecpeq_f32( qw_d2 );
const float32x4_t qw_d_inv2_1 = vmulq_f32( vrecpsq_f32( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float32x4_t qw_d_inv2_2 = vmulq_f32( vrecpsq_f32( qw_d2, qw_d_inv1_2 ), qw_d_inv1_2 );
memcpy(&(m_Dinv[i ]), &qw_d_inv2_1, sizeof(float)*4);
memcpy(&(m_Dinv[i+4]), &qw_d_inv2_2, sizeof(float)*4);
}
}
else if ( m_factor_loop_unrolling == 4 ) {
for (int i = 0; i < this->m_dim; i += 16 ) {
const float32x4_t qw_d1 = { this->m_D[i ], this->m_D[i+ 1], this->m_D[i+ 2], this->m_D[i+ 3] };
const float32x4_t qw_d2 = { this->m_D[i+ 4], this->m_D[i+ 5], this->m_D[i+ 6], this->m_D[i+ 7] };
const float32x4_t qw_d3 = { this->m_D[i+ 8], this->m_D[i+ 9], this->m_D[i+10], this->m_D[i+11] };
const float32x4_t qw_d4 = { this->m_D[i+12], this->m_D[i+13], this->m_D[i+14], this->m_D[i+15] };
const float32x4_t qw_d_inv1_1 = vrecpeq_f32( qw_d1 );
const float32x4_t qw_d_inv1_2 = vrecpeq_f32( qw_d2 );
const float32x4_t qw_d_inv1_3 = vrecpeq_f32( qw_d3 );
const float32x4_t qw_d_inv1_4 = vrecpeq_f32( qw_d4 );
const float32x4_t qw_d_inv2_1 = vmulq_f32( vrecpsq_f32( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float32x4_t qw_d_inv2_2 = vmulq_f32( vrecpsq_f32( qw_d2, qw_d_inv1_2 ), qw_d_inv1_2 );
const float32x4_t qw_d_inv2_3 = vmulq_f32( vrecpsq_f32( qw_d3, qw_d_inv1_3 ), qw_d_inv1_3 );
const float32x4_t qw_d_inv2_4 = vmulq_f32( vrecpsq_f32( qw_d4, qw_d_inv1_4 ), qw_d_inv1_4 );
memcpy(&(m_Dinv[i ]), &qw_d_inv2_1, sizeof(float)*4);
memcpy(&(m_Dinv[i+ 4]), &qw_d_inv2_2, sizeof(float)*4);
memcpy(&(m_Dinv[i+ 8]), &qw_d_inv2_3, sizeof(float)*4);
memcpy(&(m_Dinv[i+12]), &qw_d_inv2_4, sizeof(float)*4);
}
}
else if ( m_factor_loop_unrolling == 8 ) {
for (int i = 0; i < this->m_dim; i += 32 ) {
const float32x4_t qw_d1 = { this->m_D[i ], this->m_D[i+ 1], this->m_D[i+ 2], this->m_D[i+ 3] };
const float32x4_t qw_d2 = { this->m_D[i+ 4], this->m_D[i+ 5], this->m_D[i+ 6], this->m_D[i+ 7] };
const float32x4_t qw_d3 = { this->m_D[i+ 8], this->m_D[i+ 9], this->m_D[i+10], this->m_D[i+11] };
const float32x4_t qw_d4 = { this->m_D[i+12], this->m_D[i+13], this->m_D[i+14], this->m_D[i+15] };
const float32x4_t qw_d5 = { this->m_D[i+16], this->m_D[i+17], this->m_D[i+18], this->m_D[i+19] };
const float32x4_t qw_d6 = { this->m_D[i+20], this->m_D[i+21], this->m_D[i+22], this->m_D[i+23] };
const float32x4_t qw_d7 = { this->m_D[i+24], this->m_D[i+25], this->m_D[i+26], this->m_D[i+27] };
const float32x4_t qw_d8 = { this->m_D[i+28], this->m_D[i+29], this->m_D[i+30], this->m_D[i+31] };
const float32x4_t qw_d_inv1_1 = vrecpeq_f32( qw_d1 );
const float32x4_t qw_d_inv1_2 = vrecpeq_f32( qw_d2 );
const float32x4_t qw_d_inv1_3 = vrecpeq_f32( qw_d3 );
const float32x4_t qw_d_inv1_4 = vrecpeq_f32( qw_d4 );
const float32x4_t qw_d_inv1_5 = vrecpeq_f32( qw_d5 );
const float32x4_t qw_d_inv1_6 = vrecpeq_f32( qw_d6 );
const float32x4_t qw_d_inv1_7 = vrecpeq_f32( qw_d7 );
const float32x4_t qw_d_inv1_8 = vrecpeq_f32( qw_d8 );
const float32x4_t qw_d_inv2_1 = vmulq_f32( vrecpsq_f32( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float32x4_t qw_d_inv2_2 = vmulq_f32( vrecpsq_f32( qw_d2, qw_d_inv1_2 ), qw_d_inv1_2 );
const float32x4_t qw_d_inv2_3 = vmulq_f32( vrecpsq_f32( qw_d3, qw_d_inv1_3 ), qw_d_inv1_3 );
const float32x4_t qw_d_inv2_4 = vmulq_f32( vrecpsq_f32( qw_d4, qw_d_inv1_4 ), qw_d_inv1_4 );
const float32x4_t qw_d_inv2_5 = vmulq_f32( vrecpsq_f32( qw_d5, qw_d_inv1_5 ), qw_d_inv1_5 );
const float32x4_t qw_d_inv2_6 = vmulq_f32( vrecpsq_f32( qw_d6, qw_d_inv1_6 ), qw_d_inv1_6 );
const float32x4_t qw_d_inv2_7 = vmulq_f32( vrecpsq_f32( qw_d7, qw_d_inv1_7 ), qw_d_inv1_7 );
const float32x4_t qw_d_inv2_8 = vmulq_f32( vrecpsq_f32( qw_d8, qw_d_inv1_8 ), qw_d_inv1_8 );
memcpy(&(m_Dinv[i ]), &qw_d_inv2_1, sizeof(float)*4);
memcpy(&(m_Dinv[i+ 4]), &qw_d_inv2_2, sizeof(float)*4);
memcpy(&(m_Dinv[i+ 8]), &qw_d_inv2_3, sizeof(float)*4);
memcpy(&(m_Dinv[i+12]), &qw_d_inv2_4, sizeof(float)*4);
memcpy(&(m_Dinv[i+16]), &qw_d_inv2_5, sizeof(float)*4);
memcpy(&(m_Dinv[i+20]), &qw_d_inv2_6, sizeof(float)*4);
memcpy(&(m_Dinv[i+24]), &qw_d_inv2_7, sizeof(float)*4);
memcpy(&(m_Dinv[i+28]), &qw_d_inv2_8, sizeof(float)*4);
}
}
}
else {
if ( m_factor_loop_unrolling == 1 ) {
for (int i = 0; i < this->m_dim; i+=2 ) {
const float64x2_t qw_d1 = { this->m_D[i ], this->m_D[i+1] };
const float64x2_t qw_d_inv1_1 = vrecpeq_f64( qw_d1 );
const float64x2_t qw_d_inv2_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float64x2_t qw_d_inv3_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv2_1 ), qw_d_inv2_1 );
memcpy(&(m_Dinv[i ]), &qw_d_inv3_1, sizeof(double)*2);
}
}
else if ( m_factor_loop_unrolling == 2 ) {
for (int i = 0; i < this->m_dim; i+=4 ) {
const float64x2_t qw_d1 = { this->m_D[i ], this->m_D[i+1] };
const float64x2_t qw_d2 = { this->m_D[i+2], this->m_D[i+3] };
const float64x2_t qw_d_inv1_1 = vrecpeq_f64( qw_d1 );
const float64x2_t qw_d_inv1_2 = vrecpeq_f64( qw_d2 );
const float64x2_t qw_d_inv2_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float64x2_t qw_d_inv2_2 = vmulq_f64( vrecpsq_f64( qw_d2, qw_d_inv1_2 ), qw_d_inv1_2 );
const float64x2_t qw_d_inv3_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv2_1 ), qw_d_inv2_1 );
const float64x2_t qw_d_inv3_2 = vmulq_f64( vrecpsq_f64( qw_d2, qw_d_inv2_2 ), qw_d_inv2_2 );
memcpy(&(m_Dinv[i ]), &qw_d_inv3_1, sizeof(double)*2);
memcpy(&(m_Dinv[i+2]), &qw_d_inv3_2, sizeof(double)*2);
}
}
else if ( m_factor_loop_unrolling == 4 ) {
for (int i = 0; i < this->m_dim; i+=8 ) {
const float64x2_t qw_d1 = { this->m_D[i ], this->m_D[i+1] };
const float64x2_t qw_d2 = { this->m_D[i+2], this->m_D[i+3] };
const float64x2_t qw_d3 = { this->m_D[i+4], this->m_D[i+5] };
const float64x2_t qw_d4 = { this->m_D[i+6], this->m_D[i+7] };
const float64x2_t qw_d_inv1_1 = vrecpeq_f64( qw_d1 );
const float64x2_t qw_d_inv1_2 = vrecpeq_f64( qw_d2 );
const float64x2_t qw_d_inv1_3 = vrecpeq_f64( qw_d3 );
const float64x2_t qw_d_inv1_4 = vrecpeq_f64( qw_d4 );
const float64x2_t qw_d_inv2_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float64x2_t qw_d_inv2_2 = vmulq_f64( vrecpsq_f64( qw_d2, qw_d_inv1_2 ), qw_d_inv1_2 );
const float64x2_t qw_d_inv2_3 = vmulq_f64( vrecpsq_f64( qw_d3, qw_d_inv1_3 ), qw_d_inv1_3 );
const float64x2_t qw_d_inv2_4 = vmulq_f64( vrecpsq_f64( qw_d4, qw_d_inv1_4 ), qw_d_inv1_4 );
const float64x2_t qw_d_inv3_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv2_1 ), qw_d_inv2_1 );
const float64x2_t qw_d_inv3_2 = vmulq_f64( vrecpsq_f64( qw_d2, qw_d_inv2_2 ), qw_d_inv2_2 );
const float64x2_t qw_d_inv3_3 = vmulq_f64( vrecpsq_f64( qw_d3, qw_d_inv2_3 ), qw_d_inv2_3 );
const float64x2_t qw_d_inv3_4 = vmulq_f64( vrecpsq_f64( qw_d4, qw_d_inv2_4 ), qw_d_inv2_4 );
memcpy(&(m_Dinv[i ]), &qw_d_inv3_1, sizeof(double)*2);
memcpy(&(m_Dinv[i+2]), &qw_d_inv3_2, sizeof(double)*2);
memcpy(&(m_Dinv[i+4]), &qw_d_inv3_3, sizeof(double)*2);
memcpy(&(m_Dinv[i+6]), &qw_d_inv3_4, sizeof(double)*2);
}
}
else if ( m_factor_loop_unrolling == 8 ) {
for (int i = 0; i < this->m_dim; i+=16 ) {
const float64x2_t qw_d1 = { this->m_D[i ], this->m_D[i+ 1] };
const float64x2_t qw_d2 = { this->m_D[i+ 2], this->m_D[i+ 3] };
const float64x2_t qw_d3 = { this->m_D[i+ 4], this->m_D[i+ 5] };
const float64x2_t qw_d4 = { this->m_D[i+ 6], this->m_D[i+ 7] };
const float64x2_t qw_d5 = { this->m_D[i+ 8], this->m_D[i+ 9] };
const float64x2_t qw_d6 = { this->m_D[i+10], this->m_D[i+11] };
const float64x2_t qw_d7 = { this->m_D[i+12], this->m_D[i+13] };
const float64x2_t qw_d8 = { this->m_D[i+14], this->m_D[i+15] };
const float64x2_t qw_d_inv1_1 = vrecpeq_f64( qw_d1 );
const float64x2_t qw_d_inv1_2 = vrecpeq_f64( qw_d2 );
const float64x2_t qw_d_inv1_3 = vrecpeq_f64( qw_d3 );
const float64x2_t qw_d_inv1_4 = vrecpeq_f64( qw_d4 );
const float64x2_t qw_d_inv1_5 = vrecpeq_f64( qw_d5 );
const float64x2_t qw_d_inv1_6 = vrecpeq_f64( qw_d6 );
const float64x2_t qw_d_inv1_7 = vrecpeq_f64( qw_d7 );
const float64x2_t qw_d_inv1_8 = vrecpeq_f64( qw_d8 );
const float64x2_t qw_d_inv2_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv1_1 ), qw_d_inv1_1 );
const float64x2_t qw_d_inv2_2 = vmulq_f64( vrecpsq_f64( qw_d2, qw_d_inv1_2 ), qw_d_inv1_2 );
const float64x2_t qw_d_inv2_3 = vmulq_f64( vrecpsq_f64( qw_d3, qw_d_inv1_3 ), qw_d_inv1_3 );
const float64x2_t qw_d_inv2_4 = vmulq_f64( vrecpsq_f64( qw_d4, qw_d_inv1_4 ), qw_d_inv1_4 );
const float64x2_t qw_d_inv2_5 = vmulq_f64( vrecpsq_f64( qw_d5, qw_d_inv1_5 ), qw_d_inv1_5 );
const float64x2_t qw_d_inv2_6 = vmulq_f64( vrecpsq_f64( qw_d6, qw_d_inv1_6 ), qw_d_inv1_6 );
const float64x2_t qw_d_inv2_7 = vmulq_f64( vrecpsq_f64( qw_d7, qw_d_inv1_7 ), qw_d_inv1_7 );
const float64x2_t qw_d_inv2_8 = vmulq_f64( vrecpsq_f64( qw_d8, qw_d_inv1_8 ), qw_d_inv1_8 );
const float64x2_t qw_d_inv3_1 = vmulq_f64( vrecpsq_f64( qw_d1, qw_d_inv2_1 ), qw_d_inv2_1 );
const float64x2_t qw_d_inv3_2 = vmulq_f64( vrecpsq_f64( qw_d2, qw_d_inv2_2 ), qw_d_inv2_2 );
const float64x2_t qw_d_inv3_3 = vmulq_f64( vrecpsq_f64( qw_d3, qw_d_inv2_3 ), qw_d_inv2_3 );
const float64x2_t qw_d_inv3_4 = vmulq_f64( vrecpsq_f64( qw_d4, qw_d_inv2_4 ), qw_d_inv2_4 );
const float64x2_t qw_d_inv3_5 = vmulq_f64( vrecpsq_f64( qw_d5, qw_d_inv2_5 ), qw_d_inv2_5 );
const float64x2_t qw_d_inv3_6 = vmulq_f64( vrecpsq_f64( qw_d6, qw_d_inv2_6 ), qw_d_inv2_6 );
const float64x2_t qw_d_inv3_7 = vmulq_f64( vrecpsq_f64( qw_d7, qw_d_inv2_7 ), qw_d_inv2_7 );
const float64x2_t qw_d_inv3_8 = vmulq_f64( vrecpsq_f64( qw_d8, qw_d_inv2_8 ), qw_d_inv2_8 );
memcpy(&(m_Dinv[i ]), &qw_d_inv3_1, sizeof(double)*2);
memcpy(&(m_Dinv[i+ 2]), &qw_d_inv3_2, sizeof(double)*2);
memcpy(&(m_Dinv[i+ 4]), &qw_d_inv3_3, sizeof(double)*2);
memcpy(&(m_Dinv[i+ 6]), &qw_d_inv3_4, sizeof(double)*2);
memcpy(&(m_Dinv[i+ 8]), &qw_d_inv3_5, sizeof(double)*2);
memcpy(&(m_Dinv[i+10]), &qw_d_inv3_6, sizeof(double)*2);
memcpy(&(m_Dinv[i+12]), &qw_d_inv3_7, sizeof(double)*2);
memcpy(&(m_Dinv[i+14]), &qw_d_inv3_8, sizeof(double)*2);
}
}
}
for ( int i = 0; i < this->m_iteration; i++ ) {
if ( this->m_updating_x1 ) {
calcX1();
}
else {
calcX2();
}
//T err = this->getRmsX1X2Neon();
T err = this->getDistX1X2Neon();
this->m_diff_x1_x2.push_back(err);
this->m_updating_x1 = ! this->m_updating_x1;
}
}
void calcX1() {
if constexpr ( IS_COL_MAJOR ) {
calcX1ColMajor( 0, this->m_dim );
}
else {
calcX1RowMajor( 0, this->m_dim );
}
}
void calcX2() {
if constexpr ( IS_COL_MAJOR ) {
calcX2ColMajor( 0, this->m_dim );
}
else {
calcX2RowMajor( 0, this->m_dim );
}
}
virtual void calcX1ColMajor( const int row_begin, const int row_end_past_one ) {
if constexpr ( is_same< float,T >::value ) {
if ( m_factor_loop_unrolling == 1 ) {
for ( int i = row_begin; i < row_end_past_one; i += 4 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x2[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_x1_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(float)*4 );
}
}
else if ( m_factor_loop_unrolling == 2 ) {
for ( int i = row_begin; i < row_end_past_one; i += 8 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum2 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x2[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_mat2 = vld1q_f32( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
const float32x4_t qw_mc2 = vmulq_f32( qw_mat2, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f32( qw_mc2, qw_row_sum2 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_b2 = vld1q_f32( &(this->m_b[i+4]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_Dinv2 = vld1q_f32( &(this->m_Dinv[i+4]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_b_minus_sum2 = vsubq_f32( qw_b2, qw_row_sum2 );
const float32x4_t qw_x1_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
const float32x4_t qw_x1_2 = vmulq_f32( qw_b_minus_sum2 , qw_Dinv2 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(float)*4 );
memcpy( &(this->m_x1[i+4]), &qw_x1_2, sizeof(float)*4 );
}
}
else if ( m_factor_loop_unrolling == 4 ) {
for ( int i = row_begin; i < row_end_past_one; i += 16 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum2 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum3 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum4 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x2[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_mat2 = vld1q_f32( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float32x4_t qw_mat3 = vld1q_f32( &(this->m_A[ i + 8 + this->m_dim * j ]) );
const float32x4_t qw_mat4 = vld1q_f32( &(this->m_A[ i + 12 + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
const float32x4_t qw_mc2 = vmulq_f32( qw_mat2, qw_col );
const float32x4_t qw_mc3 = vmulq_f32( qw_mat3, qw_col );
const float32x4_t qw_mc4 = vmulq_f32( qw_mat4, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f32( qw_mc2, qw_row_sum2 );
qw_row_sum3 = vaddq_f32( qw_mc3, qw_row_sum3 );
qw_row_sum4 = vaddq_f32( qw_mc4, qw_row_sum4 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_b2 = vld1q_f32( &(this->m_b[i+ 4]) );
const float32x4_t qw_b3 = vld1q_f32( &(this->m_b[i+ 8]) );
const float32x4_t qw_b4 = vld1q_f32( &(this->m_b[i+12]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_Dinv2 = vld1q_f32( &(this->m_Dinv[i+ 4]) );
const float32x4_t qw_Dinv3 = vld1q_f32( &(this->m_Dinv[i+ 8]) );
const float32x4_t qw_Dinv4 = vld1q_f32( &(this->m_Dinv[i+12]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_b_minus_sum2 = vsubq_f32( qw_b2, qw_row_sum2 );
const float32x4_t qw_b_minus_sum3 = vsubq_f32( qw_b3, qw_row_sum3 );
const float32x4_t qw_b_minus_sum4 = vsubq_f32( qw_b4, qw_row_sum4 );
const float32x4_t qw_x1_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
const float32x4_t qw_x1_2 = vmulq_f32( qw_b_minus_sum2 , qw_Dinv2 );
const float32x4_t qw_x1_3 = vmulq_f32( qw_b_minus_sum3 , qw_Dinv3 );
const float32x4_t qw_x1_4 = vmulq_f32( qw_b_minus_sum4 , qw_Dinv4 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(float)*4 );
memcpy( &(this->m_x1[i+ 4]), &qw_x1_2, sizeof(float)*4 );
memcpy( &(this->m_x1[i+ 8]), &qw_x1_3, sizeof(float)*4 );
memcpy( &(this->m_x1[i+12]), &qw_x1_4, sizeof(float)*4 );
}
}
else if ( m_factor_loop_unrolling == 8 ) {
for ( int i = row_begin; i < row_end_past_one; i += 32 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum2 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum3 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum4 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum5 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum6 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum7 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum8 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x2[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_mat2 = vld1q_f32( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float32x4_t qw_mat3 = vld1q_f32( &(this->m_A[ i + 8 + this->m_dim * j ]) );
const float32x4_t qw_mat4 = vld1q_f32( &(this->m_A[ i + 12 + this->m_dim * j ]) );
const float32x4_t qw_mat5 = vld1q_f32( &(this->m_A[ i + 16 + this->m_dim * j ]) );
const float32x4_t qw_mat6 = vld1q_f32( &(this->m_A[ i + 20 + this->m_dim * j ]) );
const float32x4_t qw_mat7 = vld1q_f32( &(this->m_A[ i + 24 + this->m_dim * j ]) );
const float32x4_t qw_mat8 = vld1q_f32( &(this->m_A[ i + 28 + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
const float32x4_t qw_mc2 = vmulq_f32( qw_mat2, qw_col );
const float32x4_t qw_mc3 = vmulq_f32( qw_mat3, qw_col );
const float32x4_t qw_mc4 = vmulq_f32( qw_mat4, qw_col );
const float32x4_t qw_mc5 = vmulq_f32( qw_mat5, qw_col );
const float32x4_t qw_mc6 = vmulq_f32( qw_mat6, qw_col );
const float32x4_t qw_mc7 = vmulq_f32( qw_mat7, qw_col );
const float32x4_t qw_mc8 = vmulq_f32( qw_mat8, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f32( qw_mc2, qw_row_sum2 );
qw_row_sum3 = vaddq_f32( qw_mc3, qw_row_sum3 );
qw_row_sum4 = vaddq_f32( qw_mc4, qw_row_sum4 );
qw_row_sum5 = vaddq_f32( qw_mc5, qw_row_sum5 );
qw_row_sum6 = vaddq_f32( qw_mc6, qw_row_sum6 );
qw_row_sum7 = vaddq_f32( qw_mc7, qw_row_sum7 );
qw_row_sum8 = vaddq_f32( qw_mc8, qw_row_sum8 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_b2 = vld1q_f32( &(this->m_b[i+ 4]) );
const float32x4_t qw_b3 = vld1q_f32( &(this->m_b[i+ 8]) );
const float32x4_t qw_b4 = vld1q_f32( &(this->m_b[i+12]) );
const float32x4_t qw_b5 = vld1q_f32( &(this->m_b[i+16]) );
const float32x4_t qw_b6 = vld1q_f32( &(this->m_b[i+20]) );
const float32x4_t qw_b7 = vld1q_f32( &(this->m_b[i+24]) );
const float32x4_t qw_b8 = vld1q_f32( &(this->m_b[i+28]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_Dinv2 = vld1q_f32( &(this->m_Dinv[i+ 4]) );
const float32x4_t qw_Dinv3 = vld1q_f32( &(this->m_Dinv[i+ 8]) );
const float32x4_t qw_Dinv4 = vld1q_f32( &(this->m_Dinv[i+12]) );
const float32x4_t qw_Dinv5 = vld1q_f32( &(this->m_Dinv[i+16]) );
const float32x4_t qw_Dinv6 = vld1q_f32( &(this->m_Dinv[i+20]) );
const float32x4_t qw_Dinv7 = vld1q_f32( &(this->m_Dinv[i+24]) );
const float32x4_t qw_Dinv8 = vld1q_f32( &(this->m_Dinv[i+28]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_b_minus_sum2 = vsubq_f32( qw_b2, qw_row_sum2 );
const float32x4_t qw_b_minus_sum3 = vsubq_f32( qw_b3, qw_row_sum3 );
const float32x4_t qw_b_minus_sum4 = vsubq_f32( qw_b4, qw_row_sum4 );
const float32x4_t qw_b_minus_sum5 = vsubq_f32( qw_b5, qw_row_sum5 );
const float32x4_t qw_b_minus_sum6 = vsubq_f32( qw_b6, qw_row_sum6 );
const float32x4_t qw_b_minus_sum7 = vsubq_f32( qw_b7, qw_row_sum7 );
const float32x4_t qw_b_minus_sum8 = vsubq_f32( qw_b8, qw_row_sum8 );
const float32x4_t qw_x1_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
const float32x4_t qw_x1_2 = vmulq_f32( qw_b_minus_sum2 , qw_Dinv2 );
const float32x4_t qw_x1_3 = vmulq_f32( qw_b_minus_sum3 , qw_Dinv3 );
const float32x4_t qw_x1_4 = vmulq_f32( qw_b_minus_sum4 , qw_Dinv4 );
const float32x4_t qw_x1_5 = vmulq_f32( qw_b_minus_sum5 , qw_Dinv5 );
const float32x4_t qw_x1_6 = vmulq_f32( qw_b_minus_sum6 , qw_Dinv6 );
const float32x4_t qw_x1_7 = vmulq_f32( qw_b_minus_sum7 , qw_Dinv7 );
const float32x4_t qw_x1_8 = vmulq_f32( qw_b_minus_sum8 , qw_Dinv8 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(float)*4 );
memcpy( &(this->m_x1[i+ 4]), &qw_x1_2, sizeof(float)*4 );
memcpy( &(this->m_x1[i+ 8]), &qw_x1_3, sizeof(float)*4 );
memcpy( &(this->m_x1[i+12]), &qw_x1_4, sizeof(float)*4 );
memcpy( &(this->m_x1[i+16]), &qw_x1_5, sizeof(float)*4 );
memcpy( &(this->m_x1[i+20]), &qw_x1_6, sizeof(float)*4 );
memcpy( &(this->m_x1[i+24]), &qw_x1_7, sizeof(float)*4 );
memcpy( &(this->m_x1[i+28]), &qw_x1_8, sizeof(float)*4 );
}
}
}
else {
if ( m_factor_loop_unrolling == 1 ) {
for ( int i = row_begin; i < row_end_past_one; i += 2 ) {
float64x2_t qw_row_sum1 = { 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const double col_v = this->m_x2[j];
const float64x2_t qw_mat1 = vld1q_f64( &(this->m_A[ i + this->m_dim * j ]) );
const float64x2_t qw_col = { col_v, col_v };
const float64x2_t qw_mc1 = vmulq_f64( qw_mat1, qw_col );
qw_row_sum1 = vaddq_f64( qw_mc1, qw_row_sum1 );
}
const float64x2_t qw_b1 = vld1q_f64( &(this->m_b[i ]) );
const float64x2_t qw_Dinv1 = vld1q_f64( &(this->m_Dinv[i ]) );
const float64x2_t qw_b_minus_sum1 = vsubq_f64( qw_b1, qw_row_sum1 );
const float64x2_t qw_x1_1 = vmulq_f64( qw_b_minus_sum1 , qw_Dinv1 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(double)*2 );
}
}
else if ( m_factor_loop_unrolling == 2 ) {
for ( int i = row_begin; i < row_end_past_one; i += 4 ) {
float64x2_t qw_row_sum1 = { 0.0, 0.0 };
float64x2_t qw_row_sum2 = { 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const double col_v = this->m_x2[j];
const float64x2_t qw_mat1 = vld1q_f64( &(this->m_A[ i + this->m_dim * j ]) );
const float64x2_t qw_mat2 = vld1q_f64( &(this->m_A[ i + 2 + this->m_dim * j ]) );
const float64x2_t qw_col = { col_v, col_v };
const float64x2_t qw_mc1 = vmulq_f64( qw_mat1, qw_col );
const float64x2_t qw_mc2 = vmulq_f64( qw_mat2, qw_col );
qw_row_sum1 = vaddq_f64( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f64( qw_mc2, qw_row_sum2 );
}
const float64x2_t qw_b1 = vld1q_f64( &(this->m_b[i ]) );
const float64x2_t qw_b2 = vld1q_f64( &(this->m_b[i+2]) );
const float64x2_t qw_Dinv1 = vld1q_f64( &(this->m_Dinv[i ]) );
const float64x2_t qw_Dinv2 = vld1q_f64( &(this->m_Dinv[i+2]) );
const float64x2_t qw_b_minus_sum1 = vsubq_f64( qw_b1, qw_row_sum1 );
const float64x2_t qw_b_minus_sum2 = vsubq_f64( qw_b2, qw_row_sum2 );
const float64x2_t qw_x1_1 = vmulq_f64( qw_b_minus_sum1 , qw_Dinv1 );
const float64x2_t qw_x1_2 = vmulq_f64( qw_b_minus_sum2 , qw_Dinv2 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(double)*2 );
memcpy( &(this->m_x1[i+2]), &qw_x1_2, sizeof(double)*2 );
}
}
else if ( m_factor_loop_unrolling == 4 ) {
for ( int i = row_begin; i < row_end_past_one; i += 8 ) {
float64x2_t qw_row_sum1 = { 0.0, 0.0 };
float64x2_t qw_row_sum2 = { 0.0, 0.0 };
float64x2_t qw_row_sum3 = { 0.0, 0.0 };
float64x2_t qw_row_sum4 = { 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const double col_v = this->m_x2[j];
const float64x2_t qw_mat1 = vld1q_f64( &(this->m_A[ i + this->m_dim * j ]) );
const float64x2_t qw_mat2 = vld1q_f64( &(this->m_A[ i + 2 + this->m_dim * j ]) );
const float64x2_t qw_mat3 = vld1q_f64( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float64x2_t qw_mat4 = vld1q_f64( &(this->m_A[ i + 6 + this->m_dim * j ]) );
const float64x2_t qw_col = { col_v, col_v };
const float64x2_t qw_mc1 = vmulq_f64( qw_mat1, qw_col );
const float64x2_t qw_mc2 = vmulq_f64( qw_mat2, qw_col );
const float64x2_t qw_mc3 = vmulq_f64( qw_mat3, qw_col );
const float64x2_t qw_mc4 = vmulq_f64( qw_mat4, qw_col );
qw_row_sum1 = vaddq_f64( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f64( qw_mc2, qw_row_sum2 );
qw_row_sum3 = vaddq_f64( qw_mc3, qw_row_sum3 );
qw_row_sum4 = vaddq_f64( qw_mc4, qw_row_sum4 );
}
const float64x2_t qw_b1 = vld1q_f64( &(this->m_b[i ]) );
const float64x2_t qw_b2 = vld1q_f64( &(this->m_b[i+2]) );
const float64x2_t qw_b3 = vld1q_f64( &(this->m_b[i+4]) );
const float64x2_t qw_b4 = vld1q_f64( &(this->m_b[i+6]) );
const float64x2_t qw_Dinv1 = vld1q_f64( &(this->m_Dinv[i ]) );
const float64x2_t qw_Dinv2 = vld1q_f64( &(this->m_Dinv[i+2]) );
const float64x2_t qw_Dinv3 = vld1q_f64( &(this->m_Dinv[i+4]) );
const float64x2_t qw_Dinv4 = vld1q_f64( &(this->m_Dinv[i+6]) );
const float64x2_t qw_b_minus_sum1 = vsubq_f64( qw_b1, qw_row_sum1 );
const float64x2_t qw_b_minus_sum2 = vsubq_f64( qw_b2, qw_row_sum2 );
const float64x2_t qw_b_minus_sum3 = vsubq_f64( qw_b3, qw_row_sum3 );
const float64x2_t qw_b_minus_sum4 = vsubq_f64( qw_b4, qw_row_sum4 );
const float64x2_t qw_x1_1 = vmulq_f64( qw_b_minus_sum1 , qw_Dinv1 );
const float64x2_t qw_x1_2 = vmulq_f64( qw_b_minus_sum2 , qw_Dinv2 );
const float64x2_t qw_x1_3 = vmulq_f64( qw_b_minus_sum3 , qw_Dinv3 );
const float64x2_t qw_x1_4 = vmulq_f64( qw_b_minus_sum4 , qw_Dinv4 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(double)*2 );
memcpy( &(this->m_x1[i+2]), &qw_x1_2, sizeof(double)*2 );
memcpy( &(this->m_x1[i+4]), &qw_x1_3, sizeof(double)*2 );
memcpy( &(this->m_x1[i+6]), &qw_x1_4, sizeof(double)*2 );
}
}
else if ( m_factor_loop_unrolling == 8 ) {
for ( int i = row_begin; i < row_end_past_one; i += 16 ) {
float64x2_t qw_row_sum1 = { 0.0, 0.0 };
float64x2_t qw_row_sum2 = { 0.0, 0.0 };
float64x2_t qw_row_sum3 = { 0.0, 0.0 };
float64x2_t qw_row_sum4 = { 0.0, 0.0 };
float64x2_t qw_row_sum5 = { 0.0, 0.0 };
float64x2_t qw_row_sum6 = { 0.0, 0.0 };
float64x2_t qw_row_sum7 = { 0.0, 0.0 };
float64x2_t qw_row_sum8 = { 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const double col_v = this->m_x2[j];
const float64x2_t qw_mat1 = vld1q_f64( &(this->m_A[ i + this->m_dim * j ]) );
const float64x2_t qw_mat2 = vld1q_f64( &(this->m_A[ i + 2 + this->m_dim * j ]) );
const float64x2_t qw_mat3 = vld1q_f64( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float64x2_t qw_mat4 = vld1q_f64( &(this->m_A[ i + 6 + this->m_dim * j ]) );
const float64x2_t qw_mat5 = vld1q_f64( &(this->m_A[ i + 8 + this->m_dim * j ]) );
const float64x2_t qw_mat6 = vld1q_f64( &(this->m_A[ i + 10 + this->m_dim * j ]) );
const float64x2_t qw_mat7 = vld1q_f64( &(this->m_A[ i + 12 + this->m_dim * j ]) );
const float64x2_t qw_mat8 = vld1q_f64( &(this->m_A[ i + 14 + this->m_dim * j ]) );
const float64x2_t qw_col = { col_v, col_v };
const float64x2_t qw_mc1 = vmulq_f64( qw_mat1, qw_col );
const float64x2_t qw_mc2 = vmulq_f64( qw_mat2, qw_col );
const float64x2_t qw_mc3 = vmulq_f64( qw_mat3, qw_col );
const float64x2_t qw_mc4 = vmulq_f64( qw_mat4, qw_col );
const float64x2_t qw_mc5 = vmulq_f64( qw_mat5, qw_col );
const float64x2_t qw_mc6 = vmulq_f64( qw_mat6, qw_col );
const float64x2_t qw_mc7 = vmulq_f64( qw_mat7, qw_col );
const float64x2_t qw_mc8 = vmulq_f64( qw_mat8, qw_col );
qw_row_sum1 = vaddq_f64( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f64( qw_mc2, qw_row_sum2 );
qw_row_sum3 = vaddq_f64( qw_mc3, qw_row_sum3 );
qw_row_sum4 = vaddq_f64( qw_mc4, qw_row_sum4 );
qw_row_sum5 = vaddq_f64( qw_mc5, qw_row_sum5 );
qw_row_sum6 = vaddq_f64( qw_mc6, qw_row_sum6 );
qw_row_sum7 = vaddq_f64( qw_mc7, qw_row_sum7 );
qw_row_sum8 = vaddq_f64( qw_mc8, qw_row_sum8 );
}
const float64x2_t qw_b1 = vld1q_f64( &(this->m_b[i ]) );
const float64x2_t qw_b2 = vld1q_f64( &(this->m_b[i+ 2]) );
const float64x2_t qw_b3 = vld1q_f64( &(this->m_b[i+ 4]) );
const float64x2_t qw_b4 = vld1q_f64( &(this->m_b[i+ 6]) );
const float64x2_t qw_b5 = vld1q_f64( &(this->m_b[i+ 8]) );
const float64x2_t qw_b6 = vld1q_f64( &(this->m_b[i+10]) );
const float64x2_t qw_b7 = vld1q_f64( &(this->m_b[i+12]) );
const float64x2_t qw_b8 = vld1q_f64( &(this->m_b[i+14]) );
const float64x2_t qw_Dinv1 = vld1q_f64( &(this->m_Dinv[i ]) );
const float64x2_t qw_Dinv2 = vld1q_f64( &(this->m_Dinv[i+ 2]) );
const float64x2_t qw_Dinv3 = vld1q_f64( &(this->m_Dinv[i+ 4]) );
const float64x2_t qw_Dinv4 = vld1q_f64( &(this->m_Dinv[i+ 6]) );
const float64x2_t qw_Dinv5 = vld1q_f64( &(this->m_Dinv[i+ 8]) );
const float64x2_t qw_Dinv6 = vld1q_f64( &(this->m_Dinv[i+10]) );
const float64x2_t qw_Dinv7 = vld1q_f64( &(this->m_Dinv[i+12]) );
const float64x2_t qw_Dinv8 = vld1q_f64( &(this->m_Dinv[i+14]) );
const float64x2_t qw_b_minus_sum1 = vsubq_f64( qw_b1, qw_row_sum1 );
const float64x2_t qw_b_minus_sum2 = vsubq_f64( qw_b2, qw_row_sum2 );
const float64x2_t qw_b_minus_sum3 = vsubq_f64( qw_b3, qw_row_sum3 );
const float64x2_t qw_b_minus_sum4 = vsubq_f64( qw_b4, qw_row_sum4 );
const float64x2_t qw_b_minus_sum5 = vsubq_f64( qw_b5, qw_row_sum5 );
const float64x2_t qw_b_minus_sum6 = vsubq_f64( qw_b6, qw_row_sum6 );
const float64x2_t qw_b_minus_sum7 = vsubq_f64( qw_b7, qw_row_sum7 );
const float64x2_t qw_b_minus_sum8 = vsubq_f64( qw_b8, qw_row_sum8 );
const float64x2_t qw_x1_1 = vmulq_f64( qw_b_minus_sum1 , qw_Dinv1 );
const float64x2_t qw_x1_2 = vmulq_f64( qw_b_minus_sum2 , qw_Dinv2 );
const float64x2_t qw_x1_3 = vmulq_f64( qw_b_minus_sum3 , qw_Dinv3 );
const float64x2_t qw_x1_4 = vmulq_f64( qw_b_minus_sum4 , qw_Dinv4 );
const float64x2_t qw_x1_5 = vmulq_f64( qw_b_minus_sum5 , qw_Dinv5 );
const float64x2_t qw_x1_6 = vmulq_f64( qw_b_minus_sum6 , qw_Dinv6 );
const float64x2_t qw_x1_7 = vmulq_f64( qw_b_minus_sum7 , qw_Dinv7 );
const float64x2_t qw_x1_8 = vmulq_f64( qw_b_minus_sum8 , qw_Dinv8 );
memcpy( &(this->m_x1[i ]), &qw_x1_1, sizeof(double)*2 );
memcpy( &(this->m_x1[i+ 2]), &qw_x1_2, sizeof(double)*2 );
memcpy( &(this->m_x1[i+ 4]), &qw_x1_3, sizeof(double)*2 );
memcpy( &(this->m_x1[i+ 6]), &qw_x1_4, sizeof(double)*2 );
memcpy( &(this->m_x1[i+ 8]), &qw_x1_5, sizeof(double)*2 );
memcpy( &(this->m_x1[i+10]), &qw_x1_6, sizeof(double)*2 );
memcpy( &(this->m_x1[i+12]), &qw_x1_7, sizeof(double)*2 );
memcpy( &(this->m_x1[i+14]), &qw_x1_8, sizeof(double)*2 );
}
}
}
}
virtual void calcX2ColMajor( const int row_begin, const int row_end_past_one ) {
if constexpr ( is_same< float,T >::value ) {
if ( m_factor_loop_unrolling == 1 ) {
for ( int i = row_begin; i < row_end_past_one; i += 4 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x1[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_x2_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
memcpy( &(this->m_x2[i ]), &qw_x2_1, sizeof(float)*4 );
}
}
else if ( m_factor_loop_unrolling == 2 ) {
for ( int i = row_begin; i < row_end_past_one; i += 8 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum2 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x1[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_mat2 = vld1q_f32( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
const float32x4_t qw_mc2 = vmulq_f32( qw_mat2, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f32( qw_mc2, qw_row_sum2 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_b2 = vld1q_f32( &(this->m_b[i+4]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_Dinv2 = vld1q_f32( &(this->m_Dinv[i+4]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_b_minus_sum2 = vsubq_f32( qw_b2, qw_row_sum2 );
const float32x4_t qw_x2_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
const float32x4_t qw_x2_2 = vmulq_f32( qw_b_minus_sum2 , qw_Dinv2 );
memcpy( &(this->m_x2[i ]), &qw_x2_1, sizeof(float)*4 );
memcpy( &(this->m_x2[i+4]), &qw_x2_2, sizeof(float)*4 );
}
}
else if ( m_factor_loop_unrolling == 4 ) {
for ( int i = row_begin; i < row_end_past_one; i += 16 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum2 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum3 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum4 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x1[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_mat2 = vld1q_f32( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float32x4_t qw_mat3 = vld1q_f32( &(this->m_A[ i + 8 + this->m_dim * j ]) );
const float32x4_t qw_mat4 = vld1q_f32( &(this->m_A[ i + 12 + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
const float32x4_t qw_mc2 = vmulq_f32( qw_mat2, qw_col );
const float32x4_t qw_mc3 = vmulq_f32( qw_mat3, qw_col );
const float32x4_t qw_mc4 = vmulq_f32( qw_mat4, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f32( qw_mc2, qw_row_sum2 );
qw_row_sum3 = vaddq_f32( qw_mc3, qw_row_sum3 );
qw_row_sum4 = vaddq_f32( qw_mc4, qw_row_sum4 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_b2 = vld1q_f32( &(this->m_b[i+ 4]) );
const float32x4_t qw_b3 = vld1q_f32( &(this->m_b[i+ 8]) );
const float32x4_t qw_b4 = vld1q_f32( &(this->m_b[i+12]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_Dinv2 = vld1q_f32( &(this->m_Dinv[i+ 4]) );
const float32x4_t qw_Dinv3 = vld1q_f32( &(this->m_Dinv[i+ 8]) );
const float32x4_t qw_Dinv4 = vld1q_f32( &(this->m_Dinv[i+12]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_b_minus_sum2 = vsubq_f32( qw_b2, qw_row_sum2 );
const float32x4_t qw_b_minus_sum3 = vsubq_f32( qw_b3, qw_row_sum3 );
const float32x4_t qw_b_minus_sum4 = vsubq_f32( qw_b4, qw_row_sum4 );
const float32x4_t qw_x2_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
const float32x4_t qw_x2_2 = vmulq_f32( qw_b_minus_sum2 , qw_Dinv2 );
const float32x4_t qw_x2_3 = vmulq_f32( qw_b_minus_sum3 , qw_Dinv3 );
const float32x4_t qw_x2_4 = vmulq_f32( qw_b_minus_sum4 , qw_Dinv4 );
memcpy( &(this->m_x2[i ]), &qw_x2_1, sizeof(float)*4 );
memcpy( &(this->m_x2[i+ 4]), &qw_x2_2, sizeof(float)*4 );
memcpy( &(this->m_x2[i+ 8]), &qw_x2_3, sizeof(float)*4 );
memcpy( &(this->m_x2[i+12]), &qw_x2_4, sizeof(float)*4 );
}
}
else if ( m_factor_loop_unrolling == 8 ) {
for ( int i = row_begin; i < row_end_past_one; i += 32 ) {
float32x4_t qw_row_sum1 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum2 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum3 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum4 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum5 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum6 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum7 = { 0.0, 0.0, 0.0, 0.0 };
float32x4_t qw_row_sum8 = { 0.0, 0.0, 0.0, 0.0 };
for ( int j = 0; j < this->m_dim; j++ ) {
const float col_v = this->m_x1[j];
const float32x4_t qw_mat1 = vld1q_f32( &(this->m_A[ i + this->m_dim * j ]) );
const float32x4_t qw_mat2 = vld1q_f32( &(this->m_A[ i + 4 + this->m_dim * j ]) );
const float32x4_t qw_mat3 = vld1q_f32( &(this->m_A[ i + 8 + this->m_dim * j ]) );
const float32x4_t qw_mat4 = vld1q_f32( &(this->m_A[ i + 12 + this->m_dim * j ]) );
const float32x4_t qw_mat5 = vld1q_f32( &(this->m_A[ i + 16 + this->m_dim * j ]) );
const float32x4_t qw_mat6 = vld1q_f32( &(this->m_A[ i + 20 + this->m_dim * j ]) );
const float32x4_t qw_mat7 = vld1q_f32( &(this->m_A[ i + 24 + this->m_dim * j ]) );
const float32x4_t qw_mat8 = vld1q_f32( &(this->m_A[ i + 28 + this->m_dim * j ]) );
const float32x4_t qw_col = { col_v, col_v, col_v, col_v };
const float32x4_t qw_mc1 = vmulq_f32( qw_mat1, qw_col );
const float32x4_t qw_mc2 = vmulq_f32( qw_mat2, qw_col );
const float32x4_t qw_mc3 = vmulq_f32( qw_mat3, qw_col );
const float32x4_t qw_mc4 = vmulq_f32( qw_mat4, qw_col );
const float32x4_t qw_mc5 = vmulq_f32( qw_mat5, qw_col );
const float32x4_t qw_mc6 = vmulq_f32( qw_mat6, qw_col );
const float32x4_t qw_mc7 = vmulq_f32( qw_mat7, qw_col );
const float32x4_t qw_mc8 = vmulq_f32( qw_mat8, qw_col );
qw_row_sum1 = vaddq_f32( qw_mc1, qw_row_sum1 );
qw_row_sum2 = vaddq_f32( qw_mc2, qw_row_sum2 );
qw_row_sum3 = vaddq_f32( qw_mc3, qw_row_sum3 );
qw_row_sum4 = vaddq_f32( qw_mc4, qw_row_sum4 );
qw_row_sum5 = vaddq_f32( qw_mc5, qw_row_sum5 );
qw_row_sum6 = vaddq_f32( qw_mc6, qw_row_sum6 );
qw_row_sum7 = vaddq_f32( qw_mc7, qw_row_sum7 );
qw_row_sum8 = vaddq_f32( qw_mc8, qw_row_sum8 );
}
const float32x4_t qw_b1 = vld1q_f32( &(this->m_b[i ]) );
const float32x4_t qw_b2 = vld1q_f32( &(this->m_b[i+ 4]) );
const float32x4_t qw_b3 = vld1q_f32( &(this->m_b[i+ 8]) );
const float32x4_t qw_b4 = vld1q_f32( &(this->m_b[i+12]) );
const float32x4_t qw_b5 = vld1q_f32( &(this->m_b[i+16]) );
const float32x4_t qw_b6 = vld1q_f32( &(this->m_b[i+20]) );
const float32x4_t qw_b7 = vld1q_f32( &(this->m_b[i+24]) );
const float32x4_t qw_b8 = vld1q_f32( &(this->m_b[i+28]) );
const float32x4_t qw_Dinv1 = vld1q_f32( &(this->m_Dinv[i ]) );
const float32x4_t qw_Dinv2 = vld1q_f32( &(this->m_Dinv[i+ 4]) );
const float32x4_t qw_Dinv3 = vld1q_f32( &(this->m_Dinv[i+ 8]) );
const float32x4_t qw_Dinv4 = vld1q_f32( &(this->m_Dinv[i+12]) );
const float32x4_t qw_Dinv5 = vld1q_f32( &(this->m_Dinv[i+16]) );
const float32x4_t qw_Dinv6 = vld1q_f32( &(this->m_Dinv[i+20]) );
const float32x4_t qw_Dinv7 = vld1q_f32( &(this->m_Dinv[i+24]) );
const float32x4_t qw_Dinv8 = vld1q_f32( &(this->m_Dinv[i+28]) );
const float32x4_t qw_b_minus_sum1 = vsubq_f32( qw_b1, qw_row_sum1 );
const float32x4_t qw_b_minus_sum2 = vsubq_f32( qw_b2, qw_row_sum2 );
const float32x4_t qw_b_minus_sum3 = vsubq_f32( qw_b3, qw_row_sum3 );
const float32x4_t qw_b_minus_sum4 = vsubq_f32( qw_b4, qw_row_sum4 );
const float32x4_t qw_b_minus_sum5 = vsubq_f32( qw_b5, qw_row_sum5 );
const float32x4_t qw_b_minus_sum6 = vsubq_f32( qw_b6, qw_row_sum6 );
const float32x4_t qw_b_minus_sum7 = vsubq_f32( qw_b7, qw_row_sum7 );
const float32x4_t qw_b_minus_sum8 = vsubq_f32( qw_b8, qw_row_sum8 );
const float32x4_t qw_x2_1 = vmulq_f32( qw_b_minus_sum1 , qw_Dinv1 );
const float32x4_t qw_x2_2 = vmulq_f32( qw_b_minus_sum2 , qw_Dinv2 );
const float32x4_t qw_x2_3 = vmulq_f32( qw_b_minus_sum3 , qw_Dinv3 );
const float32x4_t qw_x2_4 = vmulq_f32( qw_b_minus_sum4 , qw_Dinv4 );
const float32x4_t qw_x2_5 = vmulq_f32( qw_b_minus_sum5 , qw_Dinv5 );
const float32x4_t qw_x2_6 = vmulq_f32( qw_b_minus_sum6 , qw_Dinv6 );
const float32x4_t qw_x2_7 = vmulq_f32( qw_b_minus_sum7 , qw_Dinv7 );
const float32x4_t qw_x2_8 = vmulq_f32( qw_b_minus_sum8 , qw_Dinv8 );