-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJacobiKernel.cl
More file actions
159 lines (125 loc) · 5.96 KB
/
JacobiKernel.cl
File metadata and controls
159 lines (125 loc) · 5.96 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
__kernel void JacobiKernel(
__global const double* pOriginUMatrix,
__global const double* pFMatrix,
__global double* pResultUMatrix,
__global const double* pStaticUMatrix,
__local double* pLocalUValues,
double h2,
int matrixStride)
{
int localColumn = get_local_id(0);
int localUValuesStride = get_local_size(0);
int lastLocalColumn = localUValuesStride - 1;
int localRow = get_local_id(1);
int lastLocalRow = get_local_size(1) - 1;
int lastGlobalColumnRow = matrixStride - 2;
for(int c = 0; c < lastGlobalColumnRow; c = c + localUValuesStride)
for(int r = 0; r < lastGlobalColumnRow; r = r + get_local_size(1))
{
int globalColumn = c + localColumn;//get_global_id(0);
int globalRow = r + localRow;//get_global_id(1);
if(lastLocalColumn > 0 && globalColumn == lastGlobalColumnRow - 1)
lastLocalColumn = localUValuesStride - 2;
if(lastLocalRow > 0 && globalRow == lastGlobalColumnRow - 1)
lastLocalRow = get_local_size(1) - 2;
if(globalColumn < lastGlobalColumnRow && globalRow < lastGlobalColumnRow)
{
pLocalUValues[localRow * localUValuesStride + localColumn] = pOriginUMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 1];
barrier(CLK_LOCAL_MEM_FENCE);
double topUValue;
if(localRow == 0)
topUValue = pOriginUMatrix[globalRow * (matrixStride) + globalColumn + 1];
else
topUValue = pLocalUValues[(localRow - 1) * localUValuesStride + localColumn];
double leftUValue;
if(localColumn == 0)
leftUValue = pOriginUMatrix[(globalRow + 1) * (matrixStride) + globalColumn];
else
leftUValue = pLocalUValues[localRow * localUValuesStride + localColumn - 1];
double rightUValue;
if(localColumn == lastLocalColumn)
rightUValue = pOriginUMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 2];
else
rightUValue = pLocalUValues[localRow * localUValuesStride + localColumn + 1];
double bottomUValue;
if(localRow == lastLocalRow)
bottomUValue = pOriginUMatrix[(globalRow + 2) * (matrixStride) + globalColumn + 1];
else
bottomUValue = pLocalUValues[(localRow + 1) * localUValuesStride + localColumn];
pResultUMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 1] =
1./4. * (topUValue + leftUValue + rightUValue + bottomUValue +
pFMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 1] * h2);
barrier(CLK_GLOBAL_MEM_FENCE);
}
}
// if(globalColumn < lastGlobalColumnRow && globalRow < lastGlobalColumnRow)
// {
// double topUValue;
// topUValue = pOriginUMatrix[globalRow * (matrixStride) + globalColumn + 1];
// double leftUValue;
// leftUValue = pOriginUMatrix[(globalRow + 1) * (matrixStride) + globalColumn];
// double rightUValue;
// rightUValue = pOriginUMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 2];
// double bottomUValue;
// bottomUValue = pOriginUMatrix[(globalRow + 2) * (matrixStride) + globalColumn + 1];
// pResultUMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 1] =
// 1./4. * (topUValue + leftUValue + rightUValue + bottomUValue +
// pFMatrix[(globalRow + 1) * (matrixStride) + globalColumn + 1] * h2);
// }
// }
// int column = get_global_id(0);
// int row = get_global_id(1);
// int lastDummyColumn = matrixStride - 2;
// int localColumn = get_local_id(0);
// int lastLocalColumn = get_local_size(0) - 1;
// if(column < lastDummyColumn)
// {
// pLocalUValues[localColumn] = pOriginUMatrix[(row + 1) * (matrixStride) + column + 1];
// barrier(CLK_LOCAL_MEM_FENCE);
// if(localColumn > 0 && localColumn < lastLocalColumn && column < (lastDummyColumn - 1))
// {
// pResultUMatrix[(row + 1) * (matrixStride) + column + 1] =
// native_divide
// (
// pOriginUMatrix[row * (matrixStride) + column + 1] +
//// pOriginUMatrix[(row + 1) * (matrixStride) + column] +
//// pOriginUMatrix[(row + 1) * (matrixStride) + column + 2] +
// pLocalUValues[localColumn - 1] +
// pLocalUValues[localColumn + 1] +
// pOriginUMatrix[(row + 2) * (matrixStride) + column + 1] +
// pFMatrix[(row + 1) * (matrixStride) + column + 1] * h2, 4.
// );
// }
// else
// {
// if(localColumn == 0)
// {
// pResultUMatrix[(row + 1) * (matrixStride) + column + 1] =
// native_divide
// (
// pOriginUMatrix[row * (matrixStride) + column + 1] +
// pOriginUMatrix[(row + 1) * (matrixStride) + column] +
//// pOriginUMatrix[(row + 1) * (matrixStride) + column + 2] +
// pLocalUValues[localColumn + 1] +
// pOriginUMatrix[(row + 2) * (matrixStride) + column + 1] +
// pFMatrix[(row + 1) * (matrixStride) + column + 1] * h2, 4.
// );
// }
// else
// {
// pResultUMatrix[(row + 1) * (matrixStride) + column + 1] =
// native_divide
// (
// pOriginUMatrix[row * (matrixStride) + column + 1] +
//// pOriginUMatrix[(row + 1) * (matrixStride) + column] +
// pLocalUValues[localColumn - 1] +
// pOriginUMatrix[(row + 1) * (matrixStride) + column + 2] +
// pOriginUMatrix[(row + 2) * (matrixStride) + column + 1] +
// pFMatrix[(row + 1) * (matrixStride) + column + 1] * h2, 4.
// );
// }
// }
// }
//// else
//// barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
}