test_conv_bias_clipped_relu.cpp 1.61 KB
Newer Older
1
2
3
4

#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
5
6
#include <migraphx/make_op.hpp>

7
8
9
10
11
12
13
#include <migraphx/instruction.hpp>

struct test_conv_bias_clipped_relu : verify_program<test_conv_bias_clipped_relu>
{
    migraphx::program create_program() const
    {
        migraphx::program p;
14
        auto* mm = p.get_main_module();
15
        auto input =
16
            mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
17
        auto weights =
18
            mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
19
        auto l0        = migraphx::literal{migraphx::shape{migraphx::shape::float_type, {4}},
20
                                    {2.0f, 2.0f, 2.0f, 2.0f}};
21
22
23
        auto bias      = mm->add_literal(l0);
        auto conv      = mm->add_instruction(migraphx::make_op("convolution"), input, weights);
        auto bcast_add = mm->add_instruction(
24
            migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", conv->get_shape().lens()}}),
25
26
            bias);
        auto bias_add = mm->add_instruction(migraphx::make_op("add"), conv, bcast_add);
27
28
        auto min_val  = mm->add_literal(0.0f);
        auto max_val  = mm->add_literal(6.0f);
29
        min_val       = mm->add_instruction(
30
            migraphx::make_op("multibroadcast", {{"out_lens", conv->get_shape().lens()}}), min_val);
31
        max_val = mm->add_instruction(
32
            migraphx::make_op("multibroadcast", {{"out_lens", conv->get_shape().lens()}}), max_val);
33
        mm->add_instruction(migraphx::make_op("clip"), bias_add, min_val, max_val);
34
35
36
        return p;
    }
};