mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-02 04:31:25 +00:00
* Add experimental builder infrastructure for composable_kernel - Add experimental/builder directory with README documentation. - Create initial test infrastructure with CMakeLists.txt and placeholder test. - Update root CMakeLists.txt to support CK_EXPERIMENTAL_BUILDER option. - Update .gitignore to not treat `experimental/builder` as a CMake build directory. This establishes the directory structure for a high-level builder pattern that will provide a semantically-clear interface for constructing CK operations, with initial focus on convolution kernels for MIOpen integration. * Fix clang formatting. * Fix CMake build infrastructure for experimental builder - Add experimental/builder CMakeLists.txt with proper subdirectory structure - Add placeholder include/ck_tile/builder CMakeLists.txt for header installation - Fix gtest.cmake to use include_guard to prevent multiple inclusions - Update root CMakeLists.txt to include full builder directory instead of just tests * Scope C++20 settingto the test code Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant GTest::gtest linkage Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Introduce basic types, and convolution algorithm concepts and limits. * Add convolution signature concepts. * Add convolution factory. * Finalize conv factory implementation for fwd convolutions. * Add type definitions for testing. * Add placeholder test. * Add convolution builder definition. * Fully functional fwd conv builder. * Test improvements. * Clean-up include headers. * Enable the limit checks for the convolution algorithm parameters. * Remove dead code. * clang formatting. * Add more tests and missing conv specialization argument. * clang formatting. * Add explicit handling of the tensor layouts. * Add complete 2D/3D layout support to CK Builder - Add missing 2D layouts: GNHWC_GKYXC_GNHWK, NGCHW_GKCYX_NGKHW - Add missing 3D layout: GNDHWC_GKZYXC_GNDHWK - Add 1D layouts (NWGC, NGCW, GNWC, NGCW_GKCX) for future support - Add 3 tests for new 2D/3D layouts - All tests pass (5/5) * Add tests for remaining 2D/3D layouts - Add test for 2D NGCHW_GKYXC_NGKHW (channels-first) with Filter1x1Stride1Pad0 - Add test for 3D NDHWGC_GKZYXC_NDHWGK (channels-last) - All 7 tests pass (complete coverage for all 2D/3D forward layouts) * Change enum converters to consteval. * 7 tests with pipeline and specialization| Test # | Dim | Type | Layout | Pipeline | Specialization | |--------|-----|------|----------------------|----------|-------------------------| | 1 | 2D | BF16 | NHWGC_GKYXC_NHWGK | V1 | DEFAULT | | 2 | 2D | FP16 | GNHWC_GKYXC_GNHWK | V3 | FILTER_1X1_PAD0 | | 3 | 2D | FP32 | NGCHW_GKCYX_NGKHW | V4 | FILTER_1X1_STRIDE1_PAD0 | | 4 | 2D | BF16 | NHWGC_GKYXC_NHWGK | V5 | FILTER_3x3 | | 5 | 3D | FP32 | NGCDHW_GKCZYX_NGKDHW | V1 | FILTER_1X1_PAD0 | | 6 | 3D | BF16 | GNDHWC_GKZYXC_GNDHWK | V3 | DEFAULT | | 7 | 3D | FP16 | NDHWGC_GKZYXC_NDHWGK | V4 | FILTER_1X1_PAD0 | * Add missing convolution layouts and provide better compile-time error in instance traits. * Fix clang formatting. * Changed I8 -> S8. * Fix signature. * Rename concepts and corresponding members. * Rename LDS related parameters. * Remove ODD_C specialization. Add V2 pipeline. * Add missing types. * Add elementwise operation to the conv signature. * Improve compile-time error message for unsupported elementwise ops. * Separate different fwd conv builder tests into separate compilation units. * Fix layout to string and add name to old CK PassThrough elementwise op. * Enable both CK and CK Tile tensor layouts in instance traits. * Fix clang-format. --------- Co-authored-by: John Shumway <jshumway@amd.com> Co-authored-by: John Shumway <john.shumwayjr@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: JH-Leon-KIM-AMD <jeonghyun.kim@amd.com>
144 lines
4.2 KiB
C++
144 lines
4.2 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "ck/utility/sequence.hpp"
|
|
#include "ck_tile/builder/types.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 method to handler the unusual .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;
|
|
}
|
|
};
|
|
|
|
// This is a C++17 deduction guide. It allows the compiler to automatically
|
|
// deduce the template argument `N` for `StringLiteral` from a string literal
|
|
// constructor argument. For example, you can write `StringLiteral s{"foo"};`
|
|
// instead of `StringLiteral<4> s{"foo"};`.
|
|
template <size_t N>
|
|
StringLiteral(const char (&)[N]) -> StringLiteral<N>;
|
|
|
|
// Helper to provide a readable error for unsupported enum values.
|
|
// The compiler will print the name of this struct in the error message, so
|
|
// the name of the enum value will appear instead of just its integer value.
|
|
template <auto T>
|
|
struct UnsupportedEnumValue
|
|
{
|
|
};
|
|
|
|
// Helper functions to convert enums to strings
|
|
constexpr std::string_view ConvDirectionToString(ConvDirection dir)
|
|
{
|
|
switch(dir)
|
|
{
|
|
case ConvDirection::FORWARD: return "Forward";
|
|
case ConvDirection::BACKWARD_DATA: return "Backward Data";
|
|
case ConvDirection::BACKWARD_WEIGHT: return "Backward Weight";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
constexpr std::string_view DataTypeToString(DataType dt)
|
|
{
|
|
switch(dt)
|
|
{
|
|
case DataType::FP16: return "FP16";
|
|
case DataType::FP32: return "FP32";
|
|
case DataType::BF16: return "BF16";
|
|
case DataType::FP8: return "FP8";
|
|
case DataType::I8: return "I8";
|
|
case DataType::U8: return "U8";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
constexpr std::string_view LayoutToString(GroupConvLayout1D layout)
|
|
{
|
|
switch(layout)
|
|
{
|
|
case GroupConvLayout1D::GNWC_GKXC_GNWK: return "GNWC_GKXC_GNWK";
|
|
case GroupConvLayout1D::NWGC_GKXC_NWGK: return "NWGC_GKXC_NWGK";
|
|
case GroupConvLayout1D::NGCW_GKXC_NGKW: return "NGCW_GKXC_NGKW";
|
|
case GroupConvLayout1D::NGCW_GKCX_NGKW: return "NGCW_GKCX_NGKW";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
constexpr std::string_view LayoutToString(GroupConvLayout2D layout)
|
|
{
|
|
switch(layout)
|
|
{
|
|
case GroupConvLayout2D::GNHWC_GKYXC_GNHWK: return "GNHWC_GKYXC_GNHWK";
|
|
case GroupConvLayout2D::NHWGC_GKYXC_NHWGK: return "NHWGC_GKYXC_NHWGK";
|
|
case GroupConvLayout2D::NGCHW_GKYXC_NGKHW: return "NGCHW_GKYXC_NGKHW";
|
|
case GroupConvLayout2D::NGCHW_GKCYX_NGKHW: return "NGCHW_GKCYX_NGKHW";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
constexpr std::string_view LayoutToString(GroupConvLayout3D layout)
|
|
{
|
|
switch(layout)
|
|
{
|
|
case GroupConvLayout3D::GNDHWC_GKZYXC_GNDHWK: return "GNDHWC_GKZYXC_GNDHWK";
|
|
case GroupConvLayout3D::NDHWGC_GKZYXC_NDHWGK: return "NDHWGC_GKZYXC_NDHWGK";
|
|
case GroupConvLayout3D::NGCDHW_GKZYXC_NGKDHW: return "NGCDHW_GKZYXC_NGKDHW";
|
|
case GroupConvLayout3D::NGCDHW_GKCZYX_NGKDHW: return "NGCDHW_GKCZYX_NGKDHW";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
} // namespace ck_tile::builder
|