NVIDIA / MatX

An efficient C++17 GPU numerical computing library with Python-like syntax

Home Page:https://nvidia.github.io/MatX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] `cmake_sample_project` cannot build when setting `MATX_EN_PYBIND11=ON` on Python >= 3.11

lucifer1004 opened this issue · comments

Describe the Bug
See the title.

To Reproduce
Build cmake_sample_project with MATX_EN_PYBIND11=ON:

cmake -S examples/cmake_sample_project -B build -DMATX_EN_PYBIND11=ON
cmake --build build

The compiler would complain:

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(446): error: pointer to incomplete class type "_frame" is not allowed
                  "  " + handle(frame->f_code->co_filename).cast<std::string>() +
                                ^

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(446): error: type name is not allowed
                  "  " + handle(frame->f_code->co_filename).cast<std::string>() +
                                                                 ^

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(446): error: expected an expression
                  "  " + handle(frame->f_code->co_filename).cast<std::string>() +
                                                                              ^

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(448): error: pointer to incomplete class type "_frame" is not allowed
                  handle(frame->f_code->co_name).cast<std::string>() + "\n";
                         ^

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(448): error: type name is not allowed
                  handle(frame->f_code->co_name).cast<std::string>() + "\n";
                                                      ^

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(448): error: expected an expression
                  handle(frame->f_code->co_name).cast<std::string>() + "\n";
                                                                   ^

/xxx/build/_deps/pybind11-src/include/pybind11/cast.h(449): error: pointer to incomplete class type "_frame" is not allowed
              frame = frame->f_back;
                      ^

/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h(2291): error: class "_ts" has no member "frame"
      PyFrameObject *frame = PyThreadState_Get()->frame;
                                                  ^

/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h(2292): error: pointer to incomplete class type "_frame" is not allowed
      if (frame && (std::string) str(frame->f_code->co_name) == name &&
                                     ^

/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h(2293): error: pointer to incomplete class type "_frame" is not allowed
          frame->f_code->co_argcount > 0) {
          ^

/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h(2296): error: pointer to incomplete class type "_frame" is not allowed
              frame->f_locals, (((static_cast <bool> (PyType_HasFeature((Py_TYPE(((PyObject*)((frame->f_code->co_varnames))))), ((1UL << 26)))) ? void (0) : __assert_fail ("PyTuple_Check(frame->f_code->co_varnames)", "/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h", 2296, __extension__ __PRETTY_FUNCTION__)), ((PyTupleObject*)((frame->f_code->co_varnames))))->ob_item[(0)]));
              ^

/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h(2296): error: pointer to incomplete class type "_frame" is not allowed
              frame->f_locals, (((static_cast <bool> (PyType_HasFeature((Py_TYPE(((PyObject*)((frame->f_code->co_varnames))))), ((1UL << 26)))) ? void (0) : __assert_fail ("PyTuple_Check(frame->f_code->co_varnames)", "/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h", 2296, __extension__ __PRETTY_FUNCTION__)), ((PyTupleObject*)((frame->f_code->co_varnames))))->ob_item[(0)]));
                                                                                               ^

/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h(2296): error: pointer to incomplete class type "_frame" is not allowed
              frame->f_locals, (((static_cast <bool> (PyType_HasFeature((Py_TYPE(((PyObject*)((frame->f_code->co_varnames))))), ((1UL << 26)))) ? void (0) : __assert_fail ("PyTuple_Check(frame->f_code->co_varnames)", "/xxx/build/_deps/pybind11-src/include/pybind11/pybind11.h", 2296, __extension__ __PRETTY_FUNCTION__)), ((PyTupleObject*)((frame->f_code->co_varnames))))->ob_item[(0)]));
                                                                                                                                                                                                                                                                                                                                                                                               ^

13 errors detected in the compilation of "/xxx/src/xxx.cu".
gmake[2]: *** [CMakeFiles/sample_matx.dir/build.make:77: CMakeFiles/sample_matx.dir/src/xxx.cu.o] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:151: CMakeFiles/sample_matx.dir/all] Error 2
gmake: *** [Makefile:111: all] Error 2

There seems to be some issue with MatX's CMakeLists.txt.

Expected Behavior
The build should work, although the sample project does not use pybind11.

Compiler Version

gcc --version
$ gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

