mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-14 02:02:46 +00:00
Introduce ck::accumulate_n() (#439)
We can use this template to eliminate duplicated iterator computing
logics. By providing return type to ck::accumulate_n(), we can avoid
type conversion operations.
[ROCm/composable_kernel commit: 730204eed0]
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||
|
||||
#include "ck/library/tensor_operation_instance/gpu/contraction_bilinear.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
using F32 = float;
|
||||
|
||||
@@ -192,20 +193,14 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
float ave_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, true});
|
||||
|
||||
ck::index_t M = std::accumulate(e_ms_ns_lengths.begin(),
|
||||
e_ms_ns_lengths.begin() + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin(), NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N = std::accumulate(e_ms_ns_lengths.begin() + NumDimM,
|
||||
e_ms_ns_lengths.begin() + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin() + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K = std::accumulate(a_ms_ks_lengths.begin() + NumDimM,
|
||||
a_ms_ks_lengths.begin() + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_ms_ks_lengths.begin() + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * M * N * K;
|
||||
std::size_t num_btype = sizeof(ADataType) * M * K + sizeof(BDataType) * K * N +
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||
|
||||
#include "ck/library/tensor_operation_instance/gpu/contraction_scale.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
using F32 = float;
|
||||
|
||||
@@ -178,20 +179,14 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
float ave_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, true});
|
||||
|
||||
ck::index_t M = std::accumulate(e_ms_ns_lengths.begin(),
|
||||
e_ms_ns_lengths.begin() + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin(), NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N = std::accumulate(e_ms_ns_lengths.begin() + NumDimM,
|
||||
e_ms_ns_lengths.begin() + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin() + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K = std::accumulate(a_ms_ks_lengths.begin() + NumDimM,
|
||||
a_ms_ks_lengths.begin() + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_ms_ks_lengths.begin() + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * M * N * K;
|
||||
std::size_t num_btype =
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ck/library/utility/device_memory.hpp"
|
||||
#include "ck/library/utility/host_tensor.hpp"
|
||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
|
||||
|
||||
@@ -317,20 +318,14 @@ int main(int argc, char* argv[])
|
||||
|
||||
float ave_time = invoker.Run(argument, StreamConfig{nullptr, time_kernel});
|
||||
|
||||
std::size_t M = std::accumulate(e_gs_ms_ns_lengths.begin() + NumDimG,
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
std::size_t M = ck::accumulate_n<ck::index_t>(
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG, NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t N = std::accumulate(e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM,
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
std::size_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t K = std::accumulate(a_gs_ms_ks_lengths.begin() + NumDimG + NumDimM,
|
||||
a_gs_ms_ks_lengths.begin() + NumDimG + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
std::size_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_gs_ms_ks_lengths.begin() + NumDimG + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * M * N * K;
|
||||
std::size_t num_btype = sizeof(ADataType) * M * K + sizeof(BDataType) * K * N +
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ck/library/utility/device_memory.hpp"
|
||||
#include "ck/library/utility/host_tensor.hpp"
|
||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
template <ck::index_t... Is>
|
||||
using S = ck::Sequence<Is...>;
|
||||
@@ -317,20 +318,14 @@ int main(int argc, char* argv[])
|
||||
|
||||
float ave_time = invoker.Run(argument, StreamConfig{nullptr, time_kernel});
|
||||
|
||||
ck::index_t M = std::accumulate(e_gs_ms_ns_lengths.begin(),
|
||||
e_gs_ms_ns_lengths.begin() + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M =
|
||||
ck::accumulate_n<ck::index_t>(e_gs_ms_ns_lengths.begin(), NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N = std::accumulate(e_gs_ms_ns_lengths.begin() + NumDimM,
|
||||
e_gs_ms_ns_lengths.begin() + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_gs_ms_ns_lengths.begin() + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K = std::accumulate(a_gs_ms_ks_lengths.begin() + NumDimM,
|
||||
a_gs_ms_ks_lengths.begin() + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_gs_ms_ks_lengths.begin() + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * M * N * K;
|
||||
std::size_t num_btype = sizeof(ADataType) * M * K + sizeof(BDataType) * K * N +
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ck/library/utility/device_memory.hpp"
|
||||
#include "ck/library/utility/host_tensor.hpp"
|
||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
template <ck::index_t... Is>
|
||||
using S = ck::Sequence<Is...>;
|
||||
@@ -358,20 +359,14 @@ int main(int argc, char* argv[])
|
||||
|
||||
float ave_time = invoker.Run(argument, StreamConfig{nullptr, time_kernel});
|
||||
|
||||
ck::index_t M = std::accumulate(e_ms_ns_lengths.begin(),
|
||||
e_ms_ns_lengths.begin() + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M =
|
||||
ck::accumulate_n<ck::index_t>(e_ms_ns_lengths.begin(), NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N = std::accumulate(e_ms_ns_lengths.begin() + NumDimM,
|
||||
e_ms_ns_lengths.begin() + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin() + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K = std::accumulate(a_ms_ks_lengths.begin() + NumDimM,
|
||||
a_ms_ks_lengths.begin() + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_ms_ks_lengths.begin() + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * M * N * K;
|
||||
std::size_t num_btype = sizeof(ADataType) * M * K + sizeof(BDataType) * K * N +
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ck/library/utility/device_memory.hpp"
|
||||
#include "ck/library/utility/host_tensor.hpp"
|
||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
template <ck::index_t... Is>
|
||||
using S = ck::Sequence<Is...>;
|
||||
@@ -341,20 +342,14 @@ int main(int argc, char* argv[])
|
||||
|
||||
float ave_time = invoker.Run(argument, StreamConfig{nullptr, time_kernel});
|
||||
|
||||
ck::index_t M = std::accumulate(e_ms_ns_lengths.begin(),
|
||||
e_ms_ns_lengths.begin() + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M =
|
||||
ck::accumulate_n<ck::index_t>(e_ms_ns_lengths.begin(), NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N = std::accumulate(e_ms_ns_lengths.begin() + NumDimM,
|
||||
e_ms_ns_lengths.begin() + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin() + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K = std::accumulate(a_ms_ks_lengths.begin() + NumDimM,
|
||||
a_ms_ks_lengths.begin() + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_ms_ks_lengths.begin() + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * M * N * K;
|
||||
std::size_t num_btype =
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "ck/library/utility/device_memory.hpp"
|
||||
#include "ck/library/utility/host_tensor.hpp"
|
||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
template <ck::index_t... Is>
|
||||
using S = ck::Sequence<Is...>;
|
||||
@@ -302,20 +303,14 @@ int main(int argc, char* argv[])
|
||||
Tensor<DDataType> d_ms_ns(d_ms_ns_lengths, d_ms_ns_strides);
|
||||
Tensor<EDataType> e_ms_ns_device_result(e_ms_ns_lengths, e_ms_ns_strides);
|
||||
|
||||
ck::index_t M_ = std::accumulate(e_ms_ns_lengths.begin(),
|
||||
e_ms_ns_lengths.begin() + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M_ =
|
||||
ck::accumulate_n<ck::index_t>(e_ms_ns_lengths.begin(), NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N_ = std::accumulate(e_ms_ns_lengths.begin() + NumDimM,
|
||||
e_ms_ns_lengths.begin() + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N_ = ck::accumulate_n<ck::index_t>(
|
||||
e_ms_ns_lengths.begin() + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K_ = std::accumulate(a_ms_ks_lengths.begin() + NumDimM,
|
||||
a_ms_ks_lengths.begin() + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K_ = ck::accumulate_n<ck::index_t>(
|
||||
a_ms_ks_lengths.begin() + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
a_tensors.push_back(a_ms_ks);
|
||||
b_tensors.push_back(b_ns_ks);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ck/library/utility/device_memory.hpp"
|
||||
#include "ck/library/utility/host_tensor.hpp"
|
||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
template <ck::index_t... Is>
|
||||
using S = ck::Sequence<Is...>;
|
||||
@@ -317,25 +318,17 @@ int main(int argc, char* argv[])
|
||||
|
||||
float ave_time = invoker.Run(argument, StreamConfig{nullptr, time_kernel});
|
||||
|
||||
ck::index_t G = std::accumulate(e_gs_ms_ns_lengths.begin(),
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t G =
|
||||
ck::accumulate_n<ck::index_t>(e_gs_ms_ns_lengths.begin(), NumDimG, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t M = std::accumulate(e_gs_ms_ns_lengths.begin() + NumDimG,
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t M = ck::accumulate_n<ck::index_t>(
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG, NumDimM, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t N = std::accumulate(e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM,
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM + NumDimN,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t N = ck::accumulate_n<ck::index_t>(
|
||||
e_gs_ms_ns_lengths.begin() + NumDimG + NumDimM, NumDimN, 1, std::multiplies<>{});
|
||||
|
||||
ck::index_t K = std::accumulate(a_gs_ms_ks_lengths.begin() + NumDimG + NumDimM,
|
||||
a_gs_ms_ks_lengths.begin() + NumDimG + NumDimM + NumDimK,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
ck::index_t K = ck::accumulate_n<ck::index_t>(
|
||||
a_gs_ms_ks_lengths.begin() + NumDimG + NumDimM, NumDimK, 1, std::multiplies<>{});
|
||||
|
||||
std::size_t flop = std::size_t(2) * G * M * N * K;
|
||||
std::size_t num_btype = sizeof(ADataType) * G * M * K + sizeof(BDataType) * G * K * N +
|
||||
|
||||
@@ -120,18 +120,14 @@ bool run_grouped_conv_conv_fwd(bool do_verification,
|
||||
const ck::index_t gemm_batch = a0_g_n_c_wis_lengths[0];
|
||||
|
||||
const ck::index_t gemm0_m_length =
|
||||
e1_g_n_k_wos_lengths[1] * std::accumulate(e1_g_n_k_wos_lengths.begin() + 3,
|
||||
e1_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
e1_g_n_k_wos_lengths[1] *
|
||||
ck::accumulate_n<ck::index_t>(
|
||||
e1_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>{});
|
||||
|
||||
const ck::index_t gemm0_n_length = b0_g_k_c_xs_lengths[1];
|
||||
|
||||
const ck::index_t gemm0_k_length =
|
||||
std::accumulate(b0_g_k_c_xs_lengths.begin() + 2,
|
||||
b0_g_k_c_xs_lengths.begin() + 2 + NDimSpatial + 1,
|
||||
ck::index_t{1},
|
||||
std::multiplies<ck::index_t>{});
|
||||
const ck::index_t gemm0_k_length = ck::accumulate_n<ck::index_t>(
|
||||
b0_g_k_c_xs_lengths.begin() + 2, NDimSpatial + 1, 1, std::multiplies<>{});
|
||||
|
||||
const ck::index_t gemm1_n_length = b1_g_k_c_xs_lengths[1];
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ck/host_utility/device_prop.hpp"
|
||||
#include "ck/host_utility/kernel_launch.hpp"
|
||||
#include "ck/host_utility/io.hpp"
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
namespace ck {
|
||||
namespace tensor_operation {
|
||||
@@ -410,10 +411,9 @@ struct DeviceGroupedConvFwdMultipleDMultipleR_Xdl_CShuffle
|
||||
{
|
||||
const index_t N = r_g_n_wos_lengths[1];
|
||||
|
||||
const index_t NHoWo = N * std::accumulate(r_g_n_wos_lengths.begin() + 2,
|
||||
r_g_n_wos_lengths.begin() + 2 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
r_g_n_wos_lengths.begin() + 2, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto r_grid_desc_mraw = make_naive_tensor_descriptor_packed(make_tuple(NHoWo));
|
||||
|
||||
@@ -435,10 +435,9 @@ struct DeviceGroupedConvFwdMultipleDMultipleR_Xdl_CShuffle
|
||||
|
||||
const index_t WoStride = r_g_n_wos_strides[NDimSpatial + 2];
|
||||
|
||||
const index_t NHoWo = N * std::accumulate(r_g_n_wos_lengths.begin() + 2,
|
||||
r_g_n_wos_lengths.begin() + 2 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
r_g_n_wos_lengths.begin() + 2, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto r_grid_desc_mraw =
|
||||
make_naive_tensor_descriptor(make_tuple(NHoWo), make_tuple(WoStride));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
#include "ck/utility/common_header.hpp"
|
||||
#include "ck/tensor_description/tensor_descriptor.hpp"
|
||||
#include "ck/tensor_description/tensor_descriptor_helper.hpp"
|
||||
@@ -47,10 +48,9 @@ struct TransformConvFwdToGemm
|
||||
if constexpr(ConvForwardSpecialization ==
|
||||
device::ConvolutionForwardSpecialization::Filter1x1Stride1Pad0)
|
||||
{
|
||||
const index_t NWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto in_gemmm_gemmk_desc =
|
||||
make_naive_tensor_descriptor_packed(make_tuple(NWo, C));
|
||||
@@ -146,10 +146,9 @@ struct TransformConvFwdToGemm
|
||||
if constexpr(ConvForwardSpecialization ==
|
||||
device::ConvolutionForwardSpecialization::Filter1x1Stride1Pad0)
|
||||
{
|
||||
const index_t NHoWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto in_gemmm_gemmk_desc =
|
||||
make_naive_tensor_descriptor_packed(make_tuple(NHoWo, C));
|
||||
@@ -262,10 +261,8 @@ struct TransformConvFwdToGemm
|
||||
device::ConvolutionForwardSpecialization::Filter1x1Stride1Pad0)
|
||||
{
|
||||
const index_t NDoHoWo =
|
||||
N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto in_gemmm_gemmk_desc =
|
||||
make_naive_tensor_descriptor_packed(make_tuple(NDoHoWo, C));
|
||||
@@ -390,10 +387,9 @@ struct TransformConvFwdToGemm
|
||||
if constexpr(ConvForwardSpecialization ==
|
||||
device::ConvolutionForwardSpecialization::Filter1x1Stride1Pad0)
|
||||
{
|
||||
const index_t NHoWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
// This is different
|
||||
const index_t WiStride = a_g_n_c_wis_strides[2 + NDimSpatial];
|
||||
@@ -506,10 +502,9 @@ struct TransformConvFwdToGemm
|
||||
if constexpr(ConvForwardSpecialization ==
|
||||
device::ConvolutionForwardSpecialization::Filter1x1Stride1Pad0)
|
||||
{
|
||||
const index_t NHoWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
// This is different
|
||||
const index_t WiStride = a_g_n_c_wis_strides[2 + NDimSpatial];
|
||||
@@ -639,10 +634,8 @@ struct TransformConvFwdToGemm
|
||||
device::ConvolutionForwardSpecialization::Filter1x1Stride1Pad0)
|
||||
{
|
||||
const index_t NDoHoWo =
|
||||
N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
// This is different
|
||||
const index_t WiStride = a_g_n_c_wis_strides[2 + NDimSpatial];
|
||||
@@ -768,10 +761,8 @@ struct TransformConvFwdToGemm
|
||||
const index_t K = b_g_k_c_xs_lengths[1];
|
||||
const index_t C = b_g_k_c_xs_lengths[2];
|
||||
|
||||
const index_t YX = std::accumulate(b_g_k_c_xs_lengths.begin() + 3,
|
||||
b_g_k_c_xs_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t YX = ck::accumulate_n<index_t>(
|
||||
b_g_k_c_xs_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto wei_gemmn_gemmk_desc =
|
||||
make_naive_tensor_descriptor_packed(make_tuple(K, YX * C));
|
||||
@@ -794,10 +785,8 @@ struct TransformConvFwdToGemm
|
||||
const index_t K = b_g_k_c_xs_lengths[1];
|
||||
const index_t C = b_g_k_c_xs_lengths[2];
|
||||
|
||||
const index_t YX = std::accumulate(b_g_k_c_xs_lengths.begin() + 3,
|
||||
b_g_k_c_xs_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t YX = ck::accumulate_n<index_t>(
|
||||
b_g_k_c_xs_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const index_t KStride = b_g_k_c_xs_strides[1];
|
||||
const index_t XStride = b_g_k_c_xs_strides[2 + NDimSpatial];
|
||||
@@ -827,10 +816,9 @@ struct TransformConvFwdToGemm
|
||||
const index_t N = c_g_n_k_wos_lengths[1];
|
||||
const index_t K = c_g_n_k_wos_lengths[2];
|
||||
|
||||
const index_t NHoWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto out_gemmm_gemmn_desc = make_naive_tensor_descriptor_packed(make_tuple(NHoWo, K));
|
||||
|
||||
@@ -855,10 +843,9 @@ struct TransformConvFwdToGemm
|
||||
const auto KStride = I1;
|
||||
const index_t WoStride = c_g_n_k_wos_strides[NDimSpatial + 2];
|
||||
|
||||
const index_t NHoWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto out_gemmm_gemmn_desc =
|
||||
make_naive_tensor_descriptor(make_tuple(NHoWo, K), make_tuple(WoStride, KStride));
|
||||
@@ -878,10 +865,9 @@ struct TransformConvFwdToGemm
|
||||
const index_t N = c_g_n_k_wos_lengths[1];
|
||||
const index_t K = c_g_n_k_wos_lengths[2];
|
||||
|
||||
const index_t NHoWo = N * std::accumulate(c_g_n_k_wos_lengths.begin() + 3,
|
||||
c_g_n_k_wos_lengths.begin() + 3 + NDimSpatial,
|
||||
index_t{1},
|
||||
std::multiplies<index_t>());
|
||||
const index_t NHoWo =
|
||||
N * ck::accumulate_n<index_t>(
|
||||
c_g_n_k_wos_lengths.begin() + 3, NDimSpatial, 1, std::multiplies<>());
|
||||
|
||||
const auto out_gemmm_gemmn_desc =
|
||||
make_naive_tensor_descriptor(make_tuple(NHoWo, K), make_tuple(I0, I1));
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "ck/ck.hpp"
|
||||
|
||||
#include "ck/library/utility/numeric.hpp"
|
||||
|
||||
namespace ck {
|
||||
namespace utils {
|
||||
namespace conv {
|
||||
@@ -55,10 +57,8 @@ struct ConvParam
|
||||
// sizeof(InDataType) * (G * N * C * <input spatial lengths product>) +
|
||||
return sizeof(InDataType) *
|
||||
(G_ * N_ * C_ *
|
||||
std::accumulate(std::begin(input_spatial_lengths_),
|
||||
std::begin(input_spatial_lengths_) + num_dim_spatial_,
|
||||
static_cast<std::size_t>(1),
|
||||
std::multiplies<std::size_t>()));
|
||||
ck::accumulate_n<std::size_t>(
|
||||
std::begin(input_spatial_lengths_), num_dim_spatial_, 1, std::multiplies<>()));
|
||||
}
|
||||
|
||||
template <typename WeiDataType>
|
||||
@@ -67,10 +67,8 @@ struct ConvParam
|
||||
// sizeof(WeiDataType) * (G * K * C * <filter spatial lengths product>) +
|
||||
return sizeof(WeiDataType) *
|
||||
(G_ * K_ * C_ *
|
||||
std::accumulate(std::begin(filter_spatial_lengths_),
|
||||
std::begin(filter_spatial_lengths_) + num_dim_spatial_,
|
||||
static_cast<std::size_t>(1),
|
||||
std::multiplies<std::size_t>()));
|
||||
ck::accumulate_n<std::size_t>(
|
||||
std::begin(filter_spatial_lengths_), num_dim_spatial_, 1, std::multiplies<>()));
|
||||
}
|
||||
|
||||
template <typename OutDataType>
|
||||
|
||||
16
library/include/ck/library/utility/numeric.hpp
Normal file
16
library/include/ck/library/utility/numeric.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
|
||||
namespace ck {
|
||||
template <typename T, typename ForwardIterator, typename Size, typename BinaryOperation>
|
||||
auto accumulate_n(ForwardIterator first, Size count, T init, BinaryOperation op)
|
||||
-> decltype(std::accumulate(first, std::next(first, count), init, op))
|
||||
{
|
||||
return std::accumulate(first, std::next(first, count), init, op);
|
||||
}
|
||||
} // namespace ck
|
||||
@@ -72,14 +72,10 @@ std::size_t ConvParam::GetFlops() const
|
||||
{
|
||||
// 2 * G * N * K * C * <output spatial lengths product> * <filter spatial lengths product>
|
||||
return static_cast<std::size_t>(2) * G_ * N_ * K_ * C_ *
|
||||
std::accumulate(std::begin(output_spatial_lengths_),
|
||||
std::begin(output_spatial_lengths_) + num_dim_spatial_,
|
||||
static_cast<std::size_t>(1),
|
||||
std::multiplies<std::size_t>()) *
|
||||
std::accumulate(std::begin(filter_spatial_lengths_),
|
||||
std::begin(filter_spatial_lengths_) + num_dim_spatial_,
|
||||
static_cast<std::size_t>(1),
|
||||
std::multiplies<std::size_t>());
|
||||
ck::accumulate_n<std::size_t>(
|
||||
std::begin(output_spatial_lengths_), num_dim_spatial_, 1, std::multiplies<>()) *
|
||||
ck::accumulate_n<std::size_t>(
|
||||
std::begin(filter_spatial_lengths_), num_dim_spatial_, 1, std::multiplies<>());
|
||||
}
|
||||
|
||||
std::string get_conv_param_parser_helper_msg()
|
||||
|
||||
Reference in New Issue
Block a user