[SOLVED] OpenCL error in clCreateContext CL_INVALID_GL SHAREGROUP REFERENCE KHR on Linux

Hello. Was trying to use the OpenCL context in JME3. I got the CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR on Linux. OpenCL support is there. Any ideas?

This happens in HelloOpenCL.java

Sep 27, 2021 4:41:22 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.4.0-stable
* Branch: HEAD
* Git Hash: cb5173b
* Build Date: 2021-05-30
Sep 27, 2021 4:41:22 PM com.jme3.system.lwjgl.LwjglContext initOpenCL
INFO: Initialize OpenCL with LWJGL3
Sep 27, 2021 4:41:22 PM com.jme3.system.lwjgl.LwjglContext initOpenCL
INFO: Available OpenCL platforms:
* Platform 1
*   Name: NVIDIA CUDA
*   Vendor: NVIDIA Corporation
*   Version: OpenCL 3.0 CUDA 11.4.136
*   Profile: FULL_PROFILE
*   Supports interop: true
*   Available devices:
*    * Device 1
*    *   Name: NVIDIA GeForce GTX 1050
*    *   Vendor: NVIDIA Corporation
*    *   Version: OpenCL 3.0 CUDA
*    *   Profile: FULL_PROFILE
*    *   Compiler version: OpenCL C 1.2 
*    *   Device type: DEFAULT
*    *   Compute units: 5
*    *   Work group size: 1024
*    *   Global memory: 2099904512B
*    *   Local memory: 49152B
*    *   Constant memory: 65536B
*    *   Supports double: true
*    *   Supports half floats: false
*    *   Supports writable 3d images: true
*    *   Supports interop: true
Sep 27, 2021 4:41:22 PM com.jme3.system.lwjgl.LwjglContext initOpenCL
INFO: chosen platform: NVIDIA CUDA
Sep 27, 2021 4:41:22 PM com.jme3.system.lwjgl.LwjglContext initOpenCL
INFO: chosen devices: [NVIDIA GeForce GTX 1050]
Sep 27, 2021 4:46:49 PM com.jme3.system.lwjgl.LwjglContext initOpenCL
SEVERE: Unable to create OpenCL context
com.jme3.opencl.OpenCLException: OpenCL error in clCreateContext: CL_INVALID_GL_CONTEXT_APPLE|CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR (0xfffffc18)

devent-X705UD ~ » clinfo                  
Number of platforms                               1
Platform Name                                   NVIDIA CUDA
Platform Vendor                                 NVIDIA Corporation
Platform Version                                OpenCL 3.0 CUDA 11.4.136
Platform Profile                                FULL_PROFILE
Platform Extensions                             cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid cl_khr_pci_bus_info
Platform Host timer resolution                  0ns
Platform Extensions function suffix             NV

Platform Name                                   NVIDIA CUDA
Number of devices                                 1
Device Name                                     NVIDIA GeForce GTX 1050
Device Vendor                                   NVIDIA Corporation
Device Vendor ID                                0x10de
Device Version                                  OpenCL 3.0 CUDA
Driver Version                                  470.74
Device OpenCL C Version                         OpenCL C 1.2 
Device Type                                     GPU
Device Topology (NV)                            PCI-E, 01:00.0
Device Profile                                  FULL_PROFILE
Device Available                                Yes
Compiler Available                              Yes
Linker Available                                Yes
Max compute units                               5
Max clock frequency                             1493MHz
Compute Capability (NV)                         6.1
Device Partition                                (core)
    Max number of sub-devices                     1
    Supported partition types                     None
    Supported affinity domains                    (n/a)
Max work item dimensions                        3
Max work item sizes                             1024x1024x64
Max work group size                             1024
Preferred work group size multiple              32
Warp size (NV)                                  32
Max sub-groups per work group                   0
Preferred / native vector sizes                 
    char                                                 1 / 1       
    short                                                1 / 1       
    int                                                  1 / 1       
    long                                                 1 / 1       
    half                                                 0 / 0        (n/a)
    float                                                1 / 1       
    double                                               1 / 1        (cl_khr_fp64)
Half-precision Floating-point support           (n/a)
Single-precision Floating-point support         (core)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  Yes
Double-precision Floating-point support         (cl_khr_fp64)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
Address bits                                    64, Little-Endian
Global memory size                              2099904512 (1.956GiB)
Error Correction support                        No
Max memory allocation                           524976128 (500.7MiB)
Unified memory for Host and Device              No
Integrated memory (NV)                          No
Shared Virtual Memory (SVM) capabilities        (core)
    Coarse-grained buffer sharing                 Yes
    Fine-grained buffer sharing                   No
    Fine-grained system sharing                   No
    Atomics                                       No
Minimum alignment for any data type             128 bytes
Alignment of base address                       4096 bits (512 bytes)
Preferred alignment for atomics                 
    SVM                                           0 bytes
    Global                                        0 bytes
    Local                                         0 bytes
