scalar_device_view.cuh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021, 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 
40  __host__ __device__ data_type type() const noexcept { return _type; }
41 
48  __device__ bool is_valid() const noexcept { return *_is_valid; }
49 
55  __device__ void set_valid(bool is_valid) noexcept { *_is_valid = is_valid; }
56 
57  protected:
58  data_type _type{type_id::EMPTY};
59  bool* _is_valid{};
60 
63 
64  scalar_device_view_base() = default;
65 };
66 
71  public:
77  template <typename T>
78  __device__ T& value() noexcept
79  {
80  return *data<T>();
81  }
82 
88  template <typename T>
89  __device__ T const& value() const noexcept
90  {
91  return *data<T>();
92  }
93 
94  template <typename T>
95  __device__ void set_value(T value)
96  {
97  *static_cast<T*>(_data) = value;
98  }
99 
105  template <typename T>
106  __device__ T* data() noexcept
107  {
108  return static_cast<T*>(_data);
109  }
115  template <typename T>
116  __device__ T const* data() const noexcept
117  {
118  return static_cast<T const*>(_data);
119  }
120 
121  protected:
122  void* _data{};
123 
137  {
138  }
139 };
140 
144 template <typename T>
146  public:
147  using value_type = T;
148 
152  __device__ T& value() noexcept { return fixed_width_scalar_device_view_base::value<T>(); }
153 
157  __device__ T const& value() const noexcept
158  {
159  return fixed_width_scalar_device_view_base::value<T>();
160  }
161 
162  __device__ void set_value(T value) { fixed_width_scalar_device_view_base::set_value<T>(value); }
163 
167  __device__ T* data() noexcept { return fixed_width_scalar_device_view_base::data<T>(); }
171  __device__ T const* data() const noexcept
172  {
173  return fixed_width_scalar_device_view_base::data<T>();
174  }
175 
176  protected:
190  {
191  }
192 };
193 
194 } // namespace detail
195 
199 template <typename T>
201  public:
204  {
205  }
206 };
207 
211 template <typename T>
213  public:
214  using rep_type = typename T::rep;
215 
216  fixed_point_scalar_device_view(data_type type, rep_type* data, bool* is_valid)
218  {
219  }
220 
221  __device__ void set_value(rep_type value) { *_data = value; }
222 
223  private:
224  rep_type* _data{};
225 };
226 
231  public:
233 
234  string_scalar_device_view(data_type type, const char* data, bool* is_valid, size_type size)
236  {
237  }
238 
242  __device__ ValueType value() const noexcept { return ValueType{this->data(), _size}; }
243 
247  __device__ char const* data() const noexcept { return static_cast<char const*>(_data); }
248 
252  __device__ size_type size() const noexcept { return _size; }
253 
254  private:
255  const char* _data{};
256  size_type _size;
257 };
258 
262 template <typename T>
264  public:
267  {
268  }
269 };
270 
274 template <typename T>
276  public:
279  {
280  }
281 };
282 
286 template <typename T>
288 {
290 }
291 
296 {
297  return string_scalar_device_view(s.type(), s.data(), s.validity_data(), s.size());
298 }
299 
303 template <typename T>
305 {
307 }
308 
312 template <typename T>
314 {
316 }
317 
321 template <typename T>
323 {
325 }
326 
327 } // 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:135
cudf::detail::fixed_width_scalar_device_view::value
__device__ T const & value() const noexcept
Returns const reference to stored value.
Definition: scalar_device_view.cuh:157
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:145
cudf::scalar::validity_data
bool * validity_data()
Returns a raw pointer to the validity bool in device memory.
Definition: scalar.hpp:92
scalar.hpp
Class definitions for cudf::scalar.
string_view.hpp
Class definition for cudf::string_view.
cudf::detail::fixed_width_scalar_device_view_base::value
__device__ T const & value() const noexcept
Returns const reference to stored value.
Definition: scalar_device_view.cuh:89
cudf::string_scalar_device_view
A type of scalar_device_view that stores a pointer to a string value.
Definition: scalar_device_view.cuh:230
types.hpp
Type declarations for libcudf.
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:63
cudf::detail::fixed_width_scalar_device_view::data
__device__ T const * data() const noexcept
Returns a const raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:171
cudf::timestamp_scalar_device_view
A type of scalar_device_view that stores a pointer to a timestamp value.
Definition: scalar_device_view.cuh:263
cudf::fixed_point_scalar::data
rep_type * data()
Returns a raw pointer to the value in device memory.
Definition: scalar.hpp:380
cudf::string_scalar_device_view::data
__device__ char const * data() const noexcept
Returns a raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:247
cudf::duration_scalar_device_view
A type of scalar_device_view that stores a pointer to a duration value.
Definition: scalar_device_view.cuh:275
cudf::detail::scalar_device_view_base::set_valid
__device__ void set_valid(bool is_valid) noexcept
Updates the validity of the value.
Definition: scalar_device_view.cuh:55
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:287
cudf::string_scalar::data
const char * data() const
Returns a raw pointer to the string in device memory.
Definition: scalar.hpp:476
cudf::numeric_scalar
An owning class to represent a numerical value in device memory.
Definition: scalar.hpp:223
cudf::detail::fixed_width_scalar_device_view_base::value
__device__ T & value() noexcept
Returns reference to stored value.
Definition: scalar_device_view.cuh:78
cudf::data_type
Indicator for the logical data type of an element in a column.
Definition: types.hpp:235
cudf::detail::fixed_width_scalar_device_view_base::_data
void * _data
Pointer to device memory containing the value.
Definition: scalar_device_view.cuh:122
cudf::duration_scalar
Definition: scalar.hpp:566
cudf::numeric_scalar_device_view
A type of scalar_device_view that stores a pointer to a numerical value.
Definition: scalar_device_view.cuh:200
cudf::fixed_point_scalar
An owning class to represent a fixed_point number in device memory.
Definition: scalar.hpp:273
cudf::string_scalar_device_view::value
__device__ ValueType value() const noexcept
Returns string_view of the value of this scalar.
Definition: scalar_device_view.cuh:242
cudf::detail::fixed_width_scalar::data
T * data()
Returns a raw pointer to the value in device memory.
Definition: scalar.hpp:169
cudf::detail::fixed_width_scalar_device_view::value
__device__ T & value() noexcept
Returns reference to stored value.
Definition: scalar_device_view.cuh:152
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:58
cudf::detail::fixed_width_scalar_device_view_base::data
__device__ T const * data() const noexcept
Returns a const raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:116
cudf::detail::scalar_device_view_base::type
__host__ __device__ data_type type() const noexcept
Returns the value type.
Definition: scalar_device_view.cuh:40
cudf::string_scalar::size
size_type size() const
Returns the size of the string in bytes.
Definition: scalar.hpp:471
cudf::string_scalar_device_view::size
__device__ size_type size() const noexcept
Returns the size of the string in bytes.
Definition: scalar_device_view.cuh:252
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:70
cudf::timestamp_scalar
Definition: scalar.hpp:534
cudf::detail::fixed_width_scalar_device_view::data
__device__ T * data() noexcept
Returns a raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:167
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:212
cudf::detail::scalar_device_view_base::_is_valid
bool * _is_valid
Definition: scalar_device_view.cuh:59
cudf::string_scalar
An owning class to represent a string in device memory.
Definition: scalar.hpp:394
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:188
cudf::scalar::type
data_type type() const noexcept
Returns the scalar's logical value type.
Definition: scalar.hpp:62
cudf::detail::fixed_width_scalar_device_view_base::data
__device__ T * data() noexcept
Returns a raw pointer to the value in device memory.
Definition: scalar_device_view.cuh:106
cudf::detail::scalar_device_view_base::is_valid
__device__ bool is_valid() const noexcept
Returns whether the scalar holds a valid value (i.e., not null).
Definition: scalar_device_view.cuh:48