inducer / pyopencl

OpenCL integration for Python, plus shiny features
http://mathema.tician.de/software/pyopencl
Other
1.05k stars 240 forks source link

CL_PRETEND_VERSION not working when installing from repo #550

Closed AwesomeCronk closed 2 years ago

AwesomeCronk commented 2 years ago

Describe the bug I am trying to install PyOpenCL with OpenGL interop support. When I import pyopencl this traceback is generated:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aweso/Source/Python/pyopencl/pyopencl/__init__.py", line 28, in <module>
    import pyopencl.cltypes  # noqa: F401
  File "/home/aweso/Source/Python/pyopencl/pyopencl/cltypes.py", line 22, in <module>
    from pyopencl.tools import get_or_register_dtype
  File "/home/aweso/Source/Python/pyopencl/pyopencl/tools.py", line 36, in <module>
    from pyopencl._cl import bitlog2  # noqa: F401
ImportError: /home/aweso/Source/Python/pyopencl/pyopencl/_cl.cpython-38-x86_64-linux-gnu.so: undefined symbol: clSetProgramSpecializationConstant

I have found that the symbol in question is an OpenCL 2.2 symbol, but the ICD loader on my system only supports 2.1 for my CPU. This is my siteconf.py:

CL_TRACE = False
CL_ENABLE_GL = True
CL_USE_SHIPPED_EXT = False
CL_PRETEND_VERSION = '2.1'
CL_INC_DIR = []
CL_LIB_DIR = []
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['-fvisibility=hidden']
LDFLAGS = ['-Wl,--no-as-needed']

To Reproduce Steps to reproduce the behavior:

  1. $ sudo apt install intel-opencl-icd
  2. $ git clone https://github.com/inducer/pyopencl; cd pyopencl
  3. $ python3 configure.py --cl-enable-gl --cl-pretend-version=2.1
  4. $ python3 -m pip install -e .
  5. Now launch Python 3 and import pyopencl. The above traceback is generated.

Expected behavior Setting CL_PRETEND_VERSION to 2.1 should inform PyOpenCL that 2.2 symbols aren't available and shouldn't be used.

Environment (please complete the following information):

Additional context This machine has no dedicated GPU.

inducer commented 2 years ago

I can't reproduce this. If I build with

CL_PRETEND_VERSION = '2.1'

in siteconf.py, run

rm -Rf build; python setup.py develop

Then I get

$ nm --dynamic pyopencl/_cl.cpython-310-x86_64-linux-gnu.so |grep Specialization

returning no results.

The symbol is also #ifdef'd with the correct version in the header: https://github.com/inducer/pyopencl/blob/291649892f4972e46c5823bfa359b37ad94d6cd5/src/wrap_cl.hpp#L4048-L4057=

AwesomeCronk commented 2 years ago

Interesting... As a side note, if I cat /etc/OpenCL/vendors/intel.icd (the only .icd there) I get this:

/usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so

So then might the issue be in how I installed the ICD or elsewhere?

I will try building it tonight, unless that's what pip install -e . does already.

inducer commented 2 years ago

Almost certainly this has nothing to do with your ICD, as the failing symbol lookup

ImportError: /home/aweso/Source/Python/pyopencl/pyopencl/_cl.cpython-38-x86_64-linux-gnu.so: undefined symbol: clSetProgramSpecializationConstant

is against the ICD loader.

The easiest way to get a working setup is to use conda forge, as described here.

AwesomeCronk commented 2 years ago

Interestingly enough, when I install using either Conda or Pip, it's stable and import pyopencl works. However, pyopencl.have_gl() returns False, confimed by the fact that get_gl_sharing_context_properties() does this:

Traceback (most recent call last):
  File "PyOpenCL_GL.py", line 96, in initializeGL
    self.initialize_buffers()
  File "PyOpenCL_GL.py", line 56, in initialize_buffers
    self.ctx, self.queue = clinit()
  File "PyOpenCL_GL.py", line 34, in clinit
    + get_gl_sharing_context_properties())
  File "/home/aweso/.local/lib/python3.8/site-packages/pyopencl/tools.py", line 502, in get_gl_sharing_context_properties
    (ctx_props.GL_CONTEXT_KHR, GLX.glXGetCurrentContext()))
AttributeError: type object 'pyopencl._cl.context_properties' has no attribute 'GL_CONTEXT_KHR'

I do need OpenGL interop support, which is why I tried installing from the git repo.

AwesomeCronk commented 2 years ago

Tried building from source via the tar.gz at https://pypi.org/project/pyopencl/#files, same problem as building from the git version.

AwesomeCronk commented 2 years ago

Intel NEO doesn't support CL-GL interops on Linux. That's the issue, not anything to do with PyOpenCL...