verify_onnx.cpp 1.43 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
#include <migraph/cpu/cpu_target.hpp>
Paul's avatar
Paul committed
5
6
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
Paul's avatar
Paul committed
7
#include <migraph/generate.hpp>
Paul's avatar
Paul committed
8
#include <miopen/miopen.h>
Paul's avatar
Paul committed
9
#include <migraph/gpu/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
16
17
18
19
20
    migraph::program::parameter_map m;
    for(auto&& x : p.get_parameter_shapes())
    {
        m[x.first] = migraph::generate_argument(x.second);
    }
    auto out = p.eval(m);
Paul's avatar
Paul committed
21
22
23
24
    std::cout << p << std::endl;
    return out;
}

Paul's avatar
Paul committed
25
migraph::argument run_gpu(std::string file)
Paul's avatar
Paul committed
26
{
Paul's avatar
Paul committed
27
    auto p = migraph::parse_onnx(file);
Paul's avatar
Paul committed
28
    p.compile(migraph::gpu::target{});
Paul's avatar
Paul committed
29

Paul's avatar
Paul committed
30
31
32
33
34
35
    migraph::program::parameter_map m;
    for(auto&& x : p.get_parameter_shapes())
    {
        m[x.first] = migraph::gpu::to_gpu(migraph::generate_argument(x.second));
    }
    auto out = migraph::gpu::from_gpu(p.eval(m));
Paul's avatar
Paul committed
36
    std::cout << p << std::endl;
Paul's avatar
Paul committed
37
    return migraph::gpu::from_gpu(out);
Paul's avatar
Paul committed
38
39
40
41
42
43
44
45
46
}

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
47
48
49
50
51
        if(x == y)
        {
            std::cout << "Passed" << std::endl;
        }
        else
Paul's avatar
Paul committed
52
53
54
55
56
57
58
        {
            std::cout << "Not equal" << std::endl;
            std::cout << x << std::endl;
            std::cout << y << std::endl;
        }
    }
}