Skip to content

Commit

Permalink
Add SYCL fallback CPU device as last SYCL device to allow distinguish…
Browse files Browse the repository at this point in the history
…ing CPU and GPU devices.
  • Loading branch information
ssheorey committed Dec 6, 2024
1 parent 61fade0 commit 3acf8d8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 50 deletions.
24 changes: 12 additions & 12 deletions cpp/open3d/core/SYCLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ SYCLContext::SYCLContext() {
} 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 sycl::device &sycl_device =
sycl::device(sycl::cpu_selector_v);
const Device open3d_device = Device("SYCL: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 {
if (devices_.size() == 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] = sycl::queue(sycl_device);
} catch (const sycl::exception &e) {
}
const sycl::device &sycl_device = sycl::device(sycl::cpu_selector_v);
const Device open3d_device =
Device("SYCL:" + std::to_string(devices_.size()));
devices_.push_back(open3d_device);
device_to_sycl_device_[open3d_device] = sycl_device;
device_to_default_queue_[open3d_device] = sycl::queue(sycl_device);
} catch (const sycl::exception &e) {
}

if (devices_.size() == 0) {
Expand Down
42 changes: 21 additions & 21 deletions cpp/open3d/core/SYCLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,32 @@ static std::string SYCLDeviceToString(const sycl::device &device) {

void PrintSYCLDevices(bool print_all) {
#ifdef BUILD_SYCL_MODULE
const char *filter = std::getenv("SYCL_DEVICE_FILTER");
const char *filter = std::getenv("ONEAPI_DEVICE_SELECTOR");
if (filter) {
utility::LogWarning(
"SYCL_DEVICE_FILTER environment variable is set to {}. To see "
"the correct device id, please unset SYCL_DEVICE_FILTER.",
"ONEAPI_DEVICE_SELECTOR environment variable is set to {}. To "
"see the correct device id, please unset "
"ONEAPI_DEVICE_SELECTOR.",
filter);
}

int nd = 0;
utility::LogInfo("# Open3D SYCL device");
try {
utility::LogInfo(
"- Device(\"SYCL:{}\"): {}", nd,
SYCLDeviceToString(sycl::device(sycl::gpu_selector_v)));
++nd;
} catch (const sycl::exception &e) {
}
try {
utility::LogInfo("# Open3D SYCL device (CPU fallback)");
utility::LogInfo(
"- Device(\"SYCL:{}\"): {}", nd,
SYCLDeviceToString(sycl::device(sycl::cpu_selector_v)));
} catch (const sycl::exception &e) {
if (nd == 0) utility::LogInfo("- Device(\"SYCL:0\"): N/A");
}
if (print_all) {
utility::LogInfo("# All SYCL devices");
const std::vector<sycl::platform> &platforms =
Expand Down Expand Up @@ -168,24 +186,6 @@ void PrintSYCLDevices(bool print_all) {
} catch (const sycl::exception &e) {
utility::LogInfo("- sycl::accelerator_selector_v: N/A");
}

utility::LogInfo("# Open3D SYCL device");
try {
const sycl::device &device = sycl::device(sycl::gpu_selector_v);
utility::LogInfo("- Device(\"SYCL:0\"): {}",
SYCLDeviceToString(device));
} catch (const sycl::exception &e) {
utility::LogInfo("- Device(\"SYCL:0\"): N/A");
}
} else {
utility::LogInfo("# Open3D SYCL device");
try {
const sycl::device &device = sycl::device(sycl::gpu_selector_v);
utility::LogInfo("- Device(\"SYCL:0\"): {}",
SYCLDeviceToString(device));
} catch (const sycl::exception &e) {
utility::LogInfo("- Device(\"SYCL:0\"): N/A");
}
}

#else
Expand Down
3 changes: 2 additions & 1 deletion cpp/tests/core/CoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ PermuteDevicePairsWithSYCL::TestCases() {
std::vector<core::Device> devices;
devices.insert(devices.end(), cpu_devices.begin(), cpu_devices.end());
devices.insert(devices.end(), cuda_devices.begin(), cuda_devices.end());
devices.insert(devices.end(), sycl_devices.begin(), sycl_devices.end());
// Skip the last SYCL device - this is the CPU fallback
devices.insert(devices.end(), sycl_devices.begin(), sycl_devices.end() - 1);

// Self-pairs and cross pairs (bidirectional).
std::vector<std::pair<core::Device, core::Device>> device_pairs;
Expand Down
25 changes: 9 additions & 16 deletions python/test/t/geometry/test_raycasting_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../..")
from open3d_test import list_devices

# RayCastingScene SYCL tests require a GPU with HW raytracing support. We don't
# detect this automatically.
# Do not enable SYCL devices on GIthub - GPU is not available and we don't
# distinguish between SYCL CPU and SYCL GPU.
enable_sycl = os.environ.get("GITHUB_ACTION", "") == ""


# test intersection with a single triangle
@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_cast_rays(device):
vertices = o3d.core.Tensor([[0, 0, 0], [1, 0, 0], [1, 1, 0]],
dtype=o3d.core.float32,
Expand Down Expand Up @@ -58,7 +51,7 @@ def test_cast_rays(device):
# we expect no errors for this test
@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_cast_lots_of_rays(device):
vertices = o3d.core.Tensor([[0, 0, 0], [1, 0, 0], [1, 1, 0]],
dtype=o3d.core.float32,
Expand All @@ -80,7 +73,7 @@ def test_cast_lots_of_rays(device):
# test occlusion with a single triangle
@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_test_occlusions(device):
vertices = o3d.core.Tensor([[0, 0, 0], [1, 0, 0], [1, 1, 0]],
dtype=o3d.core.float32,
Expand Down Expand Up @@ -118,7 +111,7 @@ def test_test_occlusions(device):
# we expect no errors for this test
@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_test_lots_of_occlusions(device):
vertices = o3d.core.Tensor([[0, 0, 0], [1, 0, 0], [1, 1, 0]],
dtype=o3d.core.float32,
Expand All @@ -139,7 +132,7 @@ def test_test_lots_of_occlusions(device):

@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_add_triangle_mesh(device):
cube = o3d.t.geometry.TriangleMesh.create_box()
cube = cube.to(device)
Expand All @@ -160,7 +153,7 @@ def test_add_triangle_mesh(device):

@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_count_intersections(device):
cube = o3d.t.geometry.TriangleMesh.create_box()
vertex_positions = cube.vertex.positions
Expand All @@ -187,7 +180,7 @@ def test_count_intersections(device):
# we expect no errors for this test
@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_count_lots_of_intersections(device):
cube = o3d.t.geometry.TriangleMesh.create_box()
vertex_positions = cube.vertex.positions
Expand All @@ -208,7 +201,7 @@ def test_count_lots_of_intersections(device):

@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_list_intersections(device):
cube = o3d.t.geometry.TriangleMesh.create_box()
vertex_positions = cube.vertex.positions
Expand Down Expand Up @@ -238,7 +231,7 @@ def test_list_intersections(device):
# we expect no errors for this test
@pytest.mark.parametrize("device",
list_devices(enable_cuda=False,
enable_sycl=enable_sycl))
enable_sycl=True))
def test_list_lots_of_intersections(device):
cube = o3d.t.geometry.TriangleMesh.create_box()
vertex_positions = cube.vertex.positions
Expand Down

0 comments on commit 3acf8d8

Please sign in to comment.