Skip to content

Commit 87acf73

Browse files
martygrantkbenzie
andauthored
[UR] Logger callback function sink (#17095)
Migrated from oneapi-src/unified-runtime#1748 This PR implements oneapi-src/unified-runtime#1330 through a new logger sink: a user configurable callback. It introduces some spec additions: - `typedef void (*ur_logger_output_callback_t)(ur_logger_level_t level, const char *pLoggerMsg, void *pUserData)` - `urSetLoggerCallback(ur_adapter_handle_t hAdapter, ur_logger_output_callback_t pfnLoggerCallback, void *pUserData, ur_logger_level_t level` )` - `urSetLoggerCallbackLevel(ur_adapter_handle_t hAdapter, ur_logger_level_t level)` - `typedef enum ur_logger_level_t` (moved the logger::level enum into the spec) This new logger sink will only be constructed once a user makes a call to `urSetLoggerCallback` (which is called from the UR `urAdapterSetLoggerCallback` entry point), supplying their own callback function. They can set the minimum logging level through `urSetLoggerCallbackLevel`. Any subsequent logging calls will additionally make a call to the supplied callback where the log level, message and user data will be sent. A callback has been setup in the SYCL RT in `sycl/source/detail/ur.cpp` to print logs to `std::err`: ``` void urLoggerCallback([[maybe_unused]] ur_logger_level_t level, const char *msg, [[maybe_unused]] void *userData) { std::cerr << msg << std::endl; } ``` A new test suite `LoggerWithCallbackSink` has been added to test this new functionality. --------- Co-authored-by: Kenneth Benzie (Benie) <k.benzie83@gmail.com>
1 parent 8b48a80 commit 87acf73

Some content is hidden

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

49 files changed

+1654
-367
lines changed

Diff for: sycl/source/detail/ur.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ void *getAdapterOpaqueData([[maybe_unused]] void *OpaqueDataParam) {
7777

7878
ur_code_location_t codeLocationCallback(void *);
7979

80+
void urLoggerCallback([[maybe_unused]] ur_logger_level_t level, const char *msg,
81+
[[maybe_unused]] void *userData) {
82+
std::cerr << msg << std::endl;
83+
}
84+
8085
namespace ur {
8186
bool trace(TraceLevel Level) {
8287
auto TraceLevelMask = SYCLConfig<SYCL_UR_TRACE>::get();
@@ -138,6 +143,11 @@ static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
138143
UrFuncInfo<UrApiKind::urAdapterGetInfo> adapterGetInfoInfo;
139144
auto adapterGetInfo =
140145
adapterGetInfoInfo.getFuncPtrFromModule(ur::getURLoaderLibrary());
146+
UrFuncInfo<UrApiKind::urAdapterSetLoggerCallback>
147+
adapterSetLoggerCallbackInfo;
148+
auto adapterSetLoggerCallback =
149+
adapterSetLoggerCallbackInfo.getFuncPtrFromModule(
150+
ur::getURLoaderLibrary());
141151

142152
bool OwnLoaderConfig = false;
143153
// If we weren't provided with a custom config handle create our own.
@@ -219,6 +229,12 @@ static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
219229
nullptr));
220230
auto syclBackend = UrToSyclBackend(adapterBackend);
221231
Adapters.emplace_back(std::make_shared<Adapter>(UrAdapter, syclBackend));
232+
233+
const char *env_value = std::getenv("UR_LOG_CALLBACK");
234+
if (env_value == nullptr || std::string(env_value) != "disabled") {
235+
CHECK_UR_SUCCESS(adapterSetLoggerCallback(UrAdapter, urLoggerCallback,
236+
nullptr, UR_LOGGER_LEVEL_INFO));
237+
}
222238
}
223239

224240
#ifdef XPTI_ENABLE_INSTRUMENTATION

Diff for: sycl/test-e2e/External/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,3 @@ cmake \
7676
make check-sycl-e2e
7777
7878
```
79-

Diff for: sycl/test-e2e/lit.cfg.py

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@
168168
lit_config.note("\tUnset " + var)
169169
llvm_config.with_environment(var, "")
170170

171+
# Disable the UR logger callback sink during test runs as output to SYCL RT can interfere with some tests relying on standard input/output
172+
llvm_config.with_environment("UR_LOG_CALLBACK", "disabled")
171173

172174
# Temporarily modify environment to be the same that we use when running tests
173175
class test_env:

Diff for: sycl/test/Unit/lit.cfg.py

+3
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ def find_shlibpath_var():
9595

9696
config.environment["SYCL_CACHE_DIR"] = config.llvm_obj_root + "/sycl_cache"
9797
lit_config.note("SYCL cache directory: {}".format(config.environment["SYCL_CACHE_DIR"]))
98+
99+
# Disable the UR logger callback sink during test runs as output to SYCL RT can interfere with some tests relying on standard input/output
100+
config.environment["UR_LOG_CALLBACK"] = "disabled"

Diff for: sycl/test/lit.cfg.py

+3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@
186186
)
187187
)
188188

189+
# Disable the UR logger callback sink during test runs as output to SYCL RT can interfere with some tests relying on standard input/output
190+
llvm_config.with_environment("UR_LOG_CALLBACK", "disabled")
191+
189192
# Dump-only tests do not have clang available
190193
if not dump_only_tests:
191194
llvm_config.use_clang(additional_flags=additional_flags)

Diff for: unified-runtime/include/ur_api.h

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: unified-runtime/include/ur_api_funcs.def

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: unified-runtime/include/ur_ddi.h

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: unified-runtime/include/ur_print.h

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)