Skip to content

Commit

Permalink
Trim device names (#2193)
Browse files Browse the repository at this point in the history
Fixes: #2187
  • Loading branch information
bernhardmgruber authored Nov 28, 2023
1 parent f23b298 commit cce9b43
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions include/alpaka/dev/Traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "alpaka/core/Common.hpp"
#include "alpaka/core/Concepts.hpp"

#include <algorithm>
#include <cctype>
#include <cstddef>
#include <string>
#include <vector>
Expand Down Expand Up @@ -65,11 +67,22 @@ namespace alpaka
return trait::GetDev<ImplementationBase>::getDev(t);
}

//! \return The device name.
namespace detail
{
inline auto trim(std::string s) -> std::string
{
auto const pred = [](char c) { return !std::isspace(c); };
s.erase(std::find_if(rbegin(s), rend(s), pred).base(), end(s));
s.erase(begin(s), std::find_if(begin(s), end(s), pred));
return s;
}
} // namespace detail

//! \return The device name with leading/trailing space characters trimmed off.
template<typename TDev>
ALPAKA_FN_HOST auto getName(TDev const& dev) -> std::string
{
return trait::GetName<TDev>::getName(dev);
return detail::trim(trait::GetName<TDev>::getName(dev));
}

//! \return The memory on the device in Bytes. Returns 0 if querying memory
Expand Down

0 comments on commit cce9b43

Please sign in to comment.