How to build my own jocl.jar?

Hi, all:

Sorry for my entry-level questions.

I downloaded jocl source code from http://www.jocl.org/downloads/downloads.html,
and I’d love to build everything locally, which means, I’ll build my own native libJOCL-linux-x86.so , as well as my own jocl.jar .

I successfully built libJOCL-linux-x86.so from within folder $JOCL_SRC_DIR/JOCLJNI, which produced a libJOCL-linux-x86.so in $JOCL_SRC_DIR/JOCLJNI/lib/linux . However, I’d love to ask how can I produce my own jocl.jar since there is no ant file or maven in this JOCL project ?
Sorry, this might just be a simple question for Java newbies.

I’m now testing the HistogramNVIDIA.java sample downloaded from http://www.jocl.org/samples/samples.html .
Everything compiles, but when I tried to run it, I got the following error messages:

Error while loading native library „JOCL-linux-x86“ with base name „JOCL“
Operating system name: Linux
Architecture : i386
Architecture bit size: 32
Stack trace from the attempt to load the library as a resource:
java.lang.NullPointerException: No resource found with name ‚/lib/libJOCL-linux-x86.so‘
at org.jocl.LibUtils.loadLibraryResource(LibUtils.java:139)
at org.jocl.LibUtils.loadLibrary(LibUtils.java:83)
at org.jocl.CL.(CL.java:47)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:185)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)
Stack trace from the attempt to load the library as a file:
java.lang.UnsatisfiedLinkError: /usr/local/lib/libJOCL-linux-x86.so: libOpenCL.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at org.jocl.LibUtils.loadLibrary(LibUtils.java:93)
at org.jocl.CL.(CL.java:47)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:185)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)
Exception in thread „main“ java.lang.UnsatisfiedLinkError: Could not load the native library
at org.jocl.LibUtils.loadLibrary(LibUtils.java:117)
at org.jocl.CL.(CL.java:47)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:185)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)

This seems to tell that without the added jar „jocl.jar“, this program won’t be able to run. So, now, I do need a self-produced jocl.jar (instead of a downloaded one). Can anybody give me a hand please.

Best Regards
JIA

Hello,

[QUOTE=jiapei100]However, I’d love to ask how can I produce my own jocl.jar since there is no ant file or maven in this JOCL project ?
[/quote]

There is a Maven repository for JOCL, so if you want to build it locally, maybe you can extract the relevant information from the POM that is available at http://repo1.maven.org/maven2/org/jocl/jocl/0.1.6/ I probably will not be able to help you much with that: Creating the POM was… a hassle, somehow. It was the first project that I put on Maven, and it took a while to get it running. Originally, I also wanted to build the native libs with an appropriate maven Plugin, but that’s probably not possible. So now the Maven build assumes that there is a „nativeLibs“ directory containing the native libraries, which then will be added to the JAR as ‚resources‘.
However, it should be possible to get the native lib into the JAR manually: The native library has to be in the „/lib/“ subdirectory inside the JAR. You can probably create such a directory in your project structure and let it be included in the JAR build, or, alternatively, add the native library in the respective directory after the JAR has been created (basically by treating the JAR as a simple ZIP file).

I’m now testing the HistogramNVIDIA.java sample downloaded from http://www.jocl.org/samples/samples.html .
Everything compiles, but when I tried to run it, I got the following error messages:


Error while loading native library "JOCL-linux-x86" with base name "JOCL"
...
Stack trace from the attempt to load the library as a resource:
java.lang.NullPointerException: No resource found with name '/lib/libJOCL-linux-x86.so'
...
Stack trace from the attempt to load the library as a file:
java.lang.UnsatisfiedLinkError: /usr/local/lib/libJOCL-linux-x86.so: libOpenCL.so: 
    cannot open shared object file: No such file or directory

First of all: Do the samples work in general on Linux32 when you are using the downloaded JAR?

If they do work, or you can not test it: The error message shows the results of the two attempts to load the native library:

  • The first message says that it could not be loaded from the JAR file, because it did not find the ‚/lib/libJOCL-linux-x86.so‘ inside the JAR.
  • The second message shows the result from the attempt do load the file directly, and this should work if the file is present. It should be found when it is located in the root directory of your project, or when it is located in a directory that is part of the LD_LIBRARY_PATH. Where did you put the „libJOCL-linux-x86.so“ that you compiled?

bye

Now, I downloaded the JOCL binary JOCL-0.1.6.jar directly from jocl.org - Downloads ,
and then put it under /usr/share/java/ …

After adding JOCL-0.1.6.jar to the project under Java Build Path, I failed to run the demo HistogramAMD.java again, and obtained the following error messages:

