From e3baed6a5f55f5a7a5c92d1b79960570996c314c Mon Sep 17 00:00:00 2001 From: Sameer Sheorey Date: Tue, 19 Nov 2024 16:28:09 -0800 Subject: [PATCH] Convert deprecated SYCL 1.2 code to SYCL 2020 --- cpp/open3d/core/Device.h | 2 +- cpp/open3d/core/SYCLContext.cpp | 4 +- cpp/open3d/core/SYCLUtils.cpp | 43 +++++++++------------- cpp/pybind/t/geometry/raycasting_scene.cpp | 4 +- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/cpp/open3d/core/Device.h b/cpp/open3d/core/Device.h index 5b04875ed20..13d6715f025 100644 --- a/cpp/open3d/core/Device.h +++ b/cpp/open3d/core/Device.h @@ -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". diff --git a/cpp/open3d/core/SYCLContext.cpp b/cpp/open3d/core/SYCLContext.cpp index 65e3f9c4bc4..6a3007d7dba 100644 --- a/cpp/open3d/core/SYCLContext.cpp +++ b/cpp/open3d/core/SYCLContext.cpp @@ -46,7 +46,7 @@ SYCLContext::SYCLContext() { // SYCL GPU. // TODO: Currently we only support one GPU device. try { - const sycl::device &sycl_device = sycl::device(sycl::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; @@ -60,7 +60,7 @@ SYCLContext::SYCLContext() { // your CPU does not have integrated GPU. try { const sycl::device &sycl_device = - sycl::device(sycl::host_selector()); + 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 " diff --git a/cpp/open3d/core/SYCLUtils.cpp b/cpp/open3d/core/SYCLUtils.cpp index c60552937c2..5860021996d 100644 --- a/cpp/open3d/core/SYCLUtils.cpp +++ b/cpp/open3d/core/SYCLUtils.cpp @@ -35,7 +35,7 @@ int SYCLDemo() { #ifdef BUILD_SYCL_MODULE // Ref: https://intel.github.io/llvm-docs/GetStartedGuide.html // Creating buffer of 4 ints to be used inside the kernel code. - sycl::buffer buffer(4); + sycl::buffer buffer(4); // Creating SYCL queue. sycl::queue q; @@ -51,13 +51,13 @@ int SYCLDemo() { cgh.parallel_for( num_workloads, [=](sycl::id<1> WIid) { // Fill buffer with indexes. - accessor[WIid] = (sycl::cl_int)WIid.get(0); + accessor[WIid] = (int)WIid.get(0); }); }); - // Getting read only access to the buffer on the host. + // Getting access to the buffer on the host. // Implicit barrier waiting for q to complete the work. - const auto host_accessor = buffer.get_access(); + const auto host_accessor = buffer.get_host_access(); // Check the results. bool mismatch_found = false; @@ -140,45 +140,38 @@ void PrintSYCLDevices(bool print_all) { utility::LogInfo("# Default SYCL selectors"); try { - const sycl::device &device = sycl::device(sycl::default_selector()); - utility::LogInfo("- sycl::default_selector() : {}", + const sycl::device &device = sycl::device(sycl::default_selector_v); + utility::LogInfo("- sycl::default_selector_v : {}", SYCLDeviceToString(device)); } catch (const sycl::exception &e) { - utility::LogInfo("- sycl::default_selector() : N/A"); + utility::LogInfo("- sycl::default_selector_v : N/A"); } try { - const sycl::device &device = sycl::device(sycl::host_selector()); - utility::LogInfo("- sycl::host_selector() : {}", + const sycl::device &device = sycl::device(sycl::cpu_selector_v); + utility::LogInfo("- sycl::cpu_selector_v : {}", SYCLDeviceToString(device)); } catch (const sycl::exception &e) { - utility::LogInfo("- sycl::host_selector() : N/A"); + utility::LogInfo("- sycl::cpu_selector_v : N/A"); } try { - const sycl::device &device = sycl::device(sycl::cpu_selector()); - utility::LogInfo("- sycl::cpu_selector() : {}", + const sycl::device &device = sycl::device(sycl::gpu_selector_v); + utility::LogInfo("- sycl::gpu_selector_v : {}", SYCLDeviceToString(device)); } catch (const sycl::exception &e) { - utility::LogInfo("- sycl::cpu_selector() : N/A"); - } - try { - const sycl::device &device = sycl::device(sycl::gpu_selector()); - utility::LogInfo("- sycl::gpu_selector() : {}", - SYCLDeviceToString(device)); - } catch (const sycl::exception &e) { - utility::LogInfo("- sycl::gpu_selector() : N/A"); + utility::LogInfo("- sycl::gpu_selector_v : N/A"); } try { const sycl::device &device = - sycl::device(sycl::accelerator_selector()); - utility::LogInfo("- sycl::accelerator_selector(): {}", + sycl::device(sycl::accelerator_selector_v); + utility::LogInfo("- sycl::accelerator_selector_v: {}", SYCLDeviceToString(device)); } catch (const sycl::exception &e) { - utility::LogInfo("- sycl::accelerator_selector(): N/A"); + utility::LogInfo("- sycl::accelerator_selector_v: N/A"); } utility::LogInfo("# Open3D SYCL device"); try { - const sycl::device &device = sycl::device(sycl::gpu_selector()); + const sycl::device &device = sycl::device(sycl::gpu_selector_v); utility::LogInfo("- Device(\"SYCL:0\"): {}", SYCLDeviceToString(device)); } catch (const sycl::exception &e) { @@ -187,7 +180,7 @@ void PrintSYCLDevices(bool print_all) { } else { utility::LogInfo("# Open3D SYCL device"); try { - const sycl::device &device = sycl::device(sycl::gpu_selector()); + const sycl::device &device = sycl::device(sycl::gpu_selector_v); utility::LogInfo("- Device(\"SYCL:0\"): {}", SYCLDeviceToString(device)); } catch (const sycl::exception &e) { diff --git a/cpp/pybind/t/geometry/raycasting_scene.cpp b/cpp/pybind/t/geometry/raycasting_scene.cpp index 1b71ba5bfaf..b611dfcfbb0 100644 --- a/cpp/pybind/t/geometry/raycasting_scene.cpp +++ b/cpp/pybind/t/geometry/raycasting_scene.cpp @@ -22,7 +22,7 @@ or compute the closest point on the surface of a mesh with respect to one or more query points. It builds an internal acceleration structure to speed up those queries. -This class supports only the CPU device. +This class supports the CPU device and SYCL GPU device. The following shows how to create a scene and compute ray intersections:: @@ -64,7 +64,7 @@ Create a RaycastingScene. Args: nthreads (int): The number of threads to use for building the scene. Set to 0 for automatic. - device (open3d.core.Device): The device to use. + device (open3d.core.Device): The device to use. Currently CPU and SYCL devices are supported. )doc"); raycasting_scene.def(