indexing_adaptor.hpp Source File

indexing_adaptor.hpp Source File#

Composable Kernel: indexing_adaptor.hpp Source File
indexing_adaptor.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
11
12namespace ck_tile {
13// pre-defined indexing adaptor used for indexing(scatter/gather)
14
15// this version cache the index inside thread register(which is also prefered in real senario)
16// however it's user's responsibility that each thread only provide one indexing, which means
17// move coordinate will not change on this dim
18template <typename IndexingType>
20{
21
23 CK_TILE_HOST_DEVICE constexpr indexing_adaptor_onshot_cached(const IndexingType& idx)
24 : cached_idx_(idx)
25 {
26 }
27 IndexingType cached_idx_;
28
29 template <typename LowIdx, typename UpIdx>
30 CK_TILE_HOST_DEVICE constexpr void calculate_lower_index(LowIdx& idx_low,
31 const UpIdx& /*idx_up*/) const
32 {
33 static_assert(LowIdx::size() == 1 && UpIdx::size() == 1,
34 "wrong! inconsistent # of dimension");
35
36 idx_low(number<0>{}) = cached_idx_;
37 }
38
39 template <typename LowIdxDiff, typename UpIdxDiff, typename LowIdx, typename UpIdx>
40 CK_TILE_HOST_DEVICE void update_lower_index(LowIdxDiff& idx_diff_low,
41 const UpIdxDiff& idx_diff_up,
42 LowIdx& /*idx_low*/,
43 const UpIdx& /*idx_up*/) const
44 {
45 // TODO: nonthing changed here
46 static_assert(LowIdxDiff::size() == 1 && UpIdxDiff::size() == 1 && LowIdx::size() == 1 &&
47 UpIdx::size() == 1,
48 "wrong! inconsistent # of dimension");
49
50 idx_diff_low(number<0>{}) = idx_diff_up[number<0>{}];
51
52 // pass the diff to lower, but not changing the actually index
53 }
54
59};
60} // namespace ck_tile
#define CK_TILE_HOST_DEVICE
Definition config.hpp:42
Definition tile/core/algorithm/cluster_descriptor.hpp:13
constant< v > number
Definition tile/core/numeric/integral_constant.hpp:37
static constexpr bool value
Definition type_traits.hpp:77
CK_TILE_HOST_DEVICE constexpr indexing_adaptor_onshot_cached(const IndexingType &idx)
Definition indexing_adaptor.hpp:23
static CK_TILE_HOST_DEVICE constexpr bool is_known_at_compile_time()
Definition indexing_adaptor.hpp:55
CK_TILE_HOST_DEVICE constexpr indexing_adaptor_onshot_cached()=default
CK_TILE_HOST_DEVICE constexpr void calculate_lower_index(LowIdx &idx_low, const UpIdx &) const
Definition indexing_adaptor.hpp:30
IndexingType cached_idx_
Definition indexing_adaptor.hpp:27
CK_TILE_HOST_DEVICE void update_lower_index(LowIdxDiff &idx_diff_low, const UpIdxDiff &idx_diff_up, LowIdx &, const UpIdx &) const
Definition indexing_adaptor.hpp:40