Max size for global variable                    0
Preferred total size of global vars             0
Global Memory cache type                        Read/Write
Global Memory cache size                        245760 (240KiB)
Global Memory cache line size                   128 bytes
Image support                                   Yes
    Max number of samplers per kernel             32
    Max size for 1D images from buffer            268435456 pixels
    Max 1D or 2D image array size                 2048 images
    Max 2D image size                             16384x32768 pixels
    Max 3D image size                             16384x16384x16384 pixels
    Max number of read image args                 256
    Max number of write image args                16
    Max number of read/write image args           0
Max number of pipe args                         0
Max active pipe reservations                    0
Max pipe packet size                            0
Local memory type                               Local
Local memory size                               49152 (48KiB)
Registers per block (NV)                        65536
Max number of constant args                     9
Max constant buffer size                        65536 (64KiB)
Max size of kernel argument                     4352 (4.25KiB)
Queue properties (on host)                      
    Out-of-order execution                        Yes
    Profiling                                     Yes
Queue properties (on device)                    
    Out-of-order execution                        No
    Profiling                                     No
    Preferred size                                0
    Max size                                      0
Max queues on device                            0
Max events on device                            0
Prefer user sync for interop                    No
Profiling timer resolution                      1000ns
Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    Sub-group independent forward progress        No
    Kernel execution timeout (NV)                 Yes
Concurrent copy and kernel execution (NV)       Yes
    Number of async copy engines                  2
    IL version                                    (n/a)
printf() buffer size                            1048576 (1024KiB)
Built-in kernels                                (n/a)
Device Extensions                               cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid cl_khr_pci_bus_info

NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  NVIDIA CUDA
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   Success [NV]
clCreateContext(NULL, ...) [default]            Success [NV]
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  No platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  Invalid device type for platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No platform

ICD loader properties
ICD loader Name                                 OpenCL ICD Loader
ICD loader Vendor                               OCL Icd free software
ICD loader Version                              2.2.11
ICD loader Profile                              OpenCL 2.1
        NOTE:   your OpenCL library only supports OpenCL 2.1,
                but some installed platforms support OpenCL 3.0.
                Programs using 3.0 features may crash
                or behave unexpectedly

I have no idea, but the code throwing the execption states it needs to be tested on linux (and osx) and is taken from https://github.com/LWJGL/lwjgl3/blob/master/modules/samples/src/test/java/org/lwjgl/demo/opencl/CLGLInteropDemo.java (if you look at the Mandelbrot.java you find the same switch statement on the platform that you find in LwjglContext.java).
Can you run the lwjgl demo or does it also crash?

Edit: I can run OpenGL with Lwjgl or JME3 just fine.
Edit2: OpenCL also runs just fine. The problem is only with the OpenCL-OpenGL buffers and the CL_GL_CONTEXT_KHR and CL_GLX_DISPLAY_KHR properties.

With CLGLInteropDemo I get the same error:

java.lang.RuntimeException: java.lang.RuntimeException: OpenCL error [-1000]
	at com.anrisoftware.anlopencl.jme.opencl.Mandelbrot.<init>(Mandelbrot.java:462)
	at com.anrisoftware.anlopencl.jme.opencl.CLGLInteropDemo$1.run(CLGLInteropDemo.java:217)
Caused by: java.lang.RuntimeException: OpenCL error [-1000]
	at com.anrisoftware.anlopencl.jme.opencl.InfoUtil.checkCLError(InfoUtil.java:114)
	at com.anrisoftware.anlopencl.jme.opencl.InfoUtil.checkCLError(InfoUtil.java:109)
	at com.anrisoftware.anlopencl.jme.opencl.Mandelbrot.<init>(Mandelbrot.java:336)
	... 1 more
GAME ON!
GAME OVER!

Not much comes to my mind then, but I remember initially when i was developing with jme on my notebook i noticed it runs on the IntelHD by default instead of on the Geforce 840M.
I dont really think so, but with your setup could it be possible it created the OpenGL context on another device than it created the OpenCL context on?

This could it be. I run my graphics card in NVIDIA OnDemand mode. The OpenCL context is created on the Nvidia device. But I don’t know if the OpenGL context is also created on the Nvidia device and not on the Intel device.

How can I tell which OpenGL context was created in JME3, the Intel or the Nvidia?

Just tried it in Nvidia mode and it works.

I just have the problem that my graphic cards tends to overheat in Nvidia mode. Also I don’t want to run always in Nvidia mode because of the power consumption.

Is there a way to tell JME3 to use Nvidia for OpenGL?

On Windows you can select the device to run on on a per application basis in the NVIDIA control panel, maybe there is some similar option for linux? maybe some of those buttons we all know saying “super hidden button to finally show the advanced settings”

On Linux, I use DRI_PRIME environment variable to switch the GPUs.

Thank you. I got some info from Arch Linux PRIME - ArchWiki
The prime-run script works fine. I have now Eclipse run in Nvidia mode.
prime-run https://gist.github.com/abenson/a5264836c4e6bf22c8c8415bb616204a

2 Likes