Skip to content

Commit

Permalink
Enable Embree build with SYCL support and OneAPI 2024.1.0 (#6808)
Browse files Browse the repository at this point in the history
* Build Embree with SYCL support and OneAPI 2024.1.0
* Switch to standard sycl:: namespace for sycl API, Rename internal open3d namespace to open3d::core::sy to avoid name collision
* count_intersections
* list_Intersection
* test_occlusion
* cast_rays
* Not available in embree yet: compute_distance, compute_signed_distance, compute_occupancy, 

---------
Co-authored-by: Sameer Sheorey <[email protected]>
Co-authored-by: Benjamin Ummenhofer <[email protected]>
  • Loading branch information
lumurillo authored Nov 20, 2024
1 parent 870dcb9 commit 5f4985b
Show file tree
Hide file tree
Showing 22 changed files with 1,092 additions and 437 deletions.
13 changes: 12 additions & 1 deletion 3rdparty/embree/embree.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ else()
endif()


if(BUILD_SYCL_MODULE)
set(ISA_ARGS ${ISA_ARGS} -DCMAKE_CXX_COMPILER=icpx)
set(ISA_ARGS ${ISA_ARGS} -DCMAKE_C_COMPILER=icx)
set(ISA_ARGS ${ISA_ARGS} -DEMBREE_SYCL_SUPPORT=ON)
list(APPEND ISA_LIBS embree4_sycl ze_wrapper)
list(APPEND ISA_BUILD_BYPRODUCTS "<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree4_sycl${CMAKE_STATIC_LIBRARY_SUFFIX}"
"<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_wrapper${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()


ExternalProject_Add(
ext_embree
PREFIX embree
Expand Down Expand Up @@ -92,10 +102,11 @@ ExternalProject_Add(
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}sys${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}math${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}tasking${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_wrapper${CMAKE_STATIC_LIBRARY_SUFFIX}
${ISA_BUILD_BYPRODUCTS}
)

ExternalProject_Get_Property(ext_embree INSTALL_DIR)
set(EMBREE_INCLUDE_DIRS ${INSTALL_DIR}/include/ ${INSTALL_DIR}/src/ext_embree/) # "/" is critical.
set(EMBREE_LIB_DIR ${INSTALL_DIR}/${Open3D_INSTALL_LIB_DIR})
set(EMBREE_LIBRARIES embree4 ${ISA_LIBS} simd lexers sys math tasking)
set(EMBREE_LIBRARIES embree4 simd lexers sys math tasking ${ISA_LIBS})
6 changes: 3 additions & 3 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ if(BUILD_GUI)
${CPP_LIBRARY} ${CPPABI_LIBRARY})
message(STATUS "Filament C++ libraries: ${CPP_LIBRARY} ${CPPABI_LIBRARY}")
if (LIBCPP_VERSION GREATER 11)
message(WARNING "libc++ (LLVM) version ${LIBCPP_VERSION} > 11 includes libunwind that "
message(WARNING "libc++ (LLVM) version ${LIBCPP_VERSION} > 11 includes libunwind that "
"interferes with the system libunwind.so.8 and may crash Python code when exceptions "
"are used. Please consider using libc++ (LLVM) v11.")
endif()
Expand Down Expand Up @@ -1697,7 +1697,7 @@ else(OPEN3D_USE_ONEAPI_PACKAGES)
INCLUDE_DIRS ${STATIC_MKL_INCLUDE_DIR}
LIB_DIR ${STATIC_MKL_LIB_DIR}
LIBRARIES ${STATIC_MKL_LIBRARIES}
DEPENDS ext_tbb ext_mkl_include ext_mkl
DEPENDS Open3D::3rdparty_tbb ext_mkl_include ext_mkl
)
if(UNIX)
target_compile_options(3rdparty_blas INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:-m64>")
Expand All @@ -1719,7 +1719,7 @@ else(OPEN3D_USE_ONEAPI_PACKAGES)
endif()
if(NOT USE_SYSTEM_TBB)
include(${Open3D_3RDPARTY_DIR}/mkl/tbb.cmake)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM TBB::tbb)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_tbb)
else()
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_tbb)
endif()
Expand Down
1 change: 1 addition & 0 deletions 3rdparty/mkl/tbb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ install(TARGETS tbb EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${Open3D_INSTALL_BIN_DIR}
COMPONENT tbb
)
add_library(${PROJECT_NAME}::3rdparty_tbb ALIAS tbb)
2 changes: 1 addition & 1 deletion cpp/open3d/core/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ std::vector<Device> Device::GetAvailableCUDADevices() {
}

std::vector<Device> Device::GetAvailableSYCLDevices() {
return sycl::GetAvailableSYCLDevices();
return sy::GetAvailableSYCLDevices();
}