Error while loading native library „JOCL-linux-x86“ with base name „JOCL“
Operating system name: Linux
Architecture : i386
Architecture bit size: 32
Stack trace from the attempt to load the library as a resource:
java.lang.UnsatisfiedLinkError: /tmp/libJOCL-linux-x861112466208952998511.so: libOpenCL.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1646)
at java.lang.Runtime.load0(Runtime.java:787)
at java.lang.System.load(System.java:1022)
at org.jocl.LibUtils.loadLibraryResource(LibUtils.java:161)
at org.jocl.LibUtils.loadLibrary(LibUtils.java:83)
at org.jocl.CL.(CL.java:47)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:185)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)
Stack trace from the attempt to load the library as a file:
java.lang.UnsatisfiedLinkError: /usr/local/lib/libJOCL-linux-x86.so: libOpenCL.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at org.jocl.LibUtils.loadLibrary(LibUtils.java:93)
at org.jocl.CL.(CL.java:47)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:185)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)
Exception in thread „main“ java.lang.UnsatisfiedLinkError: Could not load the native library
at org.jocl.LibUtils.loadLibrary(LibUtils.java:117)
at org.jocl.CL.(CL.java:47)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:185)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)

Seriously no idea what’s going on and what I should do. Anybody successfully run this demo??

Best Regards
JIA

Oh, sorry, I just noticed that it does not complain about “libJOCL-linux-x86.so”, but about “libOpenCL.so” - that should be the main shared library from the OpenCL implementation. Which implementation of OpenCL are you using (AMD or NVIDIA) ? And did you have a chance to test whether OepnCL itself is working in general?

Hi,

I made some progress but still failed with the following error message:

Unsupported GPU device; falling back to CPU …
Exception in thread „main“ org.jocl.CLException: CL_INVALID_CONTEXT
at org.jocl.CL.checkResult(CL.java:562)
at org.jocl.CL.clGetContextInfo(CL.java:4015)
at org.jocl.samples.HistogramAMD.setupCL(HistogramAMD.java:205)
at org.jocl.samples.HistogramAMD.setup(HistogramAMD.java:376)
at org.jocl.samples.HistogramAMD.main(HistogramAMD.java:44)

My working environment is:
Ubuntu 10.10 + video card (ATI Mobility Radeon X1600)
My OpenCL is „AMD APP SDK v2.3 with OpenCL™ 1.1 support“, please refer to http://developer.amd.com/gpu/AMDAPPSDK/downloads/Pages/default.aspx

Anyway, I successfully compiled and ran the hellocl demo, which can be downloaded from http://donkey.vernier.se/~yann/hellocl.c
That is to say, OpenCL is working fine on my computer.
But, why JOCL doesn’t work?

Best Regards
JIA

EDIT: Also see next post!

Hm :confused: The message
„Unsupported GPU device; falling back to CPU …“
is strange: It fails to create a context for the GPU. Sometimes there are limitations in the „Mobility“ cards, but when it works with the pure native example, this can hardly be the reason. You could add


        
        if(status[0] != CL_SUCCESS && dType == CL_DEVICE_TYPE_GPU)
        {
            System.out.println("Unsupported GPU device; falling back to CPU ...");
            context = clCreateContextFromType(null, CL_DEVICE_TYPE_CPU, null, null, status);
            **    
            if (status[0] != CL_SUCCESS)
            {
                System.out.println("...and the CPU did not work either: "+CL.stringFor_errorCode(status[0]));
            }**
        }

to see what he says there.

Additionally, could you test it with the most basic example (JOCLSample.java) ?

If this does not work, we could try to do the initialization as in the native example, with clCreateContext instead of clCreateContextFromType, although the behavior should be equal with both approaches. However, maybe we can at least narrow down the problem space a little.

bye
Marco

Ah, sorry, I just noticed that there is an error:

Instead of


System.out.println("Unsupported GPU device; falling back to CPU ...");
context = clCreateContextFromType(**null**, CL_DEVICE_TYPE_CPU, null, null, status);

it should be


System.out.println("Unsupported GPU device; falling back to CPU ...");
context = clCreateContextFromType(**contextProperties**, CL_DEVICE_TYPE_CPU, null, null, status);

If this works, it’s still only the CPU, but at least we’re one step further.

Hi, testing results.

JOCLSample.java passed

Obtaining platform…
Test PASSED
Result: [0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0]

JOCLSample_1_1.java passed as well

Enqueue buffer region read, waiting for user event
Waiting before setting event status to CL_COMPLETE
Seconds left: 3
Seconds left: 2
Seconds left: 1
Setting event status to CL_COMPLETE
Event cl_event[0xffffffff8bc1a998] reached status CL_COMPLETE, user data: Event callback user data
Buffer region was read:
10.0 12.0
18.0 20.0
Memory object cl_mem[0xffffffff8bcab6e8] was destroyed, user data: Memory object destructor callback user data
PASSED

JOCLDeviceQuery.java seems to pass as well

