DPC++ Runtime
Runtime libraries for oneAPI DPC++
task_sequence.hpp
Go to the documentation of this file.
1 //==--------------------------- task_sequence.hpp --------------------------==//
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 
11 #include <CL/__spirv/spirv_ops.hpp>
13 #include <sycl/exception.hpp>
17 
18 #include <type_traits>
19 
20 namespace sycl {
21 inline namespace _V1 {
22 namespace ext::intel::experimental {
23 
24 template <auto &f> struct task_sequence_checker : std::false_type {};
25 
26 template <typename ReturnT, typename... ArgsT, ReturnT (&f)(ArgsT...)>
27 struct task_sequence_checker<f> : std::true_type {};
28 
29 template <auto &f,
30  typename PropertyListT = oneapi::experimental::empty_properties_t>
32 
33  static_assert(task_sequence_checker<f>::value);
34 
36  "Property list is invalid.");
37 };
38 
39 template <typename ReturnT, typename... ArgsT, ReturnT (&f)(ArgsT...),
40  typename... Props>
41 #if defined(__SYCL_DEVICE_ONLY__)
42 class
43  [[__sycl_detail__::__uses_aspects__(aspect::ext_intel_fpga_task_sequence)]] task_sequence<
44 #else
46 #endif
47  f, oneapi::experimental::detail::properties_t<Props...>> {
49 
50 public:
51  task_sequence(const task_sequence &) = delete;
55 
57 #if defined(__SYCL_DEVICE_ONLY__)
58  taskSequence = __spirv_TaskSequenceCreateINTEL(
60 #else
62  "task_sequence is not supported on the host"};
63 #endif
64  }
65 
66  void async([[maybe_unused]] ArgsT... Args) {
67 #if defined(__SYCL_DEVICE_ONLY__)
68  ++outstanding;
69  __spirv_TaskSequenceAsyncINTEL(taskSequence, Args...);
70 #else
72  "task_sequence is not supported on the host"};
73 #endif
74  }
75 
76  ReturnT get() {
77 #if defined(__SYCL_DEVICE_ONLY__)
78  --outstanding;
79  return __spirv_TaskSequenceGetINTEL<ReturnT>(taskSequence);
80 #else
82  "task_sequence is not supported on the host"};
83 #endif
84  }
85 
87 #if defined(__SYCL_DEVICE_ONLY__)
88  if constexpr (!has_property<balanced_key>()) {
89  while (outstanding > 0)
90  get();
91  }
92  __spirv_TaskSequenceReleaseINTEL(taskSequence);
93 #endif
94  // Destructor shouldn't throw exception.
95  }
96 
97  template <typename propertyT> static constexpr bool has_property() {
98  return property_list_t::template has_property<propertyT>();
99  }
100 
101  template <typename propertyT> static constexpr auto get_property() {
102  return property_list_t::template get_property<propertyT>();
103  }
104 
105 private:
106 #if defined(__SYCL_DEVICE_ONLY__)
107  unsigned outstanding = 0;
108  __spv::__spirv_TaskSequenceINTEL *taskSequence;
109 #endif
110  static constexpr int32_t pipelined =
112  property_list_t, pipelined_key>::template get<int32_t>(-1);
113  static constexpr int32_t fpga_cluster =
114  has_property<fpga_cluster_key>()
115  ? static_cast<
116  typename std::underlying_type<fpga_cluster_options_enum>::type>(
119  template get<fpga_cluster_options_enum>(
121  : -1;
122  static constexpr uint32_t response_capacity =
124  property_list_t, response_capacity_key>::template get<uint32_t>(0);
125  static constexpr uint32_t invocation_capacity =
127  property_list_t, invocation_capacity_key>::template get<uint32_t>(0);
128 };
129 
130 } // namespace ext::intel::experimental
131 } // namespace _V1
132 } // namespace sycl
constexpr invocation_capacity_key::value_t< Size > invocation_capacity
constexpr fpga_cluster_key::value_t< option > fpga_cluster
constexpr pipelined_key::value_t< pipeline_directive_or_initiation_interval > pipelined
constexpr response_capacity_key::value_t< Size > response_capacity
properties< std::tuple< PropertyValueTs... > > properties_t
Definition: properties.hpp:212
detail::properties_t< Props... > property_list_t
decltype(properties{}) empty_properties_t
Definition: properties.hpp:190
pointer get() const
Definition: multi_ptr.hpp:544
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:93
Definition: access.hpp:18