mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-07-13 02:27:33 +00:00
Add missing files.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include <ck/utility/sequence.hpp>
|
||||
|
||||
namespace ck_tile::builder {
|
||||
|
||||
// Convert a static array to a sequence
|
||||
// Usage example:
|
||||
// static constexpr std::vector arr {1, 2, 3};
|
||||
// using seq = to_sequence_v<arr>; // seq is ck::Sequence<1, 2, 3>
|
||||
template <typename T, const T& Arr>
|
||||
struct to_sequence_t
|
||||
{
|
||||
private:
|
||||
template <std::size_t... Is>
|
||||
static auto get_sequence_type(std::index_sequence<Is...>) -> ck::Sequence<Arr[Is]...>;
|
||||
|
||||
// Helper to handler the .Size() method name in ck::Array.
|
||||
static constexpr auto get_size(const auto& arr)
|
||||
{
|
||||
if constexpr(requires { arr.size(); })
|
||||
{
|
||||
return arr.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
return arr.Size();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
using value = decltype(get_sequence_type(std::make_index_sequence<get_size(Arr)>{}));
|
||||
};
|
||||
|
||||
template <auto& Arr>
|
||||
using to_sequence_v = typename to_sequence_t<std::remove_cvref_t<decltype(Arr)>, Arr>::value;
|
||||
|
||||
// Wrapper function to make constexpr strings a structural type for NTTP.
|
||||
template <size_t N>
|
||||
struct StringLiteral {
|
||||
char data[N];
|
||||
constexpr StringLiteral(const char (&str)[N]) {
|
||||
for (size_t i = 0; i < N; ++i) data[i] = str[i];
|
||||
}
|
||||
|
||||
constexpr bool operator==(const StringLiteral<N>& other) const {
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (data[i] != other.data[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t N>
|
||||
StringLiteral(const char (&)[N]) -> StringLiteral<N>;
|
||||
|
||||
} // namespace ck_tile::builder
|
||||
37
experimental/builder/test/test_builder_utils.cpp
Normal file
37
experimental/builder/test/test_builder_utils.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ck/utility/sequence.hpp>
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
#include <ck_tile/builder/builder_utils.hpp>
|
||||
|
||||
namespace ck_tile::builder {
|
||||
namespace {
|
||||
|
||||
TEST(BuilderUtils, ToSequence)
|
||||
{
|
||||
static constexpr std::array<int, 4> test_arr{1, 2, 8, 16};
|
||||
using result_seq = to_sequence_v<test_arr>;
|
||||
using expected_seq = ck::Sequence<1, 2, 8, 16>;
|
||||
EXPECT_TRUE((std::is_same_v<result_seq, expected_seq>));
|
||||
}
|
||||
|
||||
TEST(BuilderUtils, ToSequenceEmpty)
|
||||
{
|
||||
static constexpr std::array<int, 0> test_arr{};
|
||||
using result_seq = to_sequence_v<test_arr>;
|
||||
using expected_seq = ck::Sequence<>;
|
||||
EXPECT_TRUE((std::is_same_v<result_seq, expected_seq>));
|
||||
}
|
||||
|
||||
Test(BuilderUtils, ConstexprString)
|
||||
{
|
||||
static constexpr ConstexprString str1{"hello"};
|
||||
static constexpr ConstexprString str2{"hello"};
|
||||
static constexpr ConstexprString str3{"world"};
|
||||
EXPECT_TRUE(str1 == str2);
|
||||
EXPECT_FALSE(str1 == str3);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace ck_tile::builder
|
||||
Reference in New Issue
Block a user