Skip to content

Commit

Permalink
Update rpath for to use python venv libs.
Browse files Browse the repository at this point in the history
PYTHON_VERSION is settable with an env var in docker_build for sycl.
Add sycl wheel links to docs.
  • Loading branch information
ssheorey committed Jan 10, 2025
1 parent 16f39aa commit c72c879
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 35 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ docs/_out
3rdparty_downloads
.python-version
cmake-build-*
.git
31 changes: 20 additions & 11 deletions cmake/Open3DSetGlobalProperties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,8 @@ function(open3d_enable_strip target)
endif()
endfunction()

# RPATH handling (for TBB DSO). Check current folder, one folder above and the lib sibling folder.
# Also check the Python virtual env /lib folder for 3rd party dependency libraries installed with `pip install`
# RPATH handling (see below). We don't install targets such as pybind, so BUILD_RPATH must be relative as well.
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
if (APPLE)
# Add options to cover the various ways in which open3d shared lib or apps can be installed wrt TBB DSO
set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/../;@loader_path/../lib/;@loader_path/../../../../")
# pybind with open3d shared lib is copied, not cmake-installed, so we need to add .. to build rpath
set(CMAKE_BUILD_RPATH "@loader_path/../")
elseif(UNIX)
set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../;$ORIGIN/../lib/;$ORIGIN/../../../../")
set(CMAKE_BUILD_RPATH "$ORIGIN/../")
endif()

