timestamps.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, 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 
17 #pragma once
18 
19 #include <limits>
20 
21 #include <cuda/std/chrono>
22 
28 namespace cudf {
29 namespace detail {
30 // TODO: Use chrono::utc_clock when available in libcu++?
31 template <class Duration>
32 using time_point = cuda::std::chrono::sys_time<Duration>;
33 
34 template <class Duration>
35 struct timestamp : time_point<Duration> {
36  // Bring over base class constructors and make them visible here
37  using time_point<Duration>::time_point;
38 
39  // This is needed as __shared__ objects of this type can't be assigned in device code
40  // when the initializer list constructs subobjects with values, which is what std::time_point
41  // does.
42  constexpr timestamp() : time_point<Duration>(Duration()){};
43 
44  // The inherited copy constructor will hide the auto generated copy constructor;
45  // hence, explicitly define and delegate
46  constexpr timestamp(const time_point<Duration>& other) : time_point<Duration>(other) {}
47 };
48 } // namespace detail
49 
60 using timestamp_D =
82 
83 static_assert(sizeof(timestamp_D) == sizeof(typename timestamp_D::rep), "");
84 static_assert(sizeof(timestamp_s) == sizeof(typename timestamp_s::rep), "");
85 static_assert(sizeof(timestamp_ms) == sizeof(typename timestamp_ms::rep), "");
86 static_assert(sizeof(timestamp_us) == sizeof(typename timestamp_us::rep), "");
87 static_assert(sizeof(timestamp_ns) == sizeof(typename timestamp_ns::rep), "");
88  // end of group
90 } // namespace cudf
91 
92 namespace std {
98 #define TIMESTAMP_LIMITS(TypeName) \
99  template <> \
100  struct numeric_limits<TypeName> { \
101  static constexpr TypeName max() noexcept { return TypeName::max(); } \
102  static constexpr TypeName lowest() noexcept \
103  { \
104  return TypeName{TypeName::duration{std::numeric_limits<typename TypeName::rep>::lowest()}}; \
105  } \
106  static constexpr TypeName min() noexcept { return TypeName::min(); } \
107  }
108 
114 
115 #undef TIMESTAMP_LIMITS
116 
117 } // namespace std
cudf::detail::timestamp
Definition: timestamps.hpp:35
cudf
cuDF interfaces
Definition: aggregation.hpp:34
TIMESTAMP_LIMITS
#define TIMESTAMP_LIMITS(TypeName)
Specialization of std::numeric_limits for cudf::detail::timestamp.
Definition: timestamps.hpp:98