This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpMSpM-Multiply-Naive-Int.cl
91 lines (71 loc) · 1.91 KB
/
SpMSpM-Multiply-Naive-Int.cl
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
// To be replaced before kernel compiling
#define MAXROW %%AROW%%
#define MAXCOL %%BCOL%%
__kernel void spmm_kernel_naive(
__global const uint * restrict ArowPtr, __global const uint * restrict Acols,
__global const int * restrict Adata,
__global const uint * restrict BrowPtr, __global const uint * restrict Bcols,
__global const int * restrict Bdata,
__global int * denseVal)
{
int currRow = get_global_id(0);
int currCol = get_global_id(1);
if( !((currRow < MAXROW) && (currCol < MAXCOL)) )
{
return;
}
int ArowCur = ArowPtr[currRow];
int ArowEnd = ArowPtr[currRow+1];
int BrowCur = BrowPtr[currCol];
int BrowEnd = BrowPtr[currCol+1];
int AcurIdx = -1;
int BcurIdx = -1;
int localSum = 0;
while ((ArowCur < ArowEnd) && (BrowCur < BrowEnd)) {
AcurIdx = Acols[ArowCur];
BcurIdx = Bcols[BrowCur];
if (AcurIdx == BcurIdx) {
localSum += Adata[ArowCur] * Bdata[BrowCur];
ArowCur++;
BrowCur++;
} else if ( AcurIdx < BcurIdx) {
ArowCur++;
} else {
BrowCur++;
}
}
denseVal[currRow*MAXCOL + currCol] = localSum;
}
__kernel void spmm_binary_kernel_naive(
__global const uint * restrict ArowPtr, __global const uint * restrict Acols,
__global const uint * restrict BrowPtr, __global const uint * restrict Bcols,
__global int * denseVal)
{
int currRow = get_global_id(0);
int currCol = get_global_id(1);
if( !((currRow < MAXROW) && (currCol < MAXCOL)) )
{
return;
}
int ArowCur = ArowPtr[currRow];
int ArowEnd = ArowPtr[currRow+1];
int BrowCur = BrowPtr[currCol];
int BrowEnd = BrowPtr[currCol+1];
int AcurIdx = -1;
int BcurIdx = -1;
int localSum = 0;
while ((ArowCur < ArowEnd) && (BrowCur < BrowEnd)) {
AcurIdx = Acols[ArowCur];
BcurIdx = Bcols[BrowCur];
if (AcurIdx == BcurIdx) {
localSum += 1;
ArowCur++;
BrowCur++;
} else if ( AcurIdx < BcurIdx) {
ArowCur++;
} else {
BrowCur++;
}
}
denseVal[currRow*MAXCOL + currCol] = localSum;
}