Skip to content

Commit 7267f76

Browse files
committed
Fix performance
Signed-off-by: cyy <[email protected]>
1 parent 348a3fb commit 7267f76

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

libkineto/include/libkineto.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ class LibkinetoApi {
9494
}
9595

9696
void initProfilerIfRegistered() {
97-
static std::once_flag once;
9897
if (activityProfiler_) {
99-
std::call_once(once, [this] {
98+
static bool once_flag = [this] {
10099
if (!activityProfiler_->isInitialized()) {
101100
activityProfiler_->init();
102101
initChildActivityProfilers();
103102
}
104-
});
103+
return true;
104+
}();
105105
}
106106
}
107107

libkineto/src/DeviceUtil.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,36 @@
88

99
#include "DeviceUtil.h"
1010

11-
#include <mutex>
12-
1311
namespace KINETO_NAMESPACE {
1412

15-
bool amdGpuAvailable = false;
16-
bool cudaGpuAvailable = false;
17-
1813
bool isAMDGpuAvailable() {
1914
#ifdef HAS_ROCTRACER
20-
static std::once_flag once;
21-
std::call_once(once, [] {
15+
static bool amdGpuAvailable = [] {
2216
// determine AMD GPU availability on the system
2317
hipError_t error;
2418
int deviceCount;
2519
error = hipGetDeviceCount(&deviceCount);
26-
amdGpuAvailable = (error == hipSuccess && deviceCount > 0);
27-
});
28-
#endif
20+
return (error == hipSuccess && deviceCount > 0);
21+
}();
2922
return amdGpuAvailable;
23+
#else
24+
return false;
25+
#endif
3026
}
3127

3228
bool isCUDAGpuAvailable() {
3329
#ifdef HAS_CUPTI
34-
static std::once_flag once;
35-
std::call_once(once, [] {
30+
static bool cudaGpuAvailable = [] {
3631
// determine CUDA GPU availability on the system
3732
cudaError_t error;
3833
int deviceCount;
3934
error = cudaGetDeviceCount(&deviceCount);
40-
cudaGpuAvailable = (error == cudaSuccess && deviceCount > 0);
41-
});
42-
#endif
35+
return (error == cudaSuccess && deviceCount > 0);
36+
}();
4337
return cudaGpuAvailable;
38+
#else
39+
return false;
40+
#endif
4441
}
4542

4643
bool isGpuAvailable() {

libkineto/test/EventProfilerTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ class EventProfilerTest : public ::testing::Test {
316316
loggers_,
317317
onDemandLoggers_);
318318

319-
for (int i = 0; i < kEventGroupCount; i++) {
320-
eventGroups_[i] = &eventGroups_[i];
319+
for (auto& eventGroup : eventGroups_) {
320+
eventGroup = &eventGroup;
321321
}
322322
for (int i = 0; i < kGroupSetCount; i++) {
323323
// Default size to 1 but can be changed by test

0 commit comments

Comments
 (0)