Number of platforms: 1
Number of devices in platform ATI Stream: 1
— Info for device Intel(R) Core™2 CPU T7200 @ 2.00GHz: —
CL_DEVICE_NAME: Intel(R) Core™2 CPU T7200 @ 2.00GHz
CL_DEVICE_VENDOR: GenuineIntel
CL_DRIVER_VERSION: 2.0
CL_DEVICE_TYPE: CL_DEVICE_TYPE_CPU
CL_DEVICE_MAX_COMPUTE_UNITS: 2
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: 3
CL_DEVICE_MAX_WORK_ITEM_SIZES: 1024 / 1024 / 1024
CL_DEVICE_MAX_WORK_GROUP_SIZE: 1024
CL_DEVICE_MAX_CLOCK_FREQUENCY: 996 MHz
CL_DEVICE_ADDRESS_BITS: 32
CL_DEVICE_MAX_MEM_ALLOC_SIZE: 512 MByte
CL_DEVICE_GLOBAL_MEM_SIZE: 1024 MByte
CL_DEVICE_ERROR_CORRECTION_SUPPORT: no
CL_DEVICE_LOCAL_MEM_TYPE: global
CL_DEVICE_LOCAL_MEM_SIZE: 32 KByte
CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 64 KByte
CL_DEVICE_QUEUE_PROPERTIES: CL_QUEUE_PROFILING_ENABLE
CL_DEVICE_IMAGE_SUPPORT: 0
CL_DEVICE_MAX_READ_IMAGE_ARGS: 0
CL_DEVICE_MAX_WRITE_IMAGE_ARGS: 0
CL_DEVICE_SINGLE_FP_CONFIG: CL_FP_DENORM CL_FP_INF_NAN CL_FP_ROUND_TO_NEAREST CL_FP_ROUND_TO_ZERO CL_FP_ROUND_TO_INF
CL_DEVICE_2D_MAX_WIDTH 0
CL_DEVICE_2D_MAX_HEIGHT 0
CL_DEVICE_3D_MAX_WIDTH 0
CL_DEVICE_3D_MAX_HEIGHT 0
CL_DEVICE_3D_MAX_DEPTH 0
CL_DEVICE_PREFERRED_VECTOR_WIDTH_ CHAR 16, SHORT 8, INT 4, LONG 2, FLOAT 4, DOUBLE 0

JOCLEventSample.java seems to be OK as well.

Initializing input data…
Obtaining platform…
Creating context…
Initializing device…
Creating command queue…
Initializing buffers…
Creating programs…
Building programs…
Creating kernels…
Setting arguments…
Enqueueing kernels…
Waiting for events…
Enqueueing output reads…
Waiting for events…
Result: 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0 …
Result: 0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0 …
Event kernel0:
Queued : 0.000 ms
Submit : 0.153 ms
Start : 0.202 ms
End : 0.560 ms
Time : 0.358 ms
Event kernel1:
Queued : 0.006 ms
Submit : 0.575 ms
Start : 0.604 ms
End : 0.944 ms
Time : 0.340 ms
Event read0:
Queued : 1.115 ms
Submit : 1.124 ms
Start : 1.126 ms
End : 1.292 ms
Time : 0.166 ms
Event read1:
Queued : 1.310 ms
Submit : 1.327 ms
Start : 1.329 ms
End : 1.472 ms
Time : 0.143 ms

Rgds
JIA

I found the problem.

When testing JOCLSimpleImage.java , I got

Creating context…
Unable to create GPU context, using CPU…
Initializing device…
Images supported: false
Images are not supported

What’s more, I’m using absolute directory to load the image, say,

String fileName = "/home/jiapei/MyPrograms/Java/Eclipse/JOCL/data/lena512color.png";

,
instead of a relative directory,

String fileName = "data/lena512color.png";

,

When using the relative directory, an error message jumped out and was telling

javax.imageio.IIOException: Can’t read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1291)
at org.jocl.samples.JOCLSimpleImage.createBufferedImage(JOCLSimpleImage.java:97)
at org.jocl.samples.JOCLSimpleImage.(JOCLSimpleImage.java:171)
at org.jocl.samples.JOCLSimpleImage$1.run(JOCLSimpleImage.java:39)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:617)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
Exception in thread „AWT-EventQueue-0“ java.lang.NullPointerException
at org.jocl.samples.JOCLSimpleImage.(JOCLSimpleImage.java:172)
at org.jocl.samples.JOCLSimpleImage$1.run(JOCLSimpleImage.java:39)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:617)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

, which seems to complain the image file can’t be found. Yes, where to put the image file so that relative directory may also work fine?

Kind Rgds
JIA

Hello

Regardless of the location of the image file: When the device does not support images, then there’s no way to use them.

According to the JOCLDeviceQuery output, the CPU is used at the moment. I think these don’t support images in general. The CPU should/could support them, but it seems it can not create a context for the GPU. Maybe you can find out whether the GPU works in the native example, by adjusting the native example to also use createContextFromType…?

bye