Skip to content

Commit

Permalink
[XLA:CPU] Replace colons with underscores in ConvertToCName.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 731736711
  • Loading branch information
Google-ML-Automation committed Feb 27, 2025
1 parent b7ae013 commit 955250f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xla/backends/cpu/codegen/symbol_name_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ bool isValidCVariableName(absl::string_view name) {
}

absl::StatusOr<std::string> ConvertToCName(absl::string_view name) {
auto maybe_c_name = absl::StrReplaceAll(name, {{".", "_"}, {"-", "_"}});
auto maybe_c_name =
absl::StrReplaceAll(name, {{".", "_"}, {"-", "_"}, {":", "_"}});
if (isValidCVariableName(maybe_c_name)) {
return maybe_c_name;
}
Expand Down
5 changes: 5 additions & 0 deletions xla/backends/cpu/codegen/symbol_name_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ TEST(SymbolNameUtilTest, Dash) {
EXPECT_EQ(result, "foo_bar");
}

TEST(SymbolNameUtilTest, Colon) {
TF_ASSERT_OK_AND_ASSIGN(auto result, xla::cpu::ConvertToCName("foo:bar"));
EXPECT_EQ(result, "foo_bar");
}

TEST(SymbolNameUtilTest, CantConvertToCNameInvalid) {
EXPECT_FALSE(xla::cpu::ConvertToCName("1_test").ok());
}
Expand Down

0 comments on commit 955250f

Please sign in to comment.