-
Notifications
You must be signed in to change notification settings - Fork 5
/
fusedMM.c
749 lines (694 loc) · 20.7 KB
/
fusedMM.c
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
#ifdef __cplusplus
extern "C"
{
#endif
#include<stdint.h>
#include<stdio.h>
#include <omp.h>
#include"kernels/include/kernels.h"
#ifdef DREAL
#define VALUETYPE double
#else
#define VALUETYPE float
#endif
#include "fusedMM.h"
#include "fusedMM_internal.h"
#define fmax(x,y) ( (x) > (y) ? (x) : (y))
#define fmin(x,y) ( (x) < (y) ? (x) : (y))
#define fabs(x) ( (x) >= 0 ? (x) : -(y))
/*============================================================================
* VOP (Vector-vector operation)
* format: out = lhs op rhs
*============================================================================*/
int KERN_VOP_COPY_LHS (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = lhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VOP_COPY_RHS (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VOP_ADD (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != rhs_dim && lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = lhs[i] + rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VOP_SUBL (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != rhs_dim && lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = - lhs[i] + rhs[i]; // subtract lhs from rhs
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VOP_SUBR (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != rhs_dim && lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = lhs[i] - rhs[i]; //subtract rhs from lhs
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VOP_MAX (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != rhs_dim && lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = fmax(lhs[i], rhs[i]);
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VOP_MIN (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != rhs_dim && lhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < out_dim; i++)
out[i] = fmin(lhs[i], rhs[i]);
return FUSEDMM_SUCCESS_RETURN;
}
/* ============================================================================
* ROP (Reduction operation)
*
*============================================================================*/
int KERN_ROP_NOOP (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, VALUETYPE *out)
{
/* Dummy function : no operation */
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_ROP_DOT (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, VALUETYPE *out)
{
#ifdef DEBUG
if (lhs_dim != rhs_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
*out = 0.0;
for (INDEXTYPE i = 0; i < lhs_dim; i++)
*out += lhs[i]*rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_ROP_ADD_LHS (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, VALUETYPE *out)
{
*out = 0.0;
for (INDEXTYPE i = 0; i < lhs_dim; i++)
*out += lhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_ROP_ADD_RHS (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, VALUETYPE *out)
{
*out = 0.0;
for (INDEXTYPE i = 0; i < rhs_dim; i++)
*out += rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_ROP_NORML (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, VALUETYPE *out)
{
*out = 0.0;
for (INDEXTYPE i = 0; i < rhs_dim; i++)
*out += lhs[i] * lhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_ROP_NORMR (INDEXTYPE lhs_dim, const VALUETYPE *lhs, INDEXTYPE rhs_dim,
const VALUETYPE *rhs, VALUETYPE *out)
{
*out = 0.0;
for (INDEXTYPE i = 0; i < rhs_dim; i++)
*out += rhs[i] * rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
/* ============================================================================
* SOP operation
* mostly user defined, default NOOP
*=============================================================================*/
int KERN_SOP_COPY(VALUETYPE val, VALUETYPE *out)
{
*out = val;
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_SOP_NOOP(VALUETYPE val, VALUETYPE *out)
{
// dummy function to avoid extra checking
return FUSEDMM_SUCCESS_RETURN;
}
/* ============================================================================
* VSC/MOP operation
* Format: out = scalar op rhs //output (vector), lhs(scalar), rhs(vector)
* Elementwise mult/add
*============================================================================*/
int KERN_VSC_NOOP(INDEXTYPE rhs_dim, const VALUETYPE *rhs, VALUETYPE scal,
INDEXTYPE out_dim, VALUETYPE *out)
{
// dummy function to avoid extra checking
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VSC_MUL(INDEXTYPE rhs_dim, const VALUETYPE *rhs, VALUETYPE scal,
INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (rhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < rhs_dim; i++)
out[i] = scal * rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_VSC_ADD(INDEXTYPE rhs_dim, const VALUETYPE *rhs, VALUETYPE scal,
INDEXTYPE out_dim, VALUETYPE *out)
{
#ifdef DEBUG
if (rhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < rhs_dim; i++)
out[i] = scal + rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
/* ============================================================================
* AOP (Accumulate operation)
* Format: out = out op rhs
*
*=============================================================================*/
int KERN_AOP_NOOP(INDEXTYPE rhs_dim, const VALUETYPE *rhs, INDEXTYPE out_dim,
VALUETYPE *out)
{
// dummy function to avoid extra checking
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_AOP_MUL(INDEXTYPE rhs_dim, const VALUETYPE *rhs, INDEXTYPE out_dim,
VALUETYPE *out)
{
#ifdef DEBUG
if (rhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < rhs_dim; i++)
out[i] *= rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_AOP_ADD(INDEXTYPE rhs_dim, const VALUETYPE *rhs, INDEXTYPE out_dim,
VALUETYPE *out)
{
#ifdef DEBUG
if (rhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < rhs_dim; i++)
out[i] += rhs[i];
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_AOP_MAX(INDEXTYPE rhs_dim, const VALUETYPE *rhs, INDEXTYPE out_dim,
VALUETYPE *out)
{
#ifdef DEBUG
if (rhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < rhs_dim; i++)
out[i] = fmax (out[i], rhs[i]);
return FUSEDMM_SUCCESS_RETURN;
}
int KERN_AOP_MIN(INDEXTYPE rhs_dim, const VALUETYPE *rhs, INDEXTYPE out_dim,
VALUETYPE *out)
{
#ifdef DEBUG
if (rhs_dim != out_dim)
{
fprintf(stderr, "dimension of lhs and rhs are not same!!!");
return FUSEDMM_FAIL_RETURN;
}
#endif
for (INDEXTYPE i = 0; i < rhs_dim; i++)
out[i] = fmin (out[i], rhs[i]);
return FUSEDMM_SUCCESS_RETURN;
}
/*=============================================================================
* Select funciton based on imessage
*
*============================================================================*/
FP_VOP_FUNC GetVOPFunc(int32_t msg)
{
FP_VOP_FUNC VOP_FUNC;
switch(msg)
{
/* no way, need to update T
* case VOP_NOOP:
VOP_FUNC = NULL;
break;
*/
case VOP_COPY_LHS:
VOP_FUNC = KERN_VOP_COPY_LHS;
break;
case VOP_COPY_RHS:
VOP_FUNC = KERN_VOP_COPY_RHS;
break;
case VOP_ADD:
VOP_FUNC = KERN_VOP_ADD;
break;
case VOP_SUBL:
VOP_FUNC = KERN_VOP_SUBL;
break;
case VOP_SUBR:
VOP_FUNC = KERN_VOP_SUBR;
break;
case VOP_MAX:
VOP_FUNC = KERN_VOP_MAX;
break;
case VOP_MIN:
VOP_FUNC = KERN_VOP_MIN;
break;
case VOP_UDEF:
VOP_FUNC = VOP_UDEF_FUNC;
break;
default:
fprintf(stderr, "Unknown VOP Message\n");
return NULL;
}
return VOP_FUNC;
}
FP_ROP_FUNC GetROPFunc(int32_t msg)
{
FP_ROP_FUNC ROP_FUNC;
switch(msg)
{
case ROP_NOOP:
ROP_FUNC = KERN_ROP_NOOP;
break;
case ROP_DOT:
ROP_FUNC = KERN_ROP_DOT;
break;
case ROP_ADD_LHS:
ROP_FUNC = KERN_ROP_ADD_LHS;
break;
case ROP_ADD_RHS:
ROP_FUNC = KERN_ROP_ADD_RHS;
break;
case ROP_NORML:
ROP_FUNC = KERN_ROP_NORML;
break;
case ROP_NORMR:
ROP_FUNC = KERN_ROP_NORMR;
break;
case ROP_UDEF:
ROP_FUNC = ROP_UDEF_FUNC;
break;
default:
fprintf(stderr, "Unknown ROP Message\n");
return NULL;
}
return(ROP_FUNC);
}
FP_SOP_FUNC GetSOPFunc(int32_t msg)
{
FP_SOP_FUNC SOP_FUNC;
switch(msg)
{
case SOP_NOOP:
SOP_FUNC = KERN_SOP_NOOP;
break;
case SOP_COPY:
SOP_FUNC = KERN_SOP_COPY;
break;
case SOP_UDEF:
SOP_FUNC = SOP_UDEF_FUNC;
break;
default:
fprintf(stderr, "Unknown SOP Message\n");
return NULL;
}
return(SOP_FUNC);
}
FP_VSC_FUNC GetVSCFunc(int32_t msg)
{
FP_VSC_FUNC VSC_FUNC;
switch(msg)
{
case VSC_NOOP:
VSC_FUNC = KERN_VSC_NOOP;
break;
case VSC_MUL:
VSC_FUNC = KERN_VSC_MUL;
break;
case VSC_ADD:
VSC_FUNC = KERN_VSC_ADD;
break;
case VSC_UDEF:
VSC_FUNC = VSC_UDEF_FUNC;
break;
default:
fprintf(stderr, "Unknown VSC Message\n");
return NULL;
}
return(VSC_FUNC);
}
FP_AOP_FUNC GetAOPFunc(int32_t msg)
{
FP_AOP_FUNC AOP_FUNC;
switch(msg)
{
case AOP_NOOP:
AOP_FUNC = KERN_AOP_NOOP;
break;
case AOP_ADD:
AOP_FUNC = KERN_AOP_ADD;
break;
case AOP_MAX:
AOP_FUNC = KERN_AOP_MAX;
break;
case AOP_MIN:
AOP_FUNC = KERN_AOP_MIN;
break;
case AOP_UDEF:
AOP_FUNC = AOP_UDEF_FUNC;
break;
default:
fprintf(stderr, "Unknown AOP Message\n");
return NULL;
}
return(AOP_FUNC);
}
int fusedMM_csr
(
const int32_t imessage, // message to dictate the operations
const INDEXTYPE m, // number of row of X
const INDEXTYPE n, // number of row of Y
const INDEXTYPE k, // dimension (col of X or Y)
const VALUETYPE alpha, // not used yet
const INDEXTYPE nnz, // nonzeros in sparse matrix
const INDEXTYPE rows, // number of rows in sparse matrix
const INDEXTYPE cols, // number of columns in sparse matrix
const VALUETYPE *val, // value of non-zeros
const INDEXTYPE *indx, // colids -> column indices
const INDEXTYPE *pntrb, // starting of rowptr for each row
const INDEXTYPE *pntre, // ending of rowptr for each row
const VALUETYPE *x, // Dense X matrix
const INDEXTYPE ldx, // 1eading dimension of X
const VALUETYPE *y, // Dense Y matrix
const INDEXTYPE ldy, // leading dimension of Y
const VALUETYPE beta, // beta value
VALUETYPE *z, // Dense matrix Z
const INDEXTYPE ldz // leading dimension size of z
)
{
int status = 0;
#ifdef ENABLE_OPT_FUSEDMM
/* ============================================================================
* call Predefined optimized kernel :
* NOTE that optimized kernel can call user defined SOP_UDEF function
* TODO: update parameterized code generator to support all vector ops.
* For now, we only support VSC_MUL and AOP_ADD which can easily
* be extended for all other vector operations.
* ===========================================================================*/
/*
* Check for GCN pattern
*/
if ( GET_VOP_FLAG(imessage) == VOP_COPY_RHS
&& GET_ROP_FLAG(imessage) == ROP_NOOP
&& GET_SOP_FLAG(imessage) == SOP_NOOP
&& GET_VSC_FLAG(imessage) == VSC_NOOP
&& GET_AOP_FLAG(imessage) == AOP_ADD)
{
#ifdef DREAL
dgfusedMM_csr('g', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#else
sgfusedMM_csr('g', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#endif
return status;
}
/*
* Check for SPMM
*/
if ( GET_VOP_FLAG(imessage) == VOP_COPY_RHS
&& GET_ROP_FLAG(imessage) == ROP_NOOP
&& GET_SOP_FLAG(imessage) == SOP_COPY
&& GET_VSC_FLAG(imessage) == VSC_MUL
&& GET_AOP_FLAG(imessage) == AOP_ADD)
{
#ifdef DREAL
dgfusedMM_csr('m', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#else
sgfusedMM_csr('m', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#endif
return status;
}
/*
* check for sigmoid kernel
* NOTE: optfusedmm can call SOP_UDEF
*/
if ( GET_VOP_FLAG(imessage) == VOP_COPY_RHS
&& GET_ROP_FLAG(imessage) == ROP_DOT
&& GET_SOP_FLAG(imessage) == SOP_UDEF
&& GET_VSC_FLAG(imessage) == VSC_MUL
&& GET_AOP_FLAG(imessage) == AOP_ADD)
{
#ifdef DREAL
dgfusedMM_csr('s', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#else
sgfusedMM_csr('s', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#endif
return status;
}
/*
* Check for t-dist / FR : SOP_UDEF may be different
* NOTE: optfusedmm calls SOP_UDEF
*/
if ( GET_VOP_FLAG(imessage) == VOP_SUBR
&& GET_ROP_FLAG(imessage) == ROP_NORMR
&& GET_SOP_FLAG(imessage) == SOP_UDEF
&& GET_VSC_FLAG(imessage) == VSC_MUL
&& GET_AOP_FLAG(imessage) == AOP_ADD)
{
//fprintf(stdout, "calling optimized t-dist\n");
#ifdef DREAL
dgfusedMM_csr('t', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#else
sgfusedMM_csr('t', m, n, k, alpha, nnz, rows, cols, val,
indx, pntrb, pntre, x, ldx, y, ldy, beta, z, ldz);
#endif
return status;
}
/*
* Reaching here means, we don't have matching optFusedMM. By default, we call
* general
*/
#ifdef MUST_OPT_FUSEDMM
fprintf(stderr, "NO opt implementation for this message! \n");
fprintf(stderr,
"Run the general FusedMM by not enabling ENABLE_OPT_FUSEDMM\n");
return FUSEDMM_NO_OPT_IMPL;
#endif
#endif
/* ===========================================================================*/
/*
* Select appropriate operation based on the message
*/
FP_VOP_FUNC VOP_FUNC = GetVOPFunc(GET_VOP_FLAG(imessage));
if(!VOP_FUNC)
return FUSEDMM_VOP_FAIL_RETURN;
FP_ROP_FUNC ROP_FUNC = GetROPFunc(GET_ROP_FLAG(imessage));
if(!ROP_FUNC)
return FUSEDMM_ROP_FAIL_RETURN;
FP_SOP_FUNC SOP_FUNC = GetSOPFunc(GET_SOP_FLAG(imessage));
if(!SOP_FUNC)
return FUSEDMM_SOP_FAIL_RETURN;
FP_VSC_FUNC VSC_FUNC = GetVSCFunc(GET_VSC_FLAG(imessage));
if(!VSC_FUNC)
return FUSEDMM_VSC_FAIL_RETURN;
FP_AOP_FUNC AOP_FUNC = GetAOPFunc(GET_AOP_FLAG(imessage));
if(!AOP_FUNC)
return FUSEDMM_AOP_FAIL_RETURN;
/*
* Implementation
*/
#if defined(PTTIME) && defined(LOAD_BALANCE)
omp_set_num_threads(NTHREADS);
#pragma omp parallel reduction(+:status)
{
INDEXTYPE RowPerThd, tt;
INDEXTYPE i, rowb, rowe;
INDEXTYPE Mnnz = 0; /* non-zero count in M rows */
INDEXTYPE deg, cumRow, curRow;
INDEXTYPE id = omp_get_thread_num();
INDEXTYPE nthreads = omp_get_num_threads();
// ASSUMPTION: dimension k is small enough to fit in stack,
// need to use some efficient allocator otherwise
VALUETYPE T[k]; /* temporary space to hold result of vector compute */
for (i=0; i < m; i++)
Mnnz += (pntre[i] - pntrb[i]);
RowPerThd = Mnnz / nthreads;
curRow = cumRow = 0;
tt = 1;
rowe = -1; /* init */
/* set rowstart for 1st thread */
if (id == 0)
rowb = 0;
for (i=0; i < m; i++)
{
deg = pntre[i] - pntrb[i];
cumRow += deg;
curRow += deg;
if (curRow > RowPerThd)
{
if (tt == id)
rowb = i;
else if (tt == id+1)
rowe = i;
curRow = 0;
RowPerThd = (Mnnz - cumRow) / (nthreads - tt);
tt += 1;
}
}
if (tt == id+1)
rowe = m;
for (i=rowb; i < rowe; i++)
#else /* not LBD or not PTTIME */
#ifdef PTTIME
#ifdef NTHREADS
omp_set_num_threads(NTHREADS);
#endif
#ifdef DYNAMIC
#ifdef DEBUG
#pragma omp parallel for schedule(dynamic) reduction(+:status)
#else
#pragma omp parallel for schedule(dynamic)
#endif
#else
#ifdef DEBUG
#pragma omp parallel for schedule(static) reduction(+:status)
#else
#pragma omp parallel for schedule(static)
#endif
#endif
#endif
for (INDEXTYPE i = 0; i < m; i++)
#endif
{
const VALUETYPE *lhs = x + i * ldx; // Xi
VALUETYPE *O = z + i * ldz; // Zi
#ifndef LOAD_BALANCE
// ASSUMPTION: feature dimension k is small enough to fit in stack,
// need to use some efficient allocator otherwise
VALUETYPE T[k]; /* temporary space to hold result of vector compute */
#endif
for (INDEXTYPE j=pntrb[i]; j < pntre[i]; j++)
{
VALUETYPE scal, out;
const VALUETYPE *cT = T; /* where T is const */
INDEXTYPE cid = indx[j];
const VALUETYPE *rhs = y + cid * ldy;
/*
* scal init with val be default to manage SPMM type operation
* It will be overwritten when ROP is used
* HERE HERE, default value of out???
*/
scal = val[j];
#ifdef DEBUG
status +=
#endif
VOP_FUNC(k,lhs,k,rhs,k,T);
#ifdef DEBUG
status +=
#endif
ROP_FUNC(k,lhs,k,cT, &scal);
#ifdef DEBUG
status +=
#endif
SOP_FUNC(scal, &out);
#ifdef DEBUG
status +=
#endif
VSC_FUNC(k,T,out, k,T);
#ifdef DEBUG
status +=
#endif
AOP_FUNC(k, T, k, O);
}
}
#if defined(PTTIME) && defined(LOAD_BALANCE)
}
#endif
return status;
}
#ifdef __cplusplus
} // extern "C"
#endif