// SPDX-License-Identifier: MIT // Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved. #pragma once #include "ck/utility/functional.hpp" #include "ck/utility/sequence.hpp" #include "ck/utility/tuple.hpp" #include "ck/utility/type.hpp" namespace ck { namespace detail { template struct static_for_impl; template struct static_for_impl> { template __host__ __device__ constexpr void operator()(F f) const { swallow{(f(Number{}), 0)...}; } }; } // namespace detail // F signature: F(Number) template struct static_for { __host__ __device__ constexpr static_for() { static_assert(Increment != 0 && (NEnd - NBegin) % Increment == 0, "Wrong! should satisfy (NEnd - NBegin) % Increment == 0"); static_assert((Increment > 0 && NBegin <= NEnd) || (Increment < 0 && NBegin >= NEnd), "wrongs! should (Increment > 0 && NBegin <= NEnd) || (Increment < 0 && " "NBegin >= NEnd)"); } template __host__ __device__ constexpr void operator()(F f) const { detail::static_for_impl::type>{}( f); } }; namespace detail { template struct applier { template __host__ __device__ constexpr void operator()(F f) const { // tweak -fbracket-depth if compilation fails. Clang default limit is 256 (f(Number{}), ...); } }; template // == sizeof...(Is) using make_applier = __make_integer_seq; } // namespace detail template struct static_for<0, N, 1> : detail::make_applier { using detail::make_applier::operator(); }; template struct static_for_range { template __host__ __device__ constexpr void operator()(F f) const { // tweak -fbracket-depth if compilation fails. Clang default limit is 256 (f(Is{}), ...); } }; template struct static_for_product; template struct static_for_product> : public static_for_range { }; template struct static_for_product, Rest...> { template __host__ __device__ constexpr void operator()(F f) const { static_for_product>{}([&](auto i0) { // static_for_product{}([&](auto... is) { // f(i0, is...); }); }); } }; struct identity { template __host__ __device__ constexpr T&& operator()(T&& arg) const noexcept { return ck::forward(arg); } }; } // namespace ck