Skip to content

[SYCL] Fix regression introduced in https://github.com/intel/llvm/pull/11517 #12002

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 7 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions sycl/source/detail/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,24 @@ const char *stringifyErrorCode(pi_int32 error) {
}

std::vector<std::string> split_string(const std::string &str, char delimeter) {
std::vector<std::string> result;
size_t beg = 0;
size_t end = 0;
while ((end = str.find(delimeter, beg)) != std::string::npos) {
result.push_back(str.substr(beg, end - beg));
beg = end + 1;
std::vector<std::string> Result;
size_t Start = 0;
size_t End = 0;
while ((End = str.find(delimeter, Start)) != std::string::npos) {
Result.push_back(str.substr(Start, End - Start));
Start = End + 1;
}
end = str.find('\0');
if (beg < end) {
result.push_back(str.substr(beg, end - beg));
// Get the last substring and ignore the null character so we wouldn't get
// double null characters \0\0 at the end of the substring
End = str.find('\0');
if (Start < End) {
std::string LastSubStr(str.substr(Start, End - Start));
// In case str has a delimeter at the end, the substring will be empty, so
// we shouldn't add it to the final vector
if (!LastSubStr.empty())
Result.push_back(LastSubStr);
}
return result;
return Result;
}

} // namespace detail
Expand Down
25 changes: 25 additions & 0 deletions sycl/unittests/kernel-and-program/DeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,28 @@ TEST_F(DeviceInfoNegativeTest, TestAspectNotSupported) {
EXPECT_EQ(Dev.has(aspect::ext_intel_memory_clock_rate), false);
EXPECT_EQ(Dev.has(aspect::ext_intel_memory_bus_width), false);
}

TEST_F(DeviceInfoTest, SplitStringDelimeterSpace) {
std::string InputString("V1 V2 V3");
std::vector<std::string> Expected{"V1", "V2", "V3"};
EXPECT_EQ(detail::split_string(InputString, ' '), Expected);
}

TEST_F(DeviceInfoTest, SplitStringDelimeterSpaceAtTheEnd) {
std::string InputString("V1 V2 V3 ");
std::vector<std::string> Expected{"V1", "V2", "V3"};
EXPECT_EQ(detail::split_string(InputString, ' '), Expected);
}

TEST_F(DeviceInfoTest, SplitStringDelimeterSemicolon) {
std::string InputString("V1;V2;V3");
std::vector<std::string> Expected{"V1", "V2", "V3"};
EXPECT_EQ(detail::split_string(InputString, ';'), Expected);
}

TEST_F(DeviceInfoTest, SplitStringCheckNoDoubleNullCharacters) {
std::string InputString("V1;V23");
std::vector<std::string> Result = detail::split_string(InputString, ';');
EXPECT_EQ(Result[0].length(), (unsigned)2);
EXPECT_EQ(Result[1].length(), (unsigned)3);
}