nvcc --version
$ nvcc: NVIDIA (R) Cuda compiler driver
$ Copyright (c) 2005-2023 NVIDIA Corporation
$ Built on Wed_Nov_22_10:17:15_PST_2023
$ Cuda compilation tools, release 12.3, V12.3.107
$ Build cuda_12.3.r12.3/compiler.33567101_0

Hi @lucifer1004 , I'm not able to reproduce this:

ld/
I have no name!@f9a8be5fb819:/repro/cmake_sample_project/build$ cmake ..
-- Found CUDAToolkit: /usr/local/cuda/include (found suitable version "12.2.140", minimum required is "11.5")
-- Using GPU architectures 70
CMake Warning (dev) at MatX/public/cpm-cmake/cmake/CPM.cmake:36 (message):
  CPM: A dependency is using a more recent CPM version
  (1.0.0-development-version) than the current project (0.32.2).  It is
  recommended to upgrade CPM to the most recent version.  See
  https://github.com/cpm-cmake/CPM.cmake for more information.
Call Stack (most recent call first):
  MatX/CMakeLists.txt:89 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found CUDAToolkit: /usr/local/cuda/include (found version "12.2.140")
-- Need CCCL. Finding...
-- CPM: adding package CCCL@2.2.0 (v2.2.0)
-- Found libcudacxx: /repro/cmake_sample_project/build/_deps/cccl-src/libcudacxx/lib/cmake/libcudacxx/libcudacxx-config.cmake (found suitable version "2.2.0.0", minimum required is "2.2.0.0")
-- Found Thrust: /repro/cmake_sample_project/build/_deps/cccl-src/thrust/thrust/cmake/thrust-config.cmake (found suitable exact version "2.2.0.0")
-- Found CUB: /repro/cmake_sample_project/build/_deps/cccl-src/cub/cub/cmake/cub-config.cmake (found suitable version "2.2.0.0", minimum required is "2.2.0.0")
-- Found CCCL: /repro/cmake_sample_project/build/_deps/cccl-src/lib/cmake/cccl/cccl-config.cmake (found version "2.2.0.0")
-- Enabling pybind11 support
-- CPM: adding package pybind11@2.6.2 (v2.6.2)
-- pybind11 v2.6.2
CMake Warning (dev) at /usr/local/share/cmake-3.23/Modules/CMakeDependentOption.cmake:89 (message):
  Policy CMP0127 is not set: cmake_dependent_option() supports full Condition
  Syntax.  Run "cmake --help-policy CMP0127" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
  build/_deps/pybind11-src/CMakeLists.txt:98 (cmake_dependent_option)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- checking python import module numpy
