DPC++ Runtime
Runtime libraries for oneAPI DPC++
alloc_shared.hpp
Go to the documentation of this file.
1 //==-------- alloc_shared.hpp - SYCL annotated usm shared 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::shared, T,
22  ListA, ListB>;
23 
24 template <typename PropertyListT>
26  detail::GetAnnotatedPtrPropertiesWithUsmKind<sycl::usm::alloc::shared,
27  PropertyListT>;
28 
30 // Aligned shared USM allocation functions with properties support
31 //
32 // This the base form of all the annotated USM shared allocation functions,
33 // which are implemented by calling the more generic "aligned_alloc_annotated"
34 // functions with the USM kind as an argument. Note that when calling
35 // "aligned_alloc_annotated", the template parameter `propertyListA` should
36 // include the `usm_kind<alloc::shared>` property to make it appear on the
37 // returned annotated_ptr of "aligned_alloc_annotated"
39 
40 template <typename propertyListA = detail::empty_properties_t,
41  typename propertyListB =
43 std::enable_if_t<
46 aligned_alloc_shared_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::shared, 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 GetAnnotatedSharedPtrProperties<propertyListA>::type>
59 std::enable_if_t<
60  CheckSharedPtrTAndPropLists<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::shared, propList);
69  return annotated_ptr<T, propertyListB>(tmp.get());
70 }
71 
72 template <typename propertyListA = detail::empty_properties_t,
73  typename propertyListB =
74  typename GetAnnotatedSharedPtrProperties<propertyListA>::type>
75 std::enable_if_t<
76  CheckSharedPtrTAndPropLists<void, propertyListA, propertyListB>::value,
77  annotated_ptr<void, propertyListB>>
78 aligned_alloc_shared_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 GetAnnotatedSharedPtrProperties<propertyListA>::type>
89 std::enable_if_t<
90  CheckSharedPtrTAndPropLists<T, propertyListA, propertyListB>::value,
91  annotated_ptr<T, propertyListB>>
93  const queue &syclQueue,
94  const propertyListA &propList = properties{}) {
95  return aligned_alloc_shared_annotated<T>(alignment, count,
96  syclQueue.get_device(),
97  syclQueue.get_context(), propList);
98 }
99 
101 // Shared USM allocation functions with properties support
102 //
103 // Note: "malloc_shared_annotated" functions call
104 // "aligned_alloc_shared_annotated" with alignment 0
106 
107 template <typename propertyListA = detail::empty_properties_t,
108  typename propertyListB =
109  typename GetAnnotatedSharedPtrProperties<propertyListA>::type>
110 std::enable_if_t<
111  CheckSharedPtrTAndPropLists<void, propertyListA, propertyListB>::value,
112  annotated_ptr<void, propertyListB>>
113 malloc_shared_annotated(size_t numBytes, const device &syclDevice,
114  const context &syclContext,
115  const propertyListA &propList = properties{}) {
116  return aligned_alloc_shared_annotated(0, numBytes, syclDevice, syclContext,
117  propList);
118 }
119 
120 template <typename T, typename propertyListA = detail::empty_properties_t,
121  typename propertyListB =
122  typename GetAnnotatedSharedPtrProperties<propertyListA>::type>
123 std::enable_if_t<
124  CheckSharedPtrTAndPropLists<T, propertyListA, propertyListB>::value,
125  annotated_ptr<T, propertyListB>>
126 malloc_shared_annotated(size_t count, const device &syclDevice,
127  const context &syclContext,
128  const propertyListA &propList = properties{}) {
129  return aligned_alloc_shared_annotated<T>(0, count, syclDevice, syclContext,
130  propList);
131 }
132 
133 template <typename propertyListA = detail::empty_properties_t,
134  typename propertyListB =
135  typename GetAnnotatedSharedPtrProperties<propertyListA>::type>
136 std::enable_if_t<
137  CheckSharedPtrTAndPropLists<void, propertyListA, propertyListB>::value,
138  annotated_ptr<void, propertyListB>>
139 malloc_shared_annotated(size_t numBytes, const queue &syclQueue,
140  const propertyListA &propList = properties{}) {
141  return malloc_shared_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 GetAnnotatedSharedPtrProperties<propertyListA>::type>
148 std::enable_if_t<
149  CheckSharedPtrTAndPropLists<T, propertyListA, propertyListB>::value,
150  annotated_ptr<T, propertyListB>>
151 malloc_shared_annotated(size_t count, const queue &syclQueue,
152  const propertyListA &propList = properties{}) {
153  return malloc_shared_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
std::enable_if_t< CheckSharedPtrTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > aligned_alloc_shared_annotated(size_t alignment, size_t numBytes, const device &syclDevice, const context &syclContext, const propertyListA &propList=properties{})
constexpr alignment_key::value_t< K > alignment
Definition: properties.hpp:75
typename detail::CheckTAndPropListsWithUsmKind< sycl::usm::alloc::shared, T, ListA, ListB > CheckSharedPtrTAndPropLists
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
std::enable_if_t< CheckSharedPtrTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > malloc_shared_annotated(size_t numBytes, const device &syclDevice, const context &syclContext, const propertyListA &propList=properties{})
Definition: access.hpp:18