LWJGL 3.1.1 - OpenCL #define Preprocessor directive causes compilation error

Started by officialhopsof, May 24, 2017, 20:10:30

Previous topic - Next topic

officialhopsof

The OpenCL Definition says that C99 preprocessor directives are available for use, however when I try to use one with LWJGL I get a build error (error code -11)

    String programSource = 
       "#define A 1\n" 
     + "kernel void foo(global int* definedNumber){\n"
     + "  *definedNumber = A;\n" 
     + "}";
    
    clProgram = CL10.clCreateProgramWithSource(clContext, programSource, errcode_ret);
    int errcode = clBuildProgram(clProgram, clDevice, "", null, NULL);
    checkCLError(errcode); // <--- Build error (errcode == -11)


If i change the programSouce to

kernel void foo(global int* definedNumber){
  *definedNumber = 1;
}


The program compiles just fine.

Are preprocessor directives not available when using LWJGL?

QuoteError Code -11
CL_BUILD_PROGRAM _FAILURE   
clBuildProgram   
if there is a failure to build the program executable. This error will be returned if clBuildProgram does not return until the build has completed.

spasi

There's nothing unusual about OpenCL in LWJGL. Inspect the CL_PROGRAM_BUILD_LOG to see what the problem is.

Evan407

I haven't gotten there yet but here is what I run
java -Dorg.lwjgl.util.Debug=true -Dorg.lwjgl.util.DebugLoader=true -cp Dependencies/lwjgl/*:. com.evanstools.opencl.demo.Demo
it provides more error reporting.

I'm able to create a context for each platform. I'm trying to retrieve all devices.
http://evansgame.com/com/evanstools/opencl/demo/Platform.java

There are error callbacks too that help. I'm still trying to find out how to use the parameters of
Quoteinvoke(long errinfo, long private_info, long cb, long user_data)

They are long data types I'm assuming ... pointers. I've been referring them to as id like a memory id or reference type or pointers. Basically all the longs are pointers.

spasi

You can find a description of the parameters in the javadoc or in the OpenCL Reference Page for clCreateContext.

Btw, I just tried your program (with the #define) and it builds without errors.

Evan407

Quote from: spasi on May 25, 2017, 18:35:05
You can find a description of the parameters in the javadoc or in the OpenCL Reference Page for clCreateContext.

Btw, I just tried your program (with the #define) and it builds without errors.
I haven't been able to test it with more than a single device. My pc only has one graphics card but my aim was to retrieve all the devices in the nature of OpenCL. I intend to use OpenCL for some image processing applications to drastically increase the speed of my iterations.

So far I've found out openCL has a pointless Work Group with the important work items which are kernel instances that are called on like functions or methods. I think there may be some hierarchy redundancy there.

The point is that there is Global and Constant memory defined by the host and then there is openCL kernel that runs off this memory using memory commands. You have to fill the buffers with the global and constant memory and then run kernel. After you can unmap a region of a memory object aka retrieve the computed results. Explicitly copying data / mapping and unmaping regions of a memory object.

Create memory objects in global memory, enqueue memory commands. Kernel execution commands.

Evan407

Quote from: Evan407 on May 25, 2017, 17:26:03
I haven't gotten there yet but here is what I run
java -Dorg.lwjgl.util.Debug=true -Dorg.lwjgl.util.DebugLoader=true -cp Dependencies/lwjgl/*:. com.evanstools.opencl.demo.Demo
it provides more error reporting.

I'm able to create a context for each platform. I'm trying to retrieve all devices.
http://evansgame.com/com/evanstools/opencl/demo/Platform.java

There are error callbacks too that help. I'm still trying to find out how to use the parameters of
Quoteinvoke(long errinfo, long private_info, long cb, long user_data)
They are long data types I'm assuming ... pointers. I've been referring them to as id like a memory id or reference type or pointers. Basically all the longs are pointers.
I've updated my code to make a command queue for each platform. Deleted 'Device.java'!

http://evansgame.com/com/evanstools/opencl/demo/

My research suggests that kernels can launch kernels aka recursion is supported. This allows me an entry point for the openCL kernel code. I need functions for the memory objects.

spasi

Quote from: Evan407 on May 25, 2017, 17:26:03I'm still trying to find out how to use the parameters of
Quoteinvoke(long errinfo, long private_info, long cb, long user_data)

You can use MemoryUtil.memASCII(errinfo) to convert the error message to a Java string. See the existing LWJGL demos for more examples.

officialhopsof

Oddly enough, I went home for the day that day, came back and it ran just fine, no errors or anything (this is a bit disconcerting but oh well, I can't seem to reproduce it now).

#unrelated
On a side note, I finished the OpenCL program and I was blown away at the results! Previously we had an engineering calculation/algorithm that took about 8 hours to run on the latest i7 (and we had to run that calculation 4-16 times for each data set). My first approach was to convert it to the Java Streams API and let it run concurrently, and I was able to reduce the time per calculation to 2 hours, way better, but still not good enough. Then I decided to use OpenCL and thus ended up on this forum, and the calculation now takes about 30 seconds to execute (on a 1080Ti with 3500 cores). Absolutely crazy! I was certainly not expecting to see that big of a jump. Thanks for the help everyone!