DPC++ Runtime
Runtime libraries for oneAPI DPC++
alloc_device.hpp
Go to the documentation of this file.
1 //==-------- alloc_device.hpp - SYCL annotated usm device allocation -------==//
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 
9 #pragma once
10 
12 
13 namespace sycl {
14 inline namespace _V1 {
15 namespace ext {
16 namespace oneapi {
17 namespace experimental {
18 
19 template <typename T, typename ListA, typename ListB>
21  typename detail::CheckTAndPropListsWithUsmKind<sycl::usm::alloc::device, T,
22  ListA, ListB>;
23 
24 template <typename PropertyListT>
26  detail::GetAnnotatedPtrPropertiesWithUsmKind<sycl::usm::alloc::device,
27  PropertyListT>;
28 
30 // "aligned_alloc_device_annotated": aligned device USM allocation functions
31 // with properties support
32 //
33 // This the base form of all the annotated USM device allocation functions,
34 // which are implemented by calling the more generic "aligned_alloc_annotated"
35 // functions with the USM kind as an argument. Note that the returned
36 // annotated_ptr of "aligned_alloc_annotated" may not contain the
37 // `usm_kind<alloc::device>`, so reconstruct the real annotated_ptr that
38 // contains usm_kind using the raw pointer of "aligned_alloc_annotated" result
40 template <typename propertyListA = detail::empty_properties_t,
41  typename propertyListB =
43 std::enable_if_t<
46 aligned_alloc_device_annotated(size_t alignment, size_t numBytes,
47  const device &syclDevice,
48  const context &syclContext,
49  const propertyListA &propList = properties{}) {
50  auto tmp =
51  aligned_alloc_annotated(alignment, numBytes, syclDevice, syclContext,
52  sycl::usm::alloc::device, propList);
53  return annotated_ptr<void, propertyListB>(tmp.get());
54 }
55 
56 template <typename T, typename propertyListA = detail::empty_properties_t,
57  typename propertyListB =
58  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
59 std::enable_if_t<
60  CheckDevicePtrTAndPropLists<T, propertyListA, propertyListB>::value,
61  annotated_ptr<T, propertyListB>>
63  const device &syclDevice,
64  const context &syclContext,
65  const propertyListA &propList = properties{}) {
66  auto tmp =
67  aligned_alloc_annotated<T>(alignment, count, syclDevice, syclContext,
68  sycl::usm::alloc::device, propList);
69  return annotated_ptr<T, propertyListB>(tmp.get());
70 }
71 
72 template <typename propertyListA = detail::empty_properties_t,
73  typename propertyListB =
74  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
75 std::enable_if_t<
76  CheckDevicePtrTAndPropLists<void, propertyListA, propertyListB>::value,
77  annotated_ptr<void, propertyListB>>
78 aligned_alloc_device_annotated(size_t alignment, size_t numBytes,
79  const queue &syclQueue,
80  const propertyListA &propList = properties{}) {
82  syclQueue.get_device(),
83  syclQueue.get_context(), propList);
84 }
85 
86 template <typename T, typename propertyListA = detail::empty_properties_t,
87  typename propertyListB =
88  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
89 std::enable_if_t<
90  CheckDevicePtrTAndPropLists<T, propertyListA, propertyListB>::value,
91  annotated_ptr<T, propertyListB>>
93  const queue &syclQueue,
94  const propertyListA &propList = properties{}) {
95  return aligned_alloc_device_annotated<T>(alignment, count,
96  syclQueue.get_device(),
97  syclQueue.get_context(), propList);
98 }
99 
101 // "malloc_device_annotated": device USM allocation functions with properties
102 // support
103 //
104 // Note: "malloc_device_annotated" functions call
105 // "aligned_alloc_device_annotated" with alignment 0
107 template <typename propertyListA = detail::empty_properties_t,
108  typename propertyListB =
109  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
110 std::enable_if_t<
111  CheckDevicePtrTAndPropLists<void, propertyListA, propertyListB>::value,
112  annotated_ptr<void, propertyListB>>
113 malloc_device_annotated(size_t numBytes, const device &syclDevice,
114  const context &syclContext,
115  const propertyListA &propList = properties{}) {
116  return aligned_alloc_device_annotated(0, numBytes, syclDevice, syclContext,
117  propList);
118 }
119 
120 template <typename T, typename propertyListA = detail::empty_properties_t,
121  typename propertyListB =
122  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
123 std::enable_if_t<
124  CheckDevicePtrTAndPropLists<T, propertyListA, propertyListB>::value,
125  annotated_ptr<T, propertyListB>>
126 malloc_device_annotated(size_t count, const device &syclDevice,
127  const context &syclContext,
128  const propertyListA &propList = properties{}) {
129  return aligned_alloc_device_annotated<T>(0, count, syclDevice, syclContext,
130  propList);
131 }
132 
133 template <typename propertyListA = detail::empty_properties_t,
134  typename propertyListB =
135  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
136 std::enable_if_t<
137  CheckDevicePtrTAndPropLists<void, propertyListA, propertyListB>::value,
138  annotated_ptr<void, propertyListB>>
139 malloc_device_annotated(size_t numBytes, const queue &syclQueue,
140  const propertyListA &propList = properties{}) {
141  return malloc_device_annotated(numBytes, syclQueue.get_device(),
142  syclQueue.get_context(), propList);
143 }
144 
145 template <typename T, typename propertyListA = detail::empty_properties_t,
146  typename propertyListB =
147  typename GetAnnotatedDevicePtrProperties<propertyListA>::type>
148 std::enable_if_t<
149  CheckDevicePtrTAndPropLists<T, propertyListA, propertyListB>::value,
150  annotated_ptr<T, propertyListB>>
151 malloc_device_annotated(size_t count, const queue &syclQueue,
152  const propertyListA &propList = properties{}) {
153  return malloc_device_annotated<T>(count, syclQueue.get_device(),
154  syclQueue.get_context(), propList);
155 }
156 
157 } // namespace experimental
158 } // namespace oneapi
159 } // namespace ext
160 } // namespace _V1
161 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:105
device get_device() const
Definition: queue.cpp:76
context get_context() const
Definition: queue.cpp:74
properties< std::tuple<> > empty_properties_t
Definition: properties.hpp:207
constexpr alignment_key::value_t< K > alignment
Definition: properties.hpp:75
std::enable_if_t< CheckDevicePtrTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > malloc_device_annotated(size_t numBytes, const device &syclDevice, const context &syclContext, const propertyListA &propList=properties{})
std::enable_if_t< CheckDevicePtrTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > aligned_alloc_device_annotated(size_t alignment, size_t numBytes, const device &syclDevice, const context &syclContext, const propertyListA &propList=properties{})
std::enable_if_t< detail::CheckTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > aligned_alloc_annotated(size_t alignment, size_t numBytes, const device &syclDevice, const context &syclContext, sycl::usm::alloc kind, const propertyListA &propList=properties{})
Definition: alloc_base.hpp:44
typename detail::CheckTAndPropListsWithUsmKind< sycl::usm::alloc::device, T, ListA, ListB > CheckDevicePtrTAndPropLists
Definition: access.hpp:18