OpenCL 1.0 ATI-Stream-v2.0.0 problem

Hello!

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);

I have followed the recommendation here and converted the code to Java:
http://developer.amd.com/support/KnowledgeBase/Lists/KnowledgeBase/DispForm.aspx?ID=71

Thanks in advace for any help

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 :wink: )

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]);

context = clCreateContextFromType(cprops[0], dType, null, null, status);

In C the original code is:
cl_context_properties cps[3] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)platform,
0
};

cl::shared_context ctx = clCreateContextFromType(cprops, options.device_type(), NULL, NULL, &error);

Best Regards!

At this point, „cprops“ is an empty array. You might either add one element to this array…

cl_context_properties cprops[] = new cl_context_properties[1];
cprops[0] = new cl_context_properties();
cprops[0].addProperty(CL_CONTEXT_PLATFORM, platform_id[0]);

or not use an array at all, since an array is not necessary in this case:

cl_context_properties contextProperties = new cl_context_properties();
contextProperties.addProperty(CL_CONTEXT_PLATFORM, platforms[0]);
cl_context context = clCreateContextFromType(contextProperties, ...);

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

http://www.jocl.org/JOCL-windows-x86.dll

If you can confirm that it now works for you as expected, I will upload the updated source code and binaries archives, and remove this temporary file.

I tested it with the following snippet, and it seemed to work:

import static org.jocl.CL.*;

import org.jocl.*;

public class JOCLPropertiesTest
{
    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]);

        // Initialize the context properties
        cl_context_properties contextProperties = new cl_context_properties();
        contextProperties.addProperty(CL_CONTEXT_PLATFORM, platforms[0]);

        // Create a context with the given properties
        cl_context context = clCreateContextFromType(contextProperties, 
            CL_DEVICE_TYPE_GPU, null, null, null);        
        System.out.println("context "+context);
    }
}

Marco13: sorry me for being a lousy programmer…
I can confirm that it works with the new .dll-file.

I thank you very much for your excellent and quick help!

best wishes from me

No, sorry for mixing „long“ and „jlong“ :wink: and thank you for pointing out this bug :slight_smile:
I will upload an updated version of the source and the libraries soon.