Khanattila / KNLMeansCL

An optimized OpenCL implementation of the Non-local means de-noising algorithm
GNU General Public License v3.0
107 stars 22 forks source link

Vapoursynth plugin load failed in linux #31

Closed fitu996 closed 6 years ago

fitu996 commented 6 years ago

I build latest version (v1.1.1) in linux and copy the .so to /usr/lib/vapoursynth/ . The plugin can not load.

Script evaluation failed:
Python exception: No attribute with the name knlm exists. Did you mistype a plugin namespace?

Traceback (most recent call last):
  File "src/cython/vapoursynth.pyx", line 1847, in vapoursynth.vpy_evaluateScript
  File "test.vpy", line 20, in <module>
    nr16y = core.knlm.KNLMeansCL(src16, d=2, a=2, s=4, h=0.8, device_type="GPU")
  File "src/cython/vapoursynth.pyx", line 1416, in vapoursynth.Core.__getattr__
AttributeError: No attribute with the name knlm exists. Did you mistype a plugin namespace?

Build log

CXXFLAGS/LDFLAGS checking...
checking for vapoursynth headers...
checking for OpenCL...

settings...
CXX          = g++
LD           = g++
STRIP        = strip
CXXFLAGS     = -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2  -fPIC  -I/usr/include/vapoursynth
LDFLAGS      = -shared -fPIC  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
LIBS         = -lOpenCL 
LIBNAME      = libknlmeanscl.so
install path = /usr/lib/vapoursynth
configure finished.
g++ -o libknlmeanscl.so -shared -fPIC  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2  -fPIC  -I/usr/include/vapoursynth -lOpenCL  KNLMeansCL/NLMKernel.cpp KNLMeansCL/NLMVapoursynth.cpp KNLMeansCL/shared/common.cpp KNLMeansCL/shared/ocl_utils.cpp KNLMeansCL/shared/startchar.cpp
In file included from KNLMeansCL/NLMKernel.cpp:24:0:
KNLMeansCL/NLMKernel.h:80:20: warning: ‘kernel_source_code’ defined but not used [-Wunused-variable]
 static const char* kernel_source_code =
                    ^~~~~~~~~~~~~~~~~~
KNLMeansCL/NLMVapoursynth.cpp: In function ‘void VapourSynthPluginCreate(const VSMap*, VSMap*, void*, VSCore*, const VSAPI*)’:
KNLMeansCL/NLMVapoursynth.cpp:714:74: warning: ‘_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)’ is deprecated [-Wdeprecated-declarations]
     d.command_queue = clCreateCommandQueue(d.context, d.deviceID, 0, &ret);
                                                                          ^
In file included from KNLMeansCL/NLMKernel.h:32:0,
                 from KNLMeansCL/NLMVapoursynth.h:22,
                 from KNLMeansCL/NLMVapoursynth.cpp:19:
/usr/include/CL/cl.h:1443:1: note: declared here
 clCreateCommandQueue(cl_context                     /* context */,
 ^~~~~~~~~~~~~~~~~~~~
strip libknlmeanscl.so
make: Entering directory '/tmp/makepkg/vapoursynth-plugin-knlmeanscl-git/src/knlmeanscl'
g++ -o libknlmeanscl.so -shared -fPIC  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2  -fPIC  -I/usr/include/vapoursynth -lOpenCL  KNLMeansCL/NLMKernel.cpp KNLMeansCL/NLMVapoursynth.cpp KNLMeansCL/shared/common.cpp KNLMeansCL/shared/ocl_utils.cpp KNLMeansCL/shared/startchar.cpp
In file included from KNLMeansCL/NLMKernel.cpp:24:0:
KNLMeansCL/NLMKernel.h:80:20: warning: ‘kernel_source_code’ defined but not used [-Wunused-variable]
 static const char* kernel_source_code =
                    ^~~~~~~~~~~~~~~~~~
KNLMeansCL/NLMVapoursynth.cpp: In function ‘void VapourSynthPluginCreate(const VSMap*, VSMap*, void*, VSCore*, const VSAPI*)’:
KNLMeansCL/NLMVapoursynth.cpp:714:74: warning: ‘_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)’ is deprecated [-Wdeprecated-declarations]
     d.command_queue = clCreateCommandQueue(d.context, d.deviceID, 0, &ret);
                                                                          ^
