I am trying to use the function:
public static synchronized int clGetPlatformInfo(cl_platform_id platform, int param_name, long param_value_size, Pointer param_value, long[] param_value_size_ret)
However I got no luck with this. I get a number (29) in param_value_size_ret and chars in param_value.
Later on I get org.jocl.CLException: CL_INVALID_CONTEXT
I’m unsure how to use the Pointer param_value correct?
Right now I do like this:
java.nio.ByteBuffer pbuf = java.nio.ByteBuffer.allocate(100);
long plong[] = new long[1];
Pointer pp = Pointer.to((java.nio.ByteBuffer) pbuf);
status = clGetPlatformInfo(platforms**,
CL_PLATFORM_VENDOR,
(long)100,
pp,
plong);
The way you are using the clGetPlatformInfo function should be correct. Here is a complete example which queries and prints the vendor string:
import static org.jocl.CL.*;
import java.nio.ByteBuffer;
import org.jocl.*;
public class JOCLVendorQuery
{
public static void main(String args[])
{
setExceptionsEnabled(true);
// Obtain the platform IDs
cl_platform_id platforms[] = new cl_platform_id[1];
clGetPlatformIDs(platforms.length, platforms, null);
System.out.println("platforms[0] "+platforms[0]);
// Obtain the size of the data that will be returned when
// querying CL_PLATFORM_VENDOR. (The pointer that will
// store the actual data is 'null', so ONLY the size of
// the result will be stored in 'vendorNameSize')
long vendorNameSize[] = new long[1];
clGetPlatformInfo(platforms[0], CL_PLATFORM_VENDOR,
0, null, vendorNameSize);
System.out.println("vendorNameSize[0] "+vendorNameSize[0]);
// Allocate a byte buffer with the required size
int size = (int)vendorNameSize[0];
ByteBuffer vendorNameByteBuffer = ByteBuffer.allocate(size);
clGetPlatformInfo(platforms[0], CL_PLATFORM_VENDOR,
size, Pointer.to(vendorNameByteBuffer), vendorNameSize);
// Create and print the resulting string:
String vendorName = new String(vendorNameByteBuffer.array());
System.out.println("vendorName: "+vendorName);
}
}
Since this does not yet involve any CL contexts, I wonder where your CL_INVALID_CONTEXT error occurs.
If necessary, I’ll try to convert the full example from the linked site to JOCL. There may be difficulties with the „cl_context_properties“, for which it is hard to find a suitable translation to Java (OpenCL obviously was designed without having Java in mind )
I think the CL_INVALID_CONTEXT occurs because the new version of the stream sdk does not longer support the creation of a context without the specification of a platform for which the context should be created. So if the fetching of the platform ids fails, it will probably cause jocl to throw an exception when creating a context. Not sure if this applies here, but this might be the cause of the exception.
I would also like to point out that the utility functions I ported from the NVIDIA SDK to JOCL (www.ithilian.com/jclu) contain some convenience functions for fetching information for platforms etc. I did not have the proper hardware setup to test it properly with the AMD Stream SDK, but normally the functions should be generic enough.
Thanks for the quick help!
Sorry if I am a bit unclear about everything. I just trying to run the HistogramAMD.java example
// output from code with creation of cl_platform_id platform_id[] etc. which is ok I guess
numPlatforms[0] 1
platforms[0] cl_platform_id[0xc991434]
Platform: Advanced Micro Devices, Inc.
The error comes with the property creation. I am unsure how to set it correct?
cl_context_properties cprops[] = new cl_context_properties[1];
// line below gives java.lang.NullPointerException
cprops[0].addProperty(CL_CONTEXT_PLATFORM, platform_id[0]);
Concerning the error you described when using the properties: That seemed to be an error of the library. I think I spotted the bug - in the end, it seemed to be a simple mix-up of „long“ and „jlong“ on native side. I have temporarily(!) uploaded an updated library to