Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run tests when distributing pyopencl? #784

Closed
doronbehar opened this issue Aug 30, 2024 · 11 comments
Closed

How to run tests when distributing pyopencl? #784

doronbehar opened this issue Aug 30, 2024 · 11 comments

Comments

@doronbehar
Copy link

Hello,

We are trying to run tests on NixOS'. However, these fail like this:

-- CL_INC_DIR not set, trying to guess it from environment variables.
-- CL_INC_DIR not set, trying to guess it from conda environment.
-- CL_INC_DIR
-- CL_LIB_DIR
-- CL_LIBNAME
-- Found Python: /nix/store/04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/bin/python3.12 (found version "3.12.4") found components: Interpreter Development.Module NumPy
'/nix/store/04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/bin/python3.12' '-c' 'import nanobind; print(nanobind.__version__)'
'/nix/store/04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/bin/python3.12' '-c' 'import nanobind; print(nanobind.cmake_dir())'
-- Looking for CL_VERSION_3_0
-- Looking for CL_VERSION_3_0 - found
-- Found OpenCL: /nix/store/0wq6jx9p4g78r8hk7rbbc64jml8qgb61-ocl-icd-2.3.2/lib/libOpenCL.so (found version "3.0")
==============================
PyOpenCL v2024.2.7 (non-git) configuration:
  PyOpenCL options: PYOPENCL_TRACE=OFF PYOPENCL_ENABLE_GL=OFF PYOPENCL_USE_SHIPPED_EXT=OFF PYOPENCL_PRETEND_CL_VERSION=
  OpenCL:           /nix/store/0wq6jx9p4g78r8hk7rbbc64jml8qgb61-ocl-icd-2.3.2/lib/libOpenCL.so [3.0]
  Python:           3.12.4 [/nix/store/04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/bin/python3.12]
  Build type:       Release
  C++ compiler:     /nix/store/lbk30k56awz9vz9qpid93fkjns0xwlhd-gcc-wrapper-13.3.0/bin/g++ [GNU ]
  CMake:            /nix/store/sa1yjb7xxrzcbd1bysj3r561vidfxxvb-cmake-3.29.6/bin/cmake [3.29.6]
  Nanobind:         2.1.0
==============================
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /build/tmpn83ceif5/build
*** Building project with Ninja...
[13/18] Building CXX object CMakeFiles/_cl.dir/src/wrap_cl.cpp.otore/izp0vcbwzsqc0z7lzg6gv38wk4za4rcv-python3.12-nanobind-2.1.0/lib/python3.12/site-packages/nanobind/src/nb_type.cpp.o.o.o.cpp.o
In file included from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /build/source/src/wrap_cl.hpp:102,
                 from /build/source/src/wrap_cl.cpp:29:
/nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
[14/18] Building CXX object CMakeFiles/_cl.dir/src/wrap_constants.cpp.o
In file included from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /build/source/src/wrap_cl.hpp:102,
                 from /build/source/src/wrap_constants.cpp:30:
/nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
[15/18] Building CXX object CMakeFiles/_cl.dir/src/wrap_mempool.cpp.o
In file included from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /build/source/src/wrap_cl.hpp:102,
                 from /build/source/src/wrap_mempool.cpp:37:
/nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
[16/18] Building CXX object CMakeFiles/_cl.dir/src/wrap_cl_part_1.cpp.o
In file included from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /build/source/src/wrap_cl.hpp:102,
                 from /build/source/src/wrap_cl_part_1.cpp:30:
/nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
[17/18] Building CXX object CMakeFiles/_cl.dir/src/wrap_cl_part_2.cpp.o
In file included from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /build/source/src/wrap_cl.hpp:102,
                 from /build/source/src/wrap_cl_part_2.cpp:31:
