/** * Create a program with all the C source code content provided as argument. * @param srcs list of the content of source code for the program * @return a program that needs to be built */ public CLProgram createProgram(String... srcs) { return createProgram(null, srcs); }
/** * Create a program with all the C source code content provided as argument. * @param srcs list of the content of source code for the program * @return a program that needs to be built */ public CLProgram createProgram(String... srcs) { return createProgram(null, srcs); }
protected CLAbstractUserProgram(CLContext context, String rawSource) { this(context.createProgram(), rawSource); }
protected CLAbstractUserProgram(CLContext context, String rawSource) { this(context.createProgram(), rawSource); }
/** * Construct with the given OpenCL program source, given in * the form of {@link String}s. * @param context the OpenCL context to use * * @param programSrcs the source of the program */ public CLImageProcessor(CLContext context, String... programSrcs) { this.context = context; CLProgram program = context.createProgram(programSrcs); this.kernel = program.createKernels()[0]; }
/** * Construct with the given OpenCL program source, given in * the form of {@link String}s. * @param context the OpenCL context to use * * @param programSrcs the source of the program */ public CLImageAnalyser(CLContext context, String... programSrcs) { this.context = context; CLProgram program = context.createProgram(programSrcs); this.kernel = program.createKernels()[0]; }
/** * Construct with the given context. * @param context the context. */ public CLImageArithmetic(CLContext context) { try { this.context = context; CLProgram program = context.createProgram(IOUtils.toString(CLImageArithmetic.class.getResource("ImageArithmetic.cl"))); loadKernels(program); } catch (IOException e) { e.printStackTrace(); } }
public synchronized CLKernel getKernel(Fun1 op, Primitive prim) throws CLBuildException { EnumMap<Primitive, CLKernel> m = fun1Kernels.get(op); if (m == null) fun1Kernels.put(op, m = new EnumMap<Primitive, CLKernel>(Primitive.class)); CLKernel kers = m.get(prim); if (kers == null) { StringBuilder out = new StringBuilder(300); String name = createVectFun1Source(op, prim, out); CLProgram prog = getContext().createProgram(out.toString()).build(); kers = prog.createKernel(name); m.put(prim, kers); } return kers; }
public synchronized CLKernel getKernel(Fun1 op, Primitive prim) throws CLBuildException { EnumMap<Primitive, CLKernel> m = fun1Kernels.get(op); if (m == null) fun1Kernels.put(op, m = new EnumMap<Primitive, CLKernel>(Primitive.class)); CLKernel kers = m.get(prim); if (kers == null) { StringBuilder out = new StringBuilder(300); String name = createVectFun1Source(op, prim, out); CLProgram prog = getContext().createProgram(out.toString()).build(); kers = prog.createKernel(name); m.put(prim, kers); } return kers; }
public synchronized CLKernel getKernel(Fun2 op, Primitive prim1, Primitive prim2, Primitive primOut, boolean secondOperandIsScalar) throws CLBuildException { Map<PrimitiveTrio, CLKernel> m = fun2Kernels.get(op); if (m == null) fun2Kernels.put(op, m = new HashMap<PrimitiveTrio, CLKernel>()); PrimitiveTrio key = new PrimitiveTrio(prim1, prim2, primOut, secondOperandIsScalar); CLKernel ker = m.get(key); if (ker == null) { StringBuilder out = new StringBuilder(300); String name = createVectFun2Source(op, prim1, prim2, primOut, out, secondOperandIsScalar); CLProgram prog = getContext().createProgram(out.toString()).build(); ker = prog.createKernel(name); m.put(key, ker); } return ker; }
public synchronized CLKernel getKernel(Fun2 op, Primitive prim1, Primitive prim2, Primitive primOut, boolean secondOperandIsScalar) throws CLBuildException { Map<PrimitiveTrio, CLKernel> m = fun2Kernels.get(op); if (m == null) fun2Kernels.put(op, m = new HashMap<PrimitiveTrio, CLKernel>()); PrimitiveTrio key = new PrimitiveTrio(prim1, prim2, primOut, secondOperandIsScalar); CLKernel ker = m.get(key); if (ker == null) { StringBuilder out = new StringBuilder(300); String name = createVectFun2Source(op, prim1, prim2, primOut, out, secondOperandIsScalar); CLProgram prog = getContext().createProgram(out.toString()).build(); ker = prog.createKernel(name); m.put(key, ker); } return ker; }
public DFT(CLQueue queue) throws IOException, CLBuildException { this.queue = queue; this.context = queue.getContext(); String source = IOUtils.readText(DFT.class.getResource("DiscreteFourierTransformProgram.cl")); program = context.createProgram(source); kernel = program.createKernel("dft"); }
ProgramImpl(String opencl) { clProgram = clContext.createProgram(PRAGMA_DOUBLE_SUPPORT + opencl); CLKernel[] clKernels = clProgram.createKernels(); for (CLKernel clKernel : clKernels) { kernels.put(clKernel.getFunctionName(), clKernel); } }
/** * Restore a program previously saved with {@link CLProgram#store(java.io.OutputStream) } * @param in will be closed * @return a CLProgram object representing the previously saved program * @throws IOException */ public CLProgram loadProgram(InputStream in) throws IOException { Pair<Map<CLDevice, byte[]>, String> binaries = CLProgram.readBinaries(Arrays.asList(getDevices()), null, in); return createProgram(binaries.getFirst(), binaries.getSecond()); }
/** * Restore a program previously saved with {@link CLProgram#store(java.io.OutputStream) } * @param in will be closed * @return a CLProgram object representing the previously saved program * @throws IOException */ public CLProgram loadProgram(InputStream in) throws IOException { Pair<Map<CLDevice, byte[]>, String> binaries = CLProgram.readBinaries(Arrays.asList(getDevices()), null, in); return createProgram(binaries.getFirst(), binaries.getSecond()); }
private void compileProgram() throws Exception{ String sources = IOUtils.readText(BufferReadTest.class.getResourceAsStream("BufferReadTest.c")); program = context.createProgram(sources).build(); } private synchronized void initializeCLContextAndQueueOrNothing(int platformNumber, int deviceNumber) {
public <T> Object testArrayArg(String type, Object array, Class<T> targetType) { long size = BridJ.sizeOf(targetType); long length = Array.getLength(array); CLBuffer<Byte> out = context.createByteBuffer(Usage.Output, size * length); StringBuilder b = new StringBuilder( "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "kernel void f(" + type + length + " arg, global " + type + "* out, long length) {\n"); for (long i = 0; i < length; i++) { b.append("out[" + i + "] = arg.s" + (i < 10 ? i + "" : ((char)((int)'a' + (i - 10))) + "") + ";\n"); } b.append("}\n"); System.out.println(b); CLKernel k = context.createProgram(b.toString()).createKernel("f", array, out, length); CLEvent e = k.enqueueTask(queue); return out.as(targetType).read(queue, e).getArray(); }
CLProgram createProgram() { CLProgram pg = createContext().createProgram("__kernel void f(__global int* a) {}"); try { pg.build(); } catch (CLBuildException ex) { assertFalse(ex.toString(), true); } return pg; }
public <T> Pointer<T> testArg(String type, Object value, Class<T> targetType) { long size = BridJ.sizeOf(targetType); CLBuffer<Byte> out = context.createByteBuffer(Usage.Output, size) ; CLKernel k = context.createProgram( // "#if __OPENCL_VERSION__ <= CL_VERSION_1_1\n" + " #pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + // "#endif\n" + "kernel void f(" + type + " arg, global " + type + "* out, long size) {\n" + "char* in = (char*) &arg;\n" + "for (long i = 0; i < size; i++) {\n" + "out[i] = in[i];\n" + "}\n" + "}" ).createKernel("f", value, out, size); CLEvent e = k.enqueueTask(queue); return out.as(targetType).read(queue, e); }
@Test public void nullArg() { CLBuffer<Byte> out = context.createByteBuffer(Usage.InputOutput, 2) ; CLKernel isInputNull = context.createProgram( "kernel void isInputNull(global int* in, global bool* out) {\n" + "*out = !in;\n" + "}" ).createKernel("isInputNull"); isInputNull.setArgs(CLKernel.NULL_POINTER_KERNEL_ARGUMENT, out); assertTrue(out.read(queue, isInputNull.enqueueTask(queue)).as(Boolean.class).get()); isInputNull.setArgs(out, out); assertFalse(out.read(queue, isInputNull.enqueueTask(queue)).as(Boolean.class).get()); }