convert.hpp 1.34 KB
Newer Older
1
2
#ifndef MIGRAPHX_GUARD_OPERATORS_CONVERT_HPP
#define MIGRAPHX_GUARD_OPERATORS_CONVERT_HPP
Shucai Xiao's avatar
Shucai Xiao committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <array>
#include <migraphx/op/binary.hpp>
#include <migraphx/operation.hpp>
#include <migraphx/check_shapes.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/streamutils.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <cmath>
#include <utility>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace op {

20
struct convert
Shucai Xiao's avatar
Shucai Xiao committed
21
{
22
23
24
25
26
27
28
29
    shape::type_t targe_type = shape::half_type;

    template <class Self, class F>
    static auto reflect(Self& self, F f)
    {
        return pack(f(self.targe_type, "target_type"));
    }

30
    std::string name() const { return "convert"; }
Shucai Xiao's avatar
Shucai Xiao committed
31
32
33
    shape compute_shape(std::vector<shape> inputs) const
    {
        check_shapes{inputs, *this}.has(1);
34
        return {targe_type, inputs.front().lens(), inputs.front().strides()};
Shucai Xiao's avatar
Shucai Xiao committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    }

    argument compute(const shape& output_shape, std::vector<argument> args) const
    {
        argument result{output_shape};
        result.visit([&](auto output) {
            args.front().visit(
                [&](auto input) { std::copy(input.begin(), input.end(), output.begin()); });
        });

        return result;
    }
};

} // namespace op
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx

#endif