integral_constant.hpp Source File

integral_constant.hpp Source File#

Composable Kernel: integral_constant.hpp Source File
tile/core/numeric/integral_constant.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
8
9namespace ck_tile {
10
11template <auto v>
13{
14 using value_type = decltype(v);
15 using type = constant; // using injected-class-name
16 static constexpr value_type value = v;
17 CK_TILE_HOST_DEVICE constexpr operator value_type() const noexcept { return value; }
18 CK_TILE_HOST_DEVICE constexpr value_type operator()() const noexcept { return value; }
19 CK_TILE_HOST_DEVICE static constexpr bool is_static() { return true; }
20};
21
22template <auto v>
23CK_TILE_HOST_DEVICE static void print(const constant<v>&)
24{
25 printf("%ld", static_cast<long>(v));
26}
27
28template <typename T, T v>
30{
31 using value_type = T;
32 using type = integral_constant; // using injected-class-name
33 static constexpr T value = v;
34};
35
36template <index_t v>
38
39template <long_index_t v>
41
42template <bool b>
44
45#define CK_TILE_LEFT_UNARY_OP(OP) \
46 template <auto x> \
47 CK_TILE_HOST_DEVICE constexpr auto operator OP(constant<x>) \
48 { \
49 return constant<(OP x)>{}; \
50 }
51
52#define CK_TILE_BINARY_OP(OP) \
53 template <auto x, auto y> \
54 CK_TILE_HOST_DEVICE constexpr auto operator OP(constant<x>, constant<y>) \
55 { \
56 return constant<(x OP y)>{}; \
57 }
58
63
82
83#undef CK_TILE_LEFT_UNARY_OP
84#undef CK_TILE_BINARY_OP
85
86template <typename T>
87struct is_constant : std::false_type
88{
89};
90template <auto v>
91struct is_constant<constant<v>> : std::true_type
92{
93};
94template <typename T>
95inline constexpr bool is_constant_v = is_constant<T>::value;
96} // namespace ck_tile
#define CK_TILE_HOST_DEVICE
Definition config.hpp:42
Definition tile/core/algorithm/cluster_descriptor.hpp:13
constexpr bool is_constant_v
Definition tile/core/numeric/integral_constant.hpp:95
constant< b > bool_constant
Definition tile/core/numeric/integral_constant.hpp:43
constant< v > number
Definition tile/core/numeric/integral_constant.hpp:37
@ constant
Definition arch.hpp:51
constant< v > long_number
Definition tile/core/numeric/integral_constant.hpp:40
Definition tile/core/numeric/integral_constant.hpp:13
CK_TILE_HOST_DEVICE constexpr value_type operator()() const noexcept
Definition tile/core/numeric/integral_constant.hpp:18
static CK_TILE_HOST_DEVICE constexpr bool is_static()
Definition tile/core/numeric/integral_constant.hpp:19
static constexpr value_type value
Definition tile/core/numeric/integral_constant.hpp:16
decltype(v) value_type
Definition tile/core/numeric/integral_constant.hpp:14
constant type
Definition tile/core/numeric/integral_constant.hpp:15
Definition tile/core/numeric/integral_constant.hpp:30
T value_type
Definition tile/core/numeric/integral_constant.hpp:31
integral_constant type
Definition tile/core/numeric/integral_constant.hpp:32
static constexpr T value
Definition tile/core/numeric/integral_constant.hpp:33
Definition tile/core/numeric/integral_constant.hpp:88
#define CK_TILE_LEFT_UNARY_OP(OP)
Definition tile/core/numeric/integral_constant.hpp:45
#define CK_TILE_BINARY_OP(OP)
Definition tile/core/numeric/integral_constant.hpp:52