Skip to content

Commit d05476f

Browse files
committed
Refactor native cpu adapter to new logger
This commit refactors the native cpu adapter to adopt the new logger introduced in d9cd223 (Integrate logger with library, 2023-02-03). Signed-off-by: Łukasz Plewa <[email protected]>
1 parent 4d0183a commit d05476f

File tree

5 files changed

+18
-25
lines changed

5 files changed

+18
-25
lines changed

source/adapters/native_cpu/adapter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
struct ur_adapter_handle_t_ {
1515
std::atomic<uint32_t> RefCount = 0;
16+
logger::Logger &logger = logger::get_logger("native_cpu");
1617
} Adapter;
1718

1819
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet(

source/adapters/native_cpu/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) {
2929
}
3030

3131
void detail::ur::die(const char *pMessage) {
32-
std::cerr << "ur_die: " << pMessage << '\n';
32+
logger::always("ur_die: {}", pMessage);
3333
std::terminate();
3434
}

source/adapters/native_cpu/common.hpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#pragma once
1212

13+
#include "logger/ur_logger.hpp"
1314
#include "ur/ur.hpp"
1415

1516
constexpr size_t MaxMessageSize = 256;
@@ -18,29 +19,24 @@ extern thread_local ur_result_t ErrorMessageCode;
1819
extern thread_local char ErrorMessage[MaxMessageSize];
1920

2021
#define DIE_NO_IMPLEMENTATION \
21-
if (PrintTrace) { \
22-
std::cerr << "Not Implemented : " << __FUNCTION__ \
23-
<< " - File : " << __FILE__; \
24-
std::cerr << " / Line : " << __LINE__ << std::endl; \
25-
} \
26-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
22+
do { \
23+
logger::error("Not Implemented : {} - File : {} / Line : {}", \
24+
__FUNCTION__, __FILE__, __LINE__); \
25+
\
26+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; \
27+
} while (false);
2728

2829
#define CONTINUE_NO_IMPLEMENTATION \
29-
if (PrintTrace) { \
30-
std::cerr << "Warning : Not Implemented : " << __FUNCTION__ \
31-
<< " - File : " << __FILE__; \
32-
std::cerr << " / Line : " << __LINE__ << std::endl; \
33-
} \
34-
return UR_RESULT_SUCCESS;
30+
do { \
31+
logger::warning("Not Implemented : {} - File : {} / Line : {}", \
32+
__FUNCTION__, __FILE__, __LINE__); \
33+
return UR_RESULT_SUCCESS; \
34+
} while (false);
3535

3636
#define CASE_UR_UNSUPPORTED(not_supported) \
3737
case not_supported: \
38-
if (PrintTrace) { \
39-
std::cerr << std::endl \
40-
<< "Unsupported UR case : " << #not_supported << " in " \
41-
<< __FUNCTION__ << ":" << __LINE__ << "(" << __FILE__ << ")" \
42-
<< std::endl; \
43-
} \
38+
logger::error("Unsupported UR case : {} in {}:{}({})", #not_supported, \
39+
__FUNCTION__, __LINE__, __FILE__); \
4440
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
4541

4642
/// ------ Error handling, matching OpenCL plugin semantics.

source/adapters/native_cpu/device.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(ur_platform_handle_t hPlatform,
3232
if (NumEntries == 0) {
3333
/// Runtime queries number of devices
3434
if (phDevices != nullptr) {
35-
if (PrintTrace) {
36-
std::cerr << "Invalid Arguments for urDevicesGet\n";
37-
}
35+
logger::error("Invalid Arguments for urDevicesGet");
3836
return UR_RESULT_ERROR_INVALID_VALUE;
3937
}
4038
return UR_RESULT_SUCCESS;

source/adapters/native_cpu/platform.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries,
2828

2929
if (NumEntries == 0) {
3030
if (phPlatforms != nullptr) {
31-
if (PrintTrace) {
32-
std::cerr << "Invalid argument combination for urPlatformsGet\n";
33-
}
31+
logger::error("Invalid argument combination for urPlatformsGet");
3432
return UR_RESULT_ERROR_INVALID_VALUE;
3533
}
3634
return UR_RESULT_SUCCESS;

0 commit comments

Comments
 (0)