scalar_device_view.cuh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2022, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
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 {
28 namespace detail {
34  public:
35  ~scalar_device_view_base() = default;
36 
41  [[nodiscard]] __host__ __device__ data_type type() const noexcept { return _type; }
42 
49  [[nodiscard]] __device__ bool is_valid() const noexcept { return *_is_valid; }
50 
56  __device__ void set_valid(bool is_valid) noexcept { *_is_valid = is_valid; }
57 
58  protected:
59  data_type _type{type_id::EMPTY};
60  bool* _is_valid{};
61 
72 
73  scalar_device_view_base() = default;
74 };
75 
80  public:
87  template <typename T>
88  __device__ T& value() noexcept
89  {
90  return *data<T>();
91  }
92 
99  template <typename T>
100  __device__ T const& value() const noexcept
101  {
102  return *data<T>();
103  }
104 
111  template <typename T>
112  __device__ void set_value(T value)
113  {
114  *static_cast<T*>(_data) = value;
115  }
116 
123  template <typename T>
124  __device__ T* data() noexcept
125  {
126  return static_cast<T*>(_data);
127  }
128 
135  template <typename T>
136  __device__ T const* data() const noexcept
137  {
138  return static_cast<T const*>(_data);
139  }
140 
141  protected:
142  void* _data{};
143 
157  {
158  }
159 };
160 
164 template <typename T>
166  public:
167  using value_type = T;
168 
174  __device__ T& value() noexcept { return fixed_width_scalar_device_view_base::value<T>(); }
175 
181  __device__ T const& value() const noexcept
182  {
183  return fixed_width_scalar_device_view_base::value<T>();
184  }
185 
191  __device__ void set_value(T value) { fixed_width_scalar_device_view_base::set_value<T>(value); }
192 
198  __device__ T* data() noexcept { return fixed_width_scalar_device_view_base::data<T>(); }
199 
205  __device__ T const* data() const noexcept
206  {
207  return fixed_width_scalar_device_view_base::data<T>();
208  }
209 
210  protected:
224  {
225  }
226 };
227 
228 } // namespace detail
229 
233 template <typename T>
235  public:
246  {
247  }
248 };
249 
253 template <typename T>
255  public:
256  using rep_type = typename T::rep;
257 
267  : detail::scalar_device_view_base(type, is_valid), _data(data)
268  {
269  }
270 
276  __device__ void set_value(rep_type value) { *_data = value; }
277 
283  __device__ rep_type const& rep() const noexcept { return *_data; }
284 
285  private:
286  rep_type* _data{};
287 };
288 
293  public:
295 
307  : detail::scalar_device_view_base(type, is_valid), _data(data), _size(size)
308  {
309  }
310 
316  [[nodiscard]] __device__ ValueType value() const noexcept
317  {
318  return ValueType{this->data(), _size};
319  }
320 
326  [[nodiscard]] __device__ char const* data() const noexcept
327  {
328  return static_cast<char const*>(_data);
329  }
330 
336  [[nodiscard]] __device__ size_type size() const noexcept { return _size; }
337 
338  private:
339  const char* _data{};
340  size_type _size;
341 };
342 
346 template <typename T>
348  public:
359  {
360  }
361 };
362 
366 template <typename T>
368  public:
379  {
380  }
381 };
382 
389 template <typename T>
391 {
393 }
394 
402 {
403  return string_scalar_device_view(s.type(), s.data(), s.validity_data(), s.size());
404 }
405 
412 template <typename T>
414 {
416 }
417 
424 template <typename T>
426 {
428 }
429 
436 template <typename T>
438 {
440 }
441 
442 } // namespace cudf
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)
Construct a new fixed width scalar device view object.
Definition: scalar_device_view.cuh:155
cudf::string_scalar_device_view::data
char const * data() const noexcept
Returns a raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:326
cudf::detail::fixed_width_scalar_device_view
A type of scalar_device_view where the value is a fixed width type.
Definition: scalar_device_view.cuh:165
cudf::detail::fixed_width_scalar_device_view::data
T * data() noexcept
Returns a raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:198
cudf::timestamp_scalar
An owning class to represent a timestamp value in device memory.
Definition: scalar.hpp:620
cudf::scalar::validity_data
bool * validity_data()
Returns a raw pointer to the validity bool in device memory.
scalar.hpp
Class definitions for cudf::scalar.
string_view.hpp
Class definition for cudf::string_view.
cudf::size_type
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
cudf::string_scalar_device_view
A type of scalar_device_view that stores a pointer to a string value.
Definition: scalar_device_view.cuh:292
cudf::detail::fixed_width_scalar_device_view::value_type
T value_type
The value type of the scalar.
Definition: scalar_device_view.cuh:167
cudf::detail::fixed_width_scalar_device_view_base::data
T const * data() const noexcept
Returns a const raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:136
cudf::string_scalar_device_view::size
size_type size() const noexcept
Returns the size of the string in bytes.
Definition: scalar_device_view.cuh:336
cudf::fixed_point_scalar_device_view::rep
rep_type const & rep() const noexcept
Get the value of the scalar, as a rep_type.
Definition: scalar_device_view.cuh:283
types.hpp
Type declarations for libcudf.
cudf::detail::fixed_width_scalar_device_view_base::set_value
void set_value(T value)
Stores the value in scalar.
Definition: scalar_device_view.cuh:112
cudf::string_scalar_device_view::string_scalar_device_view
string_scalar_device_view(data_type type, const char *data, bool *is_valid, size_type size)
Construct a new string scalar device view object from string data, size and validity pointers.
Definition: scalar_device_view.cuh:306
cudf::string_view
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:49
cudf::detail::fixed_width_scalar_device_view::set_value
void set_value(T value)
Stores the value in scalar.
Definition: scalar_device_view.cuh:191
cudf::detail::fixed_width_scalar_device_view::value
T const & value() const noexcept
Returns const reference to stored value.
Definition: scalar_device_view.cuh:181
cudf::timestamp_scalar_device_view
A type of scalar_device_view that stores a pointer to a timestamp value.
Definition: scalar_device_view.cuh:347
cudf::fixed_point_scalar::data
rep_type * data()
Returns a raw pointer to the value in device memory.
cudf::detail::fixed_width_scalar_device_view_base::data
T * data() noexcept
Returns a raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:124
cudf::detail::scalar_device_view_base::set_valid
void set_valid(bool is_valid) noexcept
Updates the validity of the value.
Definition: scalar_device_view.cuh:56
cudf::detail::fixed_width_scalar_device_view::value
T & value() noexcept
Returns reference to stored value.
Definition: scalar_device_view.cuh:174
cudf::duration_scalar_device_view
A type of scalar_device_view that stores a pointer to a duration value.
Definition: scalar_device_view.cuh:367
cudf::string_scalar_device_view::value
ValueType value() const noexcept
Returns string_view of the value of this scalar.
Definition: scalar_device_view.cuh:316
cudf::detail::fixed_width_scalar_device_view_base::value
T const & value() const noexcept
Returns const reference to stored value.
Definition: scalar_device_view.cuh:100
cudf::duration_scalar
An owning class to represent a duration value in device memory.
Definition: scalar.hpp:675
cudf::fixed_point_scalar_device_view::set_value
void set_value(rep_type value)
Stores the value in scalar.
Definition: scalar_device_view.cuh:276
cudf::fixed_point_scalar_device_view::fixed_point_scalar_device_view
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.
Definition: scalar_device_view.cuh:266
cudf::detail::scalar_device_view_base
A non-owning view of scalar from device that is trivially copyable and usable in CUDA device code.
Definition: scalar_device_view.cuh:33
cudf::get_scalar_device_view
auto get_scalar_device_view(numeric_scalar< T > &s)
Get the device view of a numeric_scalar.
Definition: scalar_device_view.cuh:390
cudf::string_scalar::data
const char * data() const
Returns a raw pointer to the string in device memory.
cudf::numeric_scalar
An owning class to represent a numerical value in device memory.
Definition: scalar.hpp:241
cudf::data_type
Indicator for the logical data type of an element in a column.
Definition: types.hpp:240
cudf::detail::fixed_width_scalar_device_view_base::_data
void * _data
Pointer to device memory containing the value.
Definition: scalar_device_view.cuh:142
cudf::duration_scalar_device_view::duration_scalar_device_view
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.
Definition: scalar_device_view.cuh:377
cudf::numeric_scalar_device_view
A type of scalar_device_view that stores a pointer to a numerical value.
Definition: scalar_device_view.cuh:234
cudf::fixed_point_scalar
An owning class to represent a fixed_point number in device memory.
Definition: scalar.hpp:301
cudf::detail::fixed_width_scalar::data
T * data()
Returns a raw pointer to the value in device memory.
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::detail::scalar_device_view_base::_type
data_type _type
Value data type.
Definition: scalar_device_view.cuh:59
cudf::detail::scalar_device_view_base::is_valid
bool is_valid() const noexcept
Returns whether the scalar holds a valid value (i.e., not null).
Definition: scalar_device_view.cuh:49
cudf::string_scalar::size
size_type size() const
Returns the size of the string in bytes.
cudf::detail::fixed_width_scalar_device_view_base
A type-erased scalar_device_view where the value is a fixed width type.
Definition: scalar_device_view.cuh:79
cudf::numeric_scalar_device_view::numeric_scalar_device_view
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.
Definition: scalar_device_view.cuh:244
cudf::fixed_point_scalar_device_view
A type of scalar_device_view that stores a pointer to a fixed_point value.
Definition: scalar_device_view.cuh:254
cudf::detail::fixed_width_scalar_device_view::data
T const * data() const noexcept
Returns a const raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:205
cudf::detail::scalar_device_view_base::_is_valid
bool * _is_valid
Definition: scalar_device_view.cuh:60
cudf::fixed_point_scalar_device_view::rep_type
typename T::rep rep_type
The representation type of the fixed_point value.
Definition: scalar_device_view.cuh:256
cudf::string_scalar
An owning class to represent a string in device memory.
Definition: scalar.hpp:427
cudf::timestamp_scalar_device_view::timestamp_scalar_device_view
timestamp_scalar_device_view(data_type type, T *data, bool *is_valid)
Construct a new timestamp scalar device view object.
Definition: scalar_device_view.cuh:357
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)
Construct a new fixed width scalar device view object.
Definition: scalar_device_view.cuh:222
cudf::detail::scalar_device_view_base::scalar_device_view_base
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.
Definition: scalar_device_view.cuh:71
cudf::scalar::type
data_type type() const noexcept
Returns the scalar's logical value type.
cudf::detail::fixed_width_scalar_device_view_base::value
T & value() noexcept
Returns reference to stored value.
Definition: scalar_device_view.cuh:88
cudf::detail::scalar_device_view_base::type
data_type type() const noexcept
Returns the value type.
Definition: scalar_device_view.cuh:41