Skip to content

Commit 4ef071d

Browse files
[UR] added filename and line number to logs (#17684)
Added an option to print line number and filename in log file. When `fileline:1` is specified in an environment variable describing log, e.g: ``` UR_LOG_LEVEL_ZERO="level:debug;flush:warning;fileline:1;output:file,juju-l0.log" ``` then every log entry will have source file and line added, like below: ``` ZE ---> zeInit(L0InitFlags) </home/user/llvm/unified-runtime/source/adapters/level_zero/common.cpp:141> ``` The significant changes are contained in the following files: - [ur_logger.hpp](https://github.com/intel/llvm/pull/17684/files#diff-2cb7f14c8cfa4e2d535a2d61e44f131cd55adb286fb14f229c0a628ab58fd8bc) - [ur_logger_details.hpp](https://github.com/intel/llvm/pull/17684/files#diff-a9f5f027ecf3e6c32c4c616a911bfe9d1924d07534e3a413794b4810a81d587e) - [ur_sinks.hpp](https://github.com/intel/llvm/pull/17684/files#diff-cb8b65e2254bc8e470f55997651ff1e11e94d0fcfd627db9a2a6b44f8bc2ef30) - [CMakeList.txt](https://github.com/intel/llvm/pull/17684/files#diff-3fbef7232733940192079cea1f55c07bce36e5e1c42b341d3583fbbf392ceef7) In the remaining files, the calls to the logger functions are replaced by macros (basically automatic change) --------- Co-authored-by: Łukasz Ślusarczyk <lukasz.slusarczyk@intel.com>
1 parent e1788ad commit 4ef071d

File tree

88 files changed

+2272
-2076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2272
-2076
lines changed

unified-runtime/scripts/templates/trcddi.cpp.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace ur_tracing_layer
4848
uint64_t instance = getContext()->notify_begin(${th.make_func_etor(n, tags, obj)}, "${th.make_func_name(n, tags, obj)}", &params);
4949

5050
auto &logger = getContext()->logger;
51-
logger.info(" ---> ${th.make_func_name(n, tags, obj)}\n");
51+
UR_LOG_L(logger, INFO, " ---> ${th.make_func_name(n, tags, obj)}\n");
5252

5353
${x}_result_t result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
5454

@@ -57,7 +57,7 @@ namespace ur_tracing_layer
5757
if (logger.getLevel() <= UR_LOGGER_LEVEL_INFO) {
5858
std::ostringstream args_str;
5959
ur::extras::printFunctionParams(args_str, ${th.make_func_etor(n, tags, obj)}, &params);
60-
logger.info(" <--- ${th.make_func_name(n, tags, obj)}({}) -> {};\n", args_str.str(), result);
60+
UR_LOG_L(logger, INFO, " <--- ${th.make_func_name(n, tags, obj)}({}) -> {};\n", args_str.str(), result);
6161
}
6262

6363
return result;

unified-runtime/scripts/templates/valddi.cpp.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace ur_validation_layer
9393
%>
9494
%if tp_input_handle_funcs and not is_related_create_get_retain_release_func:
9595
if (getContext()->enableLifetimeValidation && !getContext()->refCountContext->isReferenceValid(${tp['name']})) {
96-
getContext()->refCountContext->logInvalidReference(${tp['name']});
96+
URLOG_CTX_INVALID_REFERENCE(${tp['name']});
9797
}
9898
%endif
9999
%endfor
@@ -239,7 +239,7 @@ namespace ur_validation_layer
239239

240240
${x}_result_t context_t::tearDown() {
241241
if (enableLeakChecking) {
242-
getContext()->refCountContext->logInvalidReferences();
242+
URLOG_CTX_INVALID_REFERENCES();
243243
}
244244

245245
return ${X}_RESULT_SUCCESS;

unified-runtime/source/adapters/cuda/common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void checkErrorUR(CUresult Result, const char *Function, int Line,
7171
<< "\n\tDescription: " << ErrorString
7272
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
7373
<< ":" << Line << "\n";
74-
logger::error("{}", SS.str());
74+
UR_LOG(ERR, "{}", SS.str());
7575

7676
if (std::getenv("PI_CUDA_ABORT") != nullptr ||
7777
std::getenv("UR_CUDA_ABORT") != nullptr) {
@@ -95,7 +95,7 @@ void checkErrorUR(nvmlReturn_t Result, const char *Function, int Line,
9595
<< "\n\tDescription: " << ErrorString
9696
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
9797
<< ":" << Line << "\n";
98-
logger::error("{}", SS.str());
98+
UR_LOG(ERR, "{}", SS.str());
9999

100100
if (std::getenv("PI_CUDA_ABORT") != nullptr ||
101101
std::getenv("UR_CUDA_ABORT") != nullptr) {
@@ -115,7 +115,7 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line,
115115
SS << "\nUR ERROR:"
116116
<< "\n\tValue: " << Result << "\n\tFunction: " << Function
117117
<< "\n\tSource Location: " << File << ":" << Line << "\n";
118-
logger::error("{}", SS.str());
118+
UR_LOG(ERR, "{}", SS.str());
119119

120120
if (std::getenv("PI_CUDA_ABORT") != nullptr) {
121121
std::abort();

unified-runtime/source/adapters/cuda/device.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
286286
} else if (std::getenv("SYCL_UR_CUDA_ENABLE_IMAGE_SUPPORT") != nullptr) {
287287
Enabled = true;
288288
} else {
289-
logger::always(
289+
UR_LOG(
290+
QUIET,
290291
"Images are not fully supported by the CUDA BE, their support is "
291292
"disabled by default. Their partial support can be activated by "
292293
"setting SYCL_UR_CUDA_ENABLE_IMAGE_SUPPORT environment variable at "

unified-runtime/source/adapters/cuda/enqueue.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ ur_result_t setCuMemAdvise(CUdeviceptr DevPtr, size_t Size,
9797

9898
for (auto &UnmappedFlag : UnmappedMemAdviceFlags) {
9999
if (URAdviceFlags & UnmappedFlag) {
100-
logger::warning("Memory advice ignored because the CUDA backend does not "
101-
"support some of the specified flags.");
100+
UR_LOG(WARN, "Memory advice ignored because the CUDA backend does not "
101+
"support some of the specified flags.");
102102
return UR_RESULT_SUCCESS;
103103
}
104104
}
@@ -1608,16 +1608,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
16081608
// for managed memory. Therefore, ignore prefetch hint if concurrent managed
16091609
// memory access is not available.
16101610
if (!getAttribute(Device, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
1611-
logger::warning("Prefetch hint ignored as device does not support "
1612-
"concurrent managed access.");
1611+
UR_LOG(WARN, "Prefetch hint ignored as device does not support "
1612+
"concurrent managed access.");
16131613
return UR_RESULT_SUCCESS;
16141614
}
16151615

16161616
unsigned int IsManaged;
16171617
UR_CHECK_ERROR(cuPointerGetAttribute(
16181618
&IsManaged, CU_POINTER_ATTRIBUTE_IS_MANAGED, (CUdeviceptr)pMem));
16191619
if (!IsManaged) {
1620-
logger::warning("Prefetch hint ignored as prefetch only works with USM.");
1620+
UR_LOG(WARN, "Prefetch hint ignored as prefetch only works with USM.");
16211621
return UR_RESULT_SUCCESS;
16221622
}
16231623

@@ -1668,8 +1668,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
16681668
(advice & UR_USM_ADVICE_FLAG_DEFAULT)) {
16691669
ur_device_handle_t Device = hQueue->getDevice();
16701670
if (!getAttribute(Device, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
1671-
logger::warning("Mem advise ignored as device does not support "
1672-
"concurrent managed access.");
1671+
UR_LOG(WARN, "Mem advise ignored as device does not support "
1672+
"concurrent managed access.");
16731673
return UR_RESULT_SUCCESS;
16741674
}
16751675

unified-runtime/source/adapters/cuda/image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
812812

813813
// we don't support copying between different image types.
814814
if (pSrcImageDesc->type != pDstImageDesc->type) {
815-
logger::error(
816-
"Unsupported copy operation between different type of images");
815+
UR_LOG(ERR,
816+
"Unsupported copy operation between different type of images");
817817
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
818818
}
819819

unified-runtime/source/adapters/cuda/usm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
361361
// Otherwise, do nothing.
362362
// Set maximum size is effectively ignored.
363363
if (Limits->maxPoolableSize > 0)
364-
logger::warning("The memory pool maximum size feature requires CUDA "
365-
"12.2 or later.\n");
364+
UR_LOG(WARN, "The memory pool maximum size feature requires CUDA "
365+
"12.2 or later.\n");
366366
#endif
367367
maxSize = Limits->maxPoolableSize;
368368
size_t chunkSize = 33554432; // 32MB

unified-runtime/source/adapters/hip/common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void checkErrorUR(amd_comgr_status_t Result, const char *Function, int Line,
8686
<< "\n\tDescription: " << ErrorString
8787
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
8888
<< ":" << Line << "\n";
89-
logger::error("{}", SS.str());
89+
UR_LOG(ERR, "{}", SS.str());
9090

9191
if (std::getenv("PI_HIP_ABORT") != nullptr ||
9292
std::getenv("UR_HIP_ABORT") != nullptr) {
@@ -113,7 +113,7 @@ void checkErrorUR(hipError_t Result, const char *Function, int Line,
113113
<< "\n\tDescription: " << ErrorString
114114
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
115115
<< ":" << Line << "\n";
116-
logger::error("{}", SS.str());
116+
UR_LOG(ERR, "{}", SS.str());
117117

118118
if (std::getenv("PI_HIP_ABORT") != nullptr ||
119119
std::getenv("UR_HIP_ABORT") != nullptr) {
@@ -133,7 +133,7 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line,
133133
SS << "\nUR HIP ERROR:"
134134
<< "\n\tValue: " << Result << "\n\tFunction: " << Function
135135
<< "\n\tSource Location: " << File << ":" << Line << "\n";
136-
logger::error("{}", SS.str());
136+
UR_LOG(ERR, "{}", SS.str());
137137

138138
if (std::getenv("PI_HIP_ABORT") != nullptr ||
139139
std::getenv("UR_HIP_ABORT") != nullptr) {

unified-runtime/source/adapters/hip/enqueue.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13741374
// mem_advise.
13751375
if (!Device->getManagedMemSupport()) {
13761376
releaseEvent();
1377-
logger::warning("mem_advise ignored as device does not support "
1378-
"managed memory access.");
1377+
UR_LOG(WARN, "mem_advise ignored as device does not support "
1378+
"managed memory access.");
13791379
return UR_RESULT_SUCCESS;
13801380
}
13811381

@@ -1389,7 +1389,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13891389
// async prefetch requires USM pointer (or hip SVM) to work.
13901390
if (!attribs.isManaged) {
13911391
releaseEvent();
1392-
logger::warning("Prefetch hint ignored as prefetch only works with USM.");
1392+
UR_LOG(WARN, "Prefetch hint ignored as prefetch only works with USM.");
13931393
return UR_RESULT_SUCCESS;
13941394
}
13951395

@@ -1444,8 +1444,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
14441444
// mem_advise.
14451445
if (!Device->getManagedMemSupport()) {
14461446
releaseEvent();
1447-
logger::warning("mem_advise ignored as device does not support "
1448-
"managed memory access.");
1447+
UR_LOG(WARN, "mem_advise ignored as device does not support "
1448+
"managed memory access.");
14491449
return UR_RESULT_SUCCESS;
14501450
}
14511451

@@ -1461,8 +1461,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
14611461
UR_USM_ADVICE_FLAG_DEFAULT)) {
14621462
if (!Device->getConcurrentManagedAccess()) {
14631463
releaseEvent();
1464-
logger::warning("mem_advise ignored as device does not support "
1465-
"concurrent memory access.");
1464+
UR_LOG(WARN, "mem_advise ignored as device does not support "
1465+
"concurrent memory access.");
14661466
return UR_RESULT_SUCCESS;
14671467
}
14681468

@@ -1481,8 +1481,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
14811481
if (auto ptrAttribs = getPointerAttributes(pMem);
14821482
!ptrAttribs || !ptrAttribs->isManaged) {
14831483
releaseEvent();
1484-
logger::warning("mem_advise is ignored as the pointer argument is not "
1485-
"a shared USM pointer.");
1484+
UR_LOG(WARN, "mem_advise is ignored as the pointer argument is not "
1485+
"a shared USM pointer.");
14861486
return UR_RESULT_SUCCESS;
14871487
}
14881488

@@ -1510,8 +1510,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
15101510
// the runtime.
15111511
if (Result == UR_RESULT_ERROR_INVALID_ENUMERATION) {
15121512
releaseEvent();
1513-
logger::warning("mem_advise is ignored as the advice argument is not "
1514-
"supported by this device.");
1513+
UR_LOG(WARN, "mem_advise is ignored as the advice argument is not "
1514+
"supported by this device.");
15151515
return UR_RESULT_SUCCESS;
15161516
}
15171517
UR_CHECK_ERROR(Result);

unified-runtime/source/adapters/hip/image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
832832

833833
// we don't support copying between different image types.
834834
if (pSrcImageDesc->type != pDstImageDesc->type) {
835-
logger::error(
836-
"Unsupported copy operation between different type of images");
835+
UR_LOG(ERR,
836+
"Unsupported copy operation between different type of images");
837837
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
838838
}
839839

0 commit comments

Comments
 (0)