# open3d_set_global_properties(target)
#
Expand Down Expand Up @@ -204,4 +194,23 @@ function(open3d_set_global_properties target)
target_link_options(${target} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${HARDENING_LDFLAGS}>")
target_compile_definitions(${target} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${HARDENING_DEFINITIONS}>")

# RPATH handling. Check current folder, one folder above (cpu/pybind ->
# libtbb) and the lib sibling folder (bin/Open3D -> lib/libOpen3D). Also
# check the Python virtual env /lib folder for 3rd party dependency
# libraries installed with `pip install`
if (APPLE)
# Add options to cover the various ways in which open3d shared lib or apps can be installed wrt dependent DSOs
set_target_properties(${target} PROPERTIES
INSTALL_RPATH "@loader_path;@loader_path/../;@loader_path/../lib/:@loader_path/../../../../"
# pybind with open3d shared lib is copied, not cmake-installed, so we need to add .. to build rpath
BUILD_RPATH "@loader_path;@loader_path/../;@loader_path/../lib/:@loader_path/../../../../")
elseif(UNIX)
message(STATUS "Setting RPATH for ${target}")
# INSTALL_RPATH for C++ binaries.
set_target_properties(${target} PROPERTIES
INSTALL_RPATH "$ORIGIN;$ORIGIN/../;$ORIGIN/../lib/;$ORIGIN/../../../../"
# BUILD_RPATH for Python wheel libs and app.
BUILD_RPATH "$ORIGIN;$ORIGIN/../;$ORIGIN/../lib/;$ORIGIN/../../../../")
endif()

endfunction()
8 changes: 6 additions & 2 deletions cpp/open3d/core/SYCLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ SYCLDevice::SYCLDevice(const sycl::device &sycl_device) {
aspects.end();
if (!fp64) {
utility::LogWarning(
"SYCL device {} does not support double precision. Using "
"emulation.",
"SYCL device {} does not support double precision. Use env "
"vars 'OverrideDefaultFP64Settings=1' "
"'IGC_EnableDPEmulation=1' to enable double precision "
"emulation on Intel GPUs.",
name);
}
usm_device_allocations =
Expand All @@ -78,6 +80,7 @@ SYCLContext::SYCLContext() {
const Device open3d_device = Device("SYCL:0");
devices_.emplace(open3d_device, sycl_device);
} catch (const sycl::exception &e) {
utility::LogWarning("SYCL GPU unavailable: {}", e.what());
}

// SYCL CPU fallback.
Expand All @@ -94,6 +97,7 @@ SYCLContext::SYCLContext() {
Device("SYCL:" + std::to_string(devices_.size()));
devices_.emplace(open3d_device, sycl_device);
} catch (const sycl::exception &e) {
utility::LogWarning("SYCL CPU unavailable: {}", e.what());
}

if (devices_.size() == 0) {
Expand Down
16 changes: 8 additions & 8 deletions cpp/open3d/core/SYCLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ void PrintSYCLDevices(bool print_all) {
int nd = 0;
utility::LogInfo("# Open3D SYCL device");
try {
utility::LogInfo(
"- Device(\"SYCL:{}\"): {}", nd,
SYCLDeviceToString(sycl::device(sycl::gpu_selector_v)));
auto dev = sycl::device(sycl::gpu_selector_v);
utility::LogInfo("- Device(\"SYCL:{}\"): {}", nd,
SYCLDeviceToString(dev));
++nd;
} catch (const sycl::exception &e) {
} catch (const sycl::exception &e) { // No SYCL GPU available.
}
try {
auto dev = sycl::device(sycl::cpu_selector_v);
utility::LogInfo("# Open3D SYCL device (CPU fallback)");
utility::LogInfo(
"- Device(\"SYCL:{}\"): {}", nd,
SYCLDeviceToString(sycl::device(sycl::cpu_selector_v)));
} catch (const sycl::exception &e) {
utility::LogInfo("- Device(\"SYCL:{}\"): {}", nd,
SYCLDeviceToString(dev));
} catch (const sycl::exception &e) { // No SYCL CPU available.
if (nd == 0) utility::LogInfo("- Device(\"SYCL:0\"): N/A");
}
if (print_all) {
Expand Down
6 changes: 1 addition & 5 deletions cpp/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,10 @@ endif()
set(PYTHON_COMPILED_MODULE_DIR
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/Python/$<IF:$<BOOL:${BUILD_CUDA_MODULE}>,cuda,cpu>")

# Set BUILD_RPATH to find tbb (and a shared libOpen3D). We don't install through cmake.
if (APPLE)
set_target_properties(pybind PROPERTIES BUILD_RPATH "@loader_path;@loader_path/..")
elseif (UNIX)
if (UNIX AND NOT APPLE)
# Use RPATH instead of RUNPATH in pybind so that needed libc++.so can find child dependant libc++abi.so in RPATH
# https://stackoverflow.com/questions/69662319/managing-secondary-dependencies-of-shared-libraries
target_link_options(pybind PRIVATE "LINKER:--disable-new-dtags")
set_target_properties(pybind PROPERTIES BUILD_RPATH "$ORIGIN;$ORIGIN/..")
endif()
set_target_properties(pybind PROPERTIES
FOLDER "Python"
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ RUN apt-get update && apt-get install -y \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
&& if [ $BUILD_SYCL_MODULE = "ON" ]; then apt-get install -y intel-level-zero-gpu-raytracing ; fi \
&& rm -rf /var/lib/apt/lists/*

# pyenv
Expand Down Expand Up @@ -238,7 +239,7 @@ RUN ccache -s \
&& tar -caf /${CCACHE_TAR_NAME}.tar.xz ${CCACHE_DIR_NAME} \
&& if [[ "${PACKAGE}" = "ON" ]]; then mv /root/Open3D/build/package/open3d-devel*.tar.xz /; fi \
&& if [[ "${PACKAGE}" = "VIEWER" ]]; then mv /root/Open3D/build/package-Open3DViewer-deb/open3d-viewer-*-Linux.deb /; fi \
&& if [[ "${BUILD_SYCL_MODULE}" = "ON" && "${BUILD_SHARED_LIBS}" = "ON" ]]; then mv /root/Open3D/build/lib/python_package/pip_package/open3d-*.whl /; fi \
&& if [[ "${BUILD_SYCL_MODULE}" = "ON" && "${BUILD_SHARED_LIBS}" = "ON" ]]; then mv /root/Open3D/build/lib/python_package/pip_package/open3d*.whl /; fi \
&& ls -alh /

RUN echo "Docker build done."
2 changes: 1 addition & 1 deletion docker/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ sycl-shared_export_env() {
export BASE_IMAGE=intel/oneapi-basekit:2024.1.1-devel-ubuntu22.04
export DEVELOPER_BUILD=ON
export CCACHE_TAR_NAME=open3d-ci-sycl
export PYTHON_VERSION=3.10
export PYTHON_VERSION=${PYTHON_VERSION:-3.10}
export BUILD_SHARED_LIBS=ON
export BUILD_CUDA_MODULE=OFF
export BUILD_TENSORFLOW_OPS=ON
Expand Down
21 changes: 16 additions & 5 deletions docs/sycl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,31 @@ on Linux on Intel integrated and discrete GPUs. Currently, a single GPU
Installation
-------------

Both C++ binaries and Python wheels (Python 3.10 only for now) can be downloaded
Both C++ binaries and Python wheels can be downloaded
from the Open3D GitHub releases page. For C++, install the `OneAPI runtime
<https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html>`_
and (optionally) SYCL runtime for your `Nvidia
<https://developer.codeplay.com/products/oneapi/nvidia/download>`_ or `AMD
<https://developer.codeplay.com/products/oneapi/amd/download>`_ GPU.

For Python, the wheels will automatically install the DPC++ runtime package
(`dpcpp-cpp-rt`). You will also need `libomp5` installed: `apt-get install
libomp5-11`. Make sure to have the `correct drivers installed
(`dpcpp-cpp-rt`). Make sure to have the `correct drivers installed
<https://dgpu-docs.intel.com/driver/client/overview.html>`_ for your GPU. For
raycasting on Intel GPUs, you will also need the
`intel-level-zero-gpu-raytracing` package.


.. list-table::
:stub-columns: 1
:widths: auto

* - Linux SYCL (Ubuntu 22.04+)
- `Python 3.9 <https://github.com/isl-org/Open3D/releases/download/main-devel/open3d_xpu-0.19.0-cp39-cp39-manylinux_2_31_x86_64.whl>`__
- `Python 3.10 <https://github.com/isl-org/Open3D/releases/download/main-devel/open3d_xpu-0.19.0-cp310-cp310-manylinux_2_31_x86_64.whl>`__
- `Python 3.11 <https://github.com/isl-org/Open3D/releases/download/main-devel/open3d_xpu-0.19.0-cp311-cp311-manylinux_2_31_x86_64.whl>`__
- `Python 3.12 <https://github.com/isl-org/Open3D/releases/download/main-devel/open3d_xpu-0.19.0-cp312-cp312-manylinux_2_31_x86_64.whl>`__
- `C++ x86_64 <https://github.com/isl-org/Open3D/releases/download/v0.19.0/open3d_xpu-devel-linux-x86_64-0.19.0.tar.xz>`__

Usage
------

Expand Down Expand Up @@ -89,10 +100,10 @@ SYCL runtime are installed. You can select a specific device with the
# Print all available devices (Python):
import os os.environ["SYCL_DEVICE_ALLOWLIST"] = "BackendName:cuda" # Select CUDA GPU
import open3d as o3d
o3d.core.sycl.print_sycl_devices(print_all=true)
o3d.core.sycl.print_sycl_devices(print_all=True)
# Return a list of available devices.
o3d.core.sycl.get_available_device()
o3d.core.sycl.get_available_devices()
# Check if a device is available
o3d.core.sycl.is_available(o3d.core.Device("SYCL:0"))
Expand Down
6 changes: 4 additions & 2 deletions python/test/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ def test_binary_ew_ops(dtype, device):
np.testing.assert_equal((a - b).cpu().numpy(), np.array([2, 3, 4, 5, 6, 7]))
np.testing.assert_equal((a * b).cpu().numpy(),
np.array([8, 18, 32, 50, 72, 98]))
np.testing.assert_equal((a / b).cpu().numpy(), np.array([2, 2, 2, 2, 2, 2]))
# SYCL FP64 emulation may have precision issue.
np.testing.assert_allclose((a / b).cpu().numpy(), np.array([2, 2, 2, 2, 2, 2]))

a = o3c.Tensor(np.array([4, 6, 8, 10, 12, 14]), dtype=dtype, device=device)
a += b
Expand All @@ -610,7 +611,8 @@ def test_binary_ew_ops(dtype, device):

a = o3c.Tensor(np.array([4, 6, 8, 10, 12, 14]), dtype=dtype, device=device)
a //= b
np.testing.assert_equal(a.cpu().numpy(), np.array([2, 2, 2, 2, 2, 2]))
# SYCL FP64 emulation may have precision issue.
np.testing.assert_allclose(a.cpu().numpy(), np.array([2, 2, 2, 2, 2, 2]))


@pytest.mark.parametrize("device", list_devices(enable_sycl=True))
Expand Down

0 comments on commit c72c879

Please sign in to comment.