Skip to content

Commit d1732b4

Browse files
committed
Address feedback
1 parent 2718afb commit d1732b4

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

sycl/source/detail/kernel_program_cache.hpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -179,47 +179,50 @@ class KernelProgramCache {
179179

180180
void setContextPtr(const ContextPtr &AContext) { MParentContext = AContext; }
181181

182-
/* Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is
183-
* set.*/
182+
// Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is
183+
// set.
184184
static inline void traceProgram(const std::string &Msg,
185185
const ProgramCacheKeyT &CacheKey) {
186186
static const bool traceEnabled =
187187
SYCLConfig<SYCL_CACHE_TRACE>::isTraceInMemCache();
188-
if (traceEnabled) {
189188

190-
int ImageId = CacheKey.first.second;
191-
std::stringstream DeviceList;
192-
for (const auto &Device : CacheKey.second)
193-
DeviceList << "0x" << std::setbase(16)
194-
<< reinterpret_cast<uintptr_t>(Device) << ",";
189+
if (!traceEnabled)
190+
return;
195191

196-
std::string Identifier = "[Key:{imageId = " + std::to_string(ImageId) +
197-
",urDevice = " + DeviceList.str() + "}]: ";
192+
int ImageId = CacheKey.first.second;
193+
std::stringstream DeviceList;
194+
for (const auto &Device : CacheKey.second)
195+
DeviceList << "0x" << std::setbase(16)
196+
<< reinterpret_cast<uintptr_t>(Device) << ",";
198197

199-
// Get TID of current thread.
200-
thread_local std::thread::id this_id = std::this_thread::get_id();
201-
std::cerr << "[In-Memory Cache][Thread Id:" << this_id
202-
<< "][Program Cache]" << Identifier << Msg << std::endl;
203-
}
198+
std::string Identifier = "[Key:{imageId = " + std::to_string(ImageId) +
199+
",urDevice = " + DeviceList.str() + "}]: ";
200+
201+
// Get TID of current thread.
202+
thread_local std::thread::id this_id = std::this_thread::get_id();
203+
std::cerr << "[In-Memory Cache][Thread Id:" << this_id << "][Program Cache]"
204+
<< Identifier << Msg << std::endl;
204205
}
205206

206-
/* Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is
207-
* set.*/
207+
// Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is
208+
// set.
208209
static inline void traceKernel(const std::string &Msg,
209210
const std::string &KernelName,
210211
bool IsKernelFastCache = false) {
211212
static const bool traceEnabled =
212213
SYCLConfig<SYCL_CACHE_TRACE>::isTraceInMemCache();
213-
if (traceEnabled) {
214-
std::string Identifier =
215-
"[IsFastCache: " + std::to_string(IsKernelFastCache) +
216-
"][Key:{Name = " + KernelName + "}]: ";
217-
218-
// Get TID of current thread.
219-
thread_local std::thread::id this_id = std::this_thread::get_id();
220-
std::cerr << "[In-Memory Cache][Thread Id:" << this_id
221-
<< "][Kernel Cache]" << Identifier << Msg << std::endl;
222-
}
214+
215+
if (!traceEnabled)
216+
return;
217+
218+
std::string Identifier =
219+
"[IsFastCache: " + std::to_string(IsKernelFastCache) +
220+
"][Key:{Name = " + KernelName + "}]: ";
221+
222+
// Get TID of current thread.
223+
thread_local std::thread::id this_id = std::this_thread::get_id();
224+
std::cerr << "[In-Memory Cache][Thread Id:" << this_id << "][Kernel Cache]"
225+
<< Identifier << Msg << std::endl;
223226
}
224227

225228
Locked<ProgramCache> acquireCachedPrograms() {

sycl/test-e2e/KernelAndProgram/trace_kernel_program_cache.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
// There should be no tracing output when SYCL_CACHE_IN_MEM is not set
66
// or SYCL_CACHE_TRACE is set to 0.
77

8-
// RUN: env SYCL_CACHE_IN_MEM=0 %{run} %t.out \
9-
// RUN: | FileCheck --allow-empty --check-prefix=CHECK-NO-TRACE %s
10-
// RUN: env SYCL_CACHE_TRACE=0 %{run} %t.out \
11-
// RUN: | FileCheck --allow-empty --check-prefix=CHECK-NO-TRACE %s
8+
// RUN: env SYCL_CACHE_IN_MEM=0 %{run} %t.out 2> %t.trace1
9+
// RUN: FileCheck --allow-empty --input-file=%t.trace1 --implicit-check-not "In-Memory Cache" %s
10+
// RUN: env SYCL_CACHE_TRACE=0 %{run} %t.out 2> %t.trace2
11+
// RUN: FileCheck --allow-empty --input-file=%t.trace2 --implicit-check-not "In-Memory Cache" %s
1212

13-
// CHECK-NO-TRACE-NOT: [In-Memory Cache]{{.*}}
14-
15-
// RUN: env SYCL_CACHE_TRACE=2 %{run} %t.out 2> %t.trace
16-
// RUN: FileCheck %s --input-file=%t.trace --check-prefix=CHECK-CACHE-TRACE
13+
// RUN: env SYCL_CACHE_TRACE=2 %{run} %t.out 2> %t.trace3
14+
// RUN: FileCheck %s --input-file=%t.trace3 --check-prefix=CHECK-CACHE-TRACE
1715

1816
#include <sycl/detail/core.hpp>
1917

0 commit comments

Comments
 (0)