convolution_host_tensor_descriptor_helper.hpp Source File

convolution_host_tensor_descriptor_helper.hpp Source File#

Composable Kernel: convolution_host_tensor_descriptor_helper.hpp Source File
tile/host/convolution_host_tensor_descriptor_helper.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
9
10namespace ck_tile {
11namespace conv {
12namespace detail {
13
14template <typename OldLayout>
16{
18
20 {
21 return {0, 1, 2, 3};
22 }
24 {
25 return {0, 1, 2, 3, 4};
26 }
28 {
29 return {0, 1, 2, 3, 4, 5};
30 }
32 {
33 return {0, 1, 3, 2};
34 }
36 {
37 return {0, 1, 4, 2, 3};
38 }
40 {
41 return {0, 1, 5, 2, 3, 4};
42 }
44 {
45 return {2, 0, 3, 1};
46 }
48 {
49 return {3, 0, 4, 1, 2};
50 }
52 {
53 return {4, 0, 5, 1, 2, 3};
54 }
55 else
56 {
57 printf("%s\n", __func__);
58 throw std::runtime_error("wrong! unsupported layout");
59 }
60}
61
62} // namespace detail
63
64// make tensor descriptor for packed input tensor, and order the dimension in the order of GNCHW
65// regardless of physical layout
66template <typename InLayout>
69{
71
72 std::vector<std::size_t> physical_lengths;
73
75 {
76 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.G_),
77 static_cast<std::size_t>(param.N_),
78 static_cast<std::size_t>(param.C_)};
79
80 physical_lengths.insert(physical_lengths.end(),
81 param.input_spatial_lengths_.begin(),
82 param.input_spatial_lengths_.begin() + param.num_dim_spatial_);
83 }
85 {
86 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.G_),
87 static_cast<std::size_t>(param.N_),
88 static_cast<std::size_t>(param.C_)};
89
90 physical_lengths.insert(physical_lengths.begin() + 2,
91 param.input_spatial_lengths_.begin(),
92 param.input_spatial_lengths_.begin() + param.num_dim_spatial_);
93 }
95 {
96 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.N_),
97 static_cast<std::size_t>(param.G_),
98 static_cast<std::size_t>(param.C_)};
99
100 physical_lengths.insert(physical_lengths.begin() + 1,
101 param.input_spatial_lengths_.begin(),
102 param.input_spatial_lengths_.begin() + param.num_dim_spatial_);
103 }
104 else
105 {
106 printf("%s\n", __func__);
107 printf("%s\n", InLayout::name);
108 throw std::runtime_error("wrong! unsupported layout");
109 }
110
112 HostTensorDescriptor(physical_lengths),
114}
115
116// make tensor descriptor for packed weight tensor, and order the dimension in the order of GKCYX
117// regardless of physical layout
118template <typename WeiLayout>
121{
123
124 std::vector<std::size_t> physical_lengths;
125
127 {
128 if(param.G_ != 1)
129 {
130 throw std::runtime_error("wrong! G != 1");
131 }
132
133 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.K_),
134 static_cast<std::size_t>(param.C_)};
135
136 physical_lengths.insert(physical_lengths.end(),
137 param.filter_spatial_lengths_.begin(),
138 param.filter_spatial_lengths_.begin() + param.num_dim_spatial_);
139 }
141 {
142 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.G_),
143 static_cast<std::size_t>(param.K_),
144 static_cast<std::size_t>(param.C_)};
145
146 physical_lengths.insert(physical_lengths.end(),
147 param.filter_spatial_lengths_.begin(),
148 param.filter_spatial_lengths_.begin() + param.num_dim_spatial_);
149 }
151 {
152 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.G_),
153 static_cast<std::size_t>(param.K_),
154 static_cast<std::size_t>(param.C_)};
155
156 physical_lengths.insert(physical_lengths.begin() + 2,
157 param.filter_spatial_lengths_.begin(),
158 param.filter_spatial_lengths_.begin() + param.num_dim_spatial_);
159 }
161 {
162 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.K_),
163 static_cast<std::size_t>(param.G_),
164 static_cast<std::size_t>(param.C_)};
165
166 physical_lengths.insert(physical_lengths.begin() + 1,
167 param.filter_spatial_lengths_.begin(),
168 param.filter_spatial_lengths_.begin() + param.num_dim_spatial_);
169 }
170 else
171 {
172 printf("%s\n", __func__);
173 printf("%s\n", WeiLayout::name);
174 throw std::runtime_error("wrong! unsupported layout");
175 }
176
178 HostTensorDescriptor(physical_lengths),
180}
181
182// make tensor descriptor for packed output tensor, and order the dimension in the order of GNKHW
183// regardless of physical layout
184template <typename OutLayout>
187{
189
190 std::vector<std::size_t> physical_lengths;
191
193 {
194 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.G_),
195 static_cast<std::size_t>(param.N_),
196 static_cast<std::size_t>(param.K_)};
197
198 physical_lengths.insert(physical_lengths.end(),
199 param.output_spatial_lengths_.begin(),
200 param.output_spatial_lengths_.begin() + param.num_dim_spatial_);
201 }
202 // separate from legacy code above
204 {
205 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.G_),
206 static_cast<std::size_t>(param.N_),
207 static_cast<std::size_t>(param.K_)};
208
209 physical_lengths.insert(physical_lengths.begin() + 2,
210 param.output_spatial_lengths_.begin(),
211 param.output_spatial_lengths_.begin() + param.num_dim_spatial_);
212 }
214 {
215 physical_lengths = std::vector<std::size_t>{static_cast<std::size_t>(param.N_),
216 static_cast<std::size_t>(param.G_),
217 static_cast<std::size_t>(param.K_)};
218
219 physical_lengths.insert(physical_lengths.begin() + 1,
220 param.output_spatial_lengths_.begin(),
221 param.output_spatial_lengths_.begin() + param.num_dim_spatial_);
222 }
223 else
224 {
225 printf("%s\n", __func__);
226 printf("%s\n", OutLayout::name);
227 throw std::runtime_error("wrong! unsupported layout");
228 }
229
231 HostTensorDescriptor(physical_lengths),
233}
234
235} // namespace conv
236} // namespace ck_tile
#define CK_TILE_HOST
Definition config.hpp:40
Definition tile/host/convolution_host_tensor_descriptor_helper.hpp:12
CK_TILE_HOST std::vector< std::size_t > get_layout_transpose_gnchw_to_old()
Definition tile/host/convolution_host_tensor_descriptor_helper.hpp:15
Definition tile/host/convolution_host_tensor_descriptor_helper.hpp:11
CK_TILE_HOST HostTensorDescriptor make_weight_host_tensor_descriptor_g_k_c_xs_packed(const ck_tile::conv::ConvParam &param)
Definition tile/host/convolution_host_tensor_descriptor_helper.hpp:120
CK_TILE_HOST HostTensorDescriptor make_input_host_tensor_descriptor_g_n_c_wis_packed(const ck_tile::conv::ConvParam &param)
Definition tile/host/convolution_host_tensor_descriptor_helper.hpp:68
CK_TILE_HOST HostTensorDescriptor make_output_host_tensor_descriptor_g_n_k_wos_packed(const ck_tile::conv::ConvParam &param)
Definition tile/host/convolution_host_tensor_descriptor_helper.hpp:186
Definition tile/ops/common/tensor_layout.hpp:27
Definition tile/core/algorithm/cluster_descriptor.hpp:13
CK_TILE_HOST HostTensorDescriptor transpose_host_tensor_descriptor_given_new2old(const HostTensorDescriptor &a, const New2Old &new2old)
Definition tile/host/host_tensor.hpp:259
Descriptor for tensors in host memory.
Definition tile/host/host_tensor.hpp:102
Definition tile/host/convolution_parameter.hpp:15
std::vector< ck_tile::long_index_t > input_spatial_lengths_
Definition tile/host/convolution_parameter.hpp:130
ck_tile::long_index_t K_
Definition tile/host/convolution_parameter.hpp:126
ck_tile::long_index_t num_dim_spatial_
Definition tile/host/convolution_parameter.hpp:123
std::vector< ck_tile::long_index_t > output_spatial_lengths_
Definition tile/host/convolution_parameter.hpp:131
ck_tile::long_index_t G_
Definition tile/host/convolution_parameter.hpp:124
std::vector< ck_tile::long_index_t > filter_spatial_lengths_
Definition tile/host/convolution_parameter.hpp:129
ck_tile::long_index_t C_
Definition tile/host/convolution_parameter.hpp:127
ck_tile::long_index_t N_
Definition tile/host/convolution_parameter.hpp:125
Definition type_traits.hpp:115