scalar_device_view.cuh
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2024, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <cudf/scalar/scalar.hpp>
9 #include <cudf/types.hpp>
10 
16 namespace CUDF_EXPORT cudf {
17 namespace detail {
23  public:
24  ~scalar_device_view_base() = default;
25 
31  [[nodiscard]] __host__ __device__ data_type type() const noexcept { return _type; }
32 
39  [[nodiscard]] __device__ bool is_valid() const noexcept { return *_is_valid; }
40 
46  __device__ void set_valid(bool is_valid) noexcept { *_is_valid = is_valid; }
47 
48  protected:
49  data_type _type{type_id::EMPTY};
50  bool* _is_valid{};
52 
61  scalar_device_view_base(data_type type, bool* is_valid) : _type(type), _is_valid(is_valid) {}
62 
63  scalar_device_view_base() = default;
64 };
65 
70  public:
77  template <typename T>
78  __device__ T& value() noexcept
79  {
80  return *data<T>();
81  }
82 
89  template <typename T>
90  __device__ T const& value() const noexcept
91  {
92  return *data<T>();
93  }
94 
101  template <typename T>
102  __device__ void set_value(T value)
103  {
104  *static_cast<T*>(_data) = value;
105  }
106 
113  template <typename T>
114  __device__ T* data() noexcept
115  {
116  return static_cast<T*>(_data);
117  }
118 
125  template <typename T>
126  __device__ T const* data() const noexcept
127  {
128  return static_cast<T const*>(_data);
129  }
130 
131  protected:
132  void* _data{};
133 
146  : detail::scalar_device_view_base(type, is_valid), _data(data)
147  {
148  }
149 };
150 
154 template <typename T>
156  public:
157  using value_type = T;
158 
164  __device__ T& value() noexcept { return fixed_width_scalar_device_view_base::value<T>(); }
165 
171  __device__ T const& value() const noexcept
172  {
173  return fixed_width_scalar_device_view_base::value<T>();
174  }
175 
181  __device__ void set_value(T value) { fixed_width_scalar_device_view_base::set_value<T>(value); }
182 
188  __device__ T* data() noexcept { return fixed_width_scalar_device_view_base::data<T>(); }
189 
195  __device__ T const* data() const noexcept
196  {
197  return fixed_width_scalar_device_view_base::data<T>();
198  }
199 
200  protected:
213  : detail::fixed_width_scalar_device_view_base(type, data, is_valid)
214  {
215  }
216 };
217 
218 } // namespace detail
219 
223 template <typename T>
225  public:
235  : detail::fixed_width_scalar_device_view<T>(type, data, is_valid)
236  {
237  }
238 };
239 
243 template <typename T>
245  public:
246  using rep_type = typename T::rep;
247 
257  : detail::scalar_device_view_base(type, is_valid), _data(data)
258  {
259  }
260 
266  __device__ void set_value(rep_type value) { *_data = value; }
267 
273  __device__ rep_type const& rep() const noexcept { return *_data; }
274 
275  private:
276  rep_type* _data{};
277 };
278 
283  public:
285 
296  string_scalar_device_view(data_type type, char const* data, bool* is_valid, size_type size)
297  : detail::scalar_device_view_base(type, is_valid), _data(data), _size(size)
298  {
299  }
300 
306  [[nodiscard]] __device__ ValueType value() const noexcept
307  {
308  return ValueType{this->data(), _size};
309  }
310 
316  [[nodiscard]] __device__ char const* data() const noexcept
317  {
318  return static_cast<char const*>(_data);
319  }
320 
326  [[nodiscard]] __device__ size_type size() const noexcept { return _size; }
327 
328  private:
329  char const* _data{};
330  size_type _size;
331 };
332 
336 template <typename T>
338  public:
348  : detail::fixed_width_scalar_device_view<T>(type, data, is_valid)
349  {
350  }
351 };
352 
356 template <typename T>
358  public:
368  : detail::fixed_width_scalar_device_view<T>(type, data, is_valid)
369  {
370  }
371 };
372 
379 template <typename T>
381 {
383 }
384 
392 {
393  return string_scalar_device_view(s.type(), s.data(), s.validity_data(), s.size());
394 }
395 
402 template <typename T>
404 {
406 }
407 
414 template <typename T>
416 {
418 }
419 
426 template <typename T>
428 {
430 }
431 
432 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:238
A type-erased scalar_device_view where the value is a fixed width type.
T const & value() const noexcept
Returns const reference to stored value.
T & value() noexcept
Returns reference to stored value.
T const * data() const noexcept
Returns a const raw pointer to the value in device memory.
void set_value(T value)
Stores the value in scalar.
T * data() noexcept
Returns a raw pointer to the value in device memory.
fixed_width_scalar_device_view_base(data_type type, void *data, bool *is_valid)
Construct a new fixed width scalar device view object.
A type of scalar_device_view where the value is a fixed width type.
void set_value(T value)
Stores the value in scalar.
T & value() noexcept
Returns reference to stored value.
T * data() noexcept
Returns a raw pointer to the value in device memory.
fixed_width_scalar_device_view(data_type type, T *data, bool *is_valid)
Construct a new fixed width scalar device view object.
T const * data() const noexcept
Returns a const raw pointer to the value in device memory.
T const & value() const noexcept
Returns const reference to stored value.
T * data()
Returns a raw pointer to the value in device memory.
A non-owning view of scalar from device that is trivially copyable and usable in CUDA device code.
bool is_valid() const noexcept
Returns whether the scalar holds a valid value (i.e., not null).
void set_valid(bool is_valid) noexcept
Updates the validity of the value.
scalar_device_view_base(data_type type, bool *is_valid)
Construct a new scalar device view base object from a device pointer and a validity boolean.
data_type type() const noexcept
Returns the value type.
A type of scalar_device_view that stores a pointer to a duration value.
duration_scalar_device_view(data_type type, T *data, bool *is_valid)
Construct a new duration scalar device view object from data and validity pointers.
An owning class to represent a duration value in device memory.
Definition: scalar.hpp:656
A type of scalar_device_view that stores a pointer to a fixed_point value.
typename T::rep rep_type
The representation type of the fixed_point value.
rep_type const & rep() const noexcept
Get the value of the scalar, as a rep_type.
fixed_point_scalar_device_view(data_type type, rep_type *data, bool *is_valid)
Construct a new fixed point scalar device view object from data and validity pointers.
void set_value(rep_type value)
Stores the value in scalar.
An owning class to represent a fixed_point number in device memory.
Definition: scalar.hpp:288
rep_type * data()
Returns a raw pointer to the value in device memory.
A type of scalar_device_view that stores a pointer to a numerical value.
numeric_scalar_device_view(data_type type, T *data, bool *is_valid)
Construct a new numeric scalar device view object from data and validity pointers.
An owning class to represent a numerical value in device memory.
Definition: scalar.hpp:228
bool * validity_data()
Returns a raw pointer to the validity bool in device memory.
data_type type() const noexcept
Returns the scalar's logical value type.
A type of scalar_device_view that stores a pointer to a string value.
ValueType value() const noexcept
Returns string_view of the value of this scalar.
char const * data() const noexcept
Returns a raw pointer to the value in device memory.
size_type size() const noexcept
Returns the size of the string in bytes.
string_scalar_device_view(data_type type, char const *data, bool *is_valid, size_type size)
Construct a new string scalar device view object from string data, size and validity pointers.
An owning class to represent a string in device memory.
Definition: scalar.hpp:410
size_type size() const
Returns the size of the string in bytes.
char const * data() const
Returns a raw pointer to the string in device memory.
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:33
A type of scalar_device_view that stores a pointer to a timestamp value.
timestamp_scalar_device_view(data_type type, T *data, bool *is_valid)
Construct a new timestamp scalar device view object.
An owning class to represent a timestamp value in device memory.
Definition: scalar.hpp:600
std::unique_ptr< cudf::column > is_valid(cudf::column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a column of type_id::BOOL8 elements where for every element in input true indicates the value...
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
cuDF interfaces
Definition: host_udf.hpp:26
auto get_scalar_device_view(fixed_point_scalar< T > &s)
Get the device view of a fixed_point_scalar.
Class definitions for cudf::scalar.
Class definition for cudf::string_view.
Type declarations for libcudf.