29package com.jogamp.opencl;
31import com.jogamp.opencl.test.util.UITestCase;
32import com.jogamp.opencl.util.CLBuildConfiguration;
33import com.jogamp.opencl.util.CLProgramConfiguration;
34import com.jogamp.common.nio.Buffers;
35import com.jogamp.opencl.CLProgram.Status;
36import com.jogamp.opencl.util.CLBuildListener;
37import com.jogamp.opencl.llb.CL;
40import java.io.FileInputStream;
41import java.io.FileOutputStream;
42import java.io.IOException;
43import java.io.ObjectInputStream;
44import java.io.ObjectOutputStream;
45import java.nio.ByteBuffer;
47import java.util.concurrent.CountDownLatch;
49import org.junit.FixMethodOrder;
52import org.junit.rules.TemporaryFolder;
53import org.junit.runners.MethodSorters;
55import static org.junit.Assert.*;
56import static java.lang.System.*;
57import static com.jogamp.common.os.Platform.is32Bit;
58import static com.jogamp.opencl.CLException.newException;
59import static com.jogamp.opencl.CLProgram.CompilerOptions.*;
60import static com.jogamp.opencl.llb.CL12.CL_KERNEL_GLOBAL_WORK_SIZE;
61import static com.jogamp.opencl.llb.CL.CL_SUCCESS;
67@FixMethodOrder(MethodSorters.NAME_ASCENDING)
71 public TemporaryFolder tmpFolder =
new TemporaryFolder();
93 fail(
"expected exception but got none :(");
107 assertNotNull(kernel);
118 assertNotNull(kernel);
127 .
build(ENABLE_MAD, WARNINGS_ARE_ERRORS);
131 assertFalse(binaries.isEmpty());
134 for (
final CLDevice device : devices) {
135 assertTrue(binaries.containsKey(device));
151 assertEquals(program.
getSource().length(), 0);
159 assertNotNull(kernels);
160 assertEquals(kernels.size(), 0);
186 assertEquals(program.
getSource().length(), 0);
193 fail(
"expected an exception from createCLKernels but got: "+kernels);
211 private void builderImpl(
final boolean sync)
throws IOException, ClassNotFoundException, InterruptedException {
237 out.println(builder);
244 assertEquals(outerProgram, program);
247 final CountDownLatch countdown =
new CountDownLatch(1);
248 final CLProgram outerProgram = program;
250 final CLBuildListener buildCallback =
new CLBuildListener() {
252 public void buildFinished(
final CLProgram program) {
253 assertEquals(outerProgram, program);
254 countdown.countDown();
264 final File file = tmpFolder.newFile(
"foobar.builder");
265 final ObjectOutputStream oos =
new ObjectOutputStream(
new FileOutputStream(file));
270 ObjectInputStream ois =
new ObjectInputStream(
new FileInputStream(file));
271 final CLBuildConfiguration buildConfig = CLProgramBuilder.loadConfiguration(ois);
274 assertEquals(builder, buildConfig);
276 buildConfig.build(program);
280 ois =
new ObjectInputStream(
new FileInputStream(file));
281 final CLProgramConfiguration programConfig = CLProgramBuilder.loadConfiguration(ois, context);
282 assertNotNull(programConfig.getProgram());
284 program = programConfig.
build();
288 assertEquals(builder, builder.
clone());
295 public void test10BuilderSync() throws IOException, ClassNotFoundException, InterruptedException {
304 private static final String test20KernelSource =
"__attribute__((reqd_work_group_size(1, 1, 1))) kernel void foo(float a, int b, short c) { }\n";
315 assertNotNull(kernel);
319 out.println(
"compile workgroup size: " + wgs[0]+
" "+wgs[1]+
" "+wgs[2]);
321 assertEquals(1, wgs[0]);
322 assertEquals(1, wgs[1]);
323 assertEquals(1, wgs[2]);
339 fail(
"exception not thrown");
340 }
catch (
final IndexOutOfBoundsException expected){ }
353 final String source =
"kernel void foo(int a) { }\n"+
354 "kernel void bar(float b) { }\n";
362 for (
final CLKernel kernel : kernels.values()) {
363 out.println(
"kernel: "+kernel.toString());
366 assertNotNull(kernels.get(
"foo"));
367 assertNotNull(kernels.get(
"bar"));
369 kernels.get(
"foo").setArg(0, 42);
370 kernels.get(
"bar").setArg(0, 3.14f);
391 assertNotNull(kernel);
394 out.println(
"preferred workgroup size multiple: " + pwgsm);
397 out.println(
"private mem size: " + pms);
404 public void test60Load() throws IOException, ClassNotFoundException, InterruptedException {
405 for(
int i = 0; i < 100; i++) {
406 test02RebuildProgram();
407 test11BuilderAsync();
408 test03ProgramBinaries();
412 public static void main(
final String[] args)
throws IOException {
414 org.junit.runner.JUnitCore.
main(tstname);
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
CLDevice[] getDevices()
Returns all devices associated with this CLContext.
CLProgram createProgram(final String src)
Creates a program from the given sources, the returned program is not build yet.
static CLContext create()
Creates a context on all available devices (CL_DEVICE_TYPE_ALL).
CLDevice getMaxFlopsDevice()
Returns the device with maximal FLOPS from this context.
CLPlatform getPlatform()
Returns the CLPlatform this context is running on.
This object represents an OpenCL device.
Main Exception type for runtime OpenCL errors and failed function calls (e.g.
String getCLErrorString()
Returns a human readable String for the OpenCL error code.
High level abstraction for an OpenCL Kernel.
CLKernel rewind()
Resets the argument index to 0.
long[] getCompileWorkGroupSize(final CLDevice device)
Returns the work-group size specified by the attribute((reqd_work_group_size(X, Y,...
int position()
Returns the argument index used in the relative putArt(...) methods.
CLKernel putArg(final CLMemory<?> value)
long getPrivateMemSize(final CLDevice device)
Returns the number of bytes of private memory used by each work item in the kernel.
long getPreferredWorkGroupSizeMultiple(final CLDevice device)
Returns the preferred multiple of workgroup size to use for kernel launch.
CLProgramBuilder is a helper for building programs with more complex configurations or building multi...
static CLBuildConfiguration createConfiguration()
Creates a new CLBuildConfiguration.
void test22KerneWorkGrouplInfo()
Test of getting new kernel work group information, including those from OpenCL versions newer than 1....
static void main(final String[] args)
void test03ProgramBinaries()
void test02RebuildProgram()
void test11BuilderAsync()
Represents a OpenCL program executed on one or more CLDevices.
String getBuildLog()
Returns the build log of this program on all devices.
boolean isExecutable()
Returns true if the build status 'BUILD_SUCCESS' for at least one device of this program exists.
CLProgramConfiguration prepare()
Prepares the build for this program by returning a new CLProgramConfiguration.
Map< CLDevice, byte[]> getBinaries()
Returns the binaries for this program in an ordered Map containing the device as key and the program ...
String getSource()
Returns the source code of this program.
CLProgram build()
Builds this program for all devices associated with the context.
CLDevice[] getCLDevices()
Returns all devices associated with this program.
Map< CLDevice, Status > getBuildStatus()
Returns the build status enum of this program for each device as Map.
Map< String, CLKernel > createCLKernels()
Creates all kernels of this program and stores them a Map with the kernel name as key.
void release()
Releases this program with its kernels.
CLKernel createCLKernel(final String kernelName)
Creates a kernel with the specified kernel name.
Configures the mapping process.
static Status valueOf(final int clBuildStatus)
Java bindings to OpenCL, the Open Computing Language.
static final int CL_INVALID_PROGRAM_EXECUTABLE
Define "CL_INVALID_PROGRAM_EXECUTABLE" with expression '-45', CType: int.
Configuration representing everything needed to build an OpenCL program.
CLBuildConfiguration forDevices(CLDevice... devices)
Adds the devices as build target.
void save(ObjectOutputStream oos)
Saves this configuration to the ObjectOutputStream.
CLBuildConfiguration clone()
Clones this configuration.
CLBuildConfiguration withDefine(String name)
Adds the definition to the build configuration.
CLProgramConfiguration setProgram(CLProgram program)
Sets the program which should be build.
CLBuildConfiguration withOption(String option)
Adds the compiler option to the build configuration.
CLProgram build()
Builds or rebuilds a program.
CLProgramConfiguration forDevice(CLDevice device)
Adds the device as build target.
CLProgramConfiguration withDefine(String name)
Adds the definition to the build configuration.
CLProgramConfiguration withOption(String option)
Adds the compiler option to the build configuration.