X Tutup
Skip to content

Commit a036a57

Browse files
committed
JavaCL: added Primitive.getRequiredPragmas()
1 parent 7618e38 commit a036a57

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Blas/src/main/java/com/nativelibs4java/opencl/blas/CLKernels.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public class CLKernels {
3737

3838
private static volatile CLKernels instance;
3939

40-
private static final String PRAGMA_DOUBLE = "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n";
41-
4240
public static synchronized void setInstance(CLKernels kernels) {
4341
instance = kernels;
4442
}
@@ -120,7 +118,7 @@ public <V> boolean containsValue(Primitive primitive, CLBuffer<V> buffer, long l
120118
kernel = containsValueKernels.get(primitive);
121119
if (kernel == null) {
122120
kernel = context.createProgram((
123-
(primitive.primitiveType == double.class ? Primitive. PRAGMA_DOUBLE : "") +
121+
primitive.getRequiredPragmas() +
124122
"__kernel void containsValue( \n" +
125123
" __global const double* a, \n" +
126124
" int length, \n" +
@@ -153,7 +151,7 @@ public <V> CLEvent clear(Primitive primitive, CLBuffer<V> buffer, long length, C
153151
kernel = clearKernels.get(primitive);
154152
if (kernel == null) {
155153
kernel = context.createProgram((
156-
(primitive.primitiveType == double.class ? Primitive. PRAGMA_DOUBLE : "") +
154+
primitive.getRequiredPragmas() +
157155
"__kernel void clear_buffer( \n" +
158156
" __global double* a, \n" +
159157
" int length \n" +
@@ -188,7 +186,7 @@ public <T> CLEvent matrixMultiply(Primitive prim, CLBuffer<T> a, long aRows, lon
188186
kernel = matrixMultiplyKernels.get(prim);
189187
if (kernel == null) {
190188
String src =
191-
(prim.primitiveType == double.class ? Primitive. PRAGMA_DOUBLE : "") +
189+
prim.getRequiredPragmas() +
192190
"__kernel void mulMat( " +
193191
" __global const double* a, int aRows, int aColumns, " +
194192
" __global const double* b, int bColumns, " +
@@ -231,7 +229,7 @@ public <T> CLEvent matrixTranspose(Primitive prim, CLBuffer<T> a, long aRows, lo
231229
kernels = matrixTransposeKernels.get(prim);
232230
if (kernels == null) {
233231
String src =
234-
(prim.primitiveType == double.class ? Primitive. PRAGMA_DOUBLE : "") +
232+
prim.getRequiredPragmas() +
235233
"__kernel void transposeSelf( \n" +
236234
" __global double* a, int aRows, int aColumns \n" +
237235
") { \n" +

JavaCL/src/main/java/com/nativelibs4java/opencl/util/Primitive.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public enum Primitive {
5959
public String clTypeName() {
6060
return name().toLowerCase();
6161
}
62+
public String getRequiredPragmas() {
63+
if (primitiveType == Double.class)
64+
return "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n";
65+
return "";
66+
}
6267
}

0 commit comments

Comments
 (0)
X Tutup