/nix/store/5qnnxrlcfiiv9b84cj1n02gnfq2hbsp4-python3.12-numpy-1.26.4/lib/python3.12/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
[18/18] Linking CXX shared module _cl.cpython-312-x86_64-linux-gnu.so
*** Installing project into wheel...
-- Install configuration: "Release"
-- Installing: /build/tmpn83ceif5/wheel/platlib/pyopencl/_cl.cpython-312-x86_64-linux-gnu.so
*** Making wheel...
*** Created pyopencl-2024.2.7-cp312-cp312-linux_x86_64.whl
Successfully built pyopencl-2024.2.7-cp312-cp312-linux_x86_64.whl
Finished creating a wheel...
Finished executing pypaBuildPhase
Running phase: pythonRuntimeDepsCheckHook
@nix { "action": "setPhase", "phase": "pythonRuntimeDepsCheckHook" }
Executing pythonRuntimeDepsCheck
Checking runtime dependencies for pyopencl-2024.2.7-cp312-cp312-linux_x86_64.whl
Finished executing pythonRuntimeDepsCheck
Running phase: installPhase
@nix { "action": "setPhase", "phase": "installPhase" }
Executing pypaInstallPhase
Successfully installed pyopencl-2024.2.7-cp312-cp312-linux_x86_64.whl
Finished executing pypaInstallPhase
Running phase: pythonOutputDistPhase
@nix { "action": "setPhase", "phase": "pythonOutputDistPhase" }
Executing pythonOutputDistPhase
Finished executing pythonOutputDistPhase
Running phase: fixupPhase
@nix { "action": "setPhase", "phase": "fixupPhase" }
shrinking RPATHs of ELF executables and libraries in /nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7
shrinking /nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7/lib/python3.12/site-packages/pyopencl/_cl.cpython-312-x86_64-linux-gnu.so
checking for references to /build/ in /nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7...
patching script interpreter paths in /nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7
stripping (with command strip and flags -S -p) in  /nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7/lib
shrinking RPATHs of ELF executables and libraries in /nix/store/xjdss3svpypby8566xz03hs137fvxqdj-python3.12-pyopencl-2024.2.7-dist
checking for references to /build/ in /nix/store/xjdss3svpypby8566xz03hs137fvxqdj-python3.12-pyopencl-2024.2.7-dist...
patching script interpreter paths in /nix/store/xjdss3svpypby8566xz03hs137fvxqdj-python3.12-pyopencl-2024.2.7-dist
Executing pythonRemoveTestsDir
Finished executing pythonRemoveTestsDir
Running phase: installCheckPhase
@nix { "action": "setPhase", "phase": "installCheckPhase" }
no Makefile or custom installCheckPhase, doing nothing
Running phase: pythonCatchConflictsPhase
@nix { "action": "setPhase", "phase": "pythonCatchConflictsPhase" }
Running phase: pythonRemoveBinBytecodePhase
@nix { "action": "setPhase", "phase": "pythonRemoveBinBytecodePhase" }
Running phase: pythonImportsCheckPhase
@nix { "action": "setPhase", "phase": "pythonImportsCheckPhase" }
Executing pythonImportsCheckPhase
Check whether the following modules can be imported: pyopencl pyopencl.array pyopencl.cltypes pyopencl.compyte pyopencl.elementwise pyopencl.tools
Running phase: pytestCheckPhase
@nix { "action": "setPhase", "phase": "pytestCheckPhase" }
Executing pytestCheckPhase
============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-8.3.2, pluggy-1.5.0
rootdir: /nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7
collected 0 items / 2 errors

==================================== ERRORS ====================================
_ ERROR collecting lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_elemwise.py _
ImportError while importing test module '/nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7/lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_elemwise.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_elemwise.py:5: in <module>
    import pygpu_ndarray as gpu_ndarray
E   ModuleNotFoundError: No module named 'pygpu_ndarray'
_ ERROR collecting lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_ndarray.py _
ImportError while importing test module '/nix/store/0n166zhbcwdykb548rhs0ckdgfy8265b-python3.12-pyopencl-2024.2.7/lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_ndarray.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_ndarray.py:4: in <module>
    import pygpu_ndarray as gpu_ndarray
E   ModuleNotFoundError: No module named 'pygpu_ndarray'
=========================== short test summary info ============================
ERROR lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_elemwise.py
ERROR lib/python3.12/site-packages/pyopencl/compyte/ndarray/test_gpu_ndarray.py
!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 2 errors in 0.48s ===============================

I tried to debug this a bit myself and I don't understand what's going on in the compyte Git submodule - there is a Makefile there from more then a decade ago. I tried to make pygpu_ndarray.so and I encountered python -c print "..." errors. I also tried to override the Makefile variables so it won't rely upon Python, and I got this:

nvcc -c -g -DOFFSET -m64 -Xcompiler -fPIC,-m64 -Xlinker -rpath,/opt/lisa/os/cuda/lib64 -Xlinker -rpath,/opt/lisa/os/cuda/lib -I/opt/lisa/os/cuda/include /nix/store/04gg5w1s662l329a8kh9xcwyp0k64v5a-python3-3.12.4/include/3.12  -o pygpu_language_cuda.o pygpu_language_cuda.cu
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
make: *** [Makefile:21: pygpu_language_cuda.o] Error 1

