22 inline namespace _V1 {
23 namespace ext::oneapi::experimental {
28 if (!SyclDevice.
has(aspect::ext_oneapi_virtual_mem))
31 "Device does not support aspect::ext_oneapi_virtual_mem.");
33 ur_virtual_mem_granularity_info_t GranularityQuery = [=]() {
36 return UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM;
38 return UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED;
41 "Unrecognized granularity mode.");
44 std::shared_ptr<sycl::detail::device_impl> DeviceImpl =
46 std::shared_ptr<sycl::detail::context_impl> ContextImpl =
50 size_t InfoOutputSize;
51 Plugin->call(urVirtualMemGranularityGetInfo, ContextImpl->getHandleRef(),
52 DeviceImpl->getHandleRef(), GranularityQuery, 0,
nullptr,
54 assert(InfoOutputSize ==
sizeof(
size_t) &&
55 "Unexpected output size of granularity info query.");
57 size_t Granularity = 0;
58 Plugin->call(urVirtualMemGranularityGetInfo, ContextImpl->getHandleRef(),
59 DeviceImpl->getHandleRef(), GranularityQuery,
sizeof(
size_t),
60 &Granularity,
nullptr);
66 const std::vector<device> Devices = SyclContext.
get_devices();
68 return Dev.has(aspect::ext_oneapi_virtual_mem);
72 "One or more devices in the context does not support "
73 "aspect::ext_oneapi_virtual_mem.");
79 SYSTEM_INFO SystemInfo;
80 GetSystemInfo(&SystemInfo);
81 return static_cast<size_t>(SystemInfo.dwPageSize);
83 return static_cast<size_t>(sysconf(_SC_PAGESIZE));
90 for (
size_t I = 1; I < Devices.size(); ++I) {
92 size_t GCD = LCMGranularity;
93 size_t Rem = DevGranularity % GCD;
98 LCMGranularity *= DevGranularity / GCD;
100 return LCMGranularity;
105 std::vector<device> Devs = SyclContext.
get_devices();
107 return !Dev.has(aspect::ext_oneapi_virtual_mem);
111 "One or more devices in the supplied context does not support "
112 "aspect::ext_oneapi_virtual_mem.");
114 std::shared_ptr<sycl::detail::context_impl> ContextImpl =
117 void *OutPtr =
nullptr;
118 Plugin->call(urVirtualMemReserve, ContextImpl->getHandleRef(),
119 reinterpret_cast<void *
>(Start), NumBytes, &OutPtr);
120 return reinterpret_cast<uintptr_t
>(OutPtr);
125 std::shared_ptr<sycl::detail::context_impl> ContextImpl =
128 Plugin->call(urVirtualMemFree, ContextImpl->getHandleRef(),
129 reinterpret_cast<void *
>(Ptr), NumBytes);
136 std::shared_ptr<sycl::detail::context_impl> ContextImpl =
139 Plugin->call(urVirtualMemSetAccess, ContextImpl->getHandleRef(), Ptr,
140 NumBytes, AccessFlags);
146 std::shared_ptr<sycl::detail::context_impl> ContextImpl =
150 size_t InfoOutputSize = 0;
151 Plugin->call(urVirtualMemGetInfo, ContextImpl->getHandleRef(), Ptr, NumBytes,
152 UR_VIRTUAL_MEM_INFO_ACCESS_MODE, 0,
nullptr, &InfoOutputSize);
153 assert(InfoOutputSize ==
sizeof(ur_virtual_mem_access_flags_t) &&
154 "Unexpected output size of access mode info query.");
156 ur_virtual_mem_access_flags_t AccessFlags;
157 Plugin->call(urVirtualMemGetInfo, ContextImpl->getHandleRef(), Ptr, NumBytes,
158 UR_VIRTUAL_MEM_INFO_ACCESS_MODE,
159 sizeof(ur_virtual_mem_access_flags_t), &AccessFlags,
nullptr);
161 if (AccessFlags & UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE)
163 if (AccessFlags & UR_VIRTUAL_MEM_ACCESS_FLAG_READ_ONLY)
168 __SYCL_EXPORT
void unmap(
const void *Ptr,
size_t NumBytes,
170 std::shared_ptr<sycl::detail::context_impl> ContextImpl =
173 Plugin->call(urVirtualMemUnmap, ContextImpl->getHandleRef(), Ptr, NumBytes);
The context class represents a SYCL context on which kernel functions may be executed.
std::vector< device > get_devices() const
Gets devices associated with this SYCL context.
backend get_backend() const noexcept
Gets OpenCL interoperability context.
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
bool has(aspect Aspect) const __SYCL_WARN_IMAGE_ASPECT(Aspect)
Indicates if the SYCL device has the given feature.
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
std::shared_ptr< plugin > PluginPtr
ur_virtual_mem_access_flag_t AccessModeToVirtualAccessFlags(ext::oneapi::experimental::address_access_mode Mode)
size_t get_mem_granularity(const device &SyclDevice, const context &SyclContext, granularity_mode Mode=granularity_mode::recommended)
void unmap(const void *Ptr, size_t NumBytes, const context &SyclContext)
void set_access_mode(const void *Ptr, size_t NumBytes, address_access_mode Mode, const context &SyclContext)
address_access_mode get_access_mode(const void *Ptr, size_t NumBytes, const context &SyclContext)
void free_virtual_mem(uintptr_t Ptr, size_t NumBytes, const context &SyclContext)
uintptr_t reserve_virtual_mem(uintptr_t Start, size_t NumBytes, const context &SyclContext)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
bool any_of(const simd_mask< _Tp, _Abi > &) noexcept
bool all_of(const simd_mask< _Tp, _Abi > &) noexcept