In file included from KNLMeansCL/NLMKernel.h:32:0,
                 from KNLMeansCL/NLMVapoursynth.h:22,
                 from KNLMeansCL/NLMVapoursynth.cpp:19:
/usr/include/CL/cl.h:1443:1: note: declared here
 clCreateCommandQueue(cl_context                     /* context */,
 ^~~~~~~~~~~~~~~~~~~~
strip libknlmeanscl.so
install -d /usr/lib/vapoursynth
install -m 755 libknlmeanscl.so /usr/lib/vapoursynth
make: Leaving directory 'src/knlmeanscl'
fitu996 commented 6 years ago

version 1.1.0 works fine.

Khanattila commented 6 years ago

Hi fitu99, thanks for your report. I fixed the problem with the commit #b81a87ed

fitu996 commented 6 years ago

Where is commit #b81a87ed?

I build it from latest master branch, the problem still exist.

Khanattila commented 6 years ago

Hi fitu996, could you post the build log with the latest commit? Thank you.

fitu996 commented 6 years ago
CXXFLAGS/LDFLAGS checking...
checking for vapoursynth headers...
checking for OpenCL...

settings...
CXX          = g++
LD           = g++
STRIP        = strip
CXXFLAGS     = -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include -march=native -mtune=native -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2  -fPIC  -I/usr/include/vapoursynth
LDFLAGS      = -shared -fPIC  -Wl,-O2,--sort-common,--as-needed,-z,relro,-z,now
LIBS         = -lOpenCL 
LIBNAME      = libknlmeanscl.so
install path = /usr/lib/vapoursynth
configure finished.
g++ -o libknlmeanscl.so -shared -fPIC  -Wl,-O2,--sort-common,--as-needed,-z,relro,-z,now -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include -march=native -mtune=native -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2  -fPIC  -I/usr/include/vapoursynth -lOpenCL  KNLMeansCL/NLMKernel.cpp KNLMeansCL/NLMAvisynth.cpp KNLMeansCL/NLMVapoursynth.cpp KNLMeansCL/shared/common.cpp KNLMeansCL/shared/ocl_utils.cpp KNLMeansCL/shared/startchar.cpp
strip libknlmeanscl.so
make: Entering directory '/startdir/src/knlmeanscl'
g++ -o libknlmeanscl.so -shared -fPIC  -Wl,-O2,--sort-common,--as-needed,-z,relro,-z,now -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include -march=native -mtune=native -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2  -fPIC  -I/usr/include/vapoursynth -lOpenCL  KNLMeansCL/NLMKernel.cpp KNLMeansCL/NLMAvisynth.cpp KNLMeansCL/NLMVapoursynth.cpp KNLMeansCL/shared/common.cpp KNLMeansCL/shared/ocl_utils.cpp KNLMeansCL/shared/startchar.cpp
strip libknlmeanscl.so
install -d /usr/lib/vapoursynth
install -m 755 libknlmeanscl.so /usr/lib/vapoursynth
make: Leaving directory '/startdir/src/knlmeanscl'
fitu996 commented 6 years ago
Python 3.6.4 (default, Jan  5 2018, 02:35:40) 
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import vapoursynth as vs
>>> core=vs.get_core()
>>> print(core.version())
VapourSynth Video Processing Library
Copyright (c) 2012-2018 Fredrik Mellbin
Core R43
API R3.5
Options: -

>>> core.knlm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/cython/vapoursynth.pyx", line 1416, in vapoursynth.Core.__getattr__
AttributeError: No attribute with the name knlm exists. Did you mistype a plugin namespace?
Khanattila commented 6 years ago

What is your system?

Ubuntu MATE 16.04.04 LTS (Xenial) 64-bit system

./configure --install=/usr/lib/x86_64-linux-gnu/vapoursynth
CXXFLAGS/LDFLAGS checking...
checking for vapoursynth headers...
checking for OpenCL...
settings...
CXX          = g++
LD           = g++
STRIP        = strip
CXXFLAGS     = -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include   -fPIC  -I/usr/include/vapoursynth
LDFLAGS      = -shared -fPIC  
LIBS         = -lOpenCL 
LIBNAME      = libknlmeanscl.so
install path = /usr/lib/x86_64-linux-gnu/vapoursynth
configure finished.
g++ -o libknlmeanscl.so -shared -fPIC   -O2 -std=gnu++11 -Wall -Wno-unused-local-typedefs -I. -I./shared -I./include   -fPIC  -I/usr/include/vapoursynth -lOpenCL  KNLMeansCL/NLMKernel.cpp KNLMeansCL/NLMAvisynth.cpp KNLMeansCL/NLMVapoursynth.cpp KNLMeansCL/shared/common.cpp KNLMeansCL/shared/ocl_utils.cpp KNLMeansCL/shared/startchar.cpp
strip libknlmeanscl.so
install -d /usr/lib/x86_64-linux-gnu/vapoursynth
install -m 755 libknlmeanscl.so /usr/lib/x86_64-linux-gnu/vapoursynth
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import vapoursynth as vs
>>> core=vs.get_core()
>>> print(core.version())
VapourSynth Video Processing Library
Copyright (c) 2012-2017 Fredrik Mellbin
Core R40
API R3.5
Options: -

>>> core.knlm
<vapoursynth.Plugin object at 0x7f336b189678>
4re commented 6 years ago

Maybe not the same bug but I think I have one closely related. If you want I can make it a separate issue.

My distro is Gentoo Linux and I'm using x11-drivers/nvidia-drivers-390.42 proprietary drivers.

Plugins loads, but when I try to actually use it, it crashes with the message: vsedit: symbol lookup error: /usr/lib64/vapoursynth/libknlmeanscl.so: undefined symbol: clGetPlatformIDs

It appears this bug is only triggered when the plugin was built with the linker flags Wl,--as-needed and appeared after the refactoring and stuff between versions 1.1.1 and 1.1.0. Without them, it loads and works.

Because the build system was broken at that time it is difficult for me to track the exact commit the problem appeared.

4re commented 6 years ago

And the cause seems to be the build system does not actually tells to link against OpenCL and keep it and somehow and it gets stripped with --as-needed.

With a custom compiling script it worked fine.

sl1pkn07 commented 6 years ago

yep. seems like filtering '--as-needed' in LDFLAGS fix the problem

fitu996 commented 6 years ago

Everything works fine after disable --as-needed in LDFLAGS.

The fix of vsedit: symbol lookup error: /usr/lib64/vapoursynth/libknlmeanscl.so: undefined symbol: clGetPlatformIDs is edit/create file in /etc/OpenCL/vendors/nvidia.icd (or /etc/OpenCL/vendors/intel.icd if you want to use cpu), change it to libnvidia-opencl.so (or libintelocl.so), make sure the .so is in your library path(otherwise you may want to use full path like /opt/intel/opencl-runtime/lib64/libintelocl.so). This way works for me.

But I believe --as-needed shouldn't be blamed. Its a bug of this project. I will be appreciate if you can open this issue until this problem is really fixed.

I'm using ArchLinux nvidia 390.42 gcc 7.3.1

sl1pkn07 commented 6 years ago

The fix of vsedit: symbol lookup error: /usr/lib64/vapoursynth/libknlmeanscl.so: undefined symbol: clGetPlatformIDs is edit/create file in /etc/OpenCL/vendors/nvidia.icd (or /etc/OpenCL/vendors/intel.icd if you want to use cpu), change it to libnvidia-opencl.so (or libintelocl.so), make sure the .so is in your library path(otherwise you may want to use full path like /opt/intel/opencl-runtime/lib64/libintelocl.so). This way works for me.

this sound a missing dependencies, like opencl-driver. i'm working now for fix it

EDIT: opencl-driver is optional dependencies for ocl-icd. then is not package fault

fitu996 commented 6 years ago

@sl1pkn07 Thank you for your care. I have not meet the problem vsedit: symbol lookup error: /usr/lib64/vapoursynth/libknlmeanscl.so: undefined symbol: clGetPlatformIDs in my ArchLinux. After your quick fix, I can install this plugin using AUR helper without any pain. Thank you again. I have that problem with gentoo long time ago so I just want to tell @4re what might happend. I have switched back to ArchLinux so I do not know what gentoo do recently. But I think this may help in some way.

4re commented 6 years ago

But ofc --as-needed is not the problem, I can build this very same source code with it and it works flawlessly. The problem is the build system, probably OpenCL is not linked and the build system for some reason does not complain about it, in the end you end up with a faulty library.

I did a PR with meson as build system but travis VM's are too old for it...

Khanattila commented 6 years ago

@4re seems to have solved the problem.