-
Couldn't load subscription status.
- Fork 791
[UR] better assertions #20169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[UR] better assertions #20169
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * | ||
| * Copyright (C) 2022-2025 Intel Corporation | ||
| * | ||
| * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM | ||
| * Exceptions. See LICENSE.TXT | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| */ | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| #include "../backtrace.hpp" | ||
| #include "ur_logger.hpp" | ||
|
|
||
| namespace logger { | ||
|
|
||
| void print_backtrace() { | ||
| for (auto btLine : ur_validation_layer::getCurrentBacktrace()) { | ||
| std::cerr << btLine << std::endl; | ||
| } | ||
| } | ||
|
|
||
| static bool str_to_bool(const std::string &str) { | ||
| if (!str.empty()) { | ||
| std::string lower_value = str; | ||
| std::transform(lower_value.begin(), lower_value.end(), lower_value.begin(), | ||
| [](unsigned char c) { return std::tolower(c); }); | ||
| const std::initializer_list<std::string> true_str = {"y", "yes", "t", | ||
| "true", "1"}; | ||
| return std::find(true_str.begin(), true_str.end(), lower_value) != | ||
| true_str.end(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| Logger create_logger(std::string logger_name, bool skip_prefix, | ||
| bool skip_linebreak, ur_logger_level_t default_log_level) { | ||
| std::transform(logger_name.begin(), logger_name.end(), logger_name.begin(), | ||
| ::toupper); | ||
|
|
||
| const std::string env_var_name = "UR_LOG_" + logger_name; | ||
| const auto default_flush_level = UR_LOGGER_LEVEL_ERROR; | ||
| const std::string default_output = "stderr"; | ||
| const bool default_fileline = false; | ||
| auto flush_level = default_flush_level; | ||
| ur_logger_level_t level = default_log_level; | ||
| bool fileline = default_fileline; | ||
| std::unique_ptr<Sink> sink; | ||
|
|
||
| try { | ||
| auto map = getenv_to_map(env_var_name.c_str()); | ||
| if (!map.has_value()) { | ||
| return Logger(default_log_level, | ||
| std::make_unique<logger::StderrSink>( | ||
| std::move(logger_name), skip_prefix, skip_linebreak)); | ||
| } | ||
|
|
||
| auto kv = map->find("level"); | ||
| if (kv != map->end()) { | ||
| auto value = kv->second.front(); | ||
| level = str_to_level(std::move(value)); | ||
| map->erase(kv); | ||
| } | ||
|
|
||
| kv = map->find("flush"); | ||
| if (kv != map->end()) { | ||
| auto value = kv->second.front(); | ||
| flush_level = str_to_level(std::move(value)); | ||
| map->erase(kv); | ||
| } | ||
|
|
||
| kv = map->find("fileline"); | ||
| if (kv != map->end()) { | ||
| auto value = kv->second.front(); | ||
| fileline = str_to_bool(std::move(value)); | ||
| map->erase(kv); | ||
| } | ||
|
|
||
| std::vector<std::string> values = {default_output}; | ||
| kv = map->find("output"); | ||
| if (kv != map->end()) { | ||
| values = kv->second; | ||
| map->erase(kv); | ||
| } | ||
|
|
||
| if (!map->empty()) { | ||
| std::cerr << "Wrong logger environment variable parameter: '" | ||
| << map->begin()->first << "'. Default logger options are set."; | ||
| return Logger(default_log_level, | ||
| std::make_unique<logger::StderrSink>( | ||
| std::move(logger_name), skip_prefix, skip_linebreak)); | ||
| } | ||
|
|
||
| sink = values.size() == 2 ? sink_from_str(logger_name, values[0], values[1], | ||
| skip_prefix, skip_linebreak) | ||
| : sink_from_str(logger_name, values[0], "", | ||
| skip_prefix, skip_linebreak); | ||
| } catch (const std::invalid_argument &e) { | ||
| std::cerr << "Error when creating a logger instance from the '" | ||
| << env_var_name << "' environment variable:\n" | ||
| << e.what() << std::endl; | ||
| return Logger(default_log_level, | ||
| std::make_unique<logger::StderrSink>( | ||
| std::move(logger_name), skip_prefix, skip_linebreak)); | ||
| } | ||
|
|
||
| sink->setFlushLevel(flush_level); | ||
| sink->setFileLine(fileline); | ||
|
|
||
| return Logger(level, std::move(sink)); | ||
| } | ||
|
|
||
| } // namespace logger |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.