mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-20 21:09:08 +00:00
[CK] Add rocm_ck foundation types: DataType, Layout, Args, Ops (#7114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Add the vocabulary types that all rocm_ck schema headers build on - 9 new headers under `include/rocm_ck/`, 6 unit test files - Pure C++20, host-only — no CK Tile dependencies **Headers:** | Header | Purpose | |--------|---------| | `index_t.hpp` | `index_t`, `long_index_t` (matches ck_tile) | | `gpu_target.hpp` | `GpuTarget` enum (ISA targets) | | `datatype.hpp` | `DataType` enum (17 variants) | | `layout.hpp` | `Layout` enum (Row, Col, Auto) + stride helpers | | `fixed_string.hpp` | `FixedString<N>` — structural string for NTTPs | | `args.hpp` | Generic kernel argument buffer (ABI) | | `ops.hpp` | Operator structs (`GemmOp`, `AddOp`, ...) + `Op` variant | | `physical_tensor.hpp` | `PhysicalTensor` — maps names to Args slots | | `resolved_tensor.hpp` | `ResolvedTensor` — output of `Signature::resolve()` | **Stack**: This is PR 1 of 3 porting the rocm_ck constexpr schema from experimental to production, #7143. 1. **This PR** — Foundation types (vocabulary) 2. Schema engine — `Signature`, `resolve()`, `ArchProperties` 3. Spec factories — `GemmSpec`, `ElementwiseSpec`, `makeSpec()` ## Test plan - [ ] `ninja build-smoke-rocm-ck` builds all tests - [ ] `ctest -L ROCM_CK_SMOKE --output-on-failure` — 6 unit tests pass (86 test cases) - [ ] Default CK build (`CK_ENABLE_ROCM_CK=OFF`) unaffected 🤖 Generated with [Claude Code](https://claude.com/claude-code)
63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
// Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
// Role: types — FixedString. No runtime, no CK deps.
|
|
//
|
|
// A compile-time string for use in template parameters (NTTPs).
|
|
//
|
|
// C++20 requires template parameters to be "structural types" — loosely, types
|
|
// that are trivially comparable and don't contain pointers or references.
|
|
// std::string and std::string_view fail this requirement (internal pointer).
|
|
//
|
|
// FixedString stores the string inline in a char array, making it structural:
|
|
//
|
|
// template <PhysicalTensor PT> // PhysicalTensor contains FixedString<16>
|
|
// void dispatch() { ... }
|
|
//
|
|
// When to use FixedString vs std::string_view:
|
|
// - FixedString: the type must be structural (template parameters).
|
|
// - string_view: consteval-only types that never become template parameters
|
|
// (e.g., ResolvedTensor — see resolved_tensor.hpp).
|
|
//
|
|
// The capacity is a template parameter so each use site documents its limit:
|
|
// FixedString<16> name("bias"); // tensor names: 15 chars max
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <string_view>
|
|
|
|
namespace rocm_ck {
|
|
|
|
template <std::size_t MaxLen>
|
|
struct FixedString
|
|
{
|
|
char data[MaxLen]{};
|
|
int len = 0;
|
|
|
|
constexpr FixedString() = default;
|
|
|
|
constexpr FixedString(std::string_view sv) : len(static_cast<int>(sv.size()))
|
|
{
|
|
if(sv.size() > MaxLen - 1)
|
|
throw "FixedString: input exceeds capacity";
|
|
for(int i = 0; i < len; ++i)
|
|
data[i] = sv[i];
|
|
}
|
|
|
|
constexpr bool operator==(std::string_view sv) const
|
|
{
|
|
if(len != static_cast<int>(sv.size()))
|
|
return false;
|
|
for(int i = 0; i < len; ++i)
|
|
if(data[i] != sv[i])
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
// Required: the string_view overload above suppresses the implicit == from <=>.
|
|
constexpr bool operator==(const FixedString&) const = default;
|
|
constexpr auto operator<=>(const FixedString&) const = default;
|
|
};
|
|
|
|
} // namespace rocm_ck
|