I'm also surprised no body mentioned pygpu_ndarray in the issue tracker of Pyopencl and compyte at all.

@inducer
Copy link
Owner

inducer commented Aug 30, 2024

The only thing that's used from compyte in pyopencl is array.py and dtypes.py. The rest is (unused) vestiges of an old GPU array project that never came to fruition. I recently dropped them from compyte. #785 updates pyopencl to that version of compyte.

So tl;dr: that stuff is safe to ignore and should really never have been included in the distribution.

@doronbehar
Copy link
Author

OK, so now, are there any tests for pyopencl that I would want to run when distributing pyopencl?

@inducer
Copy link
Owner

inducer commented Aug 31, 2024

Can you assume that an ICD is installed?

@doronbehar
Copy link
Author

Can you assume that an ICD is installed?

I'm not sure what do you mean exactly.. Maybe I can.

@inducer
Copy link
Owner

inducer commented Sep 1, 2024

In OpenCL-speak, an ICD is something like pocl or a GPU driver. It's hard to test pyopencl without one. (because none of the OpenCL API calls do anything)

@doronbehar
Copy link
Author

In OpenCL-speak, an ICD is something like pocl or a GPU driver. It's hard to test pyopencl without one. (because none of the OpenCL API calls do anything)

OK I see. What command would you run to test pyopencl then? Assuming there is an ICD available.

@inducer
Copy link
Owner

inducer commented Sep 1, 2024

If you're willing to ship the test folder, simply run python3 -m pytest in that. In general, I think it'd be better to move the test folder into pyopencl package, so that it's always installed alongside.

@doronbehar
Copy link
Author

doronbehar commented Sep 4, 2024

OK - now I see that indeed the test folder is not packaged by default. Thanks :) I do experience now a more interesting error:

E   pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
_ ERROR collecting lib/python3.12/site-packages/pyopencl/test/test_wrapper.py __
../xrlajzmcwarm0rhim9kdjbf50sw2pfas-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_hooks.py:513: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
../xrlajzmcwarm0rhim9kdjbf50sw2pfas-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../7p6gx66zzh7gk0094rxis9k5sli95yzf-python3.12-pytest-8.3.2/lib/python3.12/site-packages/_pytest/python.py:245: in pytest_pycollect_makeitem
    return list(collector._genfunctions(name, obj))
../7p6gx66zzh7gk0094rxis9k5sli95yzf-python3.12-pytest-8.3.2/lib/python3.12/site-packages/_pytest/python.py:462: in _genfunctions
    self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
../xrlajzmcwarm0rhim9kdjbf50sw2pfas-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_hooks.py:574: in call_extra
    return self._hookexec(self.name, hookimpls, kwargs, firstresult)
../xrlajzmcwarm0rhim9kdjbf50sw2pfas-python3.12-pluggy-1.5.0/lib/python3.12/site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
lib/python3.12/site-packages/pyopencl/tools.py:719: in pytest_generate_tests_for_pyopencl
    arg_values, ids = get_pyopencl_fixture_arg_values()
lib/python3.12/site-packages/pyopencl/tools.py:678: in get_pyopencl_fixture_arg_values
    for platform, devices in get_test_platforms_and_devices():
lib/python3.12/site-packages/pyopencl/tools.py:646: in get_test_platforms_and_devices
    for platform in cl.get_platforms()]
E   pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR

And in all of these files:

ERROR lib/python3.12/site-packages/pyopencl/test/test_algorithm.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
ERROR lib/python3.12/site-packages/pyopencl/test/test_array.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
ERROR lib/python3.12/site-packages/pyopencl/test/test_arrays_in_structs.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
ERROR lib/python3.12/site-packages/pyopencl/test/test_clmath.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
ERROR lib/python3.12/site-packages/pyopencl/test/test_clrandom.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
ERROR lib/python3.12/site-packages/pyopencl/test/test_enqueue_copy.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR
ERROR lib/python3.12/site-packages/pyopencl/test/test_wrapper.py - pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR

Does that mean that ICD is not available in our build environment?

@inducer
Copy link
Owner

inducer commented Sep 4, 2024

Does that mean that ICD is not available in our build environment?

Yes.

@inducer
Copy link
Owner

inducer commented Sep 4, 2024

https://portablecl.org/ is an ICD that doesn't need special hardware and is fairly straightforward to install.

@doronbehar
Copy link
Author

Then this issue can be marked as resolved, unless you'd want to keep it open for discussing about the test/ directory distribution topic.

@inducer inducer closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants