integral_constant.hpp Source File

integral_constant.hpp Source File#

Composable Kernel: integral_constant.hpp Source File
utility/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
6namespace ck {
7
8template <auto v>
9struct constant
10{
11 using value_type = decltype(v);
12 using type = constant; // using injected-class-name
13 static constexpr value_type value = v;
14 __host__ __device__ constexpr operator value_type() const noexcept { return value; }
15 __host__ __device__ constexpr value_type operator()() const noexcept { return value; }
16};
17
18template <class T, T v>
20{
21 static constexpr T value = v;
22 typedef T value_type;
24};
25
26template <typename TX, TX X, typename TY, TY Y>
28{
29 return integral_constant<decltype(X + Y), X + Y>{};
30}
31
32template <typename TX, TX X, typename TY, TY Y>
34{
35 static_assert(Y <= X, "wrong!");
36 return integral_constant<decltype(X - Y), X - Y>{};
37}
38
39template <typename TX, TX X, typename TY, TY Y>
41{
42 return integral_constant<decltype(X * Y), X * Y>{};
43}
44
45template <typename TX, TX X, typename TY, TY Y>
47{
48 static_assert(Y > 0, "wrong!");
49 return integral_constant<decltype(X / Y), X / Y>{};
50}
51
52template <typename TX, TX X, typename TY, TY Y>
54{
55 static_assert(Y > 0, "wrong!");
56 return integral_constant<decltype(X % Y), X % Y>{};
57}
58
59template <bool B>
61
64} // namespace ck
Definition ck.hpp:268
bool_constant< false > false_type
Definition utility/integral_constant.hpp:63
__host__ __device__ constexpr auto operator/(integral_constant< TX, X >, integral_constant< TY, Y >)
Definition utility/integral_constant.hpp:46
bool_constant< true > true_type
Definition utility/integral_constant.hpp:62
integral_constant< bool, B > bool_constant
Definition utility/integral_constant.hpp:60
__host__ __device__ constexpr auto operator-(const MultiIndex< NSize > &a, const T &b)
Definition array_multi_index.hpp:60
__host__ __device__ constexpr auto operator+(const MultiIndex< NSize > &a, const T &b)
Definition array_multi_index.hpp:50
__host__ __device__ constexpr auto operator%(integral_constant< TX, X >, integral_constant< TY, Y >)
Definition utility/integral_constant.hpp:53
__host__ __device__ constexpr auto operator*(const MultiIndex< NSize > &a, const T &b)
Definition array_multi_index.hpp:70
Definition utility/integral_constant.hpp:10
decltype(v) value_type
Definition utility/integral_constant.hpp:11
constant type
Definition utility/integral_constant.hpp:12
__host__ __device__ constexpr value_type operator()() const noexcept
Definition utility/integral_constant.hpp:15
static constexpr value_type value
Definition utility/integral_constant.hpp:13
Definition utility/integral_constant.hpp:20
static constexpr bool value
Definition utility/integral_constant.hpp:21
integral_constant type
Definition utility/integral_constant.hpp:23
T value_type
Definition utility/integral_constant.hpp:22