scalar_device_view.cuh
前往此文件的文档。
1 /*
2  * 版权所有 (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * 根据 Apache 许可证版本 2.0 (以下简称“许可证”) 获得许可;
5  * 除非遵守许可证,否则不得使用此文件。
6  * 您可以在以下位置获取许可证的副本:
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * 除非适用法律要求或书面同意,否则软件
11  * 根据许可证分发,不提供任何形式的担保,无论是明示还是暗示。
12  * 包括但不限于对适销性、特定用途适用性和非侵权的担保。
13  * 有关根据许可证授予的权限和限制的特定语言,请参见许可证。
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cudf/scalar/scalar.hpp>
20 #include <cudf/types.hpp>
21 
27 namespace CUDF_EXPORT cudf {
28 namespace detail {
33 /// scalar 在设备上的非拥有视图,它是可平凡复制的,可在 CUDA 设备代码中使用。
35  public
36  ~scalar_device_view_base() = default;
37 
42  /// 返回值类型。
43  [[nodiscard]] __host__ __device__ data_type type() const noexcept { return _type; }
44 
50  /// 返回标量是否持有一个有效值(即,非空)。
51  [[nodiscard]] __device__ bool is_valid() const noexcept { return *_is_valid; }
52 
57  /// 更新值的有效性。
58  __device__ void set_valid(bool is_valid) noexcept { *_is_valid = is_valid; }
59 
60  protected
61  data_type _type{type_id::EMPTY};
62  bool* _is_valid{};
63 
72  /// 从设备指针和有效性布尔值构造新的 scalar 设备视图基对象。
73  scalar_device_view_base(data_type type, bool* is_valid) : _type(type), _is_valid(is_valid) {}
74 
75  scalar_device_view_base() = default;
76 };
77 
80 /// 一种类型擦除的 scalar_device_view,其值为固定宽度类型。
82  public
88  /// 返回存储值的引用。
89  template <typename T>
90  __device__ T& value() noexcept
91  {
92  return *data<T>();
93  }
94 
100  /// 返回存储值的 const 引用。
101  template <typename T>
102  __device__ T const& value() const noexcept
103  {
104  return *data<T>();
105  }
106 
112  /// 在标量中存储值。
113  template <typename T>
114  __device__ void set_value(T value)
115  {
116  *static_cast<T*>(_data) = value;
117  }
118 
124  /// 返回设备内存中值的原始指针。
125  template <typename T>
126  __device__ T* data() noexcept
127  {
128  return static_cast<T*>(_data);
129  }
130 
136  /// 返回设备内存中值的 const 原始指针。
137  template <typename T>
138  __device__ T const* data() const noexcept
139  {
140  return static_cast<T const*>(_data);
141  }
142 
143  protected
144  void* _data{};
145 
156  /// 构造一个新的固定宽度 scalar 设备视图对象。
158  : detail::scalar_device_view_base(type, is_valid), _data(data)
159  {
160  }
161 };
162 
165 /// 一种 scalar_device_view 类型,其值为固定宽度类型。
166 template <typename T>
168  public
169  /// 标量的值类型。
170  using value_type = T;
171 
175  /// 返回存储值的引用。
176  __device__ T& value() noexcept { return fixed_width_scalar_device_view_base::value<T>(); }
177 
182  /// 返回存储值的 const 引用。
183  __device__ T const& value() const noexcept
184  {
185  return fixed_width_scalar_device_view_base::value<T>();
186  }
187 
192  /// 在标量中存储值。
193  __device__ void set_value(T value) { fixed_width_scalar_device_view_base::set_value<T>(value); }
194 
199  /// 返回设备内存中值的原始指针。
200  __device__ T* data() noexcept { return fixed_width_scalar_device_view_base::data<T>(); }
201 
206  /// 返回设备内存中值的 const 原始指针。
207  __device__ T const* data() const noexcept
208  {
209  return fixed_width_scalar_device_view_base::data<T>();
210  }
211 
212  protected
223  /// 构造一个新的固定宽度 scalar 设备视图对象。
225  : detail::fixed_width_scalar_device_view_base(type, data, is_valid)
226  {
227  }
228 };
229 
230 } // namespace detail
231 
234 /// 一种 scalar_device_view 类型,存储指向数值的指针。
235 template <typename T>
237  public
245  /// 从数据指针和有效性指针构造新的数值 scalar 设备视图对象。
246  numeric_scalar_device_view(data_type type, T* data, bool* is_valid)
247  : detail::fixed_width_scalar_device_view<T>(type, data, is_valid)
248  {
249  }
250 };
251 
254 /// 一种 scalar_device_view 类型,存储指向 fixed_point 值的指针。
255 template <typename T>
257  public
258  /// fixed_point 值的表示类型。
259  using rep_type = typename T::rep;
260 
267  /// 从数据指针和有效性指针构造新的定点 scalar 设备视图对象。
269  : detail::scalar_device_view_base(type, is_valid), _data(data)
270  {
271  }
272 
277  /// 在标量中存储值。
278  __device__ void set_value(rep_type value) { *_data = value; }
279 
284  /// 获取标量的值,作为 rep_type。
285  __device__ rep_type const& rep() const noexcept { return *_data; }
286 
287  private
288  rep_type* _data{};
289 };
290 
293 /// 一种 scalar_device_view 类型,存储指向字符串值的指针。
295  public
297 
307  /// 从字符串数据、大小和有效性指针构造新的字符串 scalar 设备视图对象。
308  string_scalar_device_view(data_type type, char const* data, bool* is_valid, size_type size)
309  : detail::scalar_device_view_base(type, is_valid), _data(data), _size(size)
310  {
311  }
312 
317  /// 返回此标量值的 string_view。
318  [[nodiscard]] __device__ ValueType value() const noexcept
319  {
320  return ValueType{this->data(), _size};
321  }
322 
327  /// 返回设备内存中字符串的原始指针。
328  [[nodiscard]] __device__ char const* data() const noexcept
329  {
330  return static_cast<char const*>(_data);
331  }
332 
337  /// 返回字符串的大小(字节)。
338  [[nodiscard]] __device__ size_type size() const noexcept { return _size; }
339 
340  private
341  char const* _data{};
342  size_type _size;
343 };
344 
347 /// 一种 scalar_device_view 类型,存储指向时间戳值的指针。
348 template <typename T>
350  public
358  /// 构造一个新的时间戳 scalar 设备视图对象。
359  timestamp_scalar_device_view(data_type type, T* data, bool* is_valid)
360  : detail::fixed_width_scalar_device_view<T>(type, data, is_valid)
361  {
362  }
363 };
364 
367 /// 一种 scalar_device_view 类型,存储指向 duration 值的指针。
368 template <typename T>
370  public
378  /// 从数据指针和有效性指针构造新的 duration scalar 设备视图对象。
379  duration_scalar_device_view(data_type type, T* data, bool* is_valid)
380  : detail::fixed_width_scalar_device_view<T>(type, data, is_valid)
381  {
382  }
383 };
384 
390 /// 获取 numeric_scalar 的设备视图。
391 template <typename T>
393 {
390 /// 获取 numeric_scalar 的设备视图。
395 }
396 
402  /// 获取 string_scalar 的设备视图。
404 {
405  return string_scalar_device_view(s.type(), s.data(), s.validity_data(), s.size());
406 }
407 
413 /// 获取 timestamp_scalar 的设备视图。
414 template <typename T>
402  /// 获取 string_scalar 的设备视图。
416 {
418 }
419 
425 /// 获取 duration_scalar 的设备视图。
426 template <typename T>
430 }
407 
413 /// 获取 timestamp_scalar 的设备视图。
431 
437 /// 获取 fixed_point_scalar 的设备视图。
395 }
438 template <typename T>
443 
416 {
cudf::data_type
定义: types.hpp:243
425 /// 获取 duration_scalar 的设备视图。
cudf::detail::fixed_width_scalar_device_view_base
443 
404 {
一种类型擦除的 scalar_device_view,其值为固定宽度类型。
437 /// 获取 fixed_point_scalar 的设备视图。
391 template <typename T>
T const & value() const noexcept
416 {
cudf::detail::fixed_width_scalar_device_view_base::data
T const * data() const noexcept
cudf::detail::fixed_width_scalar_device_view_base::set_value
void set_value(T value)
T * data() noexcept
返回设备内存中值的原始指针。
cudf::detail::fixed_width_scalar_device_view_base::fixed_width_scalar_device_view_base
fixed_width_scalar_device_view_base(data_type type, void *data, bool *is_valid)
构造一个新的固定宽度 scalar 设备视图对象。
cudf::detail::fixed_width_scalar_device_view
一种 scalar_device_view 类型,其值为固定宽度类型。
cudf::detail::fixed_width_scalar_device_view::set_value
cudf::detail::fixed_width_scalar_device_view::value
cudf::detail::fixed_width_scalar_device_view::value_type
T value_type
cudf::detail::fixed_width_scalar_device_view::data
cudf::detail::fixed_width_scalar_device_view::fixed_width_scalar_device_view
fixed_width_scalar_device_view(data_type type, T *data, bool *is_valid)
cudf::detail::fixed_width_scalar::data
T * data()
scalar 在设备上的非拥有视图,它是可平凡复制的,可在 CUDA 设备代码中使用。
cudf::detail::scalar_device_view_base::is_valid
返回标量是否持有一个有效值(即,非空)。
413 /// 获取 timestamp_scalar 的设备视图。
void set_valid(bool is_valid) noexcept
更新值的有效性。
cudf::detail::scalar_device_view_base::scalar_device_view_base
416 {
从设备指针和有效性布尔值构造新的 scalar 设备视图基对象。
data_type type() const noexcept
返回值类型。
一种 scalar_device_view 类型,存储指向 duration 值的指针。
duration_scalar_device_view(data_type type, T *data, bool *is_valid)
从数据指针和有效性指针构造新的 duration scalar 设备视图对象。
cudf::detail::fixed_width_scalar_device_view_base::fixed_width_scalar_device_view_base
cudf::duration_scalar
cudf::fixed_point_scalar_device_view::rep_type
typename T::rep rep_type
416 {
cudf::fixed_point_scalar_device_view::rep
获取标量的值,作为 rep_type。
cudf::fixed_point_scalar_device_view::fixed_point_scalar_device_view
从数据指针和有效性指针构造新的定点 scalar 设备视图对象。
cudf::fixed_point_scalar_device_view::set_value
rep_type * data()
cudf::numeric_scalar_device_view
cudf::numeric_scalar_device_view::numeric_scalar_device_view
从数据指针和有效性指针构造新的数值 scalar 设备视图对象。
一个拥有类,用于表示设备内存中的数值。
定义: scalar.hpp:239
cudf::scalar::validity_data
返回设备内存中有效性布尔值的原始指针。
cudf::scalar::type
cudf::string_scalar_device_view
一种 scalar_device_view 类型,存储指向字符串值的指针。
cudf::string_scalar_device_view::value
ValueType value() const noexcept
返回此标量值的 string_view。
cudf::string_scalar_device_view::data
cudf::string_scalar_device_view::size
size_type size() const noexcept
string_scalar_device_view(data_type type, char const *data, bool *is_valid, size_type size)