include
scip2
walltime.h
Go to the documentation of this file.
1
/*
2
* Copyright 2018 The urg_stamped Authors
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
#ifndef SCIP2_WALLTIME_H
18
#define SCIP2_WALLTIME_H
19
20
#include <cstdint>
21
22
#include <
scip2/logger.h
>
23
24
namespace
scip2
25
{
26
template
<
int
DEVICE_TIMESTAMP_BITS>
27
class
Walltime
28
{
29
protected
:
30
bool
initialized_
;
31
uint32_t
time_device_prev_
;
32
uint64_t
walltime_device_base_
;
33
34
constexpr
static
uint32_t
middle_bits_
= (1 << DEVICE_TIMESTAMP_BITS) / 2;
35
36
public
:
37
uint64_t
update
(
const
uint32_t& time_device)
38
{
39
if
(!
initialized_
)
40
{
41
time_device_prev_
= time_device;
42
initialized_
=
true
;
43
}
44
45
if
(
detectDeviceTimeUnderflow
(time_device))
46
{
47
if
(
walltime_device_base_
>= (1 << DEVICE_TIMESTAMP_BITS))
48
{
49
time_device_prev_
= (1 << DEVICE_TIMESTAMP_BITS) - time_device;
50
return
walltime_device_base_
-
time_device_prev_
;
51
}
52
logger::warn
() <<
"Device time jumped. prev: "
<<
time_device_prev_
53
<<
", current: "
<< time_device << std::endl;
54
}
55
56
if
(time_device <
middle_bits_
&&
57
middle_bits_
<
time_device_prev_
)
58
{
59
walltime_device_base_
+= 1 << DEVICE_TIMESTAMP_BITS;
60
}
61
62
time_device_prev_
= time_device;
63
64
return
walltime_device_base_
+ time_device;
65
}
66
67
bool
detectDeviceTimeUnderflow
(
const
uint32_t& time_device)
const
68
{
69
return
(
time_device_prev_
<
middle_bits_
&&
70
middle_bits_
< time_device &&
71
time_device -
time_device_prev_
>
middle_bits_
);
72
}
73
74
Walltime
()
75
:
initialized_
(false)
76
,
time_device_prev_
(0)
77
,
walltime_device_base_
(0)
78
{
79
}
80
};
81
}
// namespace scip2
82
83
#endif // SCIP2_WALLTIME_H
scip2::Walltime::middle_bits_
constexpr static uint32_t middle_bits_
Definition:
walltime.h:34
logger.h
scip2::Walltime
Definition:
walltime.h:27
scip2::Walltime::update
uint64_t update(const uint32_t &time_device)
Definition:
walltime.h:37
scip2
Definition:
connection.h:30
scip2::Walltime::walltime_device_base_
uint64_t walltime_device_base_
Definition:
walltime.h:32
scip2::Walltime::initialized_
bool initialized_
Definition:
walltime.h:30
scip2::Walltime::time_device_prev_
uint32_t time_device_prev_
Definition:
walltime.h:31
scip2::Walltime::Walltime
Walltime()
Definition:
walltime.h:74
scip2::Walltime::detectDeviceTimeUnderflow
bool detectDeviceTimeUnderflow(const uint32_t &time_device) const
Definition:
walltime.h:67
scip2::logger::warn
std::ostream & warn()
Definition:
logger.cpp:101
urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Wed Dec 18 2024 03:10:57