perf_onnx.cpp 1.06 KB
Newer Older
Paul's avatar
Paul committed
1

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

Paul's avatar
Paul committed
4
5
6
7
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/verify.hpp>
Paul's avatar
Paul committed
8

Paul's avatar
Paul committed
9
migraphx::program::parameter_map create_param_map(const migraphx::program& p, bool gpu = true)
Paul's avatar
Paul committed
10
{
Paul's avatar
Paul committed
11
    migraphx::program::parameter_map m;
Paul's avatar
Paul committed
12
13
14
    for(auto&& x : p.get_parameter_shapes())
    {
        if(gpu)
Paul's avatar
Paul committed
15
            m[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second));
Paul's avatar
Paul committed
16
        else
Paul's avatar
Paul committed
17
            m[x.first] = migraphx::generate_argument(x.second);
Paul's avatar
Paul committed
18
19
20
21
22
23
24
25
26
    }
    return m;
}

int main(int argc, char const* argv[])
{
    if(argc > 1)
    {
        std::string file = argv[1];
Paul's avatar
Paul committed
27
        std::size_t n    = argc > 2 ? std::stoul(argv[2]) : 50;
Paul's avatar
Paul committed
28
        auto p           = migraphx::parse_onnx(file);
Paul's avatar
Paul committed
29
        std::cout << "Compiling ... " << std::endl;
Paul's avatar
Paul committed
30
        p.compile(migraphx::gpu::target{});
31
        std::cout << "Allocating params ... " << std::endl;
Paul's avatar
Paul committed
32
        auto m = create_param_map(p);
Paul's avatar
Paul committed
33
        std::cout << "Running performance report ... " << std::endl;
Paul's avatar
Paul committed
34
        p.perf_report(std::cout, n, m);
Paul's avatar
Paul committed
35
36
    }
}