Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

How to use open3d with gpu in python

Open Yamabukiss opened this issue 1 year ago • 8 comments

Checklist

My Question

I am using Python 3.9.17 in windows, my cuda version is 12.2, the nvidia-smi and nvcc -V commands can be answered normally. But the open3d.core.cuda.device_count() always returns 0 and the open3d.core.cuda.is_available() returns False, how to solve it?

Yamabukiss avatar Aug 14 '23 09:08 Yamabukiss

It looks to me like the wheels don't have CUDA support on windows:

from open3d._build_config import _build_config

for k,v in _build_config.items():
    print(f"{k}: {v}")
BUILD_TENSORFLOW_OPS: False
BUILD_PYTORCH_OPS: False
BUILD_CUDA_MODULE: False
BUILD_SYCL_MODULE: False
BUILD_AZURE_KINECT: True
BUILD_LIBREALSENSE: True
BUILD_SHARED_LIBS: False
BUILD_GUI: True
ENABLE_HEADLESS_RENDERING: False
BUILD_JUPYTER_EXTENSION: True
BUNDLE_OPEN3D_ML: False
GLIBCXX_USE_CXX11_ABI: False
CMAKE_BUILD_TYPE: Release
CUDA_VERSION: 
CUDA_GENCODES: 
Tensorflow_VERSION: 
Pytorch_VERSION: 
WITH_OPENMP: True

melMass avatar Aug 14 '23 10:08 melMass

You can use as cuda by building the lib yourself. First clone the selected version of open3d. Then you need to set DBUILD_CUDA_MODULE=ON:

cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX="D:/Open3D-0.17.0/install/" -DBUILD_CUDA_MODULE=ON ..

Also you if get an error related to ispc, you can set -DBUILD_ISPC_MODULE=OFF Visual Studio version depends on your environment. After that build and install the lib as explained here:

http://www.open3d.org/docs/release/compilation.html

halil-karabacak avatar Aug 14 '23 13:08 halil-karabacak

You can use as cuda by building the lib yourself. First clone the selected version of open3d. Then you need to set DBUILD_CUDA_MODULE=ON:

cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX="D:/Open3D-0.17.0/install/" -DBUILD_CUDA_MODULE=ON ..

Also you if get an error related to ispc, you can set -DBUILD_ISPC_MODULE=OFF Visual Studio version depends on your environment. After that build and install the lib as explained here:

http://www.open3d.org/docs/release/compilation.html

Now it appers:

Traceback (most recent call last):
  File "D:\project_python\pcscan_config\main.py", line 2, in <module>
    import open3d as o3d
  File "D:\anaconda\envs\yamabuki\lib\site-packages\open3d\__init__.py", line 93, in <module>
    from open3d.cpu.pybind import (core, camera, data, geometry, io, pipelines,
ModuleNotFoundError: No module named 'open3d.cpu'

Yamabukiss avatar Aug 15 '23 10:08 Yamabukiss

Now it appers:

 Traceback (most recent call last):
   File "D:\project_python\pcscan_config\main.py", line 2, in <module>
     import open3d as o3d
   File "D:\anaconda\envs\yamabuki\lib\site-packages\open3d\__init__.py", line 93, in <module>
     from open3d.cpu.pybind import (core, camera, data, geometry, io, pipelines,
 ModuleNotFoundError: No module named 'open3d.cpu'

So,

:: Activate the virtualenv first
:: Install pip package in the current python environment
cmake --build . --config Release --target install-pip-package

:: Create Python package in build/lib
cmake --build . --config Release --target python-package

:: Create pip package in build/lib
:: This creates a .whl file that you can install manually.
cmake --build . --config Release --target pip-package

this commands will add package to your interpreter in command line. If you have multiple python versions, you may try to set -DPython3_ROOT=/path/to/python . For reference I am using python 3.9 with open3d 0.17.0 with cuda without problemany issue. Also can you send the output of the python -c "import open3d; print(open3d)" I wonder if this is about your interpreter or something gone wrong during the installation.

halil-karabacak avatar Aug 16 '23 10:08 halil-karabacak

@Yamabukiss

I am pretty sure that you should not be using from open3d.cpu.pybind import core but you should be using

from open3d import core

If you have built open3d with cuda, from open3d import core will resolve to:-

from open3d.cuda.pybind import core

See the attached pic on when using Open3D built with gpu, how cpu imports fails:- Screenshot from 2023-08-16 12-43-12

saurabheights avatar Aug 16 '23 10:08 saurabheights

I also meet the same problem with open3d 0.18.0 and python 3.11

Tamako-ayd avatar Mar 29 '24 08:03 Tamako-ayd

I also encountered the same problem with open3d 0.18.0 and python 3.8. Have you solved it?

futingjun avatar May 20 '24 09:05 futingjun

I also encountered the same problem with open3d 0.18.0 and python 3.8. Have you solved it?

我用open3d0.18.0和python 3.8也遇到了同样的问题,你解决了吗?

Nope, I gave it up.

Tamako-ayd avatar May 20 '24 12:05 Tamako-ayd

Now it appers:

 Traceback (most recent call last):
   File "D:\project_python\pcscan_config\main.py", line 2, in <module>
     import open3d as o3d
   File "D:\anaconda\envs\yamabuki\lib\site-packages\open3d\__init__.py", line 93, in <module>
     from open3d.cpu.pybind import (core, camera, data, geometry, io, pipelines,
 ModuleNotFoundError: No module named 'open3d.cpu'

So,

:: Activate the virtualenv first
:: Install pip package in the current python environment
cmake --build . --config Release --target install-pip-package

:: Create Python package in build/lib
cmake --build . --config Release --target python-package

:: Create pip package in build/lib
:: This creates a .whl file that you can install manually.
cmake --build . --config Release --target pip-package

this commands will add package to your interpreter in command line. If you have multiple python versions, you may try to set -DPython3_ROOT=/path/to/python . For reference I am using python 3.9 with open3d 0.17.0 with cuda without problemany issue. Also can you send the output of the python -c "import open3d; print(open3d)" I wonder if this is about your interpreter or something gone wrong during the installation.

hi, I encountered the same problem, and I wonder what directory should I run this "cmake ..." commands? best wishes!

ZhaoRunyi avatar Oct 21 '24 15:10 ZhaoRunyi