Skip to content

[SYCL] Fix ProgramManager::kernelUsesAssert to avoid tmp string creation #17912

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 1 commit into from
Apr 9, 2025
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
4 changes: 0 additions & 4 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1824,10 +1824,6 @@ void ProgramManager::cacheKernelUsesAssertInfo(RTDeviceBinaryImage &Img) {
m_KernelUsesAssert.insert(Prop->Name);
}

bool ProgramManager::kernelUsesAssert(const std::string &KernelName) const {
return m_KernelUsesAssert.find(KernelName) != m_KernelUsesAssert.end();
}

void ProgramManager::cacheKernelImplicitLocalArg(RTDeviceBinaryImage &Img) {
const RTDeviceBinaryImage::PropertyRange &ImplicitLocalArgRange =
Img.getImplicitLocalArg();
Expand Down
12 changes: 10 additions & 2 deletions sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ class ProgramManager {
ProgramManager();
~ProgramManager() = default;

bool kernelUsesAssert(const std::string &KernelName) const;
template <typename NameT>
bool kernelUsesAssert(const NameT &KernelName) const {
return m_KernelUsesAssert.find(KernelName) != m_KernelUsesAssert.end();
}

SanitizerType kernelUsesSanitizer() const { return m_SanitizerFoundInImage; }

Expand Down Expand Up @@ -503,7 +506,12 @@ class ProgramManager {
bool m_UseSpvFile = false;
RTDeviceBinaryImageUPtr m_SpvFileImage;

std::set<std::string> m_KernelUsesAssert;
// std::less<> is a transparent comparator that enabled comparison between
// different types without temporary key_type object creation. This includes
// standard overloads, such as comparison between std::string and
// std::string_view or just char*.
using KernelUsesAssertSet = std::set<std::string, std::less<>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit; This alias feels a little overkill when it's just used here and in a unittest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is a common practice in C++ to use aliases for container types. As you pointed out, there are already two places. If we decide to change the container type in the future it is easier with alias.

KernelUsesAssertSet m_KernelUsesAssert;
std::unordered_map<std::string, int> m_KernelImplicitLocalArgPos;

// Sanitizer type used in device image
Expand Down
2 changes: 1 addition & 1 deletion sycl/unittests/program_manager/Cleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ProgramManagerExposed : public sycl::detail::ProgramManager {
return m_EliminatedKernelArgMasks;
}

std::set<std::string> &getKernelUsesAssert() { return m_KernelUsesAssert; }
KernelUsesAssertSet &getKernelUsesAssert() { return m_KernelUsesAssert; }

std::unordered_map<std::string, int> &getKernelImplicitLocalArgPos() {
return m_KernelImplicitLocalArgPos;
Expand Down