DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
usm.hpp
Go to the documentation of this file.
1 //==---------------- usm.hpp - SYCL USM ------------------------*- C++ -*---==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 // ===--------------------------------------------------------------------=== //
8 #pragma once
9 
13 
14 #include <cstddef>
15 
17 namespace sycl {
19 // Explicit USM
21 __SYCL_EXPORT void *malloc_device(size_t size, const device &dev,
22  const context &ctxt);
23 __SYCL_EXPORT void *malloc_device(size_t size, const device &dev,
24  const context &ctxt,
25  const property_list &propList);
26 __SYCL_EXPORT void *malloc_device(size_t size, const queue &q);
27 __SYCL_EXPORT void *malloc_device(size_t size, const queue &q,
28  const property_list &propList);
29 
30 __SYCL_EXPORT void *aligned_alloc_device(size_t alignment, size_t size,
31  const device &dev,
32  const context &ctxt);
33 __SYCL_EXPORT void *aligned_alloc_device(size_t alignment, size_t size,
34  const device &dev, const context &ctxt,
35  const property_list &propList);
36 __SYCL_EXPORT void *aligned_alloc_device(size_t alignment, size_t size,
37  const queue &q);
38 __SYCL_EXPORT void *aligned_alloc_device(size_t alignment, size_t size,
39  const queue &q,
40  const property_list &propList);
41 
42 __SYCL_EXPORT void free(void *ptr, const context &ctxt);
43 __SYCL_EXPORT void free(void *ptr, const queue &q);
44 
46 // Restricted USM
48 __SYCL_EXPORT void *malloc_host(size_t size, const context &ctxt);
49 __SYCL_EXPORT void *malloc_host(size_t size, const context &ctxt,
50  const property_list &propList);
51 __SYCL_EXPORT void *malloc_host(size_t size, const queue &q);
52 __SYCL_EXPORT void *malloc_host(size_t size, const queue &q,
53  const property_list &propList);
54 
55 __SYCL_EXPORT void *malloc_shared(size_t size, const device &dev,
56  const context &ctxt);
57 __SYCL_EXPORT void *malloc_shared(size_t size, const device &dev,
58  const context &ctxt,
59  const property_list &propList);
60 __SYCL_EXPORT void *malloc_shared(size_t size, const queue &q);
61 __SYCL_EXPORT void *malloc_shared(size_t size, const queue &q,
62  const property_list &propList);
63 
64 __SYCL_EXPORT void *aligned_alloc_host(size_t alignment, size_t size,
65  const context &ctxt);
66 __SYCL_EXPORT void *aligned_alloc_host(size_t alignment, size_t size,
67  const context &ctxt,
68  const property_list &propList);
69 __SYCL_EXPORT void *aligned_alloc_host(size_t alignment, size_t size,
70  const queue &q);
71 __SYCL_EXPORT void *aligned_alloc_host(size_t alignment, size_t size,
72  const queue &q,
73  const property_list &propList);
74 
75 __SYCL_EXPORT void *aligned_alloc_shared(size_t alignment, size_t size,
76  const device &dev,
77  const context &ctxt);
78 __SYCL_EXPORT void *aligned_alloc_shared(size_t alignment, size_t size,
79  const device &dev, const context &ctxt,
80  const property_list &propList);
81 __SYCL_EXPORT void *aligned_alloc_shared(size_t alignment, size_t size,
82  const queue &q);
83 __SYCL_EXPORT void *aligned_alloc_shared(size_t alignment, size_t size,
84  const queue &q,
85  const property_list &propList);
86 
88 // single form
90 __SYCL_EXPORT void *malloc(size_t size, const device &dev, const context &ctxt,
91  usm::alloc kind);
92 __SYCL_EXPORT void *malloc(size_t size, const device &dev, const context &ctxt,
93  usm::alloc kind, const property_list &propList);
94 __SYCL_EXPORT void *malloc(size_t size, const queue &q, usm::alloc kind);
95 __SYCL_EXPORT void *malloc(size_t size, const queue &q, usm::alloc kind,
96  const property_list &propList);
97 
98 __SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size,
99  const device &dev, const context &ctxt,
100  usm::alloc kind);
101 __SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size,
102  const device &dev, const context &ctxt,
103  usm::alloc kind,
104  const property_list &propList);
105 __SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size, const queue &q,
106  usm::alloc kind);
107 __SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size, const queue &q,
108  usm::alloc kind,
109  const property_list &propList);
110 
112 // Template forms
114 template <typename T>
115 T *malloc_device(size_t Count, const device &Dev, const context &Ctxt,
116  const property_list &PropList = {}) {
117  return static_cast<T *>(
118  malloc_device(Count * sizeof(T), Dev, Ctxt, PropList));
119 }
120 
121 template <typename T>
122 T *malloc_device(size_t Count, const queue &Q,
123  const property_list &PropList = {}) {
124  return malloc_device<T>(Count, Q.get_device(), Q.get_context(), PropList);
125 }
126 
127 template <typename T>
128 T *aligned_alloc_device(size_t Alignment, size_t Count, const device &Dev,
129  const context &Ctxt,
130  const property_list &PropList = {}) {
131  return static_cast<T *>(
132  aligned_alloc_device(Alignment, Count * sizeof(T), Dev, Ctxt, PropList));
133 }
134 
135 template <typename T>
136 T *aligned_alloc_device(size_t Alignment, size_t Count, const queue &Q,
137  const property_list &PropList = {}) {
138  return aligned_alloc_device<T>(Alignment, Count, Q.get_device(),
139  Q.get_context(), PropList);
140 }
141 
142 template <typename T>
143 T *malloc_host(size_t Count, const context &Ctxt,
144  const property_list &PropList = {}) {
145  return static_cast<T *>(malloc_host(Count * sizeof(T), Ctxt, PropList));
146 }
147 
148 template <typename T>
149 T *malloc_host(size_t Count, const queue &Q,
150  const property_list &PropList = {}) {
151  return malloc_host<T>(Count, Q.get_context(), PropList);
152 }
153 
154 template <typename T>
155 T *malloc_shared(size_t Count, const device &Dev, const context &Ctxt,
156  const property_list &PropList = {}) {
157  return static_cast<T *>(
158  malloc_shared(Count * sizeof(T), Dev, Ctxt, PropList));
159 }
160 
161 template <typename T>
162 T *malloc_shared(size_t Count, const queue &Q,
163  const property_list &PropList = {}) {
164  return malloc_shared<T>(Count, Q.get_device(), Q.get_context(), PropList);
165 }
166 
167 template <typename T>
168 T *aligned_alloc_host(size_t Alignment, size_t Count, const context &Ctxt,
169  const property_list &PropList = {}) {
170  return static_cast<T *>(
171  aligned_alloc_host(Alignment, Count * sizeof(T), Ctxt, PropList));
172 }
173 
174 template <typename T>
175 T *aligned_alloc_host(size_t Alignment, size_t Count, const queue &Q,
176  const property_list &PropList = {}) {
177  return aligned_alloc_host<T>(Alignment, Count, Q.get_context(), PropList);
178 }
179 
180 template <typename T>
181 T *aligned_alloc_shared(size_t Alignment, size_t Count, const device &Dev,
182  const context &Ctxt,
183  const property_list &PropList = {}) {
184  return static_cast<T *>(
185  aligned_alloc_shared(Alignment, Count * sizeof(T), Dev, Ctxt, PropList));
186 }
187 
188 template <typename T>
189 T *aligned_alloc_shared(size_t Alignment, size_t Count, const queue &Q,
190  const property_list &PropList = {}) {
191  return aligned_alloc_shared<T>(Alignment, Count, Q.get_device(),
192  Q.get_context(), PropList);
193 }
194 
195 template <typename T>
196 T *malloc(size_t Count, const device &Dev, const context &Ctxt, usm::alloc Kind,
197  const property_list &PropList = {}) {
198  return static_cast<T *>(malloc(Count * sizeof(T), Dev, Ctxt, Kind, PropList));
199 }
200 
201 template <typename T>
202 T *malloc(size_t Count, const queue &Q, usm::alloc Kind,
203  const property_list &PropList = {}) {
204  return malloc<T>(Count, Q.get_device(), Q.get_context(), Kind, PropList);
205 }
206 
207 template <typename T>
208 T *aligned_alloc(size_t Alignment, size_t Count, const device &Dev,
209  const context &Ctxt, usm::alloc Kind,
210  const property_list &PropList = {}) {
211  return static_cast<T *>(
212  aligned_alloc(Alignment, Count * sizeof(T), Dev, Ctxt, Kind, PropList));
213 }
214 
215 template <typename T>
216 T *aligned_alloc(size_t Alignment, size_t Count, const queue &Q,
217  usm::alloc Kind, const property_list &PropList = {}) {
218  return aligned_alloc<T>(Alignment, Count, Q.get_device(), Q.get_context(),
219  Kind, PropList);
220 }
221 
222 // Pointer queries
227 __SYCL_EXPORT usm::alloc get_pointer_type(const void *ptr, const context &ctxt);
228 
234 __SYCL_EXPORT device get_pointer_device(const void *ptr, const context &ctxt);
235 
236 } // namespace sycl
237 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::malloc
void * malloc(size_t size, const queue &q, usm::alloc kind, const property_list &propList)
Definition: usm.hpp:202
T
cl::sycl::info::device
device
Definition: info_desc.hpp:50
cl::sycl::malloc_host
void * malloc_host(size_t size, const queue &q, const property_list &propList)
Definition: usm.hpp:149
cl::sycl::malloc_device
void * malloc_device(size_t size, const queue &q, const property_list &propList)
Definition: usm.hpp:122
cl::sycl::free
void free(void *ptr, const queue &q)
Definition: usm_impl.cpp:191
cl::sycl::aligned_alloc
void * aligned_alloc(size_t alignment, size_t size, const queue &q, usm::alloc kind, const property_list &propList)
Definition: usm.hpp:216
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
cl::sycl::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:103
cl::sycl::info::queue
queue
Definition: info_desc.hpp:223
cl::sycl::malloc_shared
void * malloc_shared(size_t size, const queue &q, const property_list &propList)
Definition: usm.hpp:162
export.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
usm_allocator.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::get_pointer_device
device get_pointer_device(const void *ptr, const context &ctxt)
Queries the device against which the pointer was allocated Throws an invalid_object_error if ptr is a...
Definition: usm_impl.cpp:380
cl::sycl::aligned_alloc_shared
void * aligned_alloc_shared(size_t alignment, size_t size, const queue &q, const property_list &propList)
Definition: usm.hpp:189
cl::sycl::aligned_alloc_device
void * aligned_alloc_device(size_t alignment, size_t size, const queue &q, const property_list &propList)
Definition: usm.hpp:136
cl::sycl::queue::get_device
device get_device() const
Definition: queue.cpp:75
cl::sycl::get_pointer_type
usm::alloc get_pointer_type(const void *ptr, const context &ctxt)
Query the allocation type from a USM pointer.
Definition: usm_impl.cpp:330
cl::sycl::queue::get_context
context get_context() const
Definition: queue.cpp:73
cl::sycl::aligned_alloc_host
void * aligned_alloc_host(size_t alignment, size_t size, const queue &q, const property_list &propList)
Definition: usm.hpp:175
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::info::context
context
Definition: info_desc.hpp:41
usm_enums.hpp
cl::sycl::usm::alloc
alloc
Definition: usm_enums.hpp:14
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12