"src/turbomind/kernels/decoder_masked_multihead_attention.h" did not exist on "9efcac38af58b7247e205c47efe090b4c6ec7574"
shape_for_each.hpp 1018 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_SHAPE_FOR_EACH_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_SHAPE_FOR_EACH_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
#include <migraph/shape.hpp>
5
#include <migraph/config.hpp>
Paul's avatar
Paul committed
6
7
#include <algorithm>

8
namespace migraph { inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
9

Paul's avatar
Paul committed
10
template <class F>
Paul's avatar
Paul committed
11
void shape_for_each(const migraph::shape& s, F f)
Paul's avatar
Paul committed
12
13
14
15
{
    // Ensure calls to f use const ref to vector
    auto call = [&f](const std::vector<std::size_t>& i) { f(i); };
    std::vector<std::size_t> indices(s.lens().size());
Paul's avatar
Paul committed
16
17
    for(std::size_t i = 0; i < s.elements(); i++)
    {
Paul's avatar
Paul committed
18
        std::transform(s.strides().begin(),
Paul's avatar
Paul committed
19
20
21
                       s.strides().end(),
                       s.lens().begin(),
                       indices.begin(),
Paul's avatar
Paul committed
22
23
24
25
                       [&](std::size_t stride, std::size_t len) {
                           assert(len > 0 and stride > 0);
                           return (i / stride) % len;
                       });
Paul's avatar
Paul committed
26
27
28
29
        call(indices);
    }
}

30
} // inline namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
31
} // namespace migraph
Paul's avatar
Paul committed
32
33

#endif