Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
SYCLContext.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
16
17#pragma once
18
19#include <algorithm>
20#include <cstdint>
21#include <memory>
22#include <optional>
23#include <string>
24#include <vector>
25
26#include "open3d/core/Device.h"
27
28#ifdef BUILD_SYCL_MODULE
29// Host TUs forward-declare sycl::queue; SYCL-compiled TUs include the runtime.
30#if defined(SYCL_LANGUAGE_VERSION)
31#include <sycl/sycl.hpp>
32#else
33namespace sycl {
34class queue;
35}
36#endif
37#endif
38
39namespace open3d {
40namespace core {
41namespace sy {
42
44struct SYCLDevice {
45 std::string name{};
46 std::string device_type{};
48 bool fp64 = false;
50 false;
53 bool discrete_gpu = false;
54 uint64_t global_mem_size = 0;
56 uint64_t local_mem_size = 0;
61 size_t compute_units = 0;
65 std::vector<size_t> sub_group_sizes{};
66
69 bool SupportsSubgroupSize(size_t size) const {
70 return std::find(sub_group_sizes.begin(), sub_group_sizes.end(),
71 size) != sub_group_sizes.end();
72 }
73};
74
75#ifdef BUILD_SYCL_MODULE
76
80class SYCLContext {
81public:
82 SYCLContext(SYCLContext const&) = delete;
83 void operator=(SYCLContext const&) = delete;
84 ~SYCLContext();
85
87 static SYCLContext& GetInstance();
88
90 bool IsAvailable();
91
93 bool IsDeviceAvailable(const Device& device);
94
96 std::vector<Device> GetAvailableSYCLDevices();
97
99 sycl::queue GetDefaultQueue(const Device& device);
100
103 SYCLDevice GetDeviceProperties(const Device& device);
104
108 static void Clear();
109
110#if defined(SYCL_LANGUAGE_VERSION)
116 size_t GetComputeUnits(const sycl::device& sycl_device);
117#endif
118
119private:
120 SYCLContext();
121
123 struct Impl;
124 std::unique_ptr<Impl> impl_;
125};
126
127#if defined(SYCL_LANGUAGE_VERSION)
128
135sycl::queue GetQueue(const Device& device);
136
149class SYCLScopedQueue {
150public:
151 SYCLScopedQueue(const Device& device, sycl::queue queue);
152 ~SYCLScopedQueue();
153
154 SYCLScopedQueue(const SYCLScopedQueue&) = delete;
155 SYCLScopedQueue& operator=(const SYCLScopedQueue&) = delete;
156
157private:
158 Device device_;
159 // Empty if there was no prior override for `device_` (sycl::queue has no
160 // default constructor, so a nullable wrapper is used instead of a bool
161 // flag + default-constructed queue).
162 std::optional<sycl::queue> prev_queue_;
163};
164
165#endif // SYCL_LANGUAGE_VERSION
166
167#endif // BUILD_SYCL_MODULE
168
169} // namespace sy
170} // namespace core
171} // namespace open3d
sycl::device sycl_device
Definition SYCLContext.cpp:87
sycl::queue queue
Definition SYCLContext.cpp:88
Definition Device.h:18
int size
Definition FilePCD.cpp:41
std::vector< Device > GetAvailableSYCLDevices()
Return a list of available SYCL devices.
Definition SYCLUtils.cpp:179
sycl::queue GetQueue(const Device &device)
Definition SYCLContext.cpp:183
bool IsAvailable()
Returns true if there is at least one SYCL device available.
Definition SYCLUtils.cpp:148
bool IsDeviceAvailable(const Device &device)
Returns true if the specified SYCL device is available.
Definition SYCLUtils.cpp:156
Definition PinholeCameraIntrinsic.cpp:16
Cached SYCL device properties (no SYCL runtime types in this struct).
Definition SYCLContext.h:44
uint64_t global_mem_size
Definition SYCLContext.h:54
std::string device_type
cpu, gpu, host, acc, custom, unknown.
Definition SYCLContext.h:46
std::vector< size_t > sub_group_sizes
Definition SYCLContext.h:65
size_t compute_units
Definition SYCLContext.h:61
bool SupportsSubgroupSize(size_t size) const
Definition SYCLContext.h:69
std::string name
Friendly / descriptive name of the device.
Definition SYCLContext.h:45
bool discrete_gpu
Definition SYCLContext.h:53
bool usm_device_allocations
Definition SYCLContext.h:49
uint64_t local_mem_size
Local (SLM/shared) memory size in bytes available per work-group.
Definition SYCLContext.h:56
size_t max_work_group_size
Device max work-group size.
Definition SYCLContext.h:47
bool fp64
Native fp64; else may need emulation on some GPUs.
Definition SYCLContext.h:48