DPC++ Runtime
Runtime libraries for oneAPI DPC++
alloc_host.hpp
Go to the documentation of this file.
1 //==-------- alloc_host.hpp - SYCL annotated usm host 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::host, T,
22  ListA, ListB>;
23 
24 template <typename PropertyListT>
26  detail::GetAnnotatedPtrPropertiesWithUsmKind<sycl::usm::alloc::host,
27  PropertyListT>;
28 
30 // "aligned_alloc_host_annotated": Aligned host USM allocation functions with
31 // properties support
32 //
33 // This the base form of all the annotated USM host allocation functions, which
34 // are implemented by calling the more generic "aligned_alloc_annotated"
35 // functions with the USM kind as an argument. Note that when calling
36 // "aligned_alloc_annotated", the template parameter `propertyListA` should
37 // include the `usm_kind<alloc::host>` property to make it appear on the
38 // returned annotated_ptr of "aligned_alloc_annotated"
40 
41 template <typename propertyListA = detail::empty_properties_t,
42  typename propertyListB =
44 std::enable_if_t<
47 aligned_alloc_host_annotated(size_t alignment, size_t numBytes,
48  const context &syclContext,
49  const propertyListA &propList = properties{}) {
50  auto tmp = aligned_alloc_annotated(alignment, numBytes, {}, syclContext,
51  sycl::usm::alloc::host, propList);
52  return annotated_ptr<void, propertyListB>(tmp.get());
53 }
54 
55 template <typename T, typename propertyListA = detail::empty_properties_t,
56  typename propertyListB =
57  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
58 std::enable_if_t<
59  CheckHostPtrTAndPropLists<T, propertyListA, propertyListB>::value,
60  annotated_ptr<T, propertyListB>>
62  const context &syclContext,
63  const propertyListA &propList = properties{}) {
64  auto tmp = aligned_alloc_annotated<T>(alignment, count, {}, syclContext,
65  sycl::usm::alloc::host, propList);
66  return annotated_ptr<T, propertyListB>(tmp.get());
67 }
68 
69 template <typename propertyListA = detail::empty_properties_t,
70  typename propertyListB =
71  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
72 std::enable_if_t<
73  CheckHostPtrTAndPropLists<void, propertyListA, propertyListB>::value,
74  annotated_ptr<void, propertyListB>>
75 aligned_alloc_host_annotated(size_t alignment, size_t numBytes,
76  const queue &syclQueue,
77  const propertyListA &propList = properties{}) {
78  return aligned_alloc_host_annotated(alignment, numBytes,
79  syclQueue.get_context(), propList);
80 }
81 
82 template <typename T, typename propertyListA = detail::empty_properties_t,
83  typename propertyListB =
84  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
85 std::enable_if_t<
86  CheckHostPtrTAndPropLists<T, propertyListA, propertyListB>::value,
87  annotated_ptr<T, propertyListB>>
89  const queue &syclQueue,
90  const propertyListA &propList = properties{}) {
91  return aligned_alloc_host_annotated<T>(alignment, count,
92  syclQueue.get_context(), propList);
93 }
94 
96 // Host USM allocation functions with properties support
97 //
98 // Note: "malloc_host_annotated" functions call "aligned_alloc_host_annotated"
99 // with alignment 0
101 
102 template <typename propertyListA = detail::empty_properties_t,
103  typename propertyListB =
104  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
105 std::enable_if_t<
106  CheckHostPtrTAndPropLists<void, propertyListA, propertyListB>::value,
107  annotated_ptr<void, propertyListB>>
108 malloc_host_annotated(size_t numBytes, const context &syclContext,
109  const propertyListA &propList = properties{}) {
110  return aligned_alloc_host_annotated(0, numBytes, syclContext, propList);
111 }
112 
113 template <typename T, typename propertyListA = detail::empty_properties_t,
114  typename propertyListB =
115  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
116 std::enable_if_t<
117  CheckHostPtrTAndPropLists<T, propertyListA, propertyListB>::value,
118  annotated_ptr<T, propertyListB>>
119 malloc_host_annotated(size_t count, const context &syclContext,
120  const propertyListA &propList = properties{}) {
121  return aligned_alloc_host_annotated<T>(0, count, syclContext, propList);
122 }
123 
124 template <typename propertyListA = detail::empty_properties_t,
125  typename propertyListB =
126  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
127 std::enable_if_t<
128  CheckHostPtrTAndPropLists<void, propertyListA, propertyListB>::value,
129  annotated_ptr<void, propertyListB>>
130 malloc_host_annotated(size_t numBytes, const queue &syclQueue,
131  const propertyListA &propList = properties{}) {
132  return malloc_host_annotated(numBytes, syclQueue.get_context(), propList);
133 }
134 
135 template <typename T, typename propertyListA = detail::empty_properties_t,
136  typename propertyListB =
137  typename GetAnnotatedHostPtrProperties<propertyListA>::type>
138 std::enable_if_t<
139  CheckHostPtrTAndPropLists<T, propertyListA, propertyListB>::value,
140  annotated_ptr<T, propertyListB>>
141 malloc_host_annotated(size_t count, const queue &syclQueue,
142  const propertyListA &propList = properties{}) {
143  return malloc_host_annotated<T>(count, syclQueue.get_context(), propList);
144 }
145 
146 } // namespace experimental
147 } // namespace oneapi
148 } // namespace ext
149 } // namespace _V1
150 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:105
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< CheckHostPtrTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > aligned_alloc_host_annotated(size_t alignment, size_t numBytes, const context &syclContext, const propertyListA &propList=properties{})
Definition: alloc_host.hpp:47
typename detail::CheckTAndPropListsWithUsmKind< sycl::usm::alloc::host, T, ListA, ListB > CheckHostPtrTAndPropLists
Definition: alloc_host.hpp:22
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< CheckHostPtrTAndPropLists< void, propertyListA, propertyListB >::value, annotated_ptr< void, propertyListB > > malloc_host_annotated(size_t numBytes, const context &syclContext, const propertyListA &propList=properties{})
Definition: alloc_host.hpp:108
Definition: access.hpp:18