stream_execution.cpp 1.74 KB
Newer Older
mei-ye's avatar
mei-ye committed
1
2
3
4
5
6
7
8
9
10
#include <test.hpp>
#include <basic_ops.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/verify_args.hpp>

11
migraphx::program create_program()
mei-ye's avatar
mei-ye committed
12
13
14
15
16
17
18
{
    migraphx::program p;
    auto in1 = p.add_parameter("0", migraphx::shape{migraphx::shape::float_type, {32, 64, 1, 1}});
    auto in2 = p.add_parameter("1", migraphx::shape{migraphx::shape::float_type, {64, 64, 1, 1}});
    auto p1  = p.add_instruction(migraphx::op::convolution{}, in1, in2);
    auto in3 = p.add_parameter("2", migraphx::shape{migraphx::shape::float_type, {64, 64, 1, 1}});
    auto p2  = p.add_instruction(migraphx::op::convolution{}, in1, in3);
19
    p.add_instruction(migraphx::op::concat{1}, p1, p2);
mei-ye's avatar
mei-ye committed
20
21
22
23
24
25
    return p;
}

migraphx::argument run_gpu()
{
    setenv("MIGRAPHX_DISABLE_NULL_STREAM", "1", 1);
26
    migraphx::program p = create_program();
mei-ye's avatar
mei-ye committed
27
28
29
30
31
32
33
34
35
36
37
38
39
    p.compile(migraphx::gpu::target{});
    migraphx::program::parameter_map m;
    for(auto&& x : p.get_parameter_shapes())
    {
        m[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second));
    }
    auto ret_val = migraphx::gpu::from_gpu(p.eval(m));
    p.finish();
    return ret_val;
}

migraphx::argument run_cpu()
{
40
    migraphx::program p = create_program();
mei-ye's avatar
mei-ye committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    p.compile(migraphx::cpu::target{});
    migraphx::program::parameter_map m;
    for(auto&& x : p.get_parameter_shapes())
    {
        m[x.first] = migraphx::generate_argument(x.second);
    }
    return p.eval(m);
}

void gpu_stream_execution_test()
{
    auto result1 = run_gpu();
    auto result2 = run_cpu();
    verify_args("test", result2, result1);
}

int main() { gpu_stream_execution_test(); }