Bug#958700: pocl: nested(?) dlopen fails

2020-04-26 Thread Andreas Beckmann
On 26/04/2020 15.07, Rebecca N. Palmer wrote:
> Control: retitle -1 pocl: nested(?) dlopen fails
> Control: reassign -1 libpocl2 1.5-2
> Control: affects -1 src:libgpuarray python3-pyopencl
> 
> ocl-icd-libopencl1 dlopen()s ICDs (at
> https://sources.debian.org/src/ocl-icd/2.2.12-4/ocl_icd_loader.c/#L184).
>  With pocl 1.5, this dlopen() fails in some conditions (returns a NULL
> pointer).  dlerror says the problem is "undefined symbol: clRetainEvent".

libpocl.so.2 1.5 uses two symbols from libOpenCL.so.1:
# nm -D /usr/lib/x86_64-linux-gnu/libpocl.so.2.5.0 | grep Retain
 U clRetainEvent
 U clRetainKernel

So I think the failure can be reduced to

dlopen("libOpenCL.so.1", RTLD_LOCAL)
dlopen("libpocl.so.2", RTLD_LOCAL)

while it succeeds with

dlopen("libOpenCL.so.1", RTLD_GLOBAL)  // aka -lOpenCL
dlopen("libpocl.so.2", RTLD_LOCAL)

Build logs say

dpkg-shlibdeps: warning: symbol clRetainKernel used by 
debian/libpocl2/usr/lib/x86_64-linux-gnu/libpocl.so.2.5.0 found in none of the 
libraries
dpkg-shlibdeps: warning: symbol clRetainEvent used by 
debian/libpocl2/usr/lib/x86_64-linux-gnu/libpocl.so.2.5.0 found in none of the 
libraries

OK, there is an upstream commit supposed to fix this.

Andreas



Bug#958700: pocl: nested(?) dlopen fails

2020-04-26 Thread Rebecca N. Palmer

Control: retitle -1 pocl: nested(?) dlopen fails
Control: reassign -1 libpocl2 1.5-2
Control: affects -1 src:libgpuarray python3-pyopencl

ocl-icd-libopencl1 dlopen()s ICDs (at 
https://sources.debian.org/src/ocl-icd/2.2.12-4/ocl_icd_loader.c/#L184). 
 With pocl 1.5, this dlopen() fails in some conditions (returns a NULL 
pointer).  dlerror says the problem is "undefined symbol: clRetainEvent".


After such a failure, libopencl1 ignores that ICD but keeps looking for 
others.  If there aren't any (i.e. pocl is the only ICD installed), it 
returns a "no platforms found" error, hence the above test failures.


This is a regression: it does not happen with pocl from testing (1.4).

These fail:
- pygpu (libgpuarray Python interface) - import 
pygpu.gpuarray;pygpu.gpuarray.init('opencl0:0')

- libgpuarray C interface - program 2 below
- pyopencl - import pyopencl;pyopencl.get_platforms()

These succeed:
- direct C++ calls, including clRetainEvent - program 1 below
- clinfo
- beignet-dev's tester - /usr/lib/x86_64-linux-gnu/beignet/utest_run

These failures are all cases where the code trying to dlopen() pocl was 
itself dlopen()ed: Python dlopen()s C extensions (such as pyopencl and 
pygpu) on import, and libgpuarray dlopen()s libopencl.


$ gdb --args python3 -c "import pyopencl;pyopencl.get_platforms()"
[standard notice]
Reading symbols from python3...
(No debugging symbols found in python3)
(gdb) break _load_icd
Function "_load_icd" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (_load_icd) pending.
(gdb) run
Starting program: /usr/bin/python3 -c import\ 
pyopencl\;pyopencl.get_platforms\(\)

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, _load_icd (lib_path=0xe1cbc0 "libpocl.so.2.5.0", num_icds=0)
at ocl_icd_loader.c:237
237 ocl_icd_loader.c: No such file or directory.
(gdb) break dlopen
Breakpoint 2 at 0x77dd22a0: file dlopen.c, line 75.
(gdb) c
Continuing.

Breakpoint 2, __dlopen (file=file@entry=0xe1cbc0 "libpocl.so.2.5.0",
mode=mode@entry=1) at dlopen.c:75
75  dlopen.c: No such file or directory.
(gdb) finish
Run till exit from #0  __dlopen (file=file@entry=0xe1cbc0 
"libpocl.so.2.5.0",

mode=mode@entry=1) at dlopen.c:75
0x777d97eb in _load_icd (lib_path=0xe1cbc0 "libpocl.so.2.5.0",
num_icds=0) at ocl_icd_loader.c:237
237 ocl_icd_loader.c: No such file or directory.
Value returned is $1 = (void *) 0x0
(gdb) print dlerror()
$2 = 0xd9c600 "/usr/lib/x86_64-linux-gnu/libpocl.so.2.5.0: undefined 
symbol: clRetainEvent"

(gdb) quit

Test program 1 - compile with -lOpenCL
#include 
#include 
int main(){
cl_uint num_platforms;
cl_int err;
err=clGetPlatformIDs(0,NULL,_platforms);
std::printf("%i %i",err,num_platforms);
cl_int status;
cl_device_id device;
clGetDeviceIDs(NULL,CL_DEVICE_TYPE_ALL,1,,NULL);
char device_name[101];
device_name[100]=0;
clGetDeviceInfo(device,CL_DEVICE_NAME,100,device_name,NULL);
cl_context ctx = clCreateContext(NULL, 1, , NULL, NULL, );
cl_event event1 = clCreateUserEvent(ctx,NULL);
std::printf("\n%i\n",clRetainEvent(event1));
}

Test program 2 - compile with -lgpuarray
#include 
#include 
int main(){
gpucontext_props *p;
gpucontext *p2 = NULL;
int err;
gpucontext_props_new();
gpucontext_props_alloc_cache(p,0,0x10);
err = gpucontext_props_opencl_dev(p,0,0);
std::printf("%i %p",err,p);
err=gpucontext_init(,"opencl",p);
std::printf("%i %p",err,p2);
}