PXL
task_count.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright 2026 XCENA Inc.
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <pxl/v3_api_guard.hpp>
8 #include <utility>
9 
10 namespace pxl
11 {
12 namespace detail
13 {
14 
23 template <typename Builder>
24 class [[nodiscard]] TaskCountConfigured : public Builder
25 {
26 public:
27  explicit TaskCountConfigured(Builder&& builder)
28  : Builder(std::move(builder))
29  {
30  }
31 
33  TaskCountConfigured& operator=(TaskCountConfigured&&) noexcept = default;
35  TaskCountConfigured& operator=(const TaskCountConfigured&) = delete;
36 
37 // Keep every setting's lvalue/rvalue behavior identical. No storage or exported
38 // symbols are added to the underlying builders.
39 #define PXL_CONFIGURED_SETTING(method) \
40  template <typename... Args> \
41  TaskCountConfigured& method(Args&&... args)& \
42  { \
43  Builder::method(std::forward<Args>(args)...); \
44  return *this; \
45  } \
46  template <typename... Args> \
47  TaskCountConfigured&& method(Args&&... args)&& \
48  { \
49  Builder::method(std::forward<Args>(args)...); \
50  return std::move(*this); \
51  }
52 
54  PXL_CONFIGURED_SETTING(reserve)
55  PXL_CONFIGURED_SETTING(batchSize)
56  PXL_CONFIGURED_SETTING(clusterBitmap)
57  PXL_CONFIGURED_SETTING(locality)
58  PXL_CONFIGURED_SETTING(onComplete)
59  PXL_CONFIGURED_SETTING(onMessage)
60  PXL_CONFIGURED_SETTING(onError)
62  PXL_CONFIGURED_SETTING(enableProfile)
63 
64 #undef PXL_CONFIGURED_SETTING
65 
66  template <auto Func, typename... Args, typename B = Builder>
67  auto stage(Args&&... args) & -> decltype(std::declval<B&>().template stage<Func>(std::forward<Args>(args)...))
68  {
69  return Builder::template stage<Func>(std::forward<Args>(args)...);
70  }
71 
72  template <auto Func, typename... Args, typename B = Builder>
73  auto stage(Args&&... args) && -> decltype(std::declval<B&&>().template stage<Func>(std::forward<Args>(args)...))
74  {
75  return std::move(static_cast<Builder&>(*this)).template stage<Func>(std::forward<Args>(args)...);
76  }
77 
78  template <typename B = Builder>
79  auto stage() & -> decltype(std::declval<B&>().stage())
80  {
81  return Builder::stage();
82  }
83 
84  // A group returned from a temporary chain must own that chain. Borrowing
85  // it would leave a stored group pointing at a destroyed parent.
86  template <typename B = Builder>
87  auto stage() && -> decltype(std::declval<B&&>().takeStageGroup())
88  {
89  return std::move(static_cast<Builder&>(*this)).takeStageGroup();
90  }
91 };
92 
102 template <typename Builder>
103 class [[nodiscard]] TaskCountRequired
104 {
105 public:
106  explicit TaskCountRequired(Builder&& builder)
107  : builder_(std::move(builder))
108  {
109  }
110 
111  TaskCountRequired(TaskCountRequired&&) noexcept = default;
112  TaskCountRequired& operator=(TaskCountRequired&&) noexcept = default;
114  TaskCountRequired& operator=(const TaskCountRequired&) = delete;
115 
116  TaskCountConfigured<Builder> tasks(uint32_t taskCount)
117  {
118  builder_.tasks(taskCount);
119  return TaskCountConfigured<Builder>(std::move(builder_));
120  }
121 
122  template <typename... Args>
123  TaskCountRequired& reserve(Args&&... args)
124  {
125  builder_.reserve(std::forward<Args>(args)...);
126  return *this;
127  }
128 
129  template <typename... Args>
130  TaskCountRequired& batchSize(Args&&... args)
131  {
132  builder_.batchSize(std::forward<Args>(args)...);
133  return *this;
134  }
135 
136  template <typename... Args>
138  {
139  builder_.clusterBitmap(std::forward<Args>(args)...);
140  return *this;
141  }
142 
143  template <typename... Args>
144  TaskCountRequired& locality(Args&&... args)
145  {
146  builder_.locality(std::forward<Args>(args)...);
147  return *this;
148  }
149 
150  template <typename... Args>
151  TaskCountRequired& onComplete(Args&&... args)
152  {
153  builder_.onComplete(std::forward<Args>(args)...);
154  return *this;
155  }
156 
157  template <typename... Args>
158  TaskCountRequired& onMessage(Args&&... args)
159  {
160  builder_.onMessage(std::forward<Args>(args)...);
161  return *this;
162  }
163 
164  template <typename... Args>
165  TaskCountRequired& onError(Args&&... args)
166  {
167  builder_.onError(std::forward<Args>(args)...);
168  return *this;
169  }
170 
171  template <typename... Args>
172  TaskCountRequired& stream(Args&&... args)
173  {
174  builder_.stream(std::forward<Args>(args)...);
175  return *this;
176  }
177 
178  template <typename... Args>
180  {
181  builder_.enableProfile(std::forward<Args>(args)...);
182  return *this;
183  }
184 
185 private:
186  Builder builder_;
187 };
188 
189 } // namespace detail
190 } // namespace pxl
Runnable builder that preserves the value category of settings.
Definition: task_count.hpp:25
auto stage() &&-> decltype(std::declval< B && >().takeStageGroup())
Definition: task_count.hpp:87
auto stage() &-> decltype(std::declval< B & >().stage())
Definition: task_count.hpp:79
TaskCountConfigured(TaskCountConfigured &&) noexcept=default
auto stage(Args &&... args) &&-> decltype(std::declval< B && >().template stage< Func >(std::forward< Args >(args)...))
Definition: task_count.hpp:73
auto stage(Args &&... args) &-> decltype(std::declval< B & >().template stage< Func >(std::forward< Args >(args)...))
Definition: task_count.hpp:67
TaskCountConfigured(Builder &&builder)
Definition: task_count.hpp:27
Holds a launch request that still needs its task count.
Definition: task_count.hpp:104
TaskCountRequired & reserve(Args &&... args)
Definition: task_count.hpp:123
TaskCountRequired & onComplete(Args &&... args)
Definition: task_count.hpp:151
TaskCountRequired & stream(Args &&... args)
Definition: task_count.hpp:172
TaskCountRequired(Builder &&builder)
Definition: task_count.hpp:106
TaskCountRequired & locality(Args &&... args)
Definition: task_count.hpp:144
TaskCountRequired & batchSize(Args &&... args)
Definition: task_count.hpp:130
TaskCountRequired & onMessage(Args &&... args)
Definition: task_count.hpp:158
TaskCountRequired(TaskCountRequired &&) noexcept=default
TaskCountRequired & enableProfile(Args &&... args)
Definition: task_count.hpp:179
TaskCountRequired & onError(Args &&... args)
Definition: task_count.hpp:165
TaskCountRequired & clusterBitmap(Args &&... args)
Definition: task_count.hpp:137
Definition: config.hpp:13
#define PXL_CONFIGURED_SETTING(method)
Definition: task_count.hpp:39