-- checking python import module cupy
-- Configuring done
-- Generating done
-- Build files have been written to: /repro/cmake_sample_project/build
I have no name!@f9a8be5fb819:/repro/cmake_sample_project/build$ make -j VERBOSE=1
/usr/local/bin/cmake -S/repro/cmake_sample_project -B/repro/cmake_sample_project/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /repro/cmake_sample_project/build/CMakeFiles /repro/cmake_sample_project/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/repro/cmake_sample_project/build'
make  -f CMakeFiles/sample_matx.dir/build.make CMakeFiles/sample_matx.dir/depend
make[2]: Entering directory '/repro/cmake_sample_project/build'
cd /repro/cmake_sample_project/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /repro/cmake_sample_project /repro/cmake_sample_project /repro/cmake_sample_project/build /repro/cmake_sample_project/build /repro/cmake_sample_project/build/CMakeFiles/sample_matx.dir/DependInfo.cmake --color=
Dependencies file "CMakeFiles/sample_matx.dir/main.cu.o.d" is newer than depends file "/repro/cmake_sample_project/build/CMakeFiles/sample_matx.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target sample_matx
make[2]: Leaving directory '/repro/cmake_sample_project/build'
make  -f CMakeFiles/sample_matx.dir/build.make CMakeFiles/sample_matx.dir/build
make[2]: Entering directory '/repro/cmake_sample_project/build'
[ 50%] Building CUDA object CMakeFiles/sample_matx.dir/main.cu.o
/usr/local/cuda/bin/nvcc -forward-unknown-to-host-compiler -DINDEX_64_BIT -DMATX_DISABLE_CUB_CACHE=1 -DMATX_ENABLE_CUTENSOR=0 -DMATX_ENABLE_CUTLASS=0 -DMATX_ENABLE_FILEIO=1 -DMATX_ENABLE_PYBIND11=1 -DMATX_ENABLE_VIZ=0 -I/repro/cmake_sample_project/MatX/include -I/repro/cmake_sample_project/MatX/include/matx/kernels -isystem=/repro/cmake_sample_project/build/_deps/cccl-src/libcudacxx/include -isystem=/repro/cmake_sample_project/build/_deps/cccl-src/cub -isystem=/repro/cmake_sample_project/build/_deps/cccl-src/thrust -isystem=/repro/cmake_sample_project/build/_deps/pybind11-src/include -isystem=/usr/include/python3.10 -isystem=/usr/local/cuda/include -O3 -DNDEBUG --generate-code=arch=compute_70,code=[compute_70,sm_70] --expt-relaxed-constexpr -DMATX_ROOT=\"/repro/cmake_sample_project/MatX\" -fvisibility=hidden -std=c++17 -MD -MT CMakeFiles/sample_matx.dir/main.cu.o -MF CMakeFiles/sample_matx.dir/main.cu.o.d -x cu -c /repro/cmake_sample_project/main.cu -o CMakeFiles/sample_matx.dir/main.cu.o
[100%] Linking CUDA executable sample_matx
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/sample_matx.dir/link.txt --verbose=1
/usr/bin/g++ CMakeFiles/sample_matx.dir/main.cu.o -o sample_matx  /usr/lib/x86_64-linux-gnu/libpython3.10.so /usr/local/cuda/lib64/libcudart.so /usr/local/cuda/lib64/libcublasLt.so /usr/local/cuda/lib64/libcufft.so /usr/local/cuda/lib64/libcusolver.so /usr/local/cuda/lib64/libcublas.so /usr/local/cuda/lib64/libcusparse.so /usr/lib/x86_64-linux-gnu/libcuda.so /usr/local/cuda/lib64/libcurand.so /usr/local/cuda/lib64/libnvToolsExt.so -lcudadevrt -lcudart_static -lrt -lpthread -ldl  -L"/usr/local/cuda/targets/x86_64-linux/lib/stubs" -L"/usr/local/cuda/targets/x86_64-linux/lib"
make[2]: Leaving directory '/repro/cmake_sample_project/build'
[100%] Built target sample_matx
make[1]: Leaving directory '/repro/cmake_sample_project/build'
/usr/local/bin/cmake -E cmake_progress_start /repro/cmake_sample_project/build/CMakeFiles 0

Have you tried using set inside the cmake script rather than passing the variable in?
Do you maybe have a

This seems related to the Python version.

I ran into this issue when using Python 3.12, and reproduced it with Python 3.11. However, Python 3.10 is OK.

I'm able to reproduce an issue under Ubuntu 22.04 with python 3.11 side-loaded, but not the same issue:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11
examples/cmake_sample_project/build$ cmake -DMATX_EN_PYBIND11=ON -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3.11 ..
...
-- Found PythonInterp: /usr/bin/python3.11 (found version "3.11.8")
-- Found PythonLibs: python3.11
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
CMake Error at /usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Python3_LIBRARIES
  Development Development.Module Development.Embed) (found version "3.11.8")
Call Stack (most recent call first):
  /usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.23/Modules/FindPython/Support.cmake:3181 (find_package_handle_standard_args)
  /usr/local/share/cmake-3.23/Modules/FindPython3.cmake:490 (include)
  MatX/CMakeLists.txt:209 (find_package)

I might just have cmake/python3.11 configured incorrectly.

Able to recreate with Ubuntu 22.04 with python3.11 side-loaded and paths properly configured:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.11 python3.11-dev
python3.11 -m pip install numpy cupy

examples/cmake_sample_project/build$ cmake -DMATX_EN_PYBIND11=ON -DPYTHON_EXECUTABLE=/usr/bin/python3.11 -DPYTHON_LIBRARIES=/usr/lib/python3.11 -DPYTHON_INCLUDE_DIRS=/usr/include/python3.11 ..

examples/cmake_sample_project/build$ make
...
Consolidate compiler generated dependencies of target sample_matx
[ 50%] Building CUDA object CMakeFiles/sample_matx.dir/main.cu.o
/nfs/scratch.timothym_ate_1/MatX2/examples/cmake_sample_project/build/_deps/pybind11-src/include/pybind11/cast.h(446): error: pointer to incomplete class type "_frame" is not allowed
                  "  " + handle(frame->f_code->co_filename).cast<std::string>() +
...

Root cause is old pybyind11 version (v2.6.2) not compatible with python3.11+. Suggest upgrade to pybind11 v2.12.0.

Fixed by #604. Closing.