* Assumptions: * Dimensions to pad start from the third dimension (index 2). * Called by compute_shape_op() with the shape of the first input. */
| 186 | * Called by compute_shape_op() with the shape of the first input. |
| 187 | */ |
| 188 | bool 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 |
no test coverage detected