void Device::PrintAvailableDevices() {
Expand Down
2 changes: 1 addition & 1 deletion cpp/open3d/core/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Device {
enum class DeviceType {
CPU = 0,
CUDA = 1,
SYCL = 2, // SYCL gpu_selector().
SYCL = 2, // SYCL gpu_selector_v.
};

/// Default constructor -> "CPU:0".
Expand Down
22 changes: 10 additions & 12 deletions cpp/open3d/core/MemoryManagerSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: MIT
// ----------------------------------------------------------------------------

#include <CL/sycl.hpp>
#include <cstdlib>
#include <sycl/sycl.hpp>
#include <unordered_map>

#include "open3d/core/Device.h"
Expand All @@ -18,24 +18,22 @@
namespace open3d {
namespace core {

namespace sy = cl::sycl;

void* MemoryManagerSYCL::Malloc(size_t byte_size, const Device& device) {
const sy::queue& queue =
sycl::SYCLContext::GetInstance().GetDefaultQueue(device);
const sycl::queue& queue =
sy::SYCLContext::GetInstance().GetDefaultQueue(device);

#ifdef ENABLE_SYCL_UNIFIED_SHARED_MEMORY
return static_cast<void*>(sy::malloc_shared(byte_size, queue));
return static_cast<void*>(sycl::malloc_shared(byte_size, queue));
#else
return static_cast<void*>(sy::malloc_device(byte_size, queue));
return static_cast<void*>(sycl::malloc_device(byte_size, queue));
#endif
}

void MemoryManagerSYCL::Free(void* ptr, const Device& device) {
if (ptr) {
const sy::queue& queue =
sycl::SYCLContext::GetInstance().GetDefaultQueue(device);
sy::free(ptr, queue);
const sycl::queue& queue =
sy::SYCLContext::GetInstance().GetDefaultQueue(device);
sycl::free(ptr, queue);
}
}

Expand All @@ -62,8 +60,8 @@ void MemoryManagerSYCL::Memcpy(void* dst_ptr,
dst_device.ToString());
}

sy::queue queue =
sycl::SYCLContext::GetInstance().GetDefaultQueue(device_with_queue);
sycl::queue queue =
sy::SYCLContext::GetInstance().GetDefaultQueue(device_with_queue);
queue.memcpy(dst_ptr, src_ptr, num_bytes).wait_and_throw();
}

Expand Down
21 changes: 11 additions & 10 deletions cpp/open3d/core/SYCLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

#include "open3d/core/SYCLContext.h"

#include <CL/sycl.hpp>
#include <array>
#include <cstdlib>
#include <sstream>
#include <sycl/sycl.hpp>

#include "open3d/core/SYCLUtils.h"
#include "open3d/utility/Logging.h"

namespace open3d {
namespace core {
namespace sycl {
namespace sy {

SYCLContext &SYCLContext::GetInstance() {
static thread_local SYCLContext instance;
Expand All @@ -38,36 +38,37 @@ bool SYCLContext::IsDeviceAvailable(const Device &device) {
}
std::vector<Device> SYCLContext::GetAvailableSYCLDevices() { return devices_; }

sy::queue SYCLContext::GetDefaultQueue(const Device &device) {
sycl::queue SYCLContext::GetDefaultQueue(const Device &device) {
return device_to_default_queue_.at(device);
}

SYCLContext::SYCLContext() {
// SYCL GPU.
// TODO: Currently we only support one GPU device.
try {
const sy::device &sycl_device = sy::device(sy::gpu_selector());
const sycl::device &sycl_device = sycl::device(sycl::gpu_selector_v);
const Device open3d_device = Device("SYCL:0");
devices_.push_back(open3d_device);
device_to_sycl_device_[open3d_device] = sycl_device;
device_to_default_queue_[open3d_device] = sy::queue(sycl_device);
} catch (const sy::exception &e) {
device_to_default_queue_[open3d_device] = sycl::queue(sycl_device);
} catch (const sycl::exception &e) {
}

if (devices_.size() == 0) {
// SYCL CPU fallback.
// This could happen if the Intel GPGPU driver is not installed or if
// your CPU does not have integrated GPU.
try {
const sy::device &sycl_device = sy::device(sy::host_selector());
const sycl::device &sycl_device =
sycl::device(sycl::cpu_selector_v);
const Device open3d_device = Device("SYCL:0");
utility::LogWarning(
"SYCL GPU device is not available, falling back to SYCL "
"host device.");
devices_.push_back(open3d_device);
device_to_sycl_device_[open3d_device] = sycl_device;
device_to_default_queue_[open3d_device] = sy::queue(sycl_device);
} catch (const sy::exception &e) {
device_to_default_queue_[open3d_device] = sycl::queue(sycl_device);
} catch (const sycl::exception &e) {
}
}

Expand All @@ -76,6 +77,6 @@ SYCLContext::SYCLContext() {
}
}

} // namespace sycl
} // namespace sy
} // namespace core
} // namespace open3d
16 changes: 7 additions & 9 deletions cpp/open3d/core/SYCLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

#pragma once

#include <CL/sycl.hpp>
#include <sycl/sycl.hpp>
#include <unordered_map>

#include "open3d/core/Device.h"

namespace open3d {
namespace core {
namespace sycl {

namespace sy = cl::sycl;
namespace sy {

/// Singleton SYCL context manager. It maintains:
/// - A default queue for each SYCL device
Expand All @@ -45,7 +43,7 @@ class SYCLContext {
std::vector<Device> GetAvailableSYCLDevices();

/// Get the default SYCL queue given an Open3D device.
sy::queue GetDefaultQueue(const Device& device);
sycl::queue GetDefaultQueue(const Device& device);

private:
SYCLContext();
Expand All @@ -54,12 +52,12 @@ class SYCLContext {
std::vector<Device> devices_;

/// Maps core::Device to the corresponding default SYCL queue.
std::unordered_map<Device, sy::queue> device_to_default_queue_;
std::unordered_map<Device, sycl::queue> device_to_default_queue_;

/// Maps core::Device to sy::device. Internal use only for now.
std::unordered_map<Device, sy::device> device_to_sycl_device_;
/// Maps core::Device to sycl::device. Internal use only for now.
std::unordered_map<Device, sycl::device> device_to_sycl_device_;
};

} // namespace sycl
} // namespace sy
} // namespace core
} // namespace open3d
Loading

0 comments on commit 5f4985b

Please sign in to comment.