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 <[email protected]>
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

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ur_result_t initPlatforms(PlatformVec &platforms,
163163
ZE2UR_CALL(zeDriverGet, (&ZeDriverGetCount, ZeDriverGetHandles.data()));
164164
}
165165
if (ZeDriverGetCount == 0 && GlobalAdapter->ZeInitDriversCount == 0) {
166-
logger::error("\nNo Valid L0 Drivers found.\n");
166+
UR_LOG(ERR, "\nNo Valid L0 Drivers found.\n");
167167
return UR_RESULT_SUCCESS;
168168
}
169169

@@ -188,9 +188,10 @@ ur_result_t initPlatforms(PlatformVec &platforms,
188188
// newer drivers.
189189
if (ZeDriverGetProperties.driverVersion !=
190190
ZeInitDriverProperties.driverVersion) {
191-
logger::debug("\nzeDriverHandle {} added to the zeInitDrivers list "
192-
"of possible handles.\n",
193-
ZeDriverGetHandles[Y]);
191+
UR_LOG(DEBUG,
192+
"\nzeDriverHandle {} added to the zeInitDrivers list "
193+
"of possible handles.\n",
194+
ZeDriverGetHandles[Y]);
194195
ZeDrivers.push_back(ZeDriverGetHandles[Y]);
195196
}
196197
}
@@ -201,7 +202,7 @@ ur_result_t initPlatforms(PlatformVec &platforms,
201202
ZeDrivers.assign(ZeDriverGetHandles.begin(), ZeDriverGetHandles.end());
202203
}
203204
ZeDriverCount = ZeDrivers.size();
204-
logger::debug("\n{} L0 Drivers found.\n", ZeDriverCount);
205+
UR_LOG(DEBUG, "\n{} L0 Drivers found.\n", ZeDriverCount);
205206
for (uint32_t I = 0; I < ZeDriverCount; ++I) {
206207
// Keep track of the first platform init for this Driver
207208
bool DriverPlatformInit = false;
@@ -358,7 +359,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
358359
}
359360

360361
if (getenv("SYCL_ENABLE_PCI") != nullptr) {
361-
logger::warning(
362+
UR_LOG(
363+
WARN,
362364
"WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n");
363365
}
364366

@@ -380,13 +382,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
380382
if (UrL0InitAllDrivers) {
381383
L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
382384
}
383-
logger::debug("\nzeInit with flags value of {}\n",
384-
static_cast<int>(L0InitFlags));
385+
UR_LOG(DEBUG, "\nzeInit with flags value of {}\n",
386+
static_cast<int>(L0InitFlags));
385387
GlobalAdapter->ZeInitResult = ZE_CALL_NOCHECK(zeInit, (L0InitFlags));
386388
if (GlobalAdapter->ZeInitResult != ZE_RESULT_SUCCESS) {
387389
const char *ErrorString = "Unknown";
388390
zeParseError(GlobalAdapter->ZeInitResult, ErrorString);
389-
logger::error("\nzeInit failed with {}\n", ErrorString);
391+
UR_LOG(ERR, "\nzeInit failed with {}\n", ErrorString);
390392
}
391393

392394
bool useInitDrivers = false;
@@ -402,9 +404,9 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
402404
if (strncmp(versions[i].component_name, "loader",
403405
strlen("loader")) == 0) {
404406
loader_version = versions[i].component_lib_version;
405-
logger::debug("\nLevel Zero Loader Version: {}.{}.{}\n",
406-
loader_version.major, loader_version.minor,
407-
loader_version.patch);
407+
UR_LOG(DEBUG, "\nLevel Zero Loader Version: {}.{}.{}\n",
408+
loader_version.major, loader_version.minor,
409+
loader_version.patch);
408410
break;
409411
}
410412
}
@@ -437,8 +439,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
437439
GlobalAdapter->processHandle, "zeInitDrivers");
438440
#endif
439441
if (GlobalAdapter->initDriversFunctionPtr) {
440-
logger::debug("\nzeInitDrivers with flags value of {}\n",
441-
static_cast<int>(GlobalAdapter->InitDriversDesc.flags));
442+
UR_LOG(DEBUG, "\nzeInitDrivers with flags value of {}\n",
443+
static_cast<int>(GlobalAdapter->InitDriversDesc.flags));
442444
GlobalAdapter->ZeInitDriversResult =
443445
ZE_CALL_NOCHECK(GlobalAdapter->initDriversFunctionPtr,
444446
(&GlobalAdapter->ZeInitDriversCount, nullptr,
@@ -448,7 +450,7 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
448450
} else {
449451
const char *ErrorString = "Unknown";
450452
zeParseError(GlobalAdapter->ZeInitDriversResult, ErrorString);
451-
logger::error("\nzeInitDrivers failed with {}\n", ErrorString);
453+
UR_LOG(ERR, "\nzeInitDrivers failed with {}\n", ErrorString);
452454
}
453455
}
454456
}
@@ -466,12 +468,12 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
466468

467469
// Absorb the ZE_RESULT_ERROR_UNINITIALIZED and just return 0 Platforms.
468470
if (*GlobalAdapter->ZeResult == ZE_RESULT_ERROR_UNINITIALIZED) {
469-
logger::error("Level Zero Uninitialized\n");
471+
UR_LOG(ERR, "Level Zero Uninitialized\n");
470472
result = std::move(platforms);
471473
return;
472474
}
473475
if (*GlobalAdapter->ZeResult != ZE_RESULT_SUCCESS) {
474-
logger::error("Level Zero initialization failure\n");
476+
UR_LOG(ERR, "Level Zero initialization failure\n");
475477
result = ze2urResult(*GlobalAdapter->ZeResult);
476478

477479
return;
@@ -518,8 +520,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
518520
GlobalAdapter->getSysManDriversFunctionPtr &&
519521
GlobalAdapter->sysManInitFunctionPtr) {
520522
ze_init_flags_t L0ZesInitFlags = 0;
521-
logger::debug("\nzesInit with flags value of {}\n",
522-
static_cast<int>(L0ZesInitFlags));
523+
UR_LOG(DEBUG, "\nzesInit with flags value of {}\n",
524+
static_cast<int>(L0ZesInitFlags));
523525
GlobalAdapter->ZesResult = ZE_CALL_NOCHECK(
524526
GlobalAdapter->sysManInitFunctionPtr, (L0ZesInitFlags));
525527
} else {

unified-runtime/source/adapters/level_zero/async_alloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static ur_result_t enqueueUSMAllocHelper(
9292
CommandType = UR_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP;
9393
break;
9494
default:
95-
logger::error("enqueueUSMAllocHelper: unsupported USM type");
95+
UR_LOG(ERR, "enqueueUSMAllocHelper: unsupported USM type");
9696
throw UR_RESULT_ERROR_UNKNOWN;
9797
}
9898
UR_CALL(createEventAndAssociateQueue(Queue, Event, CommandType, CommandList,

0 commit comments

Comments
 (0)