verify_onnx.cpp 1.58 KB
Newer Older
Paul's avatar
Paul committed
1

Paul's avatar
Paul committed
2
#include <migraph/onnx.hpp>
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
5
6
7
#include <migraph/cpu/cpu_target.hpp>
#include <migraph/miopen/miopen_target.hpp>
#include <migraph/miopen/hip.hpp>
#include <migraph/generate.hpp>
Paul's avatar
Paul committed
8
#include <miopen/miopen.h>
Paul's avatar
Paul committed
9
#include <migraph/miopen/miopen.hpp>
Paul's avatar
Paul committed
10

Paul's avatar
Paul committed
11
migraph::argument run_cpu(std::string file)
Paul's avatar
Paul committed
12
{
Paul's avatar
Paul committed
13
14
    auto p = migraph::parse_onnx(file);
    p.compile(migraph::cpu::cpu_target{});
Paul's avatar
Paul committed
15
    auto s      = p.get_parameter_shape("Input3");
Paul's avatar
Paul committed
16
    auto input3 = migraph::generate_argument(s);
Paul's avatar
Paul committed
17
18
19
20
21
    auto out    = p.eval({{"Input3", input3}});
    std::cout << p << std::endl;
    return out;
}

Paul's avatar
Paul committed
22
migraph::argument run_gpu(std::string file)
Paul's avatar
Paul committed
23
{
Paul's avatar
Paul committed
24
25
    auto p = migraph::parse_onnx(file);
    p.compile(migraph::cpu::cpu_target{});
Paul's avatar
Paul committed
26
    auto s      = p.get_parameter_shape("Input3");
Paul's avatar
Paul committed
27
    auto input3 = migraph::miopen::to_gpu(migraph::generate_argument(s));
Paul's avatar
Paul committed
28

Paul's avatar
Paul committed
29
30
    auto output =
        migraph::miopen::to_gpu(migraph::generate_argument(p.get_parameter_shape("output")));
Paul's avatar
Paul committed
31
    auto handle = migraph::miopen::make_obj<migraph::miopen::miopen_handle>(&miopenCreate);
Paul's avatar
Paul committed
32

Paul's avatar
Paul committed
33
    auto out = p.eval({{"Input3", input3}, {"output", output}});
Paul's avatar
Paul committed
34
    std::cout << p << std::endl;
Paul's avatar
Paul committed
35
    return migraph::miopen::from_gpu(out);
Paul's avatar
Paul committed
36
37
38
39
40
41
42
43
44
}

int main(int argc, char const* argv[])
{
    if(argc > 1)
    {
        std::string file = argv[1];
        auto x           = run_cpu(file);
        auto y           = run_gpu(file);
Paul's avatar
Paul committed
45
46
47
48
49
        if(x == y)
        {
            std::cout << "Passed" << std::endl;
        }
        else
Paul's avatar
Paul committed
50
51
52
53
54
55
56
        {
            std::cout << "Not equal" << std::endl;
            std::cout << x << std::endl;
            std::cout << y << std::endl;
        }
    }
}