/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/reduce_operator_accumulate.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/reduce_operator_accumulate.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/reduce_operator_accumulate.hpp Source File
reduce_operator_accumulate.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
3 
4 #pragma once
5 
7 
8 namespace ck_tile {
9 
12 {
13  template <typename ReduceOp, typename T, typename IndexType>
14  CK_TILE_HOST_DEVICE void operator()(const ReduceOp& reduce_func,
15  T& current_value,
16  IndexType& current_index,
17  const T& new_value,
18  const IndexType& new_index) const
19  {
20  bool changed = false;
21  current_value = reduce_func(current_value, new_value, changed);
22 
23  if(changed)
24  {
25  current_index = new_index;
26  }
27  else if(new_index < current_index)
28  {
29  bool reverse_changed = false;
30  reduce_func(new_value, current_value, reverse_changed);
31 
32  if(!reverse_changed)
33  {
34  current_index = new_index;
35  }
36  }
37  }
38 };
39 
40 struct Accumulate
41 {
42  template <typename ReduceOp, typename T>
44  operator()(const ReduceOp& reduce_func, T& current_value, const T& new_value) const
45  {
46  current_value = reduce_func(current_value, new_value);
47  }
48 };
49 
50 } // namespace ck_tile
#define CK_TILE_HOST_DEVICE
Definition: config.hpp:42
Definition: cluster_descriptor.hpp:13
Definition: reduce_operator_accumulate.hpp:41
CK_TILE_HOST_DEVICE void operator()(const ReduceOp &reduce_func, T &current_value, const T &new_value) const
Definition: reduce_operator_accumulate.hpp:44
Accumulate with index tracking reductions, provides deterministic first occurring index.
Definition: reduce_operator_accumulate.hpp:12
CK_TILE_HOST_DEVICE void operator()(const ReduceOp &reduce_func, T &current_value, IndexType &current_index, const T &new_value, const IndexType &new_index) const
Definition: reduce_operator_accumulate.hpp:14