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

Function fill_split_hidden_axes

src/shape_transform_descriptor.cpp:1125–1176  ·  view source on GitHub ↗

Replace the hidden axis that is split with an axis that is missing

Source from the content-addressed store, hash-verified

1123
1124// Replace the hidden axis that is split with an axis that is missing
1125static void fill_split_hidden_axes(std::map<std::size_t, std::vector<dimension::sub*>>& axes_map,
1126 const std::vector<dimension>& dimensions,
1127 std::size_t rank)
1128{
1129 // Create a reverse map of the subdimensions to the position
1130 std::unordered_map<const dimension::sub*, std::size_t> sub_pos_map;
1131 for_each_subdimension(dimensions,
1132 range(std::numeric_limits<std::size_t>::max()),
1133 [&](const dimension::sub& sub, std::size_t i) { sub_pos_map[&sub] = i; });
1134 for(auto&& p : axes_map)
1135 {
1136 auto axis = p.first;
1137 auto subs = p.second;
1138 if(subs.size() < 2)
1139 continue;
1140 std::sort(subs.begin(), subs.end(), by(std::less<>{}, [](const dimension::sub* s) {
1141 return s->origin_axis();
1142 }));
1143 if(not std::all_of(subs.begin(), subs.end(), [](const dimension::sub* s) {
1144 return s->has_hidden_axis();
1145 }))
1146 continue;
1147
1148 auto it = std::adjacent_find(
1149 subs.begin(), subs.end(), [&](const dimension::sub* s1, const dimension::sub* s2) {
1150 return sub_pos_map.at(s1) + 1 != sub_pos_map.at(s2);
1151 });
1152 if(it != subs.end())
1153 continue;
1154 auto needed_axes = range(axis + 1, axis + subs.size());
1155 auto missing_axes = reverse(range(needed_axes.begin(), find_if(needed_axes, [&](auto a) {
1156 if(a >= rank)
1157 return true;
1158 return contains(axes_map, a);
1159 })));
1160 for_each(missing_axes.begin(),
1161 missing_axes.end(),
1162 subs.rbegin(),
1163 [&](std::size_t axis, dimension::sub* sub) {
1164 sub->hidden_axis = {axis};
1165 axes_map[axis].push_back(sub);
1166 });
1167 // Remove the subdimansions that have a different axis
1168 auto& orig_subs = p.second;
1169 orig_subs.erase(std::remove_if(orig_subs.begin(),
1170 orig_subs.end(),
1171 [&](const dimension::sub* s) {
1172 return s->origin_axis().front() != axis;
1173 }),
1174 orig_subs.end());
1175 }
1176}
1177
1178// If this is scalar, then remove all axes
1179static void remove_scalar_axis(std::vector<dimension>& dimensions)

Callers 1

simplifyMethod · 0.85

Calls 15

for_each_subdimensionFunction · 0.85
containsFunction · 0.85
atMethod · 0.80
eraseMethod · 0.80
frontMethod · 0.80
rangeFunction · 0.50
maxClass · 0.50
sortFunction · 0.50
byFunction · 0.50
all_ofFunction · 0.50
reverseFunction · 0.50
find_ifFunction · 0.50

Tested by

no test coverage detected