Skip to content

Commit a5efd29

Browse files
committed
Only check OFFLOAD_TRACE once
1 parent d71d04f commit a5efd29

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

offload/new-api/include/offload_entry_points.inc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ offload_impl_result_t offloadInit_val() {
1414
return offloadInit_impl();
1515
}
1616
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit() {
17-
if (std::getenv("OFFLOAD_TRACE")) {
17+
if (offloadConfig().TracingEnabled) {
1818
std::cout << "---> offloadInit";
1919
}
2020

2121
offload_result_t Result = offloadInit_val();
2222

23-
if (std::getenv("OFFLOAD_TRACE")) {
23+
if (offloadConfig().TracingEnabled) {
2424
std::cout << "()";
2525
std::cout << "-> " << Result << "\n";
2626
if (Result && Result->Details) {
@@ -45,13 +45,13 @@ offload_impl_result_t offloadShutDown_val() {
4545
return offloadShutDown_impl();
4646
}
4747
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown() {
48-
if (std::getenv("OFFLOAD_TRACE")) {
48+
if (offloadConfig().TracingEnabled) {
4949
std::cout << "---> offloadShutDown";
5050
}
5151

5252
offload_result_t Result = offloadShutDown_val();
5353

54-
if (std::getenv("OFFLOAD_TRACE")) {
54+
if (offloadConfig().TracingEnabled) {
5555
std::cout << "()";
5656
std::cout << "-> " << Result << "\n";
5757
if (Result && Result->Details) {
@@ -87,13 +87,13 @@ offloadPlatformGet_val(uint32_t NumEntries,
8787
}
8888
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
8989
offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *Platforms) {
90-
if (std::getenv("OFFLOAD_TRACE")) {
90+
if (offloadConfig().TracingEnabled) {
9191
std::cout << "---> offloadPlatformGet";
9292
}
9393

9494
offload_result_t Result = offloadPlatformGet_val(NumEntries, Platforms);
9595

96-
if (std::getenv("OFFLOAD_TRACE")) {
96+
if (offloadConfig().TracingEnabled) {
9797
offload_platform_get_params_t Params = {&NumEntries, &Platforms};
9898
std::cout << "(" << &Params << ")";
9999
std::cout << "-> " << Result << "\n";
@@ -126,13 +126,13 @@ offload_impl_result_t offloadPlatformGetCount_val(uint32_t *NumPlatforms) {
126126
}
127127
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
128128
offloadPlatformGetCount(uint32_t *NumPlatforms) {
129-
if (std::getenv("OFFLOAD_TRACE")) {
129+
if (offloadConfig().TracingEnabled) {
130130
std::cout << "---> offloadPlatformGetCount";
131131
}
132132

133133
offload_result_t Result = offloadPlatformGetCount_val(NumPlatforms);
134134

135-
if (std::getenv("OFFLOAD_TRACE")) {
135+
if (offloadConfig().TracingEnabled) {
136136
offload_platform_get_count_params_t Params = {&NumPlatforms};
137137
std::cout << "(" << &Params << ")";
138138
std::cout << "-> " << Result << "\n";
@@ -176,14 +176,14 @@ offloadPlatformGetInfo_val(offload_platform_handle_t Platform,
176176
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
177177
offload_platform_handle_t Platform, offload_platform_info_t PropName,
178178
size_t PropSize, void *PropValue) {
179-
if (std::getenv("OFFLOAD_TRACE")) {
179+
if (offloadConfig().TracingEnabled) {
180180
std::cout << "---> offloadPlatformGetInfo";
181181
}
182182

183183
offload_result_t Result =
184184
offloadPlatformGetInfo_val(Platform, PropName, PropSize, PropValue);
185185

186-
if (std::getenv("OFFLOAD_TRACE")) {
186+
if (offloadConfig().TracingEnabled) {
187187
offload_platform_get_info_params_t Params = {&Platform, &PropName,
188188
&PropSize, &PropValue};
189189
std::cout << "(" << &Params << ")";
@@ -225,14 +225,14 @@ offloadPlatformGetInfoSize_val(offload_platform_handle_t Platform,
225225
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
226226
offload_platform_handle_t Platform, offload_platform_info_t PropName,
227227
size_t *PropSizeRet) {
228-
if (std::getenv("OFFLOAD_TRACE")) {
228+
if (offloadConfig().TracingEnabled) {
229229
std::cout << "---> offloadPlatformGetInfoSize";
230230
}
231231

232232
offload_result_t Result =
233233
offloadPlatformGetInfoSize_val(Platform, PropName, PropSizeRet);
234234

235-
if (std::getenv("OFFLOAD_TRACE")) {
235+
if (offloadConfig().TracingEnabled) {
236236
offload_platform_get_info_size_params_t Params = {&Platform, &PropName,
237237
&PropSizeRet};
238238
std::cout << "(" << &Params << ")";
@@ -272,13 +272,13 @@ offloadDeviceGetCount_val(offload_platform_handle_t Platform,
272272
}
273273
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
274274
offload_platform_handle_t Platform, uint32_t *NumDevices) {
275-
if (std::getenv("OFFLOAD_TRACE")) {
275+
if (offloadConfig().TracingEnabled) {
276276
std::cout << "---> offloadDeviceGetCount";
277277
}
278278

279279
offload_result_t Result = offloadDeviceGetCount_val(Platform, NumDevices);
280280

281-
if (std::getenv("OFFLOAD_TRACE")) {
281+
if (offloadConfig().TracingEnabled) {
282282
offload_device_get_count_params_t Params = {&Platform, &NumDevices};
283283
std::cout << "(" << &Params << ")";
284284
std::cout << "-> " << Result << "\n";
@@ -322,13 +322,13 @@ offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t Platform,
322322
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
323323
offloadDeviceGet(offload_platform_handle_t Platform, uint32_t NumEntries,
324324
offload_device_handle_t *Devices) {
325-
if (std::getenv("OFFLOAD_TRACE")) {
325+
if (offloadConfig().TracingEnabled) {
326326
std::cout << "---> offloadDeviceGet";
327327
}
328328

329329
offload_result_t Result = offloadDeviceGet_val(Platform, NumEntries, Devices);
330330

331-
if (std::getenv("OFFLOAD_TRACE")) {
331+
if (offloadConfig().TracingEnabled) {
332332
offload_device_get_params_t Params = {&Platform, &NumEntries, &Devices};
333333
std::cout << "(" << &Params << ")";
334334
std::cout << "-> " << Result << "\n";
@@ -372,14 +372,14 @@ offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t Device,
372372
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
373373
offload_device_handle_t Device, offload_device_info_t PropName,
374374
size_t PropSize, void *PropValue) {
375-
if (std::getenv("OFFLOAD_TRACE")) {
375+
if (offloadConfig().TracingEnabled) {
376376
std::cout << "---> offloadDeviceGetInfo";
377377
}
378378

379379
offload_result_t Result =
380380
offloadDeviceGetInfo_val(Device, PropName, PropSize, PropValue);
381381

382-
if (std::getenv("OFFLOAD_TRACE")) {
382+
if (offloadConfig().TracingEnabled) {
383383
offload_device_get_info_params_t Params = {&Device, &PropName, &PropSize,
384384
&PropValue};
385385
std::cout << "(" << &Params << ")";
@@ -421,14 +421,14 @@ offloadDeviceGetInfoSize_val(offload_device_handle_t Device,
421421
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
422422
offloadDeviceGetInfoSize(offload_device_handle_t Device,
423423
offload_device_info_t PropName, size_t *PropSizeRet) {
424-
if (std::getenv("OFFLOAD_TRACE")) {
424+
if (offloadConfig().TracingEnabled) {
425425
std::cout << "---> offloadDeviceGetInfoSize";
426426
}
427427

428428
offload_result_t Result =
429429
offloadDeviceGetInfoSize_val(Device, PropName, PropSizeRet);
430430

431-
if (std::getenv("OFFLOAD_TRACE")) {
431+
if (offloadConfig().TracingEnabled) {
432432
offload_device_get_info_size_params_t Params = {&Device, &PropName,
433433
&PropSizeRet};
434434
std::cout << "(" << &Params << ")";

offload/new-api/include/offload_impl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/StringSet.h"
2222

23+
struct OffloadConfig {
24+
bool TracingEnabled = false;
25+
};
26+
27+
OffloadConfig &offloadConfig();
28+
2329
// Use the StringSet container to efficiently deduplicate repeated error
2430
// strings (e.g. if the same error is hit constantly in a long running program)
2531
llvm::StringSet<> &errorStrs();

offload/new-api/src/offload_impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ void initPlugins() {
6565
}
6666
}
6767
}
68+
69+
offloadConfig().TracingEnabled = std::getenv("OFFLOAD_TRACE");
6870
}
6971

7072
// TODO: We can properly reference count here and manage the resources in a more

offload/new-api/src/offload_lib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ offload_code_location_t *&currentCodeLocation() {
3131
return CodeLoc;
3232
}
3333

34+
OffloadConfig &offloadConfig() {
35+
static OffloadConfig Config{};
36+
return Config;
37+
}
38+
3439
// Pull in the declarations for the implementation funtions. The actual entry
3540
// points in this file wrap these.
3641
#include "offload_impl_func_decls.inc"

offload/tools/offload-tblgen/EntryPointGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
7171
OS << ") {\n";
7272

7373
// Emit pre-call prints
74-
OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
74+
OS << TAB_1 "if (offloadConfig().TracingEnabled) {\n";
7575
OS << formatv(TAB_2 "std::cout << \"---> {0}\";\n", F.getName());
7676
OS << TAB_1 "}\n\n";
7777

@@ -81,7 +81,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
8181
F.getName(), ParamNameList);
8282

8383
// Emit post-call prints
84-
OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
84+
OS << TAB_1 "if (offloadConfig().TracingEnabled) {\n";
8585
if (F.getParams().size() > 0) {
8686
OS << formatv(TAB_2 "{0} Params = {{ ", F.getParamStructName());
8787
for (const auto &Param : F.getParams()) {

0 commit comments

Comments
 (0)