forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScopedProfiling.hip.cc
90 lines (81 loc) · 2.58 KB
/
ScopedProfiling.hip.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//----------------------------------*-C++-*----------------------------------//
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file corecel/sys/ScopedProfiling.hip.cc
//! \brief The roctx implementation of \c ScopedProfiling
//---------------------------------------------------------------------------//
#include "ScopedProfiling.hh"
#include <string>
#include "celeritas_sys_config.h"
#include "corecel/io/Logger.hh"
#include "Environment.hh"
#if CELERITAS_HAVE_ROCTX
# include <roctracer/roctx.h>
#endif
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Whether profiling is enabled.
*
* This is true only if the \c CELER_ENABLE_PROFILING environment variable is
* set to a non-empty value.
*/
bool ScopedProfiling::use_profiling()
{
static bool const result = [] {
if (!celeritas::getenv("CELER_ENABLE_PROFILING").empty())
{
if (!CELERITAS_HAVE_ROCTX)
{
CELER_LOG(warning) << "Disabling profiling support "
"since ROC-TX is unavailable";
return false;
}
CELER_LOG(info) << "Enabling profiling support since the "
"'CELER_ENABLE_PROFILING' "
"environment variable is present and non-empty";
return true;
}
return false;
}();
return result;
}
//---------------------------------------------------------------------------//
/*!
* Activate profiling.
*/
void ScopedProfiling::activate(Input const& input) noexcept
{
int result = 0;
#if CELERITAS_HAVE_ROCTX
std::string temp_name{input.name};
result = roctxRangePush(temp_name.c_str());
#endif
if (result < 0)
{
activated_ = false;
CELER_LOG(warning) << "Failed to activate profiling range '"
<< input.name << "'";
}
}
//---------------------------------------------------------------------------//
/*!
* End the profiling range.
*/
void ScopedProfiling::deactivate() noexcept
{
int result = 0;
#if CELERITAS_HAVE_ROCTX
result = roctxRangePop();
#endif
if (result < 0)
{
activated_ = false;
CELER_LOG(warning) << "Failed to deactivate profiling range";
}
}
//---------------------------------------------------------------------------//
} // namespace celeritas