29package com.jogamp.opencl;
31import com.jogamp.opencl.CLMemory.Mem;
32import com.jogamp.opencl.CLMemory.GLObjectType;
33import com.jogamp.opencl.CLSampler.AddressingMode;
34import com.jogamp.opencl.CLSampler.FilteringMode;
35import com.jogamp.opencl.CLImageFormat.ChannelOrder;
36import com.jogamp.opencl.CLImageFormat.ChannelType;
37import com.jogamp.opencl.CLDevice.FPConfig;
38import com.jogamp.opencl.CLDevice.GlobalMemCacheType;
39import com.jogamp.opencl.CLDevice.LocalMemType;
40import com.jogamp.opencl.CLDevice.Type;
41import com.jogamp.opencl.CLDevice.Capabilities;
42import com.jogamp.opencl.llb.CL;
43import com.jogamp.opencl.test.util.MiscUtils;
44import com.jogamp.opencl.test.util.UITestCase;
46import java.io.IOException;
47import java.io.InputStream;
48import java.nio.ByteBuffer;
49import java.util.Arrays;
50import java.util.EnumSet;
53import org.junit.BeforeClass;
54import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
58import static org.junit.Assert.*;
59import static java.lang.System.*;
60import static com.jogamp.opencl.test.util.MiscUtils.*;
61import static com.jogamp.opencl.util.CLPlatformFilters.*;
62import static com.jogamp.opencl.CLVersion.*;
63import static com.jogamp.opencl.CLDevice.Type.*;
64import static com.jogamp.common.nio.Buffers.*;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
75 out.println(
"OS: " + System.getProperty(
"os.name"));
76 out.println(
"ARCH: " + System.getProperty(
"os.arch"));
77 out.println(
"VM: " + System.getProperty(
"java.vm.name"));
78 out.println(
"lib path: " + System.getProperty(
"java.library.path"));
93 assertTrue(
set.contains(e));
101 for (
final Type e :
Type.values()) {
109 for (
final Mem e :
Mem.values()) {
140 out.println(
" - - - highLevelTest; contextless - - - ");
145 for (
final CLPlatform platform : clPlatforms) {
147 out.println(
"platform info:");
148 out.println(
" name: "+platform.getName());
149 out.println(
" id: "+platform.ID);
150 out.println(
" profile: "+platform.getProfile());
151 out.println(
" spec version: "+platform.getSpecVersion());
152 out.println(
" impl version: "+platform.getVersion().getImplVersion());
153 out.println(
" vendor: "+platform.getVendor());
154 out.println(
" max FLOPS device: "+platform.getMaxFlopsDevice());
155 out.println(
" extensions: "+platform.getExtensions());
157 final CLDevice[] clDevices = platform.listCLDevices();
158 for (
final CLDevice device : clDevices) {
159 out.println(
"device info:");
160 out.println(
" name: "+device.getName());
161 out.println(
" profile: "+device.getProfile());
162 out.println(
" vendor: "+device.getVendor());
163 out.println(
" vendor id: "+device.getVendorID());
164 out.println(
" version: "+device.getVersion());
166 out.println(
" driver version: "+device.getDriverVersion());
167 out.println(
" type: "+device.getType());
168 out.println(
" mem base addr align: "+device.getMemBaseAddrAlign());
169 out.println(
" global mem: "+device.getGlobalMemSize()/(1024*1024)+
" MB");
170 out.println(
" max alloc mem: "+device.getMaxMemAllocSize()/(1024*1024)+
" MB");
171 out.println(
" max param size: "+device.getMaxParameterSize()+
" byte");
172 out.println(
" local mem: "+device.getLocalMemSize()/1024+
" KB");
173 out.println(
" local mem type: "+device.getLocalMemType());
174 out.println(
" global mem cache size: "+device.getGlobalMemCacheSize());
175 out.println(
" global mem cacheline size: "+device.getGlobalMemCachelineSize());
176 out.println(
" global mem cache type: "+device.getGlobalMemCacheType());
177 out.println(
" constant buffer size: "+device.getMaxConstantBufferSize());
178 out.println(
" error correction support: "+device.isErrorCorrectionSupported());
179 out.println(
" queue properties: "+device.getQueueProperties());
180 out.println(
" clock: "+device.getMaxClockFrequency()+
" MHz");
181 out.println(
" timer res: "+device.getProfilingTimerResolution()+
" ns");
182 out.println(
" max work group size: "+device.getMaxWorkGroupSize());
183 out.println(
" max compute units: "+device.getMaxComputeUnits());
184 out.println(
" max work item dimensions: "+device.getMaxWorkItemDimensions());
185 out.println(
" max work item sizes: "+Arrays.toString(device.getMaxWorkItemSizes()));
186 out.println(
" compiler available: "+device.isCompilerAvailable());
187 out.println(
" image support: "+device.isImageSupportAvailable());
188 out.println(
" max read image args: "+device.getMaxReadImageArgs());
189 out.println(
" max write image args: "+device.getMaxWriteImageArgs());
190 out.println(
" max image2d dimensions: "+Arrays.asList(device.getMaxImage2dWidth(), device.getMaxImage2dHeight()));
191 out.println(
" max image3d dimensions: "+Arrays.asList(device.getMaxImage2dWidth(), device.getMaxImage2dHeight(), device.getMaxImage3dDepth()));
192 out.println(
" number of address bits: "+device.getAddressBits());
193 out.println(
" half FP available: "+device.isHalfFPAvailable());
194 out.println(
" double FP available: "+device.isDoubleFPAvailable());
195 out.println(
" little endian: "+device.isLittleEndian());
196 out.println(
" half FP config: "+device.getHalfFPConfig());
197 out.println(
" single FP config: "+device.getSingleFPConfig());
198 out.println(
" double FP config: "+device.getDoubleFPConfig());
199 out.println(
" execution capabilities: "+device.getExecutionCapabilities());
200 out.println(
" gl memory sharing: "+device.isGLMemorySharingSupported());
201 out.println(
" extensions: "+device.getExtensions());
209 @SuppressWarnings(
"unchecked")
212 @SuppressWarnings(
"unchecked")
216 if(platformGPU !=
null) {
218 }
else if(platformCPU !=
null) {
221 fail(
"please tell us about your hardware");
228 out.println(
" - - - highLevelTest; create context - - - ");
232 final int deviceCount = devices.length;
236 assertEquals(deviceCount, c.
getDevices().length);
241 assertEquals(deviceCount, c.
getDevices().length);
244 for (
final CLDevice device : devices) {
253 assertEquals(deviceCount, c.
getDevices().length);
258 assertEquals(deviceCount, c.
getDevices().length);
265 fail(
"create with null device");
266 }
catch(
final IllegalArgumentException ex) {
271 fail(
"create with null CLDevice.Type");
272 }
catch(
final IllegalArgumentException ex) {
277 fail(
"create with null CLDevice.Type");
278 }
catch(
final IllegalArgumentException ex) {
287 out.println(
" - - - highLevelTest; global memory kernel - - - ");
294 out.println(
"context devices:");
295 for (
final CLDevice device : contextDevices) {
296 out.println(
" "+device.toString());
301 final InputStream stream = getClass().getResourceAsStream(
"testkernels.cl");
305 final CLDevice device = programDevices[0];
307 assertEquals(contextDevices.length, programDevices.length);
312 final String source = program.
getSource();
313 assertFalse(source.trim().isEmpty());
317 assertFalse(binaries.isEmpty());
319 int elementCount = 11444777;
321 int globalWorkSize = 0;
323 ByteBuffer srcA =
null;
324 ByteBuffer srcB =
null;
325 ByteBuffer dest =
null;
326 boolean allocated =
false;
328 while( !allocated ) {
331 globalWorkSize = roundUp(localWorkSize, elementCount);
332 out.println(
"allocating three buffers of size: "+globalWorkSize);
333 srcA = newDirectByteBuffer(globalWorkSize*SIZEOF_INT);
334 srcB = newDirectByteBuffer(globalWorkSize*SIZEOF_INT);
335 dest = newDirectByteBuffer(globalWorkSize*SIZEOF_INT);
338 catch(
final OutOfMemoryError oome ) {
340 elementCount /= divisor;
341 out.println(
"not enough direct buffer memory; retrying with smaller buffers");
345 fillBuffer(srcA, 23456);
346 fillBuffer(srcB, 46987);
354 vectorAddKernel.
setArg(0, clBufferA)
368 out.println(
"a+b=c result snapshot: ");
369 for(
int i = 0; i < 10; i++)
370 out.print(dest.getInt()+
", ");
371 out.println(
"...; "+dest.remaining()/SIZEOF_INT +
" more");
392 public static void main(
final String[] args)
throws IOException {
394 org.junit.runner.JUnitCore.
main(tstname);
OpenCL buffer object wrapping an optional NIO buffer.
The command queue is used to queue a set of operations for a specific CLDevice.
CLCommandQueue put1DRangeKernel(final CLKernel kernel, final long globalWorkOffset, final long globalWorkSize, final long localWorkSize)
Calls {@native clEnqueueNDRangeKernel}.
CLCommandQueue finish()
Calls {@native clFinish}.
CLCommandQueue putWriteBuffer(final CLBuffer<?> writeBuffer, final boolean blockingRead)
Calls {@native clEnqueueWriteBuffer}.
CLCommandQueue putReadBuffer(final CLBuffer<?> readBuffer, final boolean blockingRead)
Calls {@native clEnqueueReadBuffer}.
void release()
Releases the OpenCL resource.
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
List< CLMemory<? extends Buffer > > getMemoryObjects()
Returns a read only shapshot of all allocated memory objects associated with this context.
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).
final CLBuffer<?> createBuffer(final int size, final Mem... flags)
Creates a CLBuffer with the specified flags.
CLDevice getMaxFlopsDevice()
Returns the device with maximal FLOPS from this context.
List< CLProgram > getPrograms()
Returns a read only shapshot of all programs associated with this context.
This object represents an OpenCL device.
CLCommandQueue createCommandQueue()
int[] getMaxWorkItemSizes()
Returns the maximum number of work-items that can be specified in each dimension of the work-group.
High level abstraction for an OpenCL Kernel.
CLKernel setArg(final int argumentIndex, final CLMemory<?> value)
Represents a OpenCL program executed on one or more CLDevices.
String getBuildLog()
Returns the build log of this program on all devices.
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.
void release()
Releases this program with its kernels.
CLKernel createCLKernel(final String kernelName)
Creates a kernel with the specified kernel name.
Test testing the high level bindings.
static void main(final String[] args)
Enumeration for the execution capabilities of the device.
static Capabilities valueOf(final int caps)
Describes floating-point capability of the device.
ROUND_TO_INF
round to positive and negative infinity rounding modes supported.
static EnumSet< FPConfig > valuesOf(final int bitfield)
Returns a EnumSet for the given bitfield.
DENORM
denorms are supported.
Type of global memory cache supported.
static GlobalMemCacheType valueOf(final int bitfield)
Returns the matching GlobalMemCacheType for the given cl type.
Type of local memory cache supported.
static LocalMemType valueOf(final int clLocalCacheType)
Returns the matching LocalMemCacheType for the given cl type.
Enumeration for the type of a device.
static Type valueOf(final long clDeviceType)
static GLObjectType valueOf(final int type)
Configures the mapping process.
Memory settings for configuring CLMemory.
WRITE_ONLY
Enum representing CL_MEM_WRITE_ONLY.
READ_ONLY
Enum representing CL_MEM_READ_ONLY.
static Mem valueOf(final int bufferFlag)
static AddressingMode valueOf(final int mode)
static FilteringMode valueOf(final int mode)
Java bindings to OpenCL, the Open Computing Language.
static final int CL_FP_DENORM
Define "CL_FP_DENORM" with expression '(1 << 0)', CType: int.
static final int CL_FP_ROUND_TO_INF
Define "CL_FP_ROUND_TO_INF" with expression '(1 << 4)', CType: int.