MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / normalize_attributes

Function normalize_attributes

src/normalize_attributes.cpp:188–263  ·  view source on GitHub ↗

* Assumptions: * Dimensions to pad start from the third dimension (index 2). * Called by compute_shape_op() with the shape of the first input. */

Source from the content-addressed store, hash-verified

186 * Called by compute_shape_op() with the shape of the first input.
187 */
188bool normalize_attributes(operation& op, const shape& input_shape)
189{
190 bool tuned = false;
191 auto attrs = op.attributes();
192 auto val = op.to_value();
193 if(attrs.contains("normalize_padding"))
194 {
195 bool use_auto_padding =
196 (val.contains("padding_mode") and
197 (val.at("padding_mode").to<int>() != migraphx::op::padding_mode_t::default_));
198 if(not use_auto_padding)
199 {
200 auto padding = val.at(attrs.at("normalize_padding").to<std::string>());
201 auto padding_size = padding.size();
202 auto padding_start = 2;
203 if(padding_size == 2 * (input_shape.ndim() - padding_start))
204 tuned = true;
205 else if(padding_size != (input_shape.ndim() - padding_start))
206 {
207 MIGRAPHX_THROW("normalize_attributes: inconsistent padding vector size ");
208 }
209 else
210 {
211 auto result = tune_pad_attribute(padding);
212 val["padding"] = result;
213 op.from_value(val);
214 tuned = true;
215 }
216 }
217 }
218 if(not attrs.contains("normalize_axes"))
219 {
220 return tuned;
221 }
222
223 auto attr_v = attrs.at("normalize_axes").without_key();
224 for(const auto& rv : attr_v)
225 {
226 const auto& key = rv.get_key();
227 if(val.contains(key))
228 {
229 auto message = [&] { return op.name() + ": " + key + ": "; };
230 auto vv = val.at(key).without_key();
231 if(vv.is_array())
232 {
233 std::vector<int64_t> axes;
234 if(val.contains("axes"))
235 {
236 axes = val.at("axes").without_key().to_vector<int64_t>();
237 }
238 auto vec = vv.to_vector<int64_t>();
239 auto result = tune_attribute(vec, axes, rv.without_key(), input_shape, message);
240 val[key] = result;
241 op.from_value(val);
242 val = op.to_value();
243 tuned = true;
244 }
245 else

Callers 4

compute_shape_opFunction · 0.85
normalized_operatorMethod · 0.85
applyMethod · 0.85
compute_shape_opFunction · 0.85

Calls 13

tune_pad_attributeFunction · 0.85
tune_attributeFunction · 0.85
atMethod · 0.80
ndimMethod · 0.80
without_keyMethod · 0.80
is_arrayMethod · 0.80
frontMethod · 0.80
attributesMethod · 0.45
to_valueMethod · 0.45
containsMethod · 0.45
sizeMethod · 0.45
from_valueMethod · 0.45

Tested by

no test coverage detected