-
Notifications
You must be signed in to change notification settings - Fork 552
feat: auto-vectorize bf16/fp16 reduce with packed add2 intrinsics #2112
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
77672dd
883a75b
037181b
b68f250
224ba27
ce2cb1c
b1f3298
18a677a
be05f29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| #include <ctime> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| namespace tvm { | ||
| namespace runtime { | ||
|
|
@@ -17,6 +19,24 @@ const char *level_strings[] = { | |
| ": Error: ", // TVM_LOG_LEVEL_ERROR = 3 | ||
| ": Fatal: ", // TVM_LOG_LEVEL_FATAL = 4 | ||
| }; | ||
|
|
||
| constexpr const char *kSrcPrefix = "/src/"; | ||
| constexpr const size_t kSrcPrefixLength = 5; | ||
| constexpr const char *kDefaultKeyword = "DEFAULT"; | ||
|
|
||
| std::string FileToVLogMapKey(const std::string &filename) { | ||
| size_t last_src = | ||
| filename.rfind(kSrcPrefix, std::string::npos, kSrcPrefixLength); | ||
| if (last_src == std::string::npos) { | ||
| std::string no_slash_src{kSrcPrefix + 1}; | ||
| if (filename.substr(0, no_slash_src.size()) == no_slash_src) { | ||
| return filename.substr(no_slash_src.size()); | ||
| } | ||
| } | ||
| return (last_src == std::string::npos) | ||
| ? filename | ||
| : filename.substr(last_src + kSrcPrefixLength); | ||
| } | ||
| } // namespace | ||
|
|
||
| void LogMessageImpl(const std::string &file, int lineno, int level, | ||
|
|
@@ -39,6 +59,75 @@ void LogMessageImpl(const std::string &file, int lineno, int level, | |
| throw InternalError(file, lineno, message); | ||
| } | ||
|
|
||
| TvmLogDebugSettings TvmLogDebugSettings::ParseSpec(const char *opt_spec) { | ||
| TvmLogDebugSettings settings; | ||
| if (opt_spec == nullptr) { | ||
| return settings; | ||
| } | ||
| std::string spec(opt_spec); | ||
| if (spec.empty() || spec == "0") { | ||
| return settings; | ||
| } | ||
| settings.dlog_enabled_ = true; | ||
| if (spec == "1") { | ||
| return settings; | ||
| } | ||
| std::istringstream spec_stream(spec); | ||
| auto tell_pos = [&](const std::string &last_read) { | ||
| int pos = spec_stream.tellg(); | ||
| if (pos == -1) { | ||
| pos = spec.size() - last_read.size(); | ||
| } | ||
| return pos; | ||
| }; | ||
| while (spec_stream) { | ||
| std::string name; | ||
| if (!std::getline(spec_stream, name, '=')) { | ||
| break; | ||
| } | ||
| if (name.empty()) { | ||
| LOG(FATAL) << "TVM_LOG_DEBUG ill-formed at position " << tell_pos(name) | ||
| << ": empty filename"; | ||
| } | ||
| name = FileToVLogMapKey(name); | ||
| std::string level; | ||
| if (!std::getline(spec_stream, level, ',')) { | ||
| LOG(FATAL) << "TVM_LOG_DEBUG ill-formed at position " << tell_pos(level) | ||
| << ": expecting \"=<level>\" after \"" << name << "\""; | ||
| return settings; | ||
| } | ||
| if (level.empty()) { | ||
| LOG(FATAL) << "TVM_LOG_DEBUG ill-formed at position " << tell_pos(level) | ||
| << ": empty level after \"" << name << "\""; | ||
| return settings; | ||
| } | ||
| char *end_of_level = nullptr; | ||
| int level_val = static_cast<int>(strtol(level.c_str(), &end_of_level, 10)); | ||
| if (end_of_level != level.c_str() + level.size()) { | ||
| LOG(FATAL) << "TVM_LOG_DEBUG ill-formed at position " << tell_pos(level) | ||
| << ": invalid level: \"" << level << "\""; | ||
| return settings; | ||
| } | ||
| LOG(INFO) << "TVM_LOG_DEBUG enables VLOG statements in '" << name | ||
| << "' up to level " << level; | ||
|
Comment on lines
+128
to
+129
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid unconditional These lines print to stderr for every valid spec entry, even when the caller only wanted to configure VLOG gating. That makes the flag itself user-visible and can pollute tests or tooling that assert on stderr. Prefer 🤖 Prompt for AI Agents |
||
| settings.vlog_level_map_.emplace(name, level_val); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle duplicate file entries explicitly. Line 113 uses 🤖 Prompt for AI Agents |
||
| } | ||
| return settings; | ||
| } | ||
|
|
||
| bool TvmLogDebugSettings::VerboseEnabledImpl(const std::string &filename, | ||
| int level) const { | ||
| auto itr = vlog_level_map_.find(FileToVLogMapKey(filename)); | ||
| if (itr != vlog_level_map_.end()) { | ||
| return level <= itr->second; | ||
| } | ||
| itr = vlog_level_map_.find(kDefaultKeyword); | ||
| if (itr != vlog_level_map_.end()) { | ||
| return level <= itr->second; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| } // namespace detail | ||
| } // namespace runtime | ||
| } // namespace tvm | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: tile-ai/tilelang
Length of output: 1541
🏁 Script executed:
rg -A 5 -B 5 "vlog_level_map_" src/runtime/logging.ccRepository: tile-ai/tilelang
Length of output: 761
🏁 Script executed:
Repository: tile-ai/tilelang
Length of output: 42
🏁 Script executed:
Repository: tile-ai/tilelang
Length of output: 2293
Add range validation before narrowing
strtolresult toint.On lines 105–106,
strtolparses the level string as alongand directly casts tointwithout checking whether the value is in range. If a user provides a value outside[INT_MIN, INT_MAX], the cast silently wraps to an incorrect VLOG level instead of rejecting the input as malformed.Suggested fix
🤖 Prompt for AI Agents