Skip to content

Commit e252335

Browse files
committed
update adapters emitting warnings to use logger instead of setErrorMessage and link up a logger callback from SYCL RT to simply print to stdout, this is setup during adapter
initialisation in sycl/source/detail.cpp also remove setErrorMessage from OpenCL and Native CPU adapters where there was no usage
1 parent 1d6b103 commit e252335

File tree

6 files changed

+31
-50
lines changed

6 files changed

+31
-50
lines changed

sycl/source/detail/ur.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ void *getAdapterOpaqueData([[maybe_unused]] void *OpaqueDataParam) {
7777

7878
ur_code_location_t codeLocationCallback(void *);
7979

80-
void receiveLoggerMessages([[maybe_unused]] ur_logger_level_t level,
81-
const char *msg, void *userData) {
82-
// Do something with a message sent from a UR adapter
80+
void urLoggerCallback([[maybe_unused]] ur_logger_level_t level, const char *msg,
81+
[[maybe_unused]] void *userData) {
82+
std::cout << msg << std::endl;
8383
}
8484

8585
namespace ur {
@@ -143,6 +143,11 @@ static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
143143
UrFuncInfo<UrApiKind::urAdapterGetInfo> adapterGetInfoInfo;
144144
auto adapterGetInfo =
145145
adapterGetInfoInfo.getFuncPtrFromModule(ur::getURLoaderLibrary());
146+
UrFuncInfo<UrApiKind::urAdapterSetLoggerCallback>
147+
adapterSetLoggerCallbackInfo;
148+
auto adapterSetLoggerCallback =
149+
adapterSetLoggerCallbackInfo.getFuncPtrFromModule(
150+
ur::getURLoaderLibrary());
146151

147152
bool OwnLoaderConfig = false;
148153
// If we weren't provided with a custom config handle create our own.
@@ -225,8 +230,8 @@ static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
225230
auto syclBackend = UrToSyclBackend(adapterBackend);
226231
Adapters.emplace_back(std::make_shared<Adapter>(UrAdapter, syclBackend));
227232

228-
urAdapterSetLoggerCallback(UrAdapter, receiveLoggerMessages, nullptr,
229-
UR_LOGGER_LEVEL_INFO);
233+
CHECK_UR_SUCCESS(adapterSetLoggerCallback(UrAdapter, urLoggerCallback,
234+
nullptr, UR_LOGGER_LEVEL_INFO));
230235
}
231236

232237
#ifdef XPTI_ENABLE_INSTRUMENTATION

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

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

9898
for (auto &UnmappedFlag : UnmappedMemAdviceFlags) {
9999
if (URAdviceFlags & UnmappedFlag) {
100-
setErrorMessage("Memory advice ignored because the CUDA backend does not "
101-
"support some of the specified flags",
102-
UR_RESULT_SUCCESS);
103-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
100+
logger::warning("Memory advice ignored because the CUDA backend does not "
101+
"support some of the specified flags.");
104102
}
105103
}
106104

@@ -1613,19 +1611,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
16131611
// for managed memory. Therefore, ignore prefetch hint if concurrent managed
16141612
// memory access is not available.
16151613
if (!getAttribute(Device, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
1616-
setErrorMessage("Prefetch hint ignored as device does not support "
1617-
"concurrent managed access",
1618-
UR_RESULT_SUCCESS);
1619-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
1614+
logger::warning("Prefetch hint ignored as device does not support "
1615+
"concurrent managed access.");
16201616
}
16211617

16221618
unsigned int IsManaged;
16231619
UR_CHECK_ERROR(cuPointerGetAttribute(
16241620
&IsManaged, CU_POINTER_ATTRIBUTE_IS_MANAGED, (CUdeviceptr)pMem));
16251621
if (!IsManaged) {
1626-
setErrorMessage("Prefetch hint ignored as prefetch only works with USM",
1627-
UR_RESULT_SUCCESS);
1628-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
1622+
logger::warning("Prefetch hint ignored as prefetch only works with USM.");
16291623
}
16301624

16311625
ur_result_t Result = UR_RESULT_SUCCESS;
@@ -1675,9 +1669,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
16751669
(advice & UR_USM_ADVICE_FLAG_DEFAULT)) {
16761670
ur_device_handle_t Device = hQueue->getDevice();
16771671
if (!getAttribute(Device, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
1678-
setErrorMessage("Mem advise ignored as device does not support "
1679-
"concurrent managed access",
1680-
UR_RESULT_SUCCESS);
1672+
logger::warning("Mem advise ignored as device does not support "
1673+
"concurrent managed access.");
16811674
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
16821675
}
16831676

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
397397
arrayDesc.Format != CU_AD_FORMAT_SIGNED_INT32 &&
398398
arrayDesc.Format != CU_AD_FORMAT_HALF &&
399399
arrayDesc.Format != CU_AD_FORMAT_FLOAT) {
400-
setErrorMessage("PI CUDA kernels only support images with channel "
400+
setErrorMessage("UR CUDA kernels only support images with channel "
401401
"types int32, uint32, float, and half.",
402402
UR_RESULT_ERROR_ADAPTER_SPECIFIC);
403403
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "context.hpp"
1414
#include "event.hpp"
1515
#include "kernel.hpp"
16+
#include "logger/ur_logger.hpp"
1617
#include "memory.hpp"
1718
#include "queue.hpp"
1819
#include "ur_api.h"
@@ -1407,10 +1408,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
14071408
// mem_advise.
14081409
if (!Device->getManagedMemSupport()) {
14091410
releaseEvent();
1410-
setErrorMessage("mem_advise ignored as device does not support "
1411-
"managed memory access",
1412-
UR_RESULT_SUCCESS);
1413-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
1411+
logger::warning("mem_advise ignored as device does not support "
1412+
"managed memory access.");
14141413
}
14151414

14161415
hipPointerAttribute_t attribs;
@@ -1423,8 +1422,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
14231422
// async prefetch requires USM pointer (or hip SVM) to work.
14241423
if (!attribs.isManaged) {
14251424
releaseEvent();
1426-
setErrorMessage("Prefetch hint ignored as prefetch only works with USM",
1427-
UR_RESULT_SUCCESS);
1425+
logger::warning("Prefetch hint ignored as prefetch only works with USM.");
14281426
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
14291427
}
14301428

@@ -1480,10 +1478,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
14801478
// mem_advise.
14811479
if (!Device->getManagedMemSupport()) {
14821480
releaseEvent();
1483-
setErrorMessage("mem_advise ignored as device does not support "
1484-
"managed memory access",
1485-
UR_RESULT_SUCCESS);
1486-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
1481+
logger::warning("mem_advise ignored as device does not support "
1482+
"managed memory access.");
14871483
}
14881484

14891485
// Passing MEM_ADVICE_SET/MEM_ADVICE_CLEAR_PREFERRED_LOCATION to
@@ -1498,10 +1494,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
14981494
UR_USM_ADVICE_FLAG_DEFAULT)) {
14991495
if (!Device->getConcurrentManagedAccess()) {
15001496
releaseEvent();
1501-
setErrorMessage("mem_advise ignored as device does not support "
1502-
"concurrent managed access",
1503-
UR_RESULT_SUCCESS);
1504-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
1497+
logger::warning("mem_advise ignored as device does not support "
1498+
"concurrent memory access.");
15051499
}
15061500

15071501
// TODO: If pMem points to valid system-allocated pageable memory, we
@@ -1519,9 +1513,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
15191513
if (auto ptrAttribs = getPointerAttributes(pMem);
15201514
!ptrAttribs || !ptrAttribs->isManaged) {
15211515
releaseEvent();
1522-
setErrorMessage("mem_advise is ignored as the pointer argument is not "
1523-
"a shared USM pointer",
1524-
UR_RESULT_SUCCESS);
1516+
logger::warning("mem_advise is ignored as the pointer argument is not "
1517+
"a shared USM pointer.");
15251518
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
15261519
}
15271520

@@ -1549,10 +1542,8 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
15491542
// the runtime.
15501543
if (Result == UR_RESULT_ERROR_INVALID_ENUMERATION) {
15511544
releaseEvent();
1552-
setErrorMessage("mem_advise is ignored as the advice argument is not "
1553-
"supported by this device",
1554-
UR_RESULT_SUCCESS);
1555-
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
1545+
logger::warning("mem_advise is ignored as the advice argument is not "
1546+
"supported by this device.");
15561547
}
15571548
UR_CHECK_ERROR(Result);
15581549
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ namespace cl_adapter {
1616
thread_local int32_t ErrorMessageCode = 0;
1717
thread_local char ErrorMessage[MaxMessageSize]{};
1818

19-
[[maybe_unused]] void setErrorMessage(const char *Message, int32_t ErrorCode) {
20-
assert(strlen(Message) < cl_adapter::MaxMessageSize);
21-
// Copy at most MaxMessageSize - 1 bytes to ensure the resultant string is
22-
// always null terminated.
23-
strncpy(cl_adapter::ErrorMessage, Message, MaxMessageSize - 1);
24-
25-
ErrorMessageCode = ErrorCode;
26-
}
2719
} // namespace cl_adapter
2820

2921
ur_result_t mapCLErrorToUR(cl_int Result) {

unified-runtime/source/common/logger/ur_sinks.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class CallbackSink : public Sink {
240240
virtual void print(ur_logger_level_t level, const std::string &msg) override {
241241
if (callback) {
242242
callback(level, msg.c_str(), userData);
243-
}
243+
}
244244
}
245245
};
246246

0 commit comments

Comments
 (0)