mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-04 13:41:24 +00:00
* updating codegen build for MIOpen access: adding .cmake for codegen component * updating CMake * adding in header guards for some headers due to issues with hiprtc compilation in MIOpen * some more header guards * putting env file in header guard * cleaning up some includes * updated types file for hiprtc purposes * fixed types file: bit-wise/memcpy issue * updating multiple utility files to deal with standard header inclusion for hiprtc * added some more header guards in the utility files, replacing some standard header functionality * added some more header guards * fixing some conflicts in utility files, another round of header guards * fixing errors in data type file * resolved conflict errors in a few utility files * added header guards/replicated functionality in device files * resolved issues with standard headers in device files: device_base and device_grouped_conv_fwd_multiple_abd * resolved issues with standard headers in device files: device_base.hpp, device_grouped_conv_fwd_multiple_abd.hpp, device_grouped_conv_fwd_multiple_abd_xdl_cshuffle.hpp * added header guards for gridwise gemm files: gridwise_gemm_multiple_abd_xdl_cshuffle.hpp and gridwise_gemm_multiple_d_xdl_cshuffle.hpp * fixed issue with numerics header, removed from transform_conv_fwd_to_gemm and added to device_column_to_image_impl, device_grouped_conv_fwd_multiple_abd_xdl_cshuffle, device_grouped_conv_fwd_multiple_abd_xdl_cshuffle_v3, device_image_to_column_impl * replaced standard header usage and added header guards in block to ctile map and gridwise_gemm_pipeline_selector * resolved errors in device_gemm_xdl_splitk_c_shuffle files in regards to replacement of standard headers in previous commit * added replicated functionality for standard header methods in utility files * replaced standard header functionality in threadwise tensor slice transfer files and added header guards in element_wise_operation.hpp * temp fix for namespace error in MIOpen * remove standard header usage in codegen device op * removed standard header usage in elementwise files, resolved namespace errors * formatting fix * changed codegen argument to ON for testing * temporarily removing codegen compiler flag for testing purposes * added codegen flag again, set default to ON * set codegen flag default back to OFF * replaced enable_if_t standard header usage in data_type.hpp * added some debug prints to pinpoint issues in MIOpen * added print outs to debug in MIOpen * removed debug print outs from device op * resolved stdexcept include error * formatting fix * adding includes to new fp8 file to resolve ck::enable_if_t errors * made changes to amd_wave_read_first_lane * updated functionality in type utility file * fixed end of file issue * resovled errors in type utility file, added functionality to array utility file * fixed standard header usage replication in data_type file, resolves error with failing examples on navi3x * formatting fix * replaced standard header usage in amd_ck_fp8 file * added include to random_gen file * removed and replicated standard header usage from data_type and type_convert files for fp8 changes * replicated standard unsigned integer types in random_gen * resolved comments from review: put calls to reinterpret_cast for size_t in header guards * updated/added copyright headers * removed duplicate header * fixed typo in header guard * updated copyright headers --------- Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
159 lines
4.9 KiB
C++
159 lines
4.9 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
#ifndef CK_STATICALLY_INDEXED_ARRAY_MULTI_INDEX_HPP
|
|
#define CK_STATICALLY_INDEXED_ARRAY_MULTI_INDEX_HPP
|
|
|
|
#include "common_header.hpp"
|
|
#include "ck/utility/math_v2.hpp"
|
|
|
|
namespace ck {
|
|
|
|
template <index_t N>
|
|
using MultiIndex = StaticallyIndexedArray<index_t, N>;
|
|
|
|
template <typename... Xs>
|
|
__host__ __device__ constexpr auto make_multi_index(Xs&&... xs)
|
|
{
|
|
return make_statically_indexed_array<index_t>(index_t{xs}...);
|
|
}
|
|
|
|
template <index_t NSize>
|
|
__host__ __device__ constexpr auto make_zero_multi_index()
|
|
{
|
|
return unpack([](auto... xs) { return make_multi_index(xs...); },
|
|
typename uniform_sequence_gen<NSize, 0>::type{});
|
|
}
|
|
|
|
template <typename T>
|
|
__host__ __device__ constexpr auto to_multi_index(const T& x)
|
|
{
|
|
return unpack([](auto... ys) { return make_multi_index(ys...); }, x);
|
|
}
|
|
|
|
// Here should use MultiIndex<NSize>, instead of Tuple<Ys...>, although the former
|
|
// is the alias of the latter. This is because compiler cannot infer the NSize if
|
|
// using MultiIndex<NSize>
|
|
// TODO: how to fix this?
|
|
template <typename... Ys,
|
|
typename X,
|
|
enable_if_t<!ck::is_integral<X>::value && !ck::is_floating_point<X>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator+=(Tuple<Ys...>& y, const X& x)
|
|
{
|
|
static_assert(X::Size() == sizeof...(Ys), "wrong! size not the same");
|
|
constexpr index_t NSize = sizeof...(Ys);
|
|
static_for<0, NSize, 1>{}([&](auto i) { y(i) += x[i]; });
|
|
return y;
|
|
}
|
|
|
|
template <typename... Ys,
|
|
typename X,
|
|
enable_if_t<!ck::is_integral<X>::value && !ck::is_floating_point<X>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator-=(Tuple<Ys...>& y, const X& x)
|
|
{
|
|
static_assert(X::Size() == sizeof...(Ys), "wrong! size not the same");
|
|
constexpr index_t NSize = sizeof...(Ys);
|
|
static_for<0, NSize, 1>{}([&](auto i) { y(i) -= x[i]; });
|
|
return y;
|
|
}
|
|
|
|
template <typename... Xs,
|
|
typename Y,
|
|
enable_if_t<!ck::is_integral<Y>::value && !ck::is_floating_point<Y>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator+(const Tuple<Xs...>& x, const Y& y)
|
|
{
|
|
static_assert(Y::Size() == sizeof...(Xs), "wrong! size not the same");
|
|
constexpr index_t NSize = sizeof...(Xs);
|
|
|
|
Tuple<Xs...> r;
|
|
static_for<0, NSize, 1>{}([&](auto i) { r(i) = x[i] + y[i]; });
|
|
return r;
|
|
}
|
|
|
|
template <typename... Xs,
|
|
typename Y,
|
|
enable_if_t<!ck::is_integral<Y>::value && !ck::is_floating_point<Y>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator-(const Tuple<Xs...>& x, const Y& y)
|
|
{
|
|
static_assert(Y::Size() == sizeof...(Xs), "wrong! size not the same");
|
|
constexpr index_t NSize = sizeof...(Xs);
|
|
|
|
Tuple<Xs...> r;
|
|
static_for<0, NSize, 1>{}([&](auto i) { r(i) = x[i] - y[i]; });
|
|
return r;
|
|
}
|
|
|
|
template <typename... Xs,
|
|
typename Y,
|
|
enable_if_t<!ck::is_integral<Y>::value && !ck::is_floating_point<Y>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator*(const Tuple<Xs...>& x, const Y& y)
|
|
{
|
|
static_assert(Y::Size() == sizeof...(Xs), "wrong! size not the same");
|
|
constexpr index_t NSize = sizeof...(Xs);
|
|
|
|
Tuple<Xs...> r;
|
|
static_for<0, NSize, 1>{}([&](auto i) { r(i) = x[i] * y[i]; });
|
|
return r;
|
|
}
|
|
|
|
// MultiIndex = scalar * MultiIndex
|
|
template <typename... Xs,
|
|
typename Y,
|
|
enable_if_t<ck::is_integral<Y>::value || ck::is_floating_point<Y>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator*(Y a, const Tuple<Xs...>& x)
|
|
{
|
|
constexpr index_t NSize = sizeof...(Xs);
|
|
|
|
Tuple<Xs...> r;
|
|
static_for<0, NSize, 1>{}([&](auto i) { r(i) = a * x[i]; });
|
|
return r;
|
|
}
|
|
|
|
// MultiIndex = MultiIndex * scalar
|
|
template <typename... Xs,
|
|
typename Y,
|
|
enable_if_t<ck::is_integral<Y>::value || ck::is_floating_point<Y>::value, bool> = false>
|
|
__host__ __device__ constexpr auto operator*(const Tuple<Xs...>& x, Y a)
|
|
{
|
|
return a * x;
|
|
}
|
|
|
|
namespace mathext {
|
|
|
|
template <typename... Xs>
|
|
__host__ __device__ constexpr auto exp(const Tuple<Xs...>& x)
|
|
{
|
|
constexpr index_t NSize = sizeof...(Xs);
|
|
|
|
Tuple<Xs...> r;
|
|
static_for<0, NSize, 1>{}([&](auto i) { r(i) = math::exp(x[i]); });
|
|
return r;
|
|
}
|
|
|
|
template <typename... Xs, typename Y>
|
|
__host__ __device__ constexpr auto max(const Tuple<Xs...>& x, const Y& y)
|
|
{
|
|
static_assert(Y::Size() == sizeof...(Xs), "wrong! size not the same");
|
|
constexpr index_t NSize = sizeof...(Xs);
|
|
|
|
Tuple<Xs...> r;
|
|
static_for<0, NSize, 1>{}([&](auto i) { r(i) = math::max(x[i], y[i]); });
|
|
return r;
|
|
}
|
|
|
|
} // namespace mathext
|
|
|
|
template <typename... Xs>
|
|
__host__ __device__ void print_multi_index(const Tuple<Xs...>& x)
|
|
{
|
|
printf("{");
|
|
printf("MultiIndex, ");
|
|
printf("size %d,", index_t{sizeof...(Xs)});
|
|
static_for<0, sizeof...(Xs), 1>{}(
|
|
[&](auto i) { printf("%d ", static_cast<index_t>(x.At(i))); });
|
|
printf("}");
|
|
}
|
|
|
|
} // namespace ck
|
|
#endif
|