| 57 | } |
| 58 | |
| 59 | vectorize vectorize::elements(std::size_t axis, |
| 60 | const std::vector<shape>& inputs, |
| 61 | const std::vector<std::size_t>& sizes) |
| 62 | { |
| 63 | // disable vectorization for fp8 types |
| 64 | if(std::any_of(inputs.begin(), inputs.end(), [&](auto ishape) { |
| 65 | return contains(fp8_types{}.get(), ishape.type()); |
| 66 | })) |
| 67 | return {1, axis}; |
| 68 | if(std::all_of( |
| 69 | inputs.begin(), inputs.end(), [&](const auto& s) { return s.lens()[axis] == 1; })) |
| 70 | return {1, axis}; |
| 71 | std::vector<std::size_t> max_vec_size; |
| 72 | std::transform(inputs.begin(), |
| 73 | inputs.end(), |
| 74 | std::back_inserter(max_vec_size), |
| 75 | [&](const auto& input) -> std::size_t { |
| 76 | auto stride = input.strides()[axis]; |
| 77 | auto len = input.lens()[axis]; |
| 78 | if(not contains({0, 1}, stride)) |
| 79 | return 1; |
| 80 | if(len == 1 and input.elements() > sizes.front()) |
| 81 | return sizes.front(); |
| 82 | auto it = std::find_if(sizes.begin(), sizes.end(), [&](auto vsize) { |
| 83 | // The len is divisible by the size and all the strides are divisible by |
| 84 | // the size |
| 85 | return (len % vsize) == 0 and |
| 86 | std::all_of( |
| 87 | input.strides().begin(), input.strides().end(), [&](auto i) { |
| 88 | return contains({0, 1}, i) or i % vsize == 0; |
| 89 | }); |
| 90 | }); |
| 91 | if(it != sizes.end()) |
| 92 | return *it; |
| 93 | return 1; |
| 94 | }); |
| 95 | return {*std::min_element(max_vec_size.begin(), max_vec_size.end()), axis}; |
| 96 | } |
| 97 | |
| 98 | vectorize vectorize::elements(context& ctx, std::size_t axis, const std::vector<shape>& inputs) |
| 99 | { |
no test coverage detected