Commit bc5d7f75 authored by Paul's avatar Paul
Browse files

Merge from develop

parents 47c0854d a5b0afa0
#include <migraph/auto_contiguous.hpp>
#include <migraph/operators.hpp>
#include <migraph/instruction.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/instruction.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct contiguous_target
{
std::string name() const { return "contiguous"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::auto_contiguous{}};
return {migraphx::auto_contiguous{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
// TODO: Add this test case
void literal_broadcast()
{
migraph::program p;
migraphx::program p;
p.add_literal(get_2_broadcasted());
EXPECT(not p.get_shape().standard());
EXPECT(p.get_shape().broadcasted());
......@@ -28,7 +28,7 @@ void literal_broadcast()
TEST_CASE(literal_transpose)
{
migraph::program p;
migraphx::program p;
p.add_literal(get_2x2_transposed());
EXPECT(not p.get_shape().standard());
EXPECT(p.get_shape().transposed());
......@@ -39,11 +39,11 @@ TEST_CASE(literal_transpose)
TEST_CASE(after_literal_transpose)
{
migraph::program p;
migraphx::program p;
auto l = p.add_literal(get_2x2());
EXPECT(p.get_shape().standard());
EXPECT(not p.get_shape().transposed());
auto t = p.add_instruction(migraph::op::transpose{{1, 0}}, l);
auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
p.add_instruction(pass_op{}, t);
EXPECT(not p.get_shape().standard());
EXPECT(p.get_shape().transposed());
......@@ -54,12 +54,12 @@ TEST_CASE(after_literal_transpose)
TEST_CASE(after_literal_broadcast)
{
migraph::program p;
migraphx::program p;
auto l1 = p.add_literal(get_2x2());
auto l2 = p.add_literal(get_2());
EXPECT(p.get_shape().standard());
EXPECT(not p.get_shape().broadcasted());
auto b = p.add_instruction(migraph::op::broadcast{0, l1->get_shape()}, l2);
auto b = p.add_instruction(migraphx::op::broadcast{0, l1->get_shape()}, l2);
p.add_instruction(pass_op{}, b);
EXPECT(not p.get_shape().standard());
EXPECT(p.get_shape().broadcasted());
......@@ -70,11 +70,11 @@ TEST_CASE(after_literal_broadcast)
TEST_CASE(after_param_transpose)
{
migraph::program p;
auto l = p.add_parameter("2x2", {migraph::shape::float_type, {2, 2}});
migraphx::program p;
auto l = p.add_parameter("2x2", {migraphx::shape::float_type, {2, 2}});
EXPECT(p.get_shape().standard());
EXPECT(not p.get_shape().transposed());
auto t = p.add_instruction(migraph::op::transpose{{1, 0}}, l);
auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
p.add_instruction(pass_op{}, t);
EXPECT(not p.get_shape().standard());
EXPECT(p.get_shape().transposed());
......@@ -85,12 +85,12 @@ TEST_CASE(after_param_transpose)
TEST_CASE(after_param_broadcast)
{
migraph::program p;
auto l1 = p.add_parameter("2x2", {migraph::shape::float_type, {2, 2}});
auto l2 = p.add_parameter("2", {migraph::shape::float_type, {2}});
migraphx::program p;
auto l1 = p.add_parameter("2x2", {migraphx::shape::float_type, {2, 2}});
auto l2 = p.add_parameter("2", {migraphx::shape::float_type, {2}});
EXPECT(p.get_shape().standard());
EXPECT(not p.get_shape().broadcasted());
auto b = p.add_instruction(migraph::op::broadcast{0, l1->get_shape()}, l2);
auto b = p.add_instruction(migraphx::op::broadcast{0, l1->get_shape()}, l2);
p.add_instruction(pass_op{}, b);
EXPECT(not p.get_shape().standard());
EXPECT(p.get_shape().broadcasted());
......
#include <migraph/common_subexpression_elimination.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraphx/common_subexpression_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct cse_target
{
std::string name() const { return "dce"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::common_subexpression_elimination{}, migraph::dead_code_elimination{}};
return {migraphx::common_subexpression_elimination{}, migraphx::dead_code_elimination{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
TEST_CASE(cse_test1)
{
migraph::program p1;
migraphx::program p1;
{
auto one = p1.add_literal(1);
auto two = p1.add_literal(2);
auto sum1 = p1.add_instruction(migraph::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraph::op::add{}, one, two);
auto sum3 = p1.add_instruction(migraph::op::add{}, sum1, sum2);
auto sum1 = p1.add_instruction(migraphx::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraphx::op::add{}, one, two);
auto sum3 = p1.add_instruction(migraphx::op::add{}, sum1, sum2);
p1.add_instruction(pass_op{}, sum3);
}
p1.compile(cse_target{});
migraph::program p2;
migraphx::program p2;
{
auto one = p2.add_literal(1);
auto two = p2.add_literal(2);
auto sum1 = p2.add_instruction(migraph::op::add{}, one, two);
auto sum3 = p2.add_instruction(migraph::op::add{}, sum1, sum1);
auto sum1 = p2.add_instruction(migraphx::op::add{}, one, two);
auto sum3 = p2.add_instruction(migraphx::op::add{}, sum1, sum1);
p2.add_instruction(pass_op{}, sum3);
}
EXPECT(p1 == p2);
......@@ -40,24 +40,24 @@ TEST_CASE(cse_test1)
TEST_CASE(cse_test2)
{
migraph::program p1;
migraphx::program p1;
{
auto one = p1.add_literal(1);
auto two = p1.add_literal(2);
auto sum1 = p1.add_instruction(migraph::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraph::op::add{}, two, one);
auto sum3 = p1.add_instruction(migraph::op::add{}, sum1, sum2);
auto sum1 = p1.add_instruction(migraphx::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraphx::op::add{}, two, one);
auto sum3 = p1.add_instruction(migraphx::op::add{}, sum1, sum2);
p1.add_instruction(pass_op{}, sum3);
}
p1.compile(cse_target{});
migraph::program p2;
migraphx::program p2;
{
auto one = p2.add_literal(1);
auto two = p2.add_literal(2);
auto sum1 = p2.add_instruction(migraph::op::add{}, one, two);
auto sum2 = p2.add_instruction(migraph::op::add{}, two, one);
auto sum3 = p2.add_instruction(migraph::op::add{}, sum1, sum2);
auto sum1 = p2.add_instruction(migraphx::op::add{}, one, two);
auto sum2 = p2.add_instruction(migraphx::op::add{}, two, one);
auto sum3 = p2.add_instruction(migraphx::op::add{}, sum1, sum2);
p2.add_instruction(pass_op{}, sum3);
}
EXPECT(p1 == p2);
......@@ -65,22 +65,22 @@ TEST_CASE(cse_test2)
TEST_CASE(cse_test3)
{
migraph::program p1;
migraphx::program p1;
{
auto one = p1.add_literal(1);
auto two = p1.add_literal(1);
auto sum1 = p1.add_instruction(migraph::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraph::op::add{}, two, one);
auto sum3 = p1.add_instruction(migraph::op::add{}, sum1, sum2);
auto sum1 = p1.add_instruction(migraphx::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraphx::op::add{}, two, one);
auto sum3 = p1.add_instruction(migraphx::op::add{}, sum1, sum2);
p1.add_instruction(pass_op{}, sum3);
}
p1.compile(cse_target{});
migraph::program p2;
migraphx::program p2;
{
auto one = p2.add_literal(1);
auto sum1 = p2.add_instruction(migraph::op::add{}, one, one);
auto sum3 = p2.add_instruction(migraph::op::add{}, sum1, sum1);
auto sum1 = p2.add_instruction(migraphx::op::add{}, one, one);
auto sum3 = p2.add_instruction(migraphx::op::add{}, sum1, sum1);
p2.add_instruction(pass_op{}, sum3);
}
EXPECT(p1 == p2);
......@@ -88,25 +88,25 @@ TEST_CASE(cse_test3)
TEST_CASE(cse_test4)
{
migraph::program p1;
migraphx::program p1;
{
auto one = p1.add_literal(1);
auto two = p1.add_literal(1);
auto sum1 = p1.add_instruction(migraph::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraph::op::add{}, two, one);
auto sum3 = p1.add_instruction(migraph::op::add{}, sum1, one);
auto sum4 = p1.add_instruction(migraph::op::add{}, sum2, two);
auto sum5 = p1.add_instruction(migraph::op::add{}, sum4, sum3);
auto sum1 = p1.add_instruction(migraphx::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraphx::op::add{}, two, one);
auto sum3 = p1.add_instruction(migraphx::op::add{}, sum1, one);
auto sum4 = p1.add_instruction(migraphx::op::add{}, sum2, two);
auto sum5 = p1.add_instruction(migraphx::op::add{}, sum4, sum3);
p1.add_instruction(pass_op{}, sum5);
}
p1.compile(cse_target{});
migraph::program p2;
migraphx::program p2;
{
auto one = p2.add_literal(1);
auto sum1 = p2.add_instruction(migraph::op::add{}, one, one);
auto sum3 = p2.add_instruction(migraph::op::add{}, sum1, one);
auto sum5 = p2.add_instruction(migraph::op::add{}, sum3, sum3);
auto sum1 = p2.add_instruction(migraphx::op::add{}, one, one);
auto sum3 = p2.add_instruction(migraphx::op::add{}, sum1, one);
auto sum5 = p2.add_instruction(migraphx::op::add{}, sum3, sum3);
p2.add_instruction(pass_op{}, sum5);
}
EXPECT(p1 == p2);
......
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>
struct sum_cf_op
{
std::string name() const { return "sum_cf"; }
migraphx::argument compute(const migraphx::shape&, std::vector<migraphx::argument> args) const
{
migraphx::argument result;
if(args.size() != 2)
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape() != args[1].get_shape())
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape().lens().size() != 1)
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape().lens().front() != 1)
MIGRAPHX_THROW("Wrong args");
args[0].visit_at([&](auto x) {
args[1].visit_at([&](auto y) { result = migraphx::literal{x + y}.get_argument(); });
});
return result;
}
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.size() != 2)
MIGRAPHX_THROW("Wrong inputs");
return inputs.front();
}
};
struct non_computable_cf
{
std::string name() const { return "non_computable"; }
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.empty())
return {};
return inputs.front();
}
};
struct test_context
{
void finish() const {}
};
TEST_CASE(literal_test)
{
migraphx::program p;
auto lit = p.add_literal(1);
CHECK(lit->eval() == migraphx::literal{1});
}
TEST_CASE(param_test)
{
migraphx::program p;
auto lit = p.add_parameter("param", migraphx::shape{migraphx::shape::float_type, {1}});
CHECK(lit->eval().empty());
}
TEST_CASE(op_test1)
{
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_cf_op{}, one, two);
CHECK(sum->eval() == migraphx::literal{3});
}
TEST_CASE(op_test2)
{
migraphx::program p;
auto x = p.add_parameter("param", migraphx::shape{migraphx::shape::float_type, {1}});
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_cf_op{}, x, two);
CHECK(sum->eval().empty());
}
TEST_CASE(op_test3)
{
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum1 = p.add_instruction(sum_op{}, one, two);
auto sum2 = p.add_instruction(sum_cf_op{}, sum1, two);
CHECK(sum2->eval().empty());
}
TEST_CASE(compute_op_c)
{
migraphx::operation op = sum_op{};
auto one = migraphx::literal{1}.get_argument();
auto two = migraphx::literal{2}.get_argument();
EXPECT(test::throws([&] {
op.compute(migraphx::shape{migraphx::shape::float_type, {1}}, {one, two});
}));
}
TEST_CASE(compute_nop_c)
{
migraphx::operation op = non_computable_cf{};
auto one = migraphx::literal{1}.get_argument();
auto two = migraphx::literal{2}.get_argument();
EXPECT(test::throws([&] {
op.compute(migraphx::shape{migraphx::shape::float_type, {1}}, {one, two});
}));
}
TEST_CASE(compute_nop_context)
{
migraphx::operation op = non_computable_cf{};
auto one = migraphx::literal{1}.get_argument();
auto two = migraphx::literal{2}.get_argument();
migraphx::context ctx = test_context{};
EXPECT(test::throws([&] {
op.compute(ctx, migraphx::shape{migraphx::shape::float_type, {1}}, {one, two});
}));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
#include <migraph/constant_propagate.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraphx/constant_propagate.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct const_prop_target
{
std::string name() const { return "const_prop"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::constant_propagate{}, migraph::dead_code_elimination{}};
return {migraphx::constant_propagate{}, migraphx::dead_code_elimination{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
TEST_CASE(const_add1)
{
migraph::program p1;
migraphx::program p1;
auto one = p1.add_literal(1);
auto two = p1.add_literal(2);
auto sum = p1.add_instruction(migraph::op::add{}, one, two);
auto sum = p1.add_instruction(migraphx::op::add{}, one, two);
p1.add_instruction(pass_op{}, sum);
p1.compile(const_prop_target{});
migraph::program p2;
migraphx::program p2;
auto total = p2.add_literal(3);
p2.add_instruction(pass_op{}, total);
EXPECT(p1 == p2);
......@@ -31,14 +31,14 @@ TEST_CASE(const_add1)
TEST_CASE(const_add2)
{
migraph::program p1;
auto one = p1.add_parameter("one", {migraph::shape::int32_type, {1}});
migraphx::program p1;
auto one = p1.add_parameter("one", {migraphx::shape::int32_type, {1}});
auto two = p1.add_literal(2);
auto sum = p1.add_instruction(migraph::op::add{}, one, two);
auto sum = p1.add_instruction(migraphx::op::add{}, one, two);
p1.add_instruction(pass_op{}, sum);
p1.compile(const_prop_target{});
migraph::program p2;
migraphx::program p2;
auto total = p2.add_literal(3);
p2.add_instruction(pass_op{}, total);
EXPECT(p1 != p2);
......@@ -46,15 +46,15 @@ TEST_CASE(const_add2)
TEST_CASE(const_add3)
{
migraph::program p1;
migraphx::program p1;
auto one = p1.add_literal(1);
auto two = p1.add_literal(2);
auto sum1 = p1.add_instruction(migraph::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraph::op::add{}, sum1, two);
auto sum1 = p1.add_instruction(migraphx::op::add{}, one, two);
auto sum2 = p1.add_instruction(migraphx::op::add{}, sum1, two);
p1.add_instruction(pass_op{}, sum2);
p1.compile(const_prop_target{});
migraph::program p2;
migraphx::program p2;
auto total = p2.add_literal(5);
p2.add_instruction(pass_op{}, total);
EXPECT(p1 == p2);
......
#include <iostream>
#include <vector>
#include <migraph/literal.hpp>
#include <migraph/operators.hpp>
#include <migraph/instruction.hpp>
#include <migraph/cpu/target.hpp>
#include <migraph/verify.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/verify.hpp>
#include <migraphx/onnx.hpp>
#include "test.hpp"
float sigmoid(float x) { return 1 / (1 + expf(-x)); }
float elu(float a, float x) { return x > 0 ? x : a * std::expm1(x); }
TEST_CASE(slice_test)
{
{
migraph::program p;
migraphx::program p;
std::vector<int> data(2 * 2 * 3);
std::iota(data.begin(), data.end(), 0);
migraph::shape s{migraph::shape::int32_type, {2, 2, 3}};
auto l0 = p.add_literal(migraph::literal{s, data});
p.add_instruction(migraph::op::slice{{2}, {1}, {3}}, l0);
migraph::shape s2{migraph::shape::int32_type, {2, 2, 2}, {6, 3, 1}};
migraphx::shape s{migraphx::shape::int32_type, {2, 2, 3}};
auto l0 = p.add_literal(migraphx::literal{s, data});
p.add_instruction(migraphx::op::slice{{2}, {1}, {3}}, l0);
migraphx::shape s2{migraphx::shape::int32_type, {2, 2, 2}, {6, 3, 1}};
EXPECT(p.get_shape() == s2);
p.compile(migraph::cpu::target{});
migraph::shape sresult{migraph::shape::int32_type, {2, 2, 2}, {4, 2, 1}};
p.compile(migraphx::cpu::target{});
migraphx::shape sresult{migraphx::shape::int32_type, {2, 2, 2}, {4, 2, 1}};
auto result = p.eval({});
std::vector<int> gold = {1, 2, 4, 5, 7, 8, 10, 11};
std::vector<int> results_vector(2 * 2 * 2);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
EXPECT(result.get_shape() == sresult);
}
{
migraph::program p;
migraphx::program p;
std::vector<int> data(2 * 2 * 3);
std::iota(data.begin(), data.end(), 0);
migraph::shape s{migraph::shape::int32_type, {2, 2, 3}};
auto l0 = p.add_literal(migraph::literal{s, data});
p.add_instruction(migraph::op::slice{{0, 1, 2}, {0, 0, 0}, {2, 2, 2}}, l0);
migraph::shape s2{migraph::shape::int32_type, {2, 2, 2}, {6, 3, 1}};
migraphx::shape s{migraphx::shape::int32_type, {2, 2, 3}};
auto l0 = p.add_literal(migraphx::literal{s, data});
p.add_instruction(migraphx::op::slice{{0, 1, 2}, {0, 0, 0}, {2, 2, 2}}, l0);
migraphx::shape s2{migraphx::shape::int32_type, {2, 2, 2}, {6, 3, 1}};
EXPECT(p.get_shape() == s2);
p.compile(migraph::cpu::target{});
migraph::shape sresult{migraph::shape::int32_type, {2, 2, 2}, {4, 2, 1}};
p.compile(migraphx::cpu::target{});
migraphx::shape sresult{migraphx::shape::int32_type, {2, 2, 2}, {4, 2, 1}};
auto result = p.eval({});
std::vector<int> gold = {0, 1, 3, 4, 6, 7, 9, 10};
std::vector<int> results_vector(2 * 2 * 2);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
EXPECT(result.get_shape() == sresult);
}
}
......@@ -50,85 +55,148 @@ TEST_CASE(slice_test)
TEST_CASE(concat_test)
{
{
migraph::program p;
migraphx::program p;
std::size_t axis = 1;
std::vector<int> data0 = {0, 1, 5, 6};
std::vector<int> data1 = {2, 3, 4, 7, 8, 9};
std::vector<int> data2 = {10, 20};
migraph::shape s0{migraph::shape::int32_type, {2, 2}};
migraph::shape s1{migraph::shape::int32_type, {2, 3}};
migraph::shape s2{migraph::shape::int32_type, {2, 1}};
auto l0 = p.add_literal(migraph::literal{s0, data0});
auto l1 = p.add_literal(migraph::literal{s1, data1});
auto l2 = p.add_literal(migraph::literal{s2, data2});
p.add_instruction(migraph::op::concat{axis}, l0, l1, l2);
p.compile(migraph::cpu::target{});
migraphx::shape s0{migraphx::shape::int32_type, {2, 2}};
migraphx::shape s1{migraphx::shape::int32_type, {2, 3}};
migraphx::shape s2{migraphx::shape::int32_type, {2, 1}};
auto l0 = p.add_literal(migraphx::literal{s0, data0});
auto l1 = p.add_literal(migraphx::literal{s1, data1});
auto l2 = p.add_literal(migraphx::literal{s2, data2});
p.add_instruction(migraphx::op::concat{axis}, l0, l1, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<int> gold = {0, 1, 2, 3, 4, 10, 5, 6, 7, 8, 9, 20};
std::vector<int> results_vector(2 * 6);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraph::verify_range(result.get_shape().lens(), std::vector<std::size_t>({2, 6})));
EXPECT(migraphx::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(result.get_shape().lens(), std::vector<std::size_t>({2, 6})));
EXPECT(
migraph::verify_range(result.get_shape().strides(), std::vector<std::size_t>({6, 1})));
migraphx::verify_range(result.get_shape().strides(), std::vector<std::size_t>({6, 1})));
}
{
migraph::program p;
migraphx::program p;
std::size_t axis = 0;
std::vector<int> data0 = {0, 1, 2, 3};
std::vector<int> data1 = {4, 5, 6, 7, 8, 9};
std::vector<int> data2 = {10, 11};
migraph::shape s0{migraph::shape::int32_type, {2, 2}};
migraph::shape s1{migraph::shape::int32_type, {3, 2}};
migraph::shape s2{migraph::shape::int32_type, {1, 2}};
auto l0 = p.add_literal(migraph::literal{s0, data0});
auto l1 = p.add_literal(migraph::literal{s1, data1});
auto l2 = p.add_literal(migraph::literal{s2, data2});
p.add_instruction(migraph::op::concat{axis}, l0, l1, l2);
p.compile(migraph::cpu::target{});
migraphx::shape s0{migraphx::shape::int32_type, {2, 2}};
migraphx::shape s1{migraphx::shape::int32_type, {3, 2}};
migraphx::shape s2{migraphx::shape::int32_type, {1, 2}};
auto l0 = p.add_literal(migraphx::literal{s0, data0});
auto l1 = p.add_literal(migraphx::literal{s1, data1});
auto l2 = p.add_literal(migraphx::literal{s2, data2});
p.add_instruction(migraphx::op::concat{axis}, l0, l1, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<int> gold = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
std::vector<int> results_vector(6 * 2);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraph::verify_range(result.get_shape().lens(), std::vector<std::size_t>({6, 2})));
EXPECT(migraphx::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(result.get_shape().lens(), std::vector<std::size_t>({6, 2})));
EXPECT(
migraph::verify_range(result.get_shape().strides(), std::vector<std::size_t>({2, 1})));
migraphx::verify_range(result.get_shape().strides(), std::vector<std::size_t>({2, 1})));
}
}
TEST_CASE(gather_test)
{
{
migraphx::program p;
std::vector<float> data(3 * 3);
std::iota(data.begin(), data.end(), 0.5);
migraphx::shape s{migraphx::shape::float_type, {3, 3}};
auto a0 = p.add_literal(migraphx::literal{s, data});
migraphx::shape s_indices{migraphx::shape::int32_type, {1, 2}};
std::vector<int> indices{0, 2};
auto a1 = p.add_literal(migraphx::literal{s_indices, indices});
int axis = 0;
p.add_instruction(migraphx::op::gather{axis}, a0, a1);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> res_data(4 * 5);
std::vector<float> golden = {0.5f, 1.5f, 2.5f, 6.5f, 7.5f, 8.5f};
result.visit([&](auto output) { res_data.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(res_data, golden));
}
{
migraphx::program p;
std::vector<float> data(3 * 3);
std::iota(data.begin(), data.end(), 0.5);
migraphx::shape s{migraphx::shape::float_type, {3, 3}};
auto a0 = p.add_literal(migraphx::literal{s, data});
migraphx::shape s_indices{migraphx::shape::int32_type, {1, 2}};
std::vector<int> indices{0, 2};
auto a1 = p.add_literal(migraphx::literal{s_indices, indices});
int axis = 1;
p.add_instruction(migraphx::op::gather{axis}, a0, a1);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> res_data(4 * 5);
std::vector<float> golden = {0.5f, 2.5f, 3.5f, 5.5f, 6.5f, 8.5f};
result.visit([&](auto output) { res_data.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(res_data, golden));
}
{
migraphx::program p;
std::vector<float> data(3 * 3);
std::iota(data.begin(), data.end(), 0.5);
migraphx::shape s{migraphx::shape::float_type, {3, 3}};
auto a0 = p.add_literal(migraphx::literal{s, data});
migraphx::shape s_indices{migraphx::shape::int32_type, {1, 2}};
std::vector<int> indices{0, 2};
auto a1 = p.add_literal(migraphx::literal{s_indices, indices});
int axis = -1;
p.add_instruction(migraphx::op::gather{axis}, a0, a1);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> res_data(4 * 5);
std::vector<float> golden = {0.5f, 2.5f, 3.5f, 5.5f, 6.5f, 8.5f};
result.visit([&](auto output) { res_data.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(res_data, golden));
}
}
TEST_CASE(squeeze_test)
{
{
migraph::program p;
migraphx::program p;
std::vector<float> data(4 * 3 * 3);
migraph::shape s1{migraph::shape::float_type, {4, 1, 3, 1, 3}};
migraph::shape s2{migraph::shape::float_type, {4, 3, 1, 3}};
auto l0 = p.add_literal(migraph::literal{s1, data});
p.add_instruction(migraph::op::squeeze{{1}}, l0);
p.compile(migraph::cpu::target{});
migraphx::shape s1{migraphx::shape::float_type, {4, 1, 3, 1, 3}};
migraphx::shape s2{migraphx::shape::float_type, {4, 3, 1, 3}};
auto l0 = p.add_literal(migraphx::literal{s1, data});
p.add_instruction(migraphx::op::squeeze{{1}}, l0);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape() == s2);
}
{
migraph::program p;
migraphx::program p;
std::vector<float> data(4 * 3 * 3);
migraph::shape s1{migraph::shape::float_type, {4, 1, 3, 1, 3}};
migraph::shape s2{migraph::shape::float_type, {4, 1, 3, 3}};
auto l0 = p.add_literal(migraph::literal{s1, data});
p.add_instruction(migraph::op::squeeze{{3}}, l0);
p.compile(migraph::cpu::target{});
migraphx::shape s1{migraphx::shape::float_type, {4, 1, 3, 1, 3}};
migraphx::shape s2{migraphx::shape::float_type, {4, 1, 3, 3}};
auto l0 = p.add_literal(migraphx::literal{s1, data});
p.add_instruction(migraphx::op::squeeze{{3}}, l0);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape() == s2);
}
{
migraph::program p;
migraphx::program p;
std::vector<float> data(4 * 3 * 3);
migraph::shape s1{migraph::shape::float_type, {4, 1, 3, 1, 3}};
migraph::shape s2{migraph::shape::float_type, {4, 3, 3}};
auto l0 = p.add_literal(migraph::literal{s1, data});
p.add_instruction(migraph::op::squeeze{}, l0);
p.compile(migraph::cpu::target{});
migraphx::shape s1{migraphx::shape::float_type, {4, 1, 3, 1, 3}};
migraphx::shape s2{migraphx::shape::float_type, {4, 3, 3}};
auto l0 = p.add_literal(migraphx::literal{s1, data});
p.add_instruction(migraphx::op::squeeze{}, l0);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape() == s2);
}
......@@ -137,24 +205,24 @@ TEST_CASE(squeeze_test)
TEST_CASE(unsqueeze_test)
{
{
migraph::program p;
migraphx::program p;
std::vector<float> data(4 * 3 * 3);
migraph::shape s1{migraph::shape::float_type, {4, 3, 3}};
migraph::shape s2{migraph::shape::float_type, {4, 1, 3, 3}};
auto l0 = p.add_literal(migraph::literal{s1, data});
p.add_instruction(migraph::op::unsqueeze{{1}}, l0);
p.compile(migraph::cpu::target{});
migraphx::shape s1{migraphx::shape::float_type, {4, 3, 3}};
migraphx::shape s2{migraphx::shape::float_type, {4, 1, 3, 3}};
auto l0 = p.add_literal(migraphx::literal{s1, data});
p.add_instruction(migraphx::op::unsqueeze{{1}}, l0);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape() == s2);
}
{
migraph::program p;
migraphx::program p;
std::vector<float> data(4 * 3 * 3);
migraph::shape s1{migraph::shape::float_type, {4, 3, 3}};
migraph::shape s2{migraph::shape::float_type, {4, 3, 1, 3}};
auto l0 = p.add_literal(migraph::literal{s1, data});
p.add_instruction(migraph::op::unsqueeze{{2}}, l0);
p.compile(migraph::cpu::target{});
migraphx::shape s1{migraphx::shape::float_type, {4, 3, 3}};
migraphx::shape s2{migraphx::shape::float_type, {4, 3, 1, 3}};
auto l0 = p.add_literal(migraphx::literal{s1, data});
p.add_instruction(migraphx::op::unsqueeze{{2}}, l0);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape() == s2);
}
......@@ -162,42 +230,42 @@ TEST_CASE(unsqueeze_test)
TEST_CASE(globalavgpool_test)
{
migraph::program p;
auto s = migraph::shape{migraph::shape::float_type, {1, 3, 2, 2}};
auto op = migraph::op::pooling{"average"};
migraphx::program p;
auto s = migraphx::shape{migraphx::shape::float_type, {1, 3, 2, 2}};
auto op = migraphx::op::pooling{"average"};
auto lens = s.lens();
op.lengths = {lens[2], lens[3]};
std::vector<float> data{0.3, 0.2, 0.4, 0.1, 0.8, 0.5, 0.9, 0.1, 0.1, 0.7, 0.1, 0.6};
auto l0 = p.add_literal(migraph::literal{s, data});
auto l0 = p.add_literal(migraphx::literal{s, data});
p.add_instruction(op, l0);
p.compile(migraph::cpu::target{});
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{0.25, 0.575, 0.375};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(globalmaxpool_test)
{
migraph::program p;
auto s = migraph::shape{migraph::shape::float_type, {1, 3, 2, 2}};
auto op = migraph::op::pooling{"max"};
migraphx::program p;
auto s = migraphx::shape{migraphx::shape::float_type, {1, 3, 2, 2}};
auto op = migraphx::op::pooling{"max"};
auto lens = s.lens();
op.lengths = {lens[2], lens[3]};
std::vector<float> data{0.3, 0.2, 0.4, 0.1, 0.8, 0.5, 0.9, 0.1, 0.1, 0.7, 0.1, 0.6};
auto l0 = p.add_literal(migraph::literal{s, data});
auto l0 = p.add_literal(migraphx::literal{s, data});
p.add_instruction(op, l0);
p.compile(migraph::cpu::target{});
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{0.4, 0.9, 0.7};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(im2col_3x3_no_pad_identity_test)
......@@ -213,20 +281,20 @@ TEST_CASE(im2col_3x3_no_pad_identity_test)
std::vector<int32_t> input(channels * size[0] * size[1]);
std::iota(input.begin(), input.end(), 0);
migraph::program p;
migraph::shape s_image{migraph::shape::int32_type, {1, channels, size[0], size[1]}};
migraph::shape s_weights{migraph::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraph::literal{s_image, input});
auto l_weights = p.add_literal(migraph::literal{s_weights, weights});
p.add_instruction(migraph::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s_image{migraphx::shape::int32_type, {1, channels, size[0], size[1]}};
migraphx::shape s_weights{migraphx::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraphx::literal{s_image, input});
auto l_weights = p.add_literal(migraphx::literal{s_weights, weights});
p.add_instruction(migraphx::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::size_t col_height = (size[0] - f[0] + 2 * padding[0]) / stride[0] + 1;
std::size_t col_width = (size[1] - f[1] + 2 * padding[1]) / stride[1] + 1;
std::vector<float> results_vector(channels * f[0] * f[1] * col_height * col_width);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, input));
EXPECT(migraphx::verify_range(results_vector, input));
}
TEST_CASE(im2col_3x3_no_pad_test)
......@@ -242,13 +310,13 @@ TEST_CASE(im2col_3x3_no_pad_test)
std::vector<int32_t> input(channels * size[0] * size[1]);
std::iota(input.begin(), input.end(), 0);
migraph::program p;
migraph::shape s_image{migraph::shape::int32_type, {1, channels, size[0], size[1]}};
migraph::shape s_weights{migraph::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraph::literal{s_image, input});
auto l_weights = p.add_literal(migraph::literal{s_weights, weights});
p.add_instruction(migraph::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s_image{migraphx::shape::int32_type, {1, channels, size[0], size[1]}};
migraphx::shape s_weights{migraphx::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraphx::literal{s_image, input});
auto l_weights = p.add_literal(migraphx::literal{s_weights, weights});
p.add_instruction(migraphx::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<int> correct = {0, 1, 2, 4, 5, 6, 8, 9, 10, 1, 2, 3, 5, 6, 7, 9, 10, 11,
......@@ -258,7 +326,7 @@ TEST_CASE(im2col_3x3_no_pad_test)
std::size_t col_width = (size[1] - f[1] + 2 * padding[1]) / stride[1] + 1;
std::vector<float> results_vector(channels * f[0] * f[1] * col_height * col_width);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, correct));
EXPECT(migraphx::verify_range(results_vector, correct));
}
TEST_CASE(im2col_3x3_stride_2_no_pad_test)
......@@ -274,13 +342,13 @@ TEST_CASE(im2col_3x3_stride_2_no_pad_test)
std::vector<int32_t> input(channels * size[0] * size[1]);
std::iota(input.begin(), input.end(), 0);
migraph::program p;
migraph::shape s_image{migraph::shape::int32_type, {1, channels, size[0], size[1]}};
migraph::shape s_weights{migraph::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraph::literal{s_image, input});
auto l_weights = p.add_literal(migraph::literal{s_weights, weights});
p.add_instruction(migraph::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s_image{migraphx::shape::int32_type, {1, channels, size[0], size[1]}};
migraphx::shape s_weights{migraphx::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraphx::literal{s_image, input});
auto l_weights = p.add_literal(migraphx::literal{s_weights, weights});
p.add_instruction(migraphx::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<int> correct = {0, 1, 2, 6, 7, 8, 12, 13, 14, 2, 3, 4,
......@@ -291,7 +359,7 @@ TEST_CASE(im2col_3x3_stride_2_no_pad_test)
std::size_t col_width = (size[1] - f[1] + 2 * padding[1]) / stride[1] + 1;
std::vector<float> results_vector(channels * f[0] * f[1] * col_height * col_width);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, correct));
EXPECT(migraphx::verify_range(results_vector, correct));
}
TEST_CASE(im2col_3x3_with_padding_test)
......@@ -307,13 +375,13 @@ TEST_CASE(im2col_3x3_with_padding_test)
std::vector<int32_t> input(channels * size[0] * size[1]);
std::iota(input.begin(), input.end(), 0);
migraph::program p;
migraph::shape s_image{migraph::shape::int32_type, {1, channels, size[0], size[1]}};
migraph::shape s_weights{migraph::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraph::literal{s_image, input});
auto l_weights = p.add_literal(migraph::literal{s_weights, weights});
p.add_instruction(migraph::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s_image{migraphx::shape::int32_type, {1, channels, size[0], size[1]}};
migraphx::shape s_weights{migraphx::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraphx::literal{s_image, input});
auto l_weights = p.add_literal(migraphx::literal{s_weights, weights});
p.add_instruction(migraphx::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<int> correct = {0, 0, 0, 0, 0, 1, 0, 2, 3, 0, 0, 0, 0, 1, 0, 2, 3, 0,
......@@ -323,19 +391,25 @@ TEST_CASE(im2col_3x3_with_padding_test)
std::size_t col_width = (size[1] - f[1] + 2 * padding[1]) / stride[1] + 1;
std::vector<float> results_vector(channels * f[0] * f[1] * col_height * col_width);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, correct));
EXPECT(migraphx::verify_range(results_vector, correct));
}
TEST_CASE(batch_norm_inference_test)
{
migraph::program p;
const size_t width = 2, height = 2, channels = 4, batches = 2;
const float x_val = 8.0f, mean_val = 2.0f, variance_val = 4.0f, scale_val = 2.0f,
bias_val = 1.0f;
migraphx::program p;
const size_t width = 2;
const size_t height = 2;
const size_t channels = 4;
const size_t batches = 2;
const float x_val = 8.0;
const float mean_val = 2.0;
const float variance_val = 4.0;
const float scale_val = 2.0f;
const float bias_val = 1.0f;
const float output_val = scale_val * (x_val - mean_val) / (std::sqrt(variance_val)) + bias_val;
migraph::shape s{migraph::shape::float_type, {batches, channels, height, width}};
migraph::shape vars{migraph::shape::float_type, {channels}};
migraphx::shape s{migraphx::shape::float_type, {batches, channels, height, width}};
migraphx::shape vars{migraphx::shape::float_type, {channels}};
std::vector<float> x_data(width * height * channels * batches);
std::vector<float> scale_data(channels);
std::vector<float> bias_data(channels);
......@@ -348,14 +422,14 @@ TEST_CASE(batch_norm_inference_test)
std::fill(scale_data.begin(), scale_data.end(), scale_val);
std::fill(bias_data.begin(), bias_data.end(), bias_val);
auto x = p.add_literal(migraph::literal{s, x_data});
auto scale = p.add_literal(migraph::literal{vars, scale_data});
auto bias = p.add_literal(migraph::literal{vars, bias_data});
auto mean = p.add_literal(migraph::literal{vars, mean_data});
auto variance = p.add_literal(migraph::literal{vars, variance_data});
auto x = p.add_literal(migraphx::literal{s, x_data});
auto scale = p.add_literal(migraphx::literal{vars, scale_data});
auto bias = p.add_literal(migraphx::literal{vars, bias_data});
auto mean = p.add_literal(migraphx::literal{vars, mean_data});
auto variance = p.add_literal(migraphx::literal{vars, variance_data});
p.add_instruction(migraph::op::batch_norm_inference{}, x, scale, bias, mean, variance);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> result_vector(width * height * channels * batches);
......@@ -363,7 +437,7 @@ TEST_CASE(batch_norm_inference_test)
std::fill(gold.begin(), gold.end(), output_val);
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(result_vector, gold));
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(im2col_3x3_with_channels_identity_test)
......@@ -379,105 +453,163 @@ TEST_CASE(im2col_3x3_with_channels_identity_test)
std::vector<int32_t> input(channels * size[0] * size[1]);
std::iota(input.begin(), input.end(), 0);
migraph::program p;
migraph::shape s_image{migraph::shape::int32_type, {1, channels, size[0], size[1]}};
migraph::shape s_weights{migraph::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraph::literal{s_image, input});
auto l_weights = p.add_literal(migraph::literal{s_weights, weights});
p.add_instruction(migraph::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s_image{migraphx::shape::int32_type, {1, channels, size[0], size[1]}};
migraphx::shape s_weights{migraphx::shape::int32_type, {1, channels, f[0], f[1]}};
auto l_image = p.add_literal(migraphx::literal{s_image, input});
auto l_weights = p.add_literal(migraphx::literal{s_weights, weights});
p.add_instruction(migraphx::op::im2col{padding, stride, dilation}, l_image, l_weights);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::size_t col_height = (size[0] - f[0] + 2 * padding[0]) / stride[0] + 1;
std::size_t col_width = (size[1] - f[1] + 2 * padding[1]) / stride[1] + 1;
std::vector<float> results_vector(channels * f[0] * f[1] * col_height * col_width);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, input));
EXPECT(migraphx::verify_range(results_vector, input));
}
TEST_CASE(exp_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l = p.add_literal(migraph::literal{s, {-1, 0, 1}});
p.add_instruction(migraph::op::exp{}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
p.add_instruction(migraphx::op::exp{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.36787944f, 1.f, 2.71828183f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(log_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {1, 2, 3}});
p.add_instruction(migraphx::op::log{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.0f, 0.6931471806f, 1.0986122887f};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(sin_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l = p.add_literal(migraph::literal{s, {-1, 0, 1}});
p.add_instruction(migraph::op::sin{}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
p.add_instruction(migraphx::op::sin{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.84147098f, 0.f, 0.84147098f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(cos_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l = p.add_literal(migraph::literal{s, {-1, 0, 1}});
p.add_instruction(migraph::op::cos{}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
p.add_instruction(migraphx::op::cos{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.54030231f, 1.f, 0.54030231f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(tan_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l = p.add_literal(migraph::literal{s, {-1, 0, 1}});
p.add_instruction(migraph::op::tan{}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
p.add_instruction(migraphx::op::tan{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-1.55740772f, 0.0f, 1.55740772f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(asin_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
std::vector<float> data{-0.5f, 0.0f, 0.9f};
auto l = p.add_literal(migraphx::literal{s, data});
p.add_instruction(migraphx::op::asin{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.5235987756f, 0.f, 1.119769515};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(acos_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {3}};
std::vector<float> data{-0.8f, 0.0f, 1.0f};
auto l = p.add_literal(migraphx::literal{s, data});
p.add_instruction(migraphx::op::acos{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {2.4980915448f, 1.5707963268f, 0.0f};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(atan_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
p.add_instruction(migraphx::op::atan{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.7853981634f, 0.0f, 0.7853981634f};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(add_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l1 = p.add_literal(migraph::literal{s, {-1, 0, 1}});
auto l2 = p.add_literal(migraph::literal{s, {1, 2, 3}});
p.add_instruction(migraph::op::add{}, l1, l2);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l1 = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
auto l2 = p.add_literal(migraphx::literal{s, {1, 2, 3}});
p.add_instruction(migraphx::op::add{}, l1, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0, 2, 4};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(broadcast_test)
{
migraph::program p;
migraph::shape a_shape{migraph::shape::int32_type, {2, 2}};
migraphx::program p;
migraphx::shape a_shape{migraphx::shape::int32_type, {2, 2}};
std::vector<int32_t> a_data{0, 0, 0, 0};
migraph::shape b_shape{migraph::shape::int32_type, {2}};
migraphx::shape b_shape{migraphx::shape::int32_type, {2}};
std::vector<int32_t> b_data{-2, -3};
uint64_t axis = 0;
auto l1 = p.add_literal(migraph::literal{a_shape, a_data});
auto l2 = p.add_literal(migraph::literal{b_shape, b_data});
p.add_instruction(migraph::op::broadcast{axis, l1->get_shape()}, l2);
p.compile(migraph::cpu::target{});
auto l1 = p.add_literal(migraphx::literal{a_shape, a_data});
auto l2 = p.add_literal(migraphx::literal{b_shape, b_data});
p.add_instruction(migraphx::op::broadcast{axis, l1->get_shape()}, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
auto output = result.get<int32_t>();
EXPECT(output(0, 0) == -2);
......@@ -488,145 +620,159 @@ TEST_CASE(broadcast_test)
TEST_CASE(add_broadcast_test)
{
{
migraph::program p;
migraph::shape a_shape{migraph::shape::float_type, {2, 2, 3}};
migraphx::program p;
migraphx::shape a_shape{migraphx::shape::float_type, {2, 2, 3}};
std::vector<float> a_data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
migraph::shape b_shape{migraph::shape::float_type, {2, 2}};
migraphx::shape b_shape{migraphx::shape::float_type, {2, 2}};
std::vector<float> b_data{0, -1, -2, -3};
uint64_t axis = 0;
auto l1 = p.add_literal(migraph::literal{a_shape, a_data});
auto l2 = p.add_literal(migraph::literal{b_shape, b_data});
auto l3 = p.add_instruction(migraph::op::broadcast{axis, l1->get_shape()}, l2);
p.add_instruction(migraph::op::add{}, l1, l3);
p.compile(migraph::cpu::target{});
auto l1 = p.add_literal(migraphx::literal{a_shape, a_data});
auto l2 = p.add_literal(migraphx::literal{b_shape, b_data});
auto l3 = p.add_instruction(migraphx::op::broadcast{axis, l1->get_shape()}, l2);
p.add_instruction(migraphx::op::add{}, l1, l3);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape().packed());
std::vector<float> results_vector(12);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
{
migraph::program p;
migraph::shape a_shape{migraph::shape::float_type, {2, 2, 3}};
migraphx::program p;
migraphx::shape a_shape{migraphx::shape::float_type, {2, 2, 3}};
std::vector<float> a_data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
migraph::shape b_shape{migraph::shape::float_type, {2, 2, 1}};
migraphx::shape b_shape{migraphx::shape::float_type, {2, 2, 1}};
std::vector<float> b_data{0, -1, -2, -3};
auto l1 = p.add_literal(migraph::literal{a_shape, a_data});
auto l2 = p.add_literal(migraph::literal{b_shape, b_data});
auto l3 = p.add_instruction(migraph::op::multibroadcast{{2, 2, 3}}, l1);
auto l4 = p.add_instruction(migraph::op::multibroadcast{{2, 2, 3}}, l2);
p.add_instruction(migraph::op::add{}, l3, l4);
p.compile(migraph::cpu::target{});
auto l1 = p.add_literal(migraphx::literal{a_shape, a_data});
auto l2 = p.add_literal(migraphx::literal{b_shape, b_data});
auto l3 = p.add_instruction(migraphx::op::multibroadcast{{2, 2, 3}}, l1);
auto l4 = p.add_instruction(migraphx::op::multibroadcast{{2, 2, 3}}, l2);
p.add_instruction(migraphx::op::add{}, l3, l4);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
EXPECT(result.get_shape().packed());
std::vector<float> results_vector(12);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
}
TEST_CASE(sub_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l1 = p.add_literal(migraph::literal{s, {-1, 0, 1}});
auto l2 = p.add_literal(migraph::literal{s, {1, 2, 3}});
p.add_instruction(migraph::op::sub{}, l1, l2);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l1 = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
auto l2 = p.add_literal(migraphx::literal{s, {1, 2, 3}});
p.add_instruction(migraphx::op::sub{}, l1, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-2, -2, -2};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(mul_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l1 = p.add_literal(migraph::literal{s, {-1, 0, 1}});
auto l2 = p.add_literal(migraph::literal{s, {1, 2, 3}});
p.add_instruction(migraph::op::mul{}, l1, l2);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l1 = p.add_literal(migraphx::literal{s, {-1, 0, 1}});
auto l2 = p.add_literal(migraphx::literal{s, {1, 2, 3}});
p.add_instruction(migraphx::op::mul{}, l1, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-1, 0, 3};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(div_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l1 = p.add_literal(migraph::literal{s, {-1.0f, 0.5f, 1.0f}});
auto l2 = p.add_literal(migraph::literal{s, {1.0f, 2.0f, 4.0f}});
p.add_instruction(migraph::op::div{}, l1, l2);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l1 = p.add_literal(migraphx::literal{s, {-1.0f, 0.5f, 1.0f}});
auto l2 = p.add_literal(migraphx::literal{s, {1.0f, 2.0f, 4.0f}});
p.add_instruction(migraphx::op::div{}, l1, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-1.f, 0.25f, 0.25f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(relu_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l = p.add_literal(migraph::literal{s, {-1.f, 0.f, 1.f}});
p.add_instruction(migraph::op::relu{}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1.f, 0.f, 1.f}});
p.add_instruction(migraphx::op::relu{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.f, 0.f, 1.f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(leaky_relu_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto l = p.add_literal(migraph::literal{s, {-1.f, 0.f, 1.f}});
p.add_instruction(migraph::op::leaky_relu{0.01}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l = p.add_literal(migraphx::literal{s, {-1.f, 0.f, 1.f}});
p.add_instruction(migraphx::op::leaky_relu{0.01}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.01f, 0.f, 1.f};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(lrn_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {1, 5, 1, 1}};
auto l = p.add_literal(migraphx::literal{s, {-2.0f, 1.0f, 0.f, 1.0f, 2.0f}});
p.add_instruction(migraphx::op::lrn{0.0001, 0.75, 1, 5}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(5);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-2 / 1.000075, 1 / 1.00009, 0 / 1.000145, 1 / 1.00009, 2 / 1.000075};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(imagescaler_test)
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {1, 3, 2, 2}};
auto img = p.add_literal(migraph::literal{s,
{0.2,
0.3,
0.5,
0.4,
0.7,
0.8,
0.1,
0.9,
0.15,
0.25,
0.35,
0.45}});
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {1, 3, 2, 2}};
auto img = p.add_literal(migraphx::literal{s,
{0.2,
0.3,
0.5,
0.4,
0.7,
0.8,
0.1,
0.9,
0.15,
0.25,
0.35,
0.45}});
auto scale_val = p.add_literal(2.f);
auto scaled_tensor = p.add_instruction(migraph::op::scalar{s}, scale_val);
auto img_scaled = p.add_instruction(migraph::op::mul{}, img, scaled_tensor);
auto scaled_tensor = p.add_instruction(migraphx::op::scalar{s}, scale_val);
auto img_scaled = p.add_instruction(migraphx::op::mul{}, img, scaled_tensor);
auto bias_vals = p.add_literal(
migraph::literal{migraph::shape{migraph::shape::float_type, {3}}, {0.01, 0.02, 0.03}});
auto bias_bcast = p.add_instruction(migraph::op::broadcast{1, s}, bias_vals);
p.add_instruction(migraph::op::add{}, img_scaled, bias_bcast);
p.compile(migraph::cpu::target{});
migraphx::literal{migraphx::shape{migraphx::shape::float_type, {3}}, {0.01, 0.02, 0.03}});
auto bias_bcast = p.add_instruction(migraphx::op::broadcast{1, s}, bias_vals);
p.add_instruction(migraphx::op::add{}, img_scaled, bias_bcast);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(12);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
......@@ -644,105 +790,101 @@ TEST_CASE(imagescaler_test)
0.53,
0.73,
0.93};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(reshape_test)
{
migraph::shape a_shape{migraph::shape::float_type, {24, 1, 1, 1}};
migraphx::shape a_shape{migraphx::shape::float_type, {24, 1, 1, 1}};
std::vector<float> data(24);
std::iota(data.begin(), data.end(), -3);
{
migraph::program p;
auto l = p.add_literal(migraph::literal{a_shape, data});
migraphx::program p;
auto l = p.add_literal(migraphx::literal{a_shape, data});
std::vector<int64_t> new_shape = {8, 3, 1, 1};
p.add_instruction(migraph::op::reshape{new_shape}, l);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::reshape{new_shape}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, data));
EXPECT(migraphx::verify_range(results_vector, data));
}
{
migraph::program p;
auto l = p.add_literal(migraph::literal{a_shape, data});
migraphx::program p;
auto l = p.add_literal(migraphx::literal{a_shape, data});
std::vector<int64_t> new_shape = {1, 3, 4, 2};
p.add_instruction(migraph::op::reshape{new_shape}, l);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::reshape{new_shape}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, data));
EXPECT(migraphx::verify_range(results_vector, data));
}
{
migraph::program p;
auto l = p.add_literal(migraph::literal{a_shape, data});
migraphx::program p;
auto l = p.add_literal(migraphx::literal{a_shape, data});
std::vector<int64_t> new_shape = {1, 3, 4, 2};
p.add_instruction(migraph::op::reshape{new_shape}, l);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::reshape{new_shape}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, data));
EXPECT(migraphx::verify_range(results_vector, data));
}
}
template <class T>
void gemm_test()
{
migraph::program p;
std::vector<T> a = {-0.00925222, 0.56250403, 0.70107397, 0.75402161, -0.505885,
migraphx::program p;
std::vector<T> a = {-0.00925222, 0.56250403, 0.70107397, 0.75402161, -0.505885,
1.33628943, -0.11413, -0.31270559, 1.59336732, -0.19361027,
-0.91620867, 0.40108416, -0.06969921, 0.68483471, -0.39906632,
-1.66423624, 0.69040076, -1.31490171, -0.11282616, -0.79391814};
std::vector<T> b = {6.09568541e-01,
-6.10527007e-01,
3.66646462e-01,
1.18951101e-01,
5.58777432e-01,
-3.21296298e-01,
-5.95997198e-01,
-5.01425721e-01,
-2.84606807e-01,
-5.73673557e-01,
-8.99430260e-01,
-4.25103093e-01,
1.53027987e+00,
-3.81407415e-04,
-3.29650255e-01};
std::vector<T> c = {-1.56327541e+00,
-7.09570140e-01,
-5.37424982e-01,
-2.22994831e-01,
-2.15586437e+00,
2.09177941e-03,
-1.47279677e+00,
2.02627040e-01,
-6.04527691e-01,
-1.29885596e+00,
2.16294914e+00,
-1.48101497e-01};
migraph::shape a_shape{migraph::shape::get_type<T>{}, {4, 5}};
auto al = p.add_literal(migraph::literal{a_shape, a});
migraph::shape b_shape{migraph::shape::get_type<T>{}, {5, 3}};
auto bl = p.add_literal(migraph::literal{b_shape, b});
p.add_instruction(migraph::op::dot{}, al, bl);
p.compile(migraph::cpu::target{});
std::vector<float> b = {6.09568541e-01,
-6.10527007e-01,
3.66646462e-01,
1.18951101e-01,
5.58777432e-01,
-3.21296298e-01,
-5.95997198e-01,
-5.01425721e-01,
-2.84606807e-01,
-5.73673557e-01,
-8.99430260e-01,
-4.25103093e-01,
1.53027987e+00,
-3.81407415e-04,
-3.29650255e-01};
std::vector<float> c = {-1.56327541e+00,
-7.09570140e-01,
-5.37424982e-01,
-2.22994831e-01,
-2.15586437e+00,
2.09177941e-03,
-1.47279677e+00,
2.02627040e-01,
-6.04527691e-01,
-1.29885596e+00,
2.16294914e+00,
-1.48101497e-01};
migraphx::shape a_shape{migraphx::shape::get_type<T>{}, {4, 5}};
auto al = p.add_literal(migraphx::literal{a_shape, a});
migraphx::shape b_shape{migraphx::shape::get_type<T>{}, {5, 3}};
auto bl = p.add_literal(migraphx::literal{b_shape, b});
p.add_instruction(migraphx::op::dot{}, al, bl);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<T> results_vector(12);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
float tol = 1e-6;
for(int i = 0; i < results_vector.size(); i++)
{
EXPECT(std::abs(results_vector[i] - c[i]) < tol);
}
EXPECT(migraphx::verify_range(c, results_vector));
}
TEST_CASE_REGISTER(gemm_test<float>)
TEST_CASE_REGISTER(gemm_test<double>)
TEST_CASE(maxpool_test)
{
migraph::program p;
migraphx::program p;
std::vector<float> a = {
-2.1314404, -1.63041711, 1.54562736, 1.04625261, -1.42931843, -0.48703974, 0.4065806,
-0.1524526, 1.30775225, 0.45538983, -0.06631992, -1.75332725, 1.33493888, 0.47327688,
......@@ -781,25 +923,20 @@ TEST_CASE(maxpool_test)
1.95433736, 2.46601582, 1.53285873, 1.95433736, 1.06763375, 1.4545635,
1.33624589, 1.16736257, 0.6126079, 1.36892557, 2.40126371, 1.53441942,
0.52119428, 2.07681108, 0.88494766, 1.51522756, 0.54275119, 0.6629802};
migraph::shape a_shape{migraph::shape::float_type, {2, 3, 6, 6}};
auto al = p.add_literal(migraph::literal{a_shape, a});
p.add_instruction(migraph::op::pooling{"max", {{0, 0}}, {{2, 2}}, {{3, 2}}}, al);
p.compile(migraph::cpu::target{});
migraphx::shape a_shape{migraphx::shape::float_type, {2, 3, 6, 6}};
auto al = p.add_literal(migraphx::literal{a_shape, a});
p.add_instruction(migraphx::op::pooling{"max", {{0, 0}}, {{2, 2}}, {{3, 2}}}, al);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
// std::cout << result.get_shape() << std::endl;
std::vector<float> results_vector(36);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
float tol = 1e-6;
for(int i = 0; i < results_vector.size(); i++)
{
// std::cout << results_vector[i] << " " << c[i] << std::endl;
EXPECT(std::abs(results_vector[i] - c[i]) < tol);
}
EXPECT(migraphx::verify_range(results_vector, c));
}
TEST_CASE(softmax_test)
{
migraph::program p;
migraphx::program p;
std::vector<float> a = {
-5.61869681e-01, 9.07827199e-01, 1.29255986e+00, 3.18533443e-02, -1.22183852e-03,
-2.83830553e-01, -1.03245842e+00, -9.28322077e-01, -8.82696748e-01, 1.11327164e-01,
......@@ -846,19 +983,19 @@ TEST_CASE(softmax_test)
0.17377149, 0.76075399, 0.20071237, 0.32632929, 0.36892858, 0.09416146, 0.26656723,
0.42914796};
migraph::shape a_shape{migraph::shape::float_type, {5, 3, 4, 2}};
auto al = p.add_literal(migraph::literal{a_shape, a});
p.add_instruction(migraph::op::softmax{}, al);
p.compile(migraph::cpu::target{});
migraphx::shape a_shape{migraphx::shape::float_type, {5, 3, 4, 2}};
auto al = p.add_literal(migraphx::literal{a_shape, a});
p.add_instruction(migraphx::op::softmax{}, al);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(120);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, s));
EXPECT(migraphx::verify_range(results_vector, s));
}
TEST_CASE(conv2d_test)
{
migraph::program p;
migraphx::program p;
std::vector<float> a = {
2.71567607, -0.9960829, 0.91671127, 0.28140706, 0.63235772, 0.08077253, 0.80927712,
-0.59108931, -1.05421555, -2.76622486, -0.85044265, -0.52049929, 0.67726439, -0.65290606,
......@@ -904,24 +1041,24 @@ TEST_CASE(conv2d_test)
0.71606487,
-0.55201721,
-0.46427044};
migraph::shape a_shape{migraph::shape::float_type, {2, 3, 4, 4}};
auto al = p.add_literal(migraph::literal{a_shape, a});
migraphx::shape a_shape{migraphx::shape::float_type, {2, 3, 4, 4}};
auto al = p.add_literal(migraphx::literal{a_shape, a});
migraph::shape c_shape{migraph::shape::float_type, {2, 3, 3, 3}};
auto cl = p.add_literal(migraph::literal{c_shape, c});
migraphx::shape c_shape{migraphx::shape::float_type, {2, 3, 3, 3}};
auto cl = p.add_literal(migraphx::literal{c_shape, c});
p.add_instruction(migraph::op::convolution{}, al, cl);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::convolution{}, al, cl);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(16);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, s));
EXPECT(migraphx::verify_range(results_vector, s));
}
TEST_CASE(conv2d_padding_test)
{
migraph::program p;
migraphx::program p;
std::vector<float> a = {
2.71567607, -0.9960829, 0.91671127, 0.28140706, 0.63235772, 0.08077253, 0.80927712,
-0.59108931, -1.05421555, -2.76622486, -0.85044265, -0.52049929, 0.67726439, -0.65290606,
......@@ -960,24 +1097,24 @@ TEST_CASE(conv2d_padding_test)
-0.20369984, -0.83037728, -1.40423918, -0.46160448, -0.22944322, 0.36074194, 0.49579027,
0.46527559};
migraph::shape a_shape{migraph::shape::float_type, {2, 3, 4, 4}};
auto al = p.add_literal(migraph::literal{a_shape, a});
migraphx::shape a_shape{migraphx::shape::float_type, {2, 3, 4, 4}};
auto al = p.add_literal(migraphx::literal{a_shape, a});
migraph::shape c_shape{migraph::shape::float_type, {2, 3, 3, 3}};
auto cl = p.add_literal(migraph::literal{c_shape, c});
migraphx::shape c_shape{migraphx::shape::float_type, {2, 3, 3, 3}};
auto cl = p.add_literal(migraphx::literal{c_shape, c});
p.add_instruction(migraph::op::convolution{{{1, 1}}, {{1, 1}}}, al, cl);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::convolution{{{1, 1}}, {{1, 1}}}, al, cl);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(64);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, s));
EXPECT(migraphx::verify_range(results_vector, s));
}
TEST_CASE(conv2d_padding_stride_test)
{
migraph::program p;
migraphx::program p;
std::vector<float> a = {
2.71567607, -0.9960829, 0.91671127, 0.28140706, 0.63235772, 0.08077253, 0.80927712,
-0.59108931, -1.05421555, -2.76622486, -0.85044265, -0.52049929, 0.67726439, -0.65290606,
......@@ -1021,33 +1158,33 @@ TEST_CASE(conv2d_padding_stride_test)
-0.16138598,
0.79344082};
migraph::shape a_shape{migraph::shape::float_type, {2, 3, 4, 4}};
auto al = p.add_literal(migraph::literal{a_shape, a});
migraphx::shape a_shape{migraphx::shape::float_type, {2, 3, 4, 4}};
auto al = p.add_literal(migraphx::literal{a_shape, a});
migraph::shape c_shape{migraph::shape::float_type, {2, 3, 3, 3}};
auto cl = p.add_literal(migraph::literal{c_shape, c});
migraphx::shape c_shape{migraphx::shape::float_type, {2, 3, 3, 3}};
auto cl = p.add_literal(migraphx::literal{c_shape, c});
p.add_instruction(migraph::op::convolution{{{1, 1}}, {{2, 2}}}, al, cl);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::convolution{{{1, 1}}, {{2, 2}}}, al, cl);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(16);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector, s));
EXPECT(migraphx::verify_range(results_vector, s));
}
TEST_CASE(transpose_test)
{
migraph::shape a_shape{migraph::shape::float_type, {1, 2, 2, 3}};
migraphx::shape a_shape{migraphx::shape::float_type, {1, 2, 2, 3}};
std::vector<float> data(12);
std::iota(data.begin(), data.end(), 0);
{
migraph::program p;
auto l = p.add_literal(migraph::literal{a_shape, data});
migraphx::program p;
auto l = p.add_literal(migraphx::literal{a_shape, data});
std::vector<int64_t> perm = {0, 3, 1, 2};
p.add_instruction(migraph::op::transpose{perm}, l);
p.compile(migraph::cpu::target{});
p.add_instruction(migraphx::op::transpose{perm}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
result.visit([&](auto output) {
......@@ -1056,31 +1193,31 @@ TEST_CASE(transpose_test)
});
}
{
migraph::program p;
auto l = p.add_literal(migraph::literal{a_shape, data});
migraphx::program p;
auto l = p.add_literal(migraphx::literal{a_shape, data});
std::vector<int64_t> perm = {0, 3, 1, 2};
auto result = p.add_instruction(migraph::op::transpose{perm}, l);
p.add_instruction(migraph::op::contiguous{}, result);
p.compile(migraph::cpu::target{});
auto result = p.add_instruction(migraphx::op::transpose{perm}, l);
p.add_instruction(migraphx::op::contiguous{}, result);
p.compile(migraphx::cpu::target{});
auto result2 = p.eval({});
std::vector<float> results_vector(12);
result2.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
}
TEST_CASE(contiguous_test)
{
migraph::shape a_shape{migraph::shape::float_type, {1, 3, 2, 2}, {12, 1, 6, 3}};
migraphx::shape a_shape{migraphx::shape::float_type, {1, 3, 2, 2}, {12, 1, 6, 3}};
std::vector<float> data(12);
std::iota(data.begin(), data.end(), 0);
migraph::program p;
auto l = p.add_literal(migraph::literal{a_shape, data});
p.add_instruction(migraph::op::contiguous{}, l);
p.compile(migraph::cpu::target{});
migraphx::program p;
auto l = p.add_literal(migraphx::literal{a_shape, data});
p.add_instruction(migraphx::op::contiguous{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(12);
......@@ -1088,7 +1225,154 @@ TEST_CASE(contiguous_test)
std::vector<size_t> new_lens = {1, 3, 2, 2};
std::vector<size_t> new_strides = {12, 1, 6, 3};
std::vector<float> gold = {0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11};
EXPECT(migraph::verify_range(results_vector, gold));
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(identity_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
std::vector<int> data{1, 2, 3, 4};
auto l = p.add_literal(migraphx::literal{s, data});
p.add_instruction(migraphx::op::identity{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<int> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(std::equal(data.begin(), data.end(), results_vector.begin()));
}
TEST_CASE(abs_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l = p.add_literal(migraphx::literal{s, {-1, 2, -3, 4}});
p.add_instruction(migraphx::op::abs{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 2, 3, 4};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(sigmoid_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l = p.add_literal(migraphx::literal{s, {-1, 2, -3, 4}});
p.add_instruction(migraphx::op::sigmoid{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{sigmoid(-1), sigmoid(2), sigmoid(-3), sigmoid(4)};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(sinh_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l = p.add_literal(migraphx::literal{s, {-1.0, 2.0, -3.0, 4.0}});
p.add_instruction(migraphx::op::sinh{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{sinhf(-1), sinhf(2), sinhf(-3), sinhf(4)};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(cosh_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l = p.add_literal(migraphx::literal{s, {-1.0, 2.0, -3.0, 4.0}});
p.add_instruction(migraphx::op::cosh{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{coshf(-1), coshf(2), coshf(-3), coshf(4)};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(tanh_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l = p.add_literal(migraphx::literal{s, {-1.0, 2.0, -3.0, 4.0}});
p.add_instruction(migraphx::op::tanh{}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{tanhf(-1), tanhf(2), tanhf(-3), tanhf(4)};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(elu_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l = p.add_literal(migraphx::literal{s, {-1.0, 2.0, -3.0, 4.0}});
float alpha = 0.5;
p.add_instruction(migraphx::op::elu{alpha}, l);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{elu(alpha, -1), elu(alpha, 2), elu(alpha, -3), elu(alpha, 4)};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(max_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l0 = p.add_literal(migraphx::literal{s, {1, 4, 3}});
auto l1 = p.add_literal(migraphx::literal{s, {2, 8, 6}});
auto l2 = p.add_literal(migraphx::literal{s, {7, 5, 9}});
auto curr_max = p.add_instruction(migraphx::op::max{}, l0, l1);
p.add_instruction(migraphx::op::max{}, curr_max, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{7, 8, 9};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(min_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l0 = p.add_literal(migraphx::literal{s, {1, 4, 3}});
auto l1 = p.add_literal(migraphx::literal{s, {2, 8, 6}});
auto l2 = p.add_literal(migraphx::literal{s, {7, 5, 9}});
auto curr_min = p.add_instruction(migraphx::op::min{}, l0, l1);
p.add_instruction(migraphx::op::min{}, curr_min, l2);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 4, 3};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(pad_test)
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
auto l0 = p.add_literal(migraphx::literal{s, {1, 2, 3, 4}});
p.add_instruction(migraphx::op::pad{{1, 1, 1, 1}}, l0);
p.compile(migraphx::cpu::target{});
auto result = p.eval({});
std::vector<float> results_vector(16);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 0};
EXPECT(migraphx::verify_range(results_vector, gold));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
#include <iostream>
#include <vector>
#include <migraphx/literal.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/verify.hpp>
#include <migraphx/onnx.hpp>
#include "test.hpp"
TEST_CASE(rnn_forward)
{
std::size_t batch_size = 2;
std::size_t seq_len = 2;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
std::vector<float> w_data{0.4691,
0.3185,
-0.2227,
0.4423,
-0.0609,
-0.2803,
0.1744,
0.3146,
0.4049,
-0.3973,
-0.0890,
-0.1636};
std::vector<float> r_data{-0.0456,
0.1061,
0.1574,
-0.4928,
-0.4300,
-0.1909,
-0.0225,
-0.2668,
0.1840,
-0.4453,
-0.4896,
0.1302,
-0.0929,
0.3545,
-0.4981,
0.0616};
std::vector<float> bias_data{
-0.4938, 0.4355, -0.3186, 0.2094, 0.1037, -0.1071, 0.4504, -0.3990};
std::vector<float> ih_data(num_dirct * batch_size * hidden_size, 0);
std::vector<float> input(seq_len * batch_size * input_size, 0);
input[0] = input[1] = 1.0;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
float clip = 0.0f;
// concatenation of hidden states as program output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{0.37780784,
0.61055139,
0.55168478,
-0.5888475,
-0.37144644,
0.31708236,
0.13104209,
-0.18736027,
0.03445704,
0.19167931,
-0.3946827,
-0.30889652,
-0.22276389,
0.44193283,
-0.16477929,
-0.11893477};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// rnn last output as program output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto out_hs = p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::forward, clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{0.03445704,
0.19167931,
-0.3946827,
-0.30889652,
-0.22276389,
0.44193283,
-0.16477929,
-0.11893477};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
// multiple rnn_last_output operators
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto out_hs = p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::forward, clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{0.03445704,
0.19167931,
-0.3946827,
-0.30889652,
-0.22276389,
0.44193283,
-0.16477929,
-0.11893477};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
// 3 args
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto out_hs = p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::forward, clip},
seq,
w,
r);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{
0.2935145, -0.23719997, -0.31123261, -0.18357255, 0., 0., 0., 0.};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
// seq_len = 1
{
seq_len = 1;
std::vector<float> input_1(seq_len * batch_size * input_size, 0);
input_1[0] = input_1[1] = 1.0;
migraphx::shape in_shape_1{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape_1, input_1});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{0.37780784,
0.61055139,
0.55168478,
-0.5888475,
-0.37144644,
0.31708236,
0.13104209,
-0.18736027};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(rnn_reverse)
{
std::size_t batch_size = 2;
std::size_t seq_len = 2;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
std::vector<float> w_data{-0.0296,
-0.1341,
0.1761,
-0.2325,
-0.0717,
0.1852,
0.2720,
0.1471,
-0.1097,
0.3363,
-0.0587,
-0.2302};
std::vector<float> r_data{0.2528,
-0.2333,
0.3973,
0.1593,
-0.0388,
0.1702,
0.3829,
-0.0712,
-0.1668,
0.3074,
-0.2854,
0.4049,
-0.3737,
-0.1051,
0.4482,
-0.2841};
std::vector<float> bias_data{-0.3188, 0.1341, -0.4446, 0.1389, 0.3117, 0.3664, 0.2352, 0.2552};
std::vector<float> input(seq_len * batch_size * input_size, 0);
input[0] = input[1] = 1.0;
std::vector<float> ih_data(num_dirct * batch_size * hidden_size, 0);
float clip = 0.0f;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
// concatenation of hidden states as program output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::reverse, clip},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.29385301,
0.16796815,
0.51075965,
0.40258689,
-0.13818839,
0.44124447,
0.14365635,
0.14803654,
-0.0070999,
0.46251031,
-0.20639211,
0.37488942,
-0.0070999,
0.46251031,
-0.20639211,
0.37488942};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// rnn last output as program output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto out_hs = p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::reverse, clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{-0.29385301,
0.16796815,
0.51075965,
0.40258689,
-0.13818839,
0.44124447,
0.14365635,
0.14803654};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
}
TEST_CASE(rnn_bidirectional)
{
std::size_t batch_size = 2;
std::size_t seq_len = 2;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
std::vector<float> w_data{0.4691, 0.3185, -0.2227, 0.4423, -0.0609, -0.2803,
0.1744, 0.3146, 0.4049, -0.3973, -0.0890, -0.1636,
-0.0296, -0.1341, 0.1761, -0.2325, -0.0717, 0.1852,
0.2720, 0.1471, -0.1097, 0.3363, -0.0587, -0.2302};
std::vector<float> r_data{-0.0456, 0.1061, 0.1574, -0.4928, -0.4300, -0.1909, -0.0225,
-0.2668, 0.1840, -0.4453, -0.4896, 0.1302, -0.0929, 0.3545,
-0.4981, 0.0616, 0.2528, -0.2333, 0.3973, 0.1593, -0.0388,
0.1702, 0.3829, -0.0712, -0.1668, 0.3074, -0.2854, 0.4049,
-0.3737, -0.1051, 0.4482, -0.2841};
std::vector<float> bias_data{-0.4938,
0.4355,
-0.3186,
0.2094,
0.1037,
-0.1071,
0.4504,
-0.3990,
-0.3188,
0.1341,
-0.4446,
0.1389,
0.3117,
0.3664,
0.2352,
0.2552};
std::vector<float> input(seq_len * batch_size * input_size, 0);
input[0] = input[1] = 1.0;
std::vector<float> ih_data(num_dirct * batch_size * hidden_size, 0);
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
float clip = 0.0f;
// concatenation of hidden state for program output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.37780784, 0.61055139, 0.55168478, -0.5888475, -0.37144644, 0.31708236,
0.13104209, -0.18736027, -0.29385301, 0.16796815, 0.51075965, 0.40258689,
-0.13818839, 0.44124447, 0.14365635, 0.14803654, 0.03445704, 0.19167931,
-0.3946827, -0.30889652, -0.22276389, 0.44193283, -0.16477929, -0.11893477,
-0.0070999, 0.46251031, -0.20639211, 0.37488942, -0.0070999, 0.46251031,
-0.20639211, 0.37488942};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last rnn output for program output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto out_hs =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{0.03445704,
0.19167931,
-0.3946827,
-0.30889652,
-0.22276389,
0.44193283,
-0.16477929,
-0.11893477,
-0.29385301,
0.16796815,
0.51075965,
0.40258689,
-0.13818839,
0.44124447,
0.14365635,
0.14803654};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
// 4 args
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto out_hs =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias);
p.add_instruction(migraphx::op::rnn_last_output{}, out_hs);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{0.03445704,
0.19167931,
-0.3946827,
-0.30889652,
-0.22276389,
0.44193283,
-0.16477929,
-0.11893477,
-0.29385301,
0.16796815,
0.51075965,
0.40258689,
-0.13818839,
0.44124447,
0.14365635,
0.14803654};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
// 3 args
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r);
p.compile(migraphx::cpu::target{});
auto last_output = p.eval({});
std::vector<float> last_output_data;
last_output.visit([&](auto out) { last_output_data.assign(out.begin(), out.end()); });
std::vector<float> last_output_data_gold{
0.6570473, 0.36392266, 0.45342238, -0.45127486, 0., 0., 0., 0.,
-0.16225325, -0.29515147, 0.39617197, 0.27068236, 0., 0., 0., 0.,
0.2935145, -0.23719997, -0.31123261, -0.18357255, 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0.};
EXPECT(migraphx::verify_range(last_output_data, last_output_data_gold));
}
// concatenation of hidden state for program output
{
seq_len = 1;
std::vector<float> input_1(seq_len * batch_size * input_size, 0);
input_1[0] = input_1[1] = 1.0;
migraphx::shape in_shape_1{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape_1, input_1});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(
migraphx::op::rnn{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{0.37780784,
0.61055139,
0.55168478,
-0.5888475,
-0.37144644,
0.31708236,
0.13104209,
-0.18736027,
-0.16915828,
0.1938169,
0.20667936,
0.58609703,
-0.0070999,
0.46251031,
-0.20639211,
0.37488942};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_forward)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3485, -0.0378, -0.1782, 0.1416, -0.3096, -0.2212, -0.3883, 0.1983, -0.2418,
0.1480, -0.3255, 0.1359, -0.3551, -0.3605, -0.3482, -0.1424, -0.0495, -0.1640,
-0.1979, -0.2577, -0.4097, -0.1211, -0.0412, 0.1801, 0.1721, -0.4327, -0.0498,
0.2628, -0.1573, -0.1577, 0.2759, -0.2023, -0.1185, -0.2136, 0.1294, -0.2331,
0.0701, 0.4316, 0.0480, 0.0247, -0.0166, -0.2729, 0.1712, -0.3984, -0.3905};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
0.2848, -0.2851, -0.3466, -0.1718, -0.1492, -0.0082, 0.2452, -0.0401, 0.3399, 0.2529,
-0.0953, -0.0903, -0.1518, -0.1373, 0.3848, -0.0130, -0.4339, 0.0406, -0.1926, -0.1131,
0.4285, -0.0013, 0.2243, 0.2752, 0.1776, -0.1720, 0.0822, -0.0295, 0.1062, -0.2721,
-0.2736, -0.1826, 0.3541, -0.4259, 0.2188, 0.0706, 0.3650, 0.3947, 0.2522, 0.2179,
-0.0744, 0.2122, -0.4346, 0.2760, 0.4076, 0.1183, -0.1500, -0.1704, 0.3090, -0.0706,
-0.2442, 0.3021, 0.1680, 0.0783, -0.3754, -0.3469, -0.2972, -0.0170, 0.4143, 0.3801,
0.3852, -0.1170, -0.2937, 0.2979, -0.1357, 0.4257, 0.3884, -0.2916, 0.1071, 0.0934,
0.3645, -0.4310, -0.3480, 0.0702, -0.1558};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
0.0560, 0.0310, -0.1669, -0.0781, 0.1793, -0.1758, 0.3173, -0.1650, -0.3732, 0.2946,
-0.0912, 0.3118, 0.1391, 0.2755, 0.2695, -0.1059, -0.2357, 0.3629, -0.2534, -0.0494,
0.0556, 0.0881, -0.2592, -0.2213, 0.2310, -0.4044, 0.1801, 0.1438, 0.3108, -0.3607};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{
-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// concatenation of hidden states for output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
-0.27298412, 0.42363745, -0.09368783, 0.4823072, -0.02183238, -0.6873896,
0.16144305, 0.31932795, 0.6104771, 0.79759157, -0.31791314, 0.5249062,
0.08800987, 0.46404213, -0.11872687, -0.26210734, 0.34448293, -0.0176422,
0.48523626, 0.60002893, -0.3969709, 0.43360898, 0.35775262, 0.23280787,
-0.52179873, -0.21944991, 0.4535257, -0.13735442, 0.51757574, 0.50380427};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last output for output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.3969709,
0.43360898,
0.35775262,
0.23280787,
-0.52179873,
-0.21944991,
0.4535257,
-0.13735442,
0.51757574,
0.50380427};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// two rnn_last_output operators after gru
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.3969709,
0.43360898,
0.35775262,
0.23280787,
-0.52179873,
-0.21944991,
0.4535257,
-0.13735442,
0.51757574,
0.50380427};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last output for output, linear_before_reset = 0
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
0},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.53291196,
0.50160867,
0.39010462,
0.39292926,
-0.5960838,
-0.38451535,
0.454239,
-0.10620412,
0.6014447,
0.43445644};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_forward_args)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3485, -0.0378, -0.1782, 0.1416, -0.3096, -0.2212, -0.3883, 0.1983, -0.2418,
0.1480, -0.3255, 0.1359, -0.3551, -0.3605, -0.3482, -0.1424, -0.0495, -0.1640,
-0.1979, -0.2577, -0.4097, -0.1211, -0.0412, 0.1801, 0.1721, -0.4327, -0.0498,
0.2628, -0.1573, -0.1577, 0.2759, -0.2023, -0.1185, -0.2136, 0.1294, -0.2331,
0.0701, 0.4316, 0.0480, 0.0247, -0.0166, -0.2729, 0.1712, -0.3984, -0.3905};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
0.2848, -0.2851, -0.3466, -0.1718, -0.1492, -0.0082, 0.2452, -0.0401, 0.3399, 0.2529,
-0.0953, -0.0903, -0.1518, -0.1373, 0.3848, -0.0130, -0.4339, 0.0406, -0.1926, -0.1131,
0.4285, -0.0013, 0.2243, 0.2752, 0.1776, -0.1720, 0.0822, -0.0295, 0.1062, -0.2721,
-0.2736, -0.1826, 0.3541, -0.4259, 0.2188, 0.0706, 0.3650, 0.3947, 0.2522, 0.2179,
-0.0744, 0.2122, -0.4346, 0.2760, 0.4076, 0.1183, -0.1500, -0.1704, 0.3090, -0.0706,
-0.2442, 0.3021, 0.1680, 0.0783, -0.3754, -0.3469, -0.2972, -0.0170, 0.4143, 0.3801,
0.3852, -0.1170, -0.2937, 0.2979, -0.1357, 0.4257, 0.3884, -0.2916, 0.1071, 0.0934,
0.3645, -0.4310, -0.3480, 0.0702, -0.1558};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
0.0560, 0.0310, -0.1669, -0.0781, 0.1793, -0.1758, 0.3173, -0.1650, -0.3732, 0.2946,
-0.0912, 0.3118, 0.1391, 0.2755, 0.2695, -0.1059, -0.2357, 0.3629, -0.2534, -0.0494,
0.0556, 0.0881, -0.2592, -0.2213, 0.2310, -0.4044, 0.1801, 0.1438, 0.3108, -0.3607};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{
-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// 3 args
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.114674, -0.129581, -0.218156, -0.140788, -0.114242,
-0.346569, 0.321367, -0.0838253, 0.102097, 0.00232137,
-0.149055, 0.0590743, -0.0533094, -0.0446122, -0.112588,
0.0153261, 0.168883, -0.326836, 0.0843562, 0.160872,
-0.232523, 0.00214573, 0.231693, -0.160475, -0.518952,
0.0467166, 0.12327, -0.374162, 0.137778, 0.251976};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 4 args (bias is used)
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
bias);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.273619, 0.0931375, -0.104717, 0.0203752, -0.0797887,
-0.493948, 0.472118, -0.0336318, 0.332706, 0.0182268,
-0.341684, 0.38063, 0.0589275, 0.2644, -0.115737,
-0.152324, 0.442277, -0.201626, 0.408909, 0.12905,
-0.416866, 0.377186, 0.32922, 0.162214, -0.519973,
-0.140072, 0.465076, -0.229563, 0.500164, 0.195166};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 4 args (ih is used)
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
und,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.0801064, 0.27025, -0.20704, 0.333579, -0.0452438,
-0.56265, 0.061061, 0.262172, 0.405193, 0.775226,
-0.100683, 0.258729, -0.0187297, 0.215815, -0.108936,
-0.0941018, 0.129665, -0.159421, 0.190636, 0.597412,
-0.197, 0.0885705, 0.269396, -0.0414511, -0.515137,
-0.03075, 0.158326, -0.296488, 0.177983, 0.519498};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_forward_actv_funcs)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3485, -0.0378, -0.1782, 0.1416, -0.3096, -0.2212, -0.3883, 0.1983, -0.2418,
0.1480, -0.3255, 0.1359, -0.3551, -0.3605, -0.3482, -0.1424, -0.0495, -0.1640,
-0.1979, -0.2577, -0.4097, -0.1211, -0.0412, 0.1801, 0.1721, -0.4327, -0.0498,
0.2628, -0.1573, -0.1577, 0.2759, -0.2023, -0.1185, -0.2136, 0.1294, -0.2331,
0.0701, 0.4316, 0.0480, 0.0247, -0.0166, -0.2729, 0.1712, -0.3984, -0.3905};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
0.2848, -0.2851, -0.3466, -0.1718, -0.1492, -0.0082, 0.2452, -0.0401, 0.3399, 0.2529,
-0.0953, -0.0903, -0.1518, -0.1373, 0.3848, -0.0130, -0.4339, 0.0406, -0.1926, -0.1131,
0.4285, -0.0013, 0.2243, 0.2752, 0.1776, -0.1720, 0.0822, -0.0295, 0.1062, -0.2721,
-0.2736, -0.1826, 0.3541, -0.4259, 0.2188, 0.0706, 0.3650, 0.3947, 0.2522, 0.2179,
-0.0744, 0.2122, -0.4346, 0.2760, 0.4076, 0.1183, -0.1500, -0.1704, 0.3090, -0.0706,
-0.2442, 0.3021, 0.1680, 0.0783, -0.3754, -0.3469, -0.2972, -0.0170, 0.4143, 0.3801,
0.3852, -0.1170, -0.2937, 0.2979, -0.1357, 0.4257, 0.3884, -0.2916, 0.1071, 0.0934,
0.3645, -0.4310, -0.3480, 0.0702, -0.1558};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
0.0560, 0.0310, -0.1669, -0.0781, 0.1793, -0.1758, 0.3173, -0.1650, -0.3732, 0.2946,
-0.0912, 0.3118, 0.1391, 0.2755, 0.2695, -0.1059, -0.2357, 0.3629, -0.2534, -0.0494,
0.0556, 0.0881, -0.2592, -0.2213, 0.2310, -0.4044, 0.1801, 0.1438, 0.3108, -0.3607};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{
-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// no activation function specified, so default is used.
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs = p.add_instruction(
migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::forward, clip, 1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.3969709,
0.43360898,
0.35775262,
0.23280787,
-0.52179873,
-0.21944991,
0.4535257,
-0.13735442,
0.51757574,
0.50380427};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 1 activation function (sigmoid) specified
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{0.26905832, 0.5669211, 0.20464146, 0.67195725, 0.24752215,
0.11411376, 0.12353572, 0.4245067, 0.73908687, 0.8644615,
0.34754312, 0.61424744, 0.36769435, 0.6499579, 0.3168031,
0.3296533, 0.3055136, 0.42514813, 0.6851256, 0.7967266,
0.35652235, 0.6033026, 0.52634895, 0.5815402, 0.3001663,
0.39814138, 0.4354002, 0.4310627, 0.6708563, 0.7509278};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 1 activation function (tanh) specified
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs = p.add_instruction(
migraphx::op::gru{
hidden_size, {migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip, 1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.49333298,
-0.06104589,
0.5629142,
-0.97955984,
-0.9314696,
-0.03033514,
0.5280315,
-0.27354342,
0.65615714,
0.53612584};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// seq length of 1
{
migraphx::program p;
seq_len = 1;
migraphx::shape in_shape_one{migraphx::shape::float_type,
{seq_len, batch_size, input_size}};
std::vector<float> input_one{-0.8432, -0.9887, 1.3041, -2.6430, -0.3306, -0.8504};
auto seq = p.add_literal(migraphx::literal{in_shape_one, input_one});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.27298412,
0.42363745,
-0.09368783,
0.4823072,
-0.02183238,
-0.6873896,
0.16144305,
0.31932795,
0.6104771,
0.79759157};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_reverse)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3485, -0.0378, -0.1782, 0.1416, -0.3096, -0.2212, -0.3883, 0.1983, -0.2418,
0.1480, -0.3255, 0.1359, -0.3551, -0.3605, -0.3482, -0.1424, -0.0495, -0.1640,
-0.1979, -0.2577, -0.4097, -0.1211, -0.0412, 0.1801, 0.1721, -0.4327, -0.0498,
0.2628, -0.1573, -0.1577, 0.2759, -0.2023, -0.1185, -0.2136, 0.1294, -0.2331,
0.0701, 0.4316, 0.0480, 0.0247, -0.0166, -0.2729, 0.1712, -0.3984, -0.3905};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
0.2848, -0.2851, -0.3466, -0.1718, -0.1492, -0.0082, 0.2452, -0.0401, 0.3399, 0.2529,
-0.0953, -0.0903, -0.1518, -0.1373, 0.3848, -0.0130, -0.4339, 0.0406, -0.1926, -0.1131,
0.4285, -0.0013, 0.2243, 0.2752, 0.1776, -0.1720, 0.0822, -0.0295, 0.1062, -0.2721,
-0.2736, -0.1826, 0.3541, -0.4259, 0.2188, 0.0706, 0.3650, 0.3947, 0.2522, 0.2179,
-0.0744, 0.2122, -0.4346, 0.2760, 0.4076, 0.1183, -0.1500, -0.1704, 0.3090, -0.0706,
-0.2442, 0.3021, 0.1680, 0.0783, -0.3754, -0.3469, -0.2972, -0.0170, 0.4143, 0.3801,
0.3852, -0.1170, -0.2937, 0.2979, -0.1357, 0.4257, 0.3884, -0.2916, 0.1071, 0.0934,
0.3645, -0.4310, -0.3480, 0.0702, -0.1558};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
0.0560, 0.0310, -0.1669, -0.0781, 0.1793, -0.1758, 0.3173, -0.1650, -0.3732, 0.2946,
-0.0912, 0.3118, 0.1391, 0.2755, 0.2695, -0.1059, -0.2357, 0.3629, -0.2534, -0.0494,
0.0556, 0.0881, -0.2592, -0.2213, 0.2310, -0.4044, 0.1801, 0.1438, 0.3108, -0.3607};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{
-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// concatenation of hidden states for output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.263403, 0.317655, -0.00634162, 0.200443, -0.349125,
-0.600874, 0.542386, -0.0856531, 0.55703, 0.54711,
-0.276245, 0.521348, 0.302874, 0.394353, -0.334369,
-0.187861, 0.213553, -0.0708377, 0.545435, 0.654301,
-0.329512, 0.476095, 0.284044, 0.392077, -0.369226,
-0.3275, -0.027301, 0.143774, 0.655686, 0.782831};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last output for output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.263403,
0.317655,
-0.00634162,
0.200443,
-0.349125,
-0.600874,
0.542386,
-0.0856531,
0.55703,
0.54711};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last output for output, linear_before_reset = 0
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip,
0},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.388654,
0.384975,
0.0179455,
0.350101,
-0.456872,
-0.690085,
0.534512,
-0.0558191,
0.646604,
0.463943};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// no activation function specified, so default is used.
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(
migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::reverse, clip, 1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.263403, 0.317655, -0.00634162, 0.200443, -0.349125,
-0.600874, 0.542386, -0.0856531, 0.55703, 0.54711,
-0.276245, 0.521348, 0.302874, 0.394353, -0.334369,
-0.187861, 0.213553, -0.0708377, 0.545435, 0.654301,
-0.329512, 0.476095, 0.284044, 0.392077, -0.369226,
-0.3275, -0.027301, 0.143774, 0.655686, 0.782831};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// seq length of 1
{
migraphx::program p;
seq_len = 1;
migraphx::shape in_shape_one{migraphx::shape::float_type,
{seq_len, batch_size, input_size}};
std::vector<float> input_one{-0.8432, -0.9887, 1.3041, -2.6430, -0.3306, -0.8504};
auto seq = p.add_literal(migraphx::literal{in_shape_one, input_one});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.272984,
0.423637,
-0.0936878,
0.482307,
-0.0218324,
-0.68739,
0.161443,
0.319328,
0.610477,
0.797592};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_bidirectional)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3809, 0.4283, 0.2294, -0.1018, -0.1226, -0.0037, 0.2449, -0.2712, -0.1418,
0.1363, -0.3453, -0.0693, -0.2281, 0.2699, -0.2024, -0.3085, -0.3338, 0.4109,
0.2605, -0.1019, -0.2813, 0.3323, -0.1590, 0.0788, -0.3535, 0.0397, 0.2732,
0.2906, 0.0519, 0.3617, -0.2664, 0.1441, 0.0464, -0.1057, 0.2204, -0.3294,
0.3670, 0.1411, 0.3852, 0.3572, 0.3918, 0.0483, -0.3906, -0.2841, -0.2778,
-0.4272, 0.2335, -0.1811, -0.3885, -0.1279, 0.1000, 0.0206, -0.3284, -0.0353,
0.1197, 0.1190, 0.3862, 0.0965, -0.0492, 0.2657, -0.1430, 0.0597, 0.1408,
-0.0315, 0.1248, 0.0751, 0.3838, 0.3020, 0.0515, 0.2375, -0.4255, 0.1714,
-0.0432, 0.3447, -0.2441, -0.3989, -0.3428, -0.4204, -0.4080, -0.2683, -0.0996,
-0.1685, -0.0532, -0.1258, 0.1663, -0.3526, -0.3915, -0.1721, 0.1292, -0.2279};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
-0.2683, 0.0699, -0.4021, -0.1379, 0.0042, -0.2447, 0.4006, 0.0270, -0.0446, 0.1063,
0.1381, 0.1310, -0.3596, 0.3869, 0.3929, 0.2750, 0.0890, 0.3069, -0.1691, -0.2194,
-0.1066, 0.3187, -0.4369, -0.0603, -0.0834, -0.1182, -0.2047, 0.3253, -0.2931, 0.2082,
0.0424, 0.1111, -0.2773, -0.0279, -0.0869, 0.1413, -0.4227, -0.3672, 0.4137, 0.0609,
0.4223, -0.4032, 0.2945, 0.3600, 0.3345, -0.3880, -0.0192, -0.0090, -0.2648, 0.4339,
-0.0155, 0.4437, -0.1766, 0.1957, 0.2475, 0.3773, -0.2710, 0.3289, -0.2077, -0.2534,
-0.0832, -0.1632, 0.0728, 0.2520, 0.4153, 0.1659, -0.4342, 0.0541, 0.1812, -0.2305,
0.4440, 0.0946, 0.0410, -0.4381, -0.3161, 0.3906, -0.3958, -0.4238, 0.1975, 0.3440,
0.1437, -0.0568, 0.1492, -0.4248, -0.3304, 0.2786, -0.1328, -0.3740, -0.3566, 0.3074,
0.0924, 0.2684, -0.1527, 0.1826, 0.2424, 0.2002, 0.3479, -0.1089, 0.3472, -0.3677,
-0.4231, -0.0798, -0.3709, 0.3924, 0.2774, -0.3690, -0.0233, 0.2845, 0.1969, 0.1618,
-0.3742, -0.3619, 0.2925, -0.1838, -0.1495, -0.3747, 0.0341, -0.4243, -0.0732, -0.3997,
0.2139, 0.2425, 0.4171, -0.3358, 0.3534, 0.0938, -0.0582, -0.2681, -0.4293, 0.1027,
0.4101, 0.2641, -0.4110, -0.1681, 0.3582, -0.2089, 0.0852, 0.0963, 0.3866, 0.1955,
-0.2174, 0.1996, -0.2252, 0.1748, 0.1833, -0.3155, 0.2567, -0.4387, 0.3402, 0.0599};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
-0.1582, -0.0826, 0.4008, 0.0118, 0.2511, 0.1900, -0.2838, 0.2549, -0.2484, 0.2363,
-0.4083, -0.0295, -0.1161, 0.1211, 0.2509, -0.1414, -0.2628, -0.2992, 0.1517, 0.1817,
-0.2783, 0.3183, -0.1629, -0.3108, -0.3418, 0.0411, 0.2203, 0.2187, -0.2990, -0.0416,
0.0209, -0.1024, 0.4443, -0.4420, -0.0330, -0.3591, -0.2990, 0.2167, 0.1395, 0.2317,
0.1318, 0.1909, -0.3615, 0.1953, -0.2582, -0.2217, 0.3723, 0.1458, 0.2630, -0.0377,
0.1754, 0.0800, -0.3964, -0.3247, 0.4219, -0.0900, 0.3553, 0.2614, -0.1298, -0.1124};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348,
0.4178, 1.0175, 0.9212, -0.0468, 0.5691, -0.0882, 0.8340,
0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// concatenation of hidden states for output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.0352243, 0.0146756, 0.00570925, 0.152446, 0.208683, 0.214342, -0.0454273,
-0.135177, -0.0800739, 0.903659, 0.0248217, 0.435231, -0.144448, 0.101531,
-0.111305, 0.381317, 0.468983, 0.230557, 0.348021, 0.180229, -0.0930435,
0.174108, -0.063834, 0.0909285, 0.22759, -0.221983, -0.139656, -0.0938906,
-0.247681, 0.69647, -0.159396, 0.299061, -0.116652, 0.238649, 0.109945,
0.192866, 0.307073, 0.191113, 0.658287, -0.0340374, -0.0959787, 0.0794681,
0.241526, 0.321104, 0.00693533, -0.311839, -0.12802, -0.16643, -0.393849,
0.648851, -0.395918, 0.231694, -0.160503, 0.383289, 0.0879262, -0.0254665,
0.079043, 0.322652, 0.752701, 0.243775};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last output for output
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.0959787, 0.0794681, 0.241526, 0.321104, 0.00693533,
-0.311839, -0.12802, -0.16643, -0.393849, 0.648851,
0.0248217, 0.435231, -0.144448, 0.101531, -0.111305,
0.381317, 0.468983, 0.230557, 0.348021, 0.180229};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// last output for output, linear_before_reset = 0
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
0},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
-0.09280921, 0.18506107, 0.32247013, 0.17034212, -0.00115255, -0.29865006, -0.04513004,
-0.10688055, -0.4767866, 0.6317833, 0.00286336, 0.53692746, -0.00617076, 0.04564289,
-0.18030001, 0.39584228, 0.53879917, 0.384983, 0.2759448, 0.11611474};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_bidirectional_args)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3809, 0.4283, 0.2294, -0.1018, -0.1226, -0.0037, 0.2449, -0.2712, -0.1418,
0.1363, -0.3453, -0.0693, -0.2281, 0.2699, -0.2024, -0.3085, -0.3338, 0.4109,
0.2605, -0.1019, -0.2813, 0.3323, -0.1590, 0.0788, -0.3535, 0.0397, 0.2732,
0.2906, 0.0519, 0.3617, -0.2664, 0.1441, 0.0464, -0.1057, 0.2204, -0.3294,
0.3670, 0.1411, 0.3852, 0.3572, 0.3918, 0.0483, -0.3906, -0.2841, -0.2778,
-0.4272, 0.2335, -0.1811, -0.3885, -0.1279, 0.1000, 0.0206, -0.3284, -0.0353,
0.1197, 0.1190, 0.3862, 0.0965, -0.0492, 0.2657, -0.1430, 0.0597, 0.1408,
-0.0315, 0.1248, 0.0751, 0.3838, 0.3020, 0.0515, 0.2375, -0.4255, 0.1714,
-0.0432, 0.3447, -0.2441, -0.3989, -0.3428, -0.4204, -0.4080, -0.2683, -0.0996,
-0.1685, -0.0532, -0.1258, 0.1663, -0.3526, -0.3915, -0.1721, 0.1292, -0.2279};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
-0.2683, 0.0699, -0.4021, -0.1379, 0.0042, -0.2447, 0.4006, 0.0270, -0.0446, 0.1063,
0.1381, 0.1310, -0.3596, 0.3869, 0.3929, 0.2750, 0.0890, 0.3069, -0.1691, -0.2194,
-0.1066, 0.3187, -0.4369, -0.0603, -0.0834, -0.1182, -0.2047, 0.3253, -0.2931, 0.2082,
0.0424, 0.1111, -0.2773, -0.0279, -0.0869, 0.1413, -0.4227, -0.3672, 0.4137, 0.0609,
0.4223, -0.4032, 0.2945, 0.3600, 0.3345, -0.3880, -0.0192, -0.0090, -0.2648, 0.4339,
-0.0155, 0.4437, -0.1766, 0.1957, 0.2475, 0.3773, -0.2710, 0.3289, -0.2077, -0.2534,
-0.0832, -0.1632, 0.0728, 0.2520, 0.4153, 0.1659, -0.4342, 0.0541, 0.1812, -0.2305,
0.4440, 0.0946, 0.0410, -0.4381, -0.3161, 0.3906, -0.3958, -0.4238, 0.1975, 0.3440,
0.1437, -0.0568, 0.1492, -0.4248, -0.3304, 0.2786, -0.1328, -0.3740, -0.3566, 0.3074,
0.0924, 0.2684, -0.1527, 0.1826, 0.2424, 0.2002, 0.3479, -0.1089, 0.3472, -0.3677,
-0.4231, -0.0798, -0.3709, 0.3924, 0.2774, -0.3690, -0.0233, 0.2845, 0.1969, 0.1618,
-0.3742, -0.3619, 0.2925, -0.1838, -0.1495, -0.3747, 0.0341, -0.4243, -0.0732, -0.3997,
0.2139, 0.2425, 0.4171, -0.3358, 0.3534, 0.0938, -0.0582, -0.2681, -0.4293, 0.1027,
0.4101, 0.2641, -0.4110, -0.1681, 0.3582, -0.2089, 0.0852, 0.0963, 0.3866, 0.1955,
-0.2174, 0.1996, -0.2252, 0.1748, 0.1833, -0.3155, 0.2567, -0.4387, 0.3402, 0.0599};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
-0.1582, -0.0826, 0.4008, 0.0118, 0.2511, 0.1900, -0.2838, 0.2549, -0.2484, 0.2363,
-0.4083, -0.0295, -0.1161, 0.1211, 0.2509, -0.1414, -0.2628, -0.2992, 0.1517, 0.1817,
-0.2783, 0.3183, -0.1629, -0.3108, -0.3418, 0.0411, 0.2203, 0.2187, -0.2990, -0.0416,
0.0209, -0.1024, 0.4443, -0.4420, -0.0330, -0.3591, -0.2990, 0.2167, 0.1395, 0.2317,
0.1318, 0.1909, -0.3615, 0.1953, -0.2582, -0.2217, 0.3723, 0.1458, 0.2630, -0.0377,
0.1754, 0.0800, -0.3964, -0.3247, 0.4219, -0.0900, 0.3553, 0.2614, -0.1298, -0.1124};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348,
0.4178, 1.0175, 0.9212, -0.0468, 0.5691, -0.0882, 0.8340,
0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// 3 args
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
0},
seq,
w,
r);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.0863793, -0.227845, 0.0283059, -0.258645, 0.14187, 0.43541, 0.190748,
-0.530196, -0.440444, 0.293767, 0.0402142, 0.0788687, -0.013, -0.233298,
-0.0739615, 0.467104, 0.446285, 0.306097, 0.125636, 0.272524, 0.0949838,
0.0522264, -0.0872712, -0.084203, 0.140013, 0.12739, -0.0111171, -0.431119,
-0.468382, 0.388067, -0.109174, -0.119064, -0.0242958, -0.180555, 0.118983,
0.341578, 0.275472, 0.0853083, 0.332205, -0.0498387, 0.140338, 0.0319435,
0.247019, 0.275848, -0.158223, 0.0495464, -0.0681034, -0.418158, -0.523234,
0.469122, -0.306578, -0.221095, -0.106449, -0.248934, -0.00682121, 0.288407,
0.198708, 0.0695644, 0.211621, 0.00246037};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 4 args (bias is used)
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
-0.156667, -0.248473, 0.0255282, -0.24566, 0.211589, 0.192707, 0.253025,
-0.515283, -0.414174, 0.227127, 0.124773, 0.284532, -0.203929, -0.120517,
-0.2794, 0.547635, 0.518549, 0.0447674, 0.258461, 0.0502881, -0.219516,
0.0927382, -0.0760062, -0.0906231, 0.237615, -0.215638, 0.0128074, -0.425813,
-0.433378, 0.375383, -0.0381738, 0.117793, -0.180851, -0.0841245, -0.116649,
0.419469, 0.393515, -0.076395, 0.427436, -0.264071, -0.185829, 0.0483585,
0.242955, 0.25233, 0.0148512, -0.304127, -0.0616653, -0.411568, -0.491748,
0.476508, -0.313413, -0.0361821, -0.173037, -0.235731, -0.163113, 0.349008,
0.248674, -0.0295413, 0.291437, -0.165005};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 4 args (ih is used)
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
und,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.248571, 0.0982155, 0.00808877, 0.0986508, 0.0969705, 0.434692, -0.141696,
-0.164271, -0.121157, 0.863222, -0.0718357, 0.137711, 0.109221, -0.00207995,
0.0331223, 0.262705, 0.346587, 0.457158, 0.240744, 0.404261, 0.222779,
0.179757, -0.0845316, 0.0690347, 0.10204, 0.100155, -0.190286, -0.122062,
-0.274379, 0.547281, -0.226753, -0.0397069, 0.120404, 0.171299, 0.259989,
0.0864604, 0.111322, 0.331784, 0.604653, 0.181017, 0.237426, 0.0911999,
0.233106, 0.32996, -0.17175, 0.0190231, -0.154805, -0.205631, -0.405354,
0.519054, -0.380409, -0.0350301, -0.00633752, 0.403791, 0.181883, -0.0977917,
-0.0339407, 0.413089, 0.721238, 0.431879};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
TEST_CASE(gru_bidirectional_actv_funcs)
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, input_size}};
std::vector<float> w_data{
0.3809, 0.4283, 0.2294, -0.1018, -0.1226, -0.0037, 0.2449, -0.2712, -0.1418,
0.1363, -0.3453, -0.0693, -0.2281, 0.2699, -0.2024, -0.3085, -0.3338, 0.4109,
0.2605, -0.1019, -0.2813, 0.3323, -0.1590, 0.0788, -0.3535, 0.0397, 0.2732,
0.2906, 0.0519, 0.3617, -0.2664, 0.1441, 0.0464, -0.1057, 0.2204, -0.3294,
0.3670, 0.1411, 0.3852, 0.3572, 0.3918, 0.0483, -0.3906, -0.2841, -0.2778,
-0.4272, 0.2335, -0.1811, -0.3885, -0.1279, 0.1000, 0.0206, -0.3284, -0.0353,
0.1197, 0.1190, 0.3862, 0.0965, -0.0492, 0.2657, -0.1430, 0.0597, 0.1408,
-0.0315, 0.1248, 0.0751, 0.3838, 0.3020, 0.0515, 0.2375, -0.4255, 0.1714,
-0.0432, 0.3447, -0.2441, -0.3989, -0.3428, -0.4204, -0.4080, -0.2683, -0.0996,
-0.1685, -0.0532, -0.1258, 0.1663, -0.3526, -0.3915, -0.1721, 0.1292, -0.2279};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size, hidden_size}};
std::vector<float> r_data{
-0.2683, 0.0699, -0.4021, -0.1379, 0.0042, -0.2447, 0.4006, 0.0270, -0.0446, 0.1063,
0.1381, 0.1310, -0.3596, 0.3869, 0.3929, 0.2750, 0.0890, 0.3069, -0.1691, -0.2194,
-0.1066, 0.3187, -0.4369, -0.0603, -0.0834, -0.1182, -0.2047, 0.3253, -0.2931, 0.2082,
0.0424, 0.1111, -0.2773, -0.0279, -0.0869, 0.1413, -0.4227, -0.3672, 0.4137, 0.0609,
0.4223, -0.4032, 0.2945, 0.3600, 0.3345, -0.3880, -0.0192, -0.0090, -0.2648, 0.4339,
-0.0155, 0.4437, -0.1766, 0.1957, 0.2475, 0.3773, -0.2710, 0.3289, -0.2077, -0.2534,
-0.0832, -0.1632, 0.0728, 0.2520, 0.4153, 0.1659, -0.4342, 0.0541, 0.1812, -0.2305,
0.4440, 0.0946, 0.0410, -0.4381, -0.3161, 0.3906, -0.3958, -0.4238, 0.1975, 0.3440,
0.1437, -0.0568, 0.1492, -0.4248, -0.3304, 0.2786, -0.1328, -0.3740, -0.3566, 0.3074,
0.0924, 0.2684, -0.1527, 0.1826, 0.2424, 0.2002, 0.3479, -0.1089, 0.3472, -0.3677,
-0.4231, -0.0798, -0.3709, 0.3924, 0.2774, -0.3690, -0.0233, 0.2845, 0.1969, 0.1618,
-0.3742, -0.3619, 0.2925, -0.1838, -0.1495, -0.3747, 0.0341, -0.4243, -0.0732, -0.3997,
0.2139, 0.2425, 0.4171, -0.3358, 0.3534, 0.0938, -0.0582, -0.2681, -0.4293, 0.1027,
0.4101, 0.2641, -0.4110, -0.1681, 0.3582, -0.2089, 0.0852, 0.0963, 0.3866, 0.1955,
-0.2174, 0.1996, -0.2252, 0.1748, 0.1833, -0.3155, 0.2567, -0.4387, 0.3402, 0.0599};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
std::vector<float> bias_data{
-0.1582, -0.0826, 0.4008, 0.0118, 0.2511, 0.1900, -0.2838, 0.2549, -0.2484, 0.2363,
-0.4083, -0.0295, -0.1161, 0.1211, 0.2509, -0.1414, -0.2628, -0.2992, 0.1517, 0.1817,
-0.2783, 0.3183, -0.1629, -0.3108, -0.3418, 0.0411, 0.2203, 0.2187, -0.2990, -0.0416,
0.0209, -0.1024, 0.4443, -0.4420, -0.0330, -0.3591, -0.2990, 0.2167, 0.1395, 0.2317,
0.1318, 0.1909, -0.3615, 0.1953, -0.2582, -0.2217, 0.3723, 0.1458, 0.2630, -0.0377,
0.1754, 0.0800, -0.3964, -0.3247, 0.4219, -0.0900, 0.3553, 0.2614, -0.1298, -0.1124};
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
std::vector<float> input{-0.8432,
-0.9887,
1.3041,
-2.6430,
-0.3306,
-0.8504,
-0.3933,
0.5151,
-0.2951,
0.0093,
-1.1948,
-0.1239,
0.0373,
1.3211,
0.7854,
-0.4838,
-1.0536,
-0.2529};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
std::vector<float> ih_data{-0.0468, 0.5691, -0.0882, 0.8340, 0.1483, -0.3902, -0.5348,
0.4178, 1.0175, 0.9212, -0.0468, 0.5691, -0.0882, 0.8340,
0.1483, -0.3902, -0.5348, 0.4178, 1.0175, 0.9212};
float clip = 0.0f;
// no activation function specified, so default is used.
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs = p.add_instruction(
migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip, 1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{-0.0959787, 0.0794681, 0.241526, 0.321104, 0.00693533,
-0.311839, -0.12802, -0.16643, -0.393849, 0.648851,
0.0248217, 0.435231, -0.144448, 0.101531, -0.111305,
0.381317, 0.468983, 0.230557, 0.348021, 0.180229};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 1 activation function (sigmoid) specified
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}},
migraphx::op::rnn_direction::bidirectional,
clip,
0},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.325495, 0.469214, 0.164517, 0.585327, 0.328398, 0.457928, 0.065011, 0.35986,
0.545029, 0.859425, 0.427923, 0.667133, 0.41591, 0.540971, 0.365475, 0.482058,
0.565495, 0.556993, 0.607649, 0.543627, 0.428915, 0.537405, 0.306046, 0.518399,
0.403561, 0.410694, 0.301163, 0.407397, 0.471334, 0.726446, 0.309389, 0.612072,
0.360619, 0.590861, 0.366545, 0.367001, 0.433829, 0.501275, 0.72481, 0.512745,
0.463795, 0.539649, 0.487682, 0.554471, 0.395916, 0.430744, 0.415923, 0.424275,
0.409655, 0.698256, 0.126883, 0.554374, 0.216137, 0.671491, 0.263833, 0.0678646,
0.132732, 0.477083, 0.802206, 0.626802};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 1 activation function (tanh) specified
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.0919632, -0.398302, -0.0267752, -0.326771, 0.401983, 0.949841, 0.557779,
-0.745259, -1.52726, 0.946066, 0.330446, 0.301982, -0.443763, -0.0655817,
-0.326473, 0.861394, 0.560799, -0.101768, 0.145142, 0.128956, -0.329758,
0.458253, -0.339208, 0.289109, 0.36728, -1.09574, -0.181394, -0.575781,
-0.823083, 0.804262, -0.0965933, 0.20405, -0.430215, 0.00884668, 0.0716857,
0.844222, 0.516472, -0.191571, 0.596968, -0.545405, -0.336693, -0.0280516,
0.339058, 1.00367, 0.12655, -0.0984504, -0.174945, -0.5365, 0.183188,
0.66716, -0.704461, -0.393346, -0.627123, 0.210395, 0.0563026, 0.31419,
0.759629, 0.000258222, 0.350835, -0.682684};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 3 activation functions specified
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
auto concat_hs = p.add_instruction(
migraphx::op::gru{hidden_size,
{migraphx::op::tanh{}, migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, concat_hs);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{0.351019, 0.474363, 0.570719, 0.717703, 0.468843,
1.15142, 0.457633, 0.300962, 0.361245, 0.666199,
0.330446, 0.301982, -0.443763, -0.0655817, -0.326473,
0.861394, 0.560799, -0.101768, 0.145142, 0.128956};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// 4 activation functions all specified
{
migraphx::program p;
auto seq = p.add_literal(migraphx::literal{in_shape, input});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{},
migraphx::op::tanh{},
migraphx::op::sigmoid{},
migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{
0.0352243, 0.0146756, 0.00570925, 0.152446, 0.208683, 0.214342, -0.0454273,
-0.135177, -0.0800739, 0.903659, 0.0248217, 0.435231, -0.144448, 0.101531,
-0.111305, 0.381317, 0.468983, 0.230557, 0.348021, 0.180229, -0.0930435,
0.174108, -0.063834, 0.0909285, 0.22759, -0.221983, -0.139656, -0.0938906,
-0.247681, 0.69647, -0.159396, 0.299061, -0.116652, 0.238649, 0.109945,
0.192866, 0.307073, 0.191113, 0.658287, -0.0340374, -0.0959787, 0.0794681,
0.241526, 0.321104, 0.00693533, -0.311839, -0.12802, -0.16643, -0.393849,
0.648851, -0.395918, 0.231694, -0.160503, 0.383289, 0.0879262, -0.0254665,
0.079043, 0.322652, 0.752701, 0.243775};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
// seq length of 1
{
migraphx::program p;
seq_len = 1;
migraphx::shape in_shape_one{migraphx::shape::float_type,
{seq_len, batch_size, input_size}};
std::vector<float> input_one{-0.8432, -0.9887, 1.3041, -2.6430, -0.3306, -0.8504};
auto seq = p.add_literal(migraphx::literal{in_shape_one, input_one});
auto w = p.add_literal(migraphx::literal{w_shape, w_data});
auto r = p.add_literal(migraphx::literal{r_shape, r_data});
auto bias = p.add_literal(migraphx::literal{b_shape, bias_data});
auto und = p.add_instruction(migraphx::op::undefined{});
auto ih = p.add_literal(migraphx::literal{ih_shape, ih_data});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip,
1},
seq,
w,
r,
bias,
und,
ih);
p.compile(migraphx::cpu::target{});
auto hs_concat = p.eval({});
std::vector<float> hs_data;
hs_concat.visit([&](auto output) { hs_data.assign(output.begin(), output.end()); });
std::vector<float> hs_data_gold{0.0352243, 0.0146756, 0.00570925, 0.152446, 0.208683,
0.214342, -0.0454273, -0.135177, -0.0800739, 0.903659,
-0.0271321, 0.624762, -0.117084, 0.509115, -0.0175078,
-0.144492, -0.0115366, 0.409153, 0.487015, 0.550755};
EXPECT(migraphx::verify_range(hs_data, hs_data_gold));
}
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
#include <migraph/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <test.hpp>
struct dce_target
{
std::string name() const { return "dce"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::dead_code_elimination{}};
return {migraphx::dead_code_elimination{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
TEST_CASE(simple_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -23,13 +24,13 @@ TEST_CASE(simple_test)
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == count);
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(simple_test_nop)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -39,13 +40,13 @@ TEST_CASE(simple_test_nop)
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == count);
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(simple_test_nop2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -55,13 +56,13 @@ TEST_CASE(simple_test_nop2)
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == 2);
auto result = p.eval({});
EXPECT(result == migraph::literal{});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(duplicate_test1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -71,13 +72,13 @@ TEST_CASE(duplicate_test1)
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == (count - 1));
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(duplicate_test2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -88,13 +89,13 @@ TEST_CASE(duplicate_test2)
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == (count - 2));
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(depth_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -107,8 +108,25 @@ TEST_CASE(depth_test)
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == (count - 4));
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(undefined_test)
{
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto undef = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(sum_op{}, one, two);
auto count = std::distance(p.begin(), p.end());
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == count - 1);
EXPECT(not p.has_instruction(undef));
auto result = p.eval({});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
#include <migraph/eliminate_allocation.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraphx/eliminate_allocation.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
......@@ -8,25 +8,26 @@ struct eliminate_allocation_target
{
std::size_t align = 32;
std::string name() const { return "eliminate_allocation"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::eliminate_allocation{"allocate", align}, migraph::dead_code_elimination{}};
return {migraphx::eliminate_allocation{"allocate", align},
migraphx::dead_code_elimination{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
struct allocate
{
migraph::shape s{};
migraphx::shape s{};
std::string name() const { return "allocate"; }
migraph::shape compute_shape(const std::vector<migraph::shape>& inputs) const
migraphx::shape compute_shape(const std::vector<migraphx::shape>& inputs) const
{
migraph::check_shapes{inputs}.has(0);
migraphx::check_shapes{inputs}.has(0);
return s;
}
migraph::argument compute(migraph::context&,
const migraph::shape& output_shape,
const std::vector<migraph::argument>&) const
migraphx::argument compute(migraphx::context&,
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
}
......@@ -34,74 +35,74 @@ struct allocate
TEST_CASE(basic)
{
migraph::program p;
auto a1 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {8}}});
migraphx::program p;
auto a1 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {8}}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {40}}});
auto a2 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {40}}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
auto a3 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {200}}});
auto a3 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {200}}});
p.add_instruction(pass_op{}, a3, p2);
p.compile(eliminate_allocation_target{});
EXPECT(p.get_shape() == migraph::shape{migraph::shape::float_type, {200}});
EXPECT(p.get_shape() == migraphx::shape{migraphx::shape::float_type, {200}});
EXPECT(p.get_parameter_shape("memory").bytes() == (8 * 4 + 40 * 4 + 200 * 4));
}
TEST_CASE(aligned)
{
migraph::program p;
auto a1 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1}}});
migraphx::program p;
auto a1 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {1}}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2}}});
auto a2 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2}}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
auto a3 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {200}}});
auto a3 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {200}}});
p.add_instruction(pass_op{}, a3, p2);
p.compile(eliminate_allocation_target{});
EXPECT(p.get_shape() == migraph::shape{migraph::shape::float_type, {200}});
EXPECT(p.get_shape() == migraphx::shape{migraphx::shape::float_type, {200}});
EXPECT(p.get_parameter_shape("memory").bytes() == (32 + 32 + 200 * 4));
}
TEST_CASE(unaligned)
{
migraph::program p;
auto a1 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1}}});
migraphx::program p;
auto a1 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {1}}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2}}});
auto a2 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2}}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
auto a3 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {200}}});
auto a3 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {200}}});
p.add_instruction(pass_op{}, a3, p2);
p.compile(eliminate_allocation_target{1});
EXPECT(p.get_shape() == migraph::shape{migraph::shape::float_type, {200}});
EXPECT(p.get_shape() == migraphx::shape{migraphx::shape::float_type, {200}});
EXPECT(p.get_parameter_shape("memory").bytes() == (1 * 4 + 2 * 4 + 200 * 4));
}
TEST_CASE(float_aligned)
{
migraph::program p;
auto a1 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1}}});
migraphx::program p;
auto a1 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {1}}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2}}});
auto a2 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2}}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
auto a3 = p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {200}}});
auto a3 = p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {200}}});
p.add_instruction(pass_op{}, a3, p2);
p.compile(eliminate_allocation_target{4});
EXPECT(p.get_shape() == migraph::shape{migraph::shape::float_type, {200}});
EXPECT(p.get_shape() == migraphx::shape{migraphx::shape::float_type, {200}});
EXPECT(p.get_parameter_shape("memory").bytes() == (1 * 4 + 2 * 4 + 200 * 4));
}
int main(int argc, const char* argv[])
{
setenv("MIGRAPH_DISABLE_MEMORY_COLORING", "1", 1);
setenv("MIGRAPHX_DISABLE_MEMORY_COLORING", "1", 1);
test::run(argc, argv);
}
#include <migraph/eliminate_concat.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraphx/eliminate_concat.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct concat
{
concat(std::size_t axis) { op.axis = axis; }
migraph::op::concat op;
migraphx::op::concat op;
std::string name() const { return "eliminate_concat::concat"; }
migraph::shape compute_shape(std::vector<migraph::shape> inputs) const
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
return op.compute_shape(std::move(inputs));
}
migraph::argument compute(migraph::context&,
const migraph::shape& output_shape,
const std::vector<migraph::argument>&) const
migraphx::argument compute(migraphx::context&,
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
}
......@@ -28,9 +28,9 @@ struct concat_test_optimization
/// A unique name used to identify the allocate operator
std::string allocate() const { return "allocate"; }
/// Return the lowered concat operator
migraph::op::concat get_concat(const migraph::operation& op) const
migraphx::op::concat get_concat(const migraphx::operation& op) const
{
return migraph::any_cast<concat>(op).op;
return migraphx::any_cast<concat>(op).op;
}
};
......@@ -38,81 +38,166 @@ struct eliminate_concat_target
{
std::size_t align = 32;
std::string name() const { return "eliminate_target"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::eliminate_concat{concat_test_optimization{}},
migraph::dead_code_elimination{}};
return {migraphx::eliminate_concat{concat_test_optimization{}},
migraphx::dead_code_elimination{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
struct allocate
{
migraph::shape s{};
migraphx::shape s{};
std::string name() const { return "allocate"; }
migraph::shape compute_shape(const std::vector<migraph::shape>& inputs) const
migraphx::shape compute_shape(const std::vector<migraphx::shape>& inputs) const
{
migraph::check_shapes{inputs}.has(0);
migraphx::check_shapes{inputs}.has(0);
return s;
}
migraph::argument compute(migraph::context&,
const migraph::shape& output_shape,
const std::vector<migraph::argument>&) const
migraphx::argument compute(migraphx::context&,
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
}
};
struct fred_op
struct simple_op
{
std::string name() const { return "fred_op"; }
migraph::shape compute_shape(const std::vector<migraph::shape>& inputs) const
std::string name() const { return "simple_op"; }
migraphx::shape compute_shape(const std::vector<migraphx::shape>& inputs) const
{
migraph::check_shapes{inputs}.has(1);
migraphx::check_shapes{inputs}.has(1);
return inputs.at(0);
}
migraph::argument compute(migraph::context&,
const migraph::shape&,
const std::vector<migraph::argument>& args) const
migraphx::argument compute(migraphx::context&,
const migraphx::shape&,
const std::vector<migraphx::argument>& args) const
{
return args.at(0);
}
int output_alias(const std::vector<migraphx::shape>&) const { return 0; }
};
template <class... Ts>
migraphx::shape create_shape(Ts... xs)
{
return migraphx::shape{migraphx::shape::float_type, {std::size_t(xs)...}};
}
using load = migraphx::op::load;
using identity = migraphx::op::identity;
TEST_CASE(simple)
{
auto create_test_program = [] {
migraphx::program p;
auto a1 = p.add_instruction(allocate{create_shape(1)});
auto p1 = p.add_instruction(simple_op{}, a1);
auto a2 = p.add_instruction(allocate{create_shape(1)});
auto p2 = p.add_instruction(simple_op{}, a2);
std::size_t axis = 0;
auto a3 = p.add_instruction(allocate{create_shape(2)});
p.add_instruction(concat(axis), p1, p2, a3);
return p;
};
auto create_control_program = [] {
migraphx::program p;
auto a1 = p.add_instruction(allocate{create_shape(2)});
auto l1 = p.add_instruction(load{create_shape(1), 0}, a1);
auto p1 = p.add_instruction(simple_op{}, l1);
auto l2 = p.add_instruction(load{create_shape(1), 4}, a1);
auto p2 = p.add_instruction(simple_op{}, l2);
p.add_instruction(identity{}, a1, p1, p2);
return p;
};
auto p1 = create_test_program();
auto p2 = create_control_program();
p1.compile(eliminate_concat_target{});
EXPECT(p1 == p2);
}
TEST_CASE(nested)
{
auto concat_test_program = [](auto& p) {
auto a1 = p.add_instruction(allocate{create_shape(1)});
auto p1 = p.add_instruction(simple_op{}, a1);
auto a2 = p.add_instruction(allocate{create_shape(1)});
auto p2 = p.add_instruction(simple_op{}, a2);
std::size_t axis = 0;
auto a3 = p.add_instruction(allocate{create_shape(2)});
return p.add_instruction(concat(axis), p1, p2, a3);
};
auto create_test_program = [&] {
migraphx::program p;
auto concat1 = concat_test_program(p);
auto concat2 = concat_test_program(p);
std::size_t axis = 0;
auto a1 = p.add_instruction(allocate{create_shape(4)});
p.add_instruction(concat(axis), concat1, concat2, a1);
return p;
};
auto concat_control_program = [](auto& p, auto a1) {
auto l1 = p.add_instruction(load{create_shape(1), 0}, a1);
auto p1 = p.add_instruction(simple_op{}, l1);
auto l2 = p.add_instruction(load{create_shape(1), 4}, a1);
auto p2 = p.add_instruction(simple_op{}, l2);
return p.add_instruction(identity{}, a1, p1, p2);
};
auto create_control_program = [&] {
migraphx::program p;
auto a1 = p.add_instruction(allocate{create_shape(4)});
auto l1 = p.add_instruction(load{create_shape(2), 0}, a1);
auto concat1 = concat_control_program(p, l1);
auto l2 = p.add_instruction(load{create_shape(2), 8}, a1);
auto concat2 = concat_control_program(p, l2);
p.add_instruction(identity{}, a1, concat1, concat2);
return p;
};
auto p1 = create_test_program();
auto p2 = create_control_program();
p1.compile(eliminate_concat_target{});
EXPECT(p1 == p2);
}
TEST_CASE(basic)
{
auto create_test_program = []() {
migraph::program p;
auto create_test_program = [] {
migraphx::program p;
auto a1 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1, 2, 8, 8}}});
auto p1 = p.add_instruction(fred_op{}, a1);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {1, 2, 8, 8}}});
auto p1 = p.add_instruction(simple_op{}, a1);
auto a2 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1, 3, 8, 8}}});
auto p2 = p.add_instruction(fred_op{}, a2);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {1, 3, 8, 8}}});
auto p2 = p.add_instruction(simple_op{}, a2);
auto a3 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1, 5, 8, 8}}});
auto p3 = p.add_instruction(fred_op{}, a3);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {1, 5, 8, 8}}});
auto p3 = p.add_instruction(simple_op{}, a3);
std::size_t axis = 1;
auto a4 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1, 10, 8, 8}}});
auto a4 = p.add_instruction(
allocate{migraphx::shape{migraphx::shape::float_type, {1, 10, 8, 8}}});
p.add_instruction(concat(axis), p1, p2, p3, a4);
return p;
};
auto create_control_program = []() {
migraph::program p;
auto a1 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {1, 10, 8, 8}}});
auto create_control_program = [] {
migraphx::program p;
auto a1 = p.add_instruction(
allocate{migraphx::shape{migraphx::shape::float_type, {1, 10, 8, 8}}});
auto l1 = p.add_instruction(
migraph::op::load{migraph::shape{migraph::shape::float_type, {1, 2, 8, 8}}, 0}, {a1});
auto p1 = p.add_instruction(fred_op{}, l1);
load{migraphx::shape{migraphx::shape::float_type, {1, 2, 8, 8}}, 0}, {a1});
auto p1 = p.add_instruction(simple_op{}, l1);
auto l2 = p.add_instruction(
migraph::op::load{migraph::shape{migraph::shape::float_type, {1, 3, 8, 8}}, 512}, {a1});
auto p2 = p.add_instruction(fred_op{}, l2);
load{migraphx::shape{migraphx::shape::float_type, {1, 3, 8, 8}}, 512}, {a1});
auto p2 = p.add_instruction(simple_op{}, l2);
auto l3 = p.add_instruction(
migraph::op::load{migraph::shape{migraph::shape::float_type, {1, 5, 8, 8}}, 1280},
{a1});
auto p3 = p.add_instruction(fred_op{}, l3);
p.add_instruction(migraph::op::identity{}, {a1, p1, p2, p3});
load{migraphx::shape{migraphx::shape::float_type, {1, 5, 8, 8}}, 1280}, {a1});
auto p3 = p.add_instruction(simple_op{}, l3);
p.add_instruction(identity{}, {a1, p1, p2, p3});
return p;
};
......@@ -125,37 +210,37 @@ TEST_CASE(basic)
TEST_CASE(wont_work)
{
auto create_test_program = []() {
migraph::program p;
auto create_test_program = [] {
migraphx::program p;
auto a1 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 2, 8, 8}}});
auto p1 = p.add_instruction(fred_op{}, a1);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2, 2, 8, 8}}});
auto p1 = p.add_instruction(simple_op{}, a1);
auto a2 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 3, 8, 8}}});
auto p2 = p.add_instruction(fred_op{}, a2);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2, 3, 8, 8}}});
auto p2 = p.add_instruction(simple_op{}, a2);
auto a3 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 5, 8, 8}}});
auto p3 = p.add_instruction(fred_op{}, a3);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2, 5, 8, 8}}});
auto p3 = p.add_instruction(simple_op{}, a3);
std::size_t axis = 1;
auto a4 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 10, 8, 8}}});
auto a4 = p.add_instruction(
allocate{migraphx::shape{migraphx::shape::float_type, {2, 10, 8, 8}}});
p.add_instruction(concat(axis), p1, p2, p3, a4);
return p;
};
auto create_control_program = []() {
migraph::program p;
auto create_control_program = [] {
migraphx::program p;
auto a1 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 2, 8, 8}}});
auto p1 = p.add_instruction(fred_op{}, a1);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2, 2, 8, 8}}});
auto p1 = p.add_instruction(simple_op{}, a1);
auto a2 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 3, 8, 8}}});
auto p2 = p.add_instruction(fred_op{}, a2);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2, 3, 8, 8}}});
auto p2 = p.add_instruction(simple_op{}, a2);
auto a3 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 5, 8, 8}}});
auto p3 = p.add_instruction(fred_op{}, a3);
p.add_instruction(allocate{migraphx::shape{migraphx::shape::float_type, {2, 5, 8, 8}}});
auto p3 = p.add_instruction(simple_op{}, a3);
std::size_t axis = 1;
auto a4 =
p.add_instruction(allocate{migraph::shape{migraph::shape::float_type, {2, 10, 8, 8}}});
auto a4 = p.add_instruction(
allocate{migraphx::shape{migraphx::shape::float_type, {2, 10, 8, 8}}});
p.add_instruction(concat(axis), p1, p2, p3, a4);
return p;
};
......
#include <migraph/eliminate_contiguous.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct eliminate_contiguous_target
{
std::string name() const { return "eliminate_contiguous"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::eliminate_contiguous{}, migraph::dead_code_elimination{}};
return {migraphx::eliminate_contiguous{}, migraphx::dead_code_elimination{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
TEST_CASE(standard_op)
{
migraph::program p;
migraphx::program p;
auto l = p.add_literal(get_2x2());
auto t = p.add_instruction(migraph::op::transpose{{1, 0}}, l);
auto c = p.add_instruction(migraph::op::contiguous{}, t);
auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
auto c = p.add_instruction(migraphx::op::contiguous{}, t);
p.add_instruction(pass_standard_op{}, c);
auto count = std::distance(p.begin(), p.end());
p.compile(eliminate_contiguous_target{});
......@@ -28,10 +28,10 @@ TEST_CASE(standard_op)
TEST_CASE(non_standard_op)
{
migraph::program p;
migraphx::program p;
auto l = p.add_literal(get_2x2());
auto t = p.add_instruction(migraph::op::transpose{{1, 0}}, l);
auto c = p.add_instruction(migraph::op::contiguous{}, t);
auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
auto c = p.add_instruction(migraphx::op::contiguous{}, t);
p.add_instruction(pass_op{}, c);
auto count = std::distance(p.begin(), p.end());
p.compile(eliminate_contiguous_target{});
......
#include <migraph/program.hpp>
#include <migraph/iterator_for.hpp>
#include <migraph/instruction.hpp>
#include <migraphx/program.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/instruction.hpp>
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>
struct id_target
{
struct context
{
void finish() const {}
};
migraphx::context ctx = context{};
std::string name() const { return "id"; }
std::vector<migraph::pass> get_passes(migraph::context&) const { return {}; }
migraph::context get_context() const { return {}; }
std::vector<migraphx::pass> get_passes(migraphx::context&) const { return {}; }
migraphx::context get_context() const { return ctx; }
};
struct id_ctx_op
{
std::string name() const { return "id_ctx_op"; }
migraphx::argument
compute(id_target::context&, const migraphx::shape&, std::vector<migraphx::argument> args) const
{
if(args.empty())
return {};
return args.front();
}
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.empty())
return {};
return inputs.front();
}
int output_alias(const std::vector<migraphx::shape>&) const { return 0; }
};
struct id_ctx_final_op
{
std::string name() const { return "id_ctx_final_op"; }
migraphx::argument compute(const migraphx::shape&, std::vector<migraphx::argument> args) const
{
if(args.empty())
return {};
return args.front();
}
void finalize(id_target::context&, const migraphx::shape&, const std::vector<migraphx::shape>&)
{
}
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.empty())
return {};
return inputs.front();
}
int output_alias(const std::vector<migraphx::shape>&) const { return 0; }
};
struct reverse_pass
{
std::string name() const { return "reverse_pass"; }
void apply(migraph::program& p) const
void apply(migraphx::program& p) const
{
for(auto ins : migraph::iterator_for(p))
for(auto ins : migraphx::iterator_for(p))
{
if(ins->name() == "sum")
{
......@@ -36,35 +84,35 @@ struct reverse_pass
struct reverse_target
{
std::string name() const { return "reverse"; }
std::vector<migraph::pass> get_passes(migraph::context&) const { return {reverse_pass{}}; }
migraph::context get_context() const { return {}; }
std::vector<migraphx::pass> get_passes(migraphx::context&) const { return {reverse_pass{}}; }
migraphx::context get_context() const { return {}; }
};
struct double_reverse_target
{
std::string name() const { return "double_reverse"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {reverse_pass{}, reverse_pass{}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
TEST_CASE(literal_test1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(sum_op{}, one, two);
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(literal_test2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -72,15 +120,15 @@ TEST_CASE(literal_test2)
p.add_instruction(sum_op{}, sum1, two);
auto result = p.eval({});
EXPECT(result == migraph::literal{5});
EXPECT(result != migraph::literal{3});
EXPECT(result == migraphx::literal{5});
EXPECT(result != migraphx::literal{3});
}
TEST_CASE(print_test)
{
migraph::program p;
migraphx::program p;
auto x = p.add_parameter("x", {migraph::shape::int64_type});
auto x = p.add_parameter("x", {migraphx::shape::int64_type});
auto two = p.add_literal(2);
p.add_instruction(sum_op{}, x, two);
......@@ -92,36 +140,36 @@ TEST_CASE(print_test)
TEST_CASE(param_test)
{
migraph::program p;
migraphx::program p;
auto x = p.add_parameter("x", {migraph::shape::int64_type});
auto y = p.add_parameter("y", {migraph::shape::int64_type});
auto x = p.add_parameter("x", {migraphx::shape::int64_type});
auto y = p.add_parameter("y", {migraphx::shape::int64_type});
p.add_instruction(sum_op{}, x, y);
auto result = p.eval(
{{"x", migraph::literal{1}.get_argument()}, {"y", migraph::literal{2}.get_argument()}});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
{{"x", migraphx::literal{1}.get_argument()}, {"y", migraphx::literal{2}.get_argument()}});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(param_error_test)
{
migraph::program p;
migraphx::program p;
auto x = p.add_parameter("x", {migraph::shape::int64_type});
auto y = p.add_parameter("y", {migraph::shape::int64_type});
auto x = p.add_parameter("x", {migraphx::shape::int64_type});
auto y = p.add_parameter("y", {migraphx::shape::int64_type});
p.add_instruction(sum_op{}, x, y);
EXPECT(test::throws<migraph::exception>(
EXPECT(test::throws<migraphx::exception>(
[&] {
p.eval({{"x", migraph::literal{1}.get_argument()}});
p.eval({{"x", migraphx::literal{1}.get_argument()}});
},
"Parameter not found: y"));
}
TEST_CASE(replace_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -130,13 +178,13 @@ TEST_CASE(replace_test)
EXPECT(bool{p.validate() == p.end()});
auto result = p.eval({});
EXPECT(result == migraph::literal{1});
EXPECT(result != migraph::literal{3});
EXPECT(result == migraphx::literal{1});
EXPECT(result != migraphx::literal{3});
}
TEST_CASE(replace_ins_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -146,13 +194,13 @@ TEST_CASE(replace_ins_test)
EXPECT(bool{p.validate() == p.end()});
auto result = p.eval({});
EXPECT(result == migraph::literal{1});
EXPECT(result != migraph::literal{3});
EXPECT(result == migraphx::literal{1});
EXPECT(result != migraphx::literal{3});
}
TEST_CASE(replace_ins_test2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -163,13 +211,13 @@ TEST_CASE(replace_ins_test2)
EXPECT(bool{p.validate() == p.end()});
auto result = p.eval({});
EXPECT(result == migraph::literal{2});
EXPECT(result != migraph::literal{3});
EXPECT(result == migraphx::literal{2});
EXPECT(result != migraphx::literal{3});
}
TEST_CASE(insert_replace_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
......@@ -181,47 +229,95 @@ TEST_CASE(insert_replace_test)
EXPECT(bool{p.validate() == p.end()});
auto result = p.eval({});
EXPECT(result == migraph::literal{4});
EXPECT(result != migraph::literal{5});
EXPECT(result == migraphx::literal{4});
EXPECT(result != migraphx::literal{5});
}
TEST_CASE(target_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(sum_op{}, one, two);
p.compile(id_target{});
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(reverse_target_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(sum_op{}, two, one);
p.compile(reverse_target{});
auto result = p.eval({});
EXPECT(result == migraph::literal{1});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{1});
EXPECT(result != migraphx::literal{4});
}
TEST_CASE(double_reverse_target_test)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(sum_op{}, two, one);
p.compile(double_reverse_target{});
auto result = p.eval({});
EXPECT(result == migraph::literal{3});
EXPECT(result != migraph::literal{4});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
// Check that the program doesnt modify the context directly, and only the operators modify the
// context
TEST_CASE(eval_context1)
{
migraphx::program p;
id_target t{};
EXPECT(is_shared(t.ctx, t.get_context()));
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(sum_op{}, one, two);
p.compile(t);
EXPECT(is_shared(t.ctx, p.get_context()));
p.eval({});
EXPECT(is_shared(t.ctx, p.get_context()));
}
TEST_CASE(eval_context2)
{
migraphx::program p;
id_target t{};
EXPECT(is_shared(t.ctx, t.get_context()));
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(id_ctx_op{}, one, two);
p.compile(t);
EXPECT(is_shared(t.ctx, p.get_context()));
p.eval({});
// id_ctx_op will modify the context
EXPECT(not is_shared(t.ctx, p.get_context()));
}
TEST_CASE(eval_context3)
{
migraphx::program p;
id_target t{};
EXPECT(is_shared(t.ctx, t.get_context()));
auto one = p.add_literal(1);
auto two = p.add_literal(2);
p.add_instruction(id_ctx_final_op{}, one, two);
p.compile(t);
// Finalizer will modify the context
EXPECT(not is_shared(t.ctx, p.get_context()));
auto ctx = p.get_context();
p.eval({});
EXPECT(is_shared(ctx, p.get_context()));
EXPECT(not is_shared(t.ctx, p.get_context()));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
#include <migraph/fwd_conv_batchnorm_rewrite.hpp>
#include <migraph/program.hpp>
#include <migraph/cpu/target.hpp>
#include <migraph/operators.hpp>
#include <migraph/instruction.hpp>
#include <migraphx/fwd_conv_batchnorm_rewrite.hpp>
#include <migraphx/program.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/instruction.hpp>
#include <test.hpp>
#include <migraph/verify.hpp>
#include <migraphx/verify.hpp>
TEST_CASE(fwd_conv_batchnorm_rewrite_test)
{
......@@ -30,29 +30,30 @@ TEST_CASE(fwd_conv_batchnorm_rewrite_test)
-0.62146691, -2.40572931, -1.47175612, 1.49654601, -1.07070376, -0.65908074, -0.28457694,
1.60046717, 0.20677642, -1.51844486, 0.41203847, -0.01285751, 0.07948031, -0.91507006,
-1.59481079, -0.12856238, 0.39970482, -1.89015158, 0.66969754, 0.10312618};
migraph::shape xs{migraph::shape::float_type, {1, 3, 6, 6}};
migraph::shape ws{migraph::shape::float_type, {1, 3, 3, 3}};
migraph::shape vars{migraph::shape::float_type, {1}};
migraphx::shape xs{migraphx::shape::float_type, {1, 3, 6, 6}};
migraphx::shape ws{migraphx::shape::float_type, {1, 3, 3, 3}};
migraphx::shape vars{migraphx::shape::float_type, {1}};
auto create_program = [&]() {
migraph::program p;
auto x = p.add_literal(xs, xdata);
auto w = p.add_literal(ws, wdata);
auto conv = p.add_instruction(migraph::op::convolution{{{0, 0}}, {{1, 1}}, {{1, 1}}}, x, w);
auto scale = p.add_literal(migraph::literal{vars, {3.0f}});
auto bias = p.add_literal(migraph::literal{vars, {8.1f}});
auto mean = p.add_literal(migraph::literal{vars, {4.0f}});
auto variance = p.add_literal(migraph::literal{vars, {37.11f}});
p.add_instruction(migraph::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
migraphx::program p;
auto x = p.add_literal(xs, xdata);
auto w = p.add_literal(ws, wdata);
auto conv =
p.add_instruction(migraphx::op::convolution{{{0, 0}}, {{1, 1}}, {{1, 1}}}, x, w);
auto scale = p.add_literal(migraphx::literal{vars, {3.0f}});
auto bias = p.add_literal(migraphx::literal{vars, {8.1f}});
auto mean = p.add_literal(migraphx::literal{vars, {4.0f}});
auto variance = p.add_literal(migraphx::literal{vars, {37.11f}});
p.add_instruction(migraphx::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
return p;
};
migraph::program p1 = create_program();
migraph::program p2 = create_program();
migraph::fwd_conv_batchnorm_rewrite opt;
migraphx::program p1 = create_program();
migraphx::program p2 = create_program();
migraphx::fwd_conv_batchnorm_rewrite opt;
opt.apply(p2);
p1.compile(migraph::cpu::target{});
p2.compile(migraph::cpu::target{});
p1.compile(migraphx::cpu::target{});
p2.compile(migraphx::cpu::target{});
auto result1 = p1.eval({});
auto result2 = p2.eval({});
......@@ -61,7 +62,7 @@ TEST_CASE(fwd_conv_batchnorm_rewrite_test)
std::vector<float> results_vector2;
result1.visit([&](auto output) { results_vector1.assign(output.begin(), output.end()); });
result2.visit([&](auto output) { results_vector2.assign(output.begin(), output.end()); });
EXPECT(migraph::verify_range(results_vector1, results_vector2));
EXPECT(migraphx::verify_range(results_vector1, results_vector2));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
#include <test.hpp>
#include <basic_ops.hpp>
#include <migraph/program.hpp>
#include <migraph/instruction.hpp>
#include <migraph/generate.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/hip.hpp>
void gpu_literal_test()
{
migraph::program p;
auto lit = generate_literal(migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
migraphx::program p;
auto lit = generate_literal(migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_literal(lit);
p.compile(migraph::gpu::target{});
p.compile(migraphx::gpu::target{});
auto scratch = p.get_parameter("scratch");
if(scratch == p.end())
{
auto result = p.eval({});
EXPECT(lit == migraph::gpu::from_gpu(result));
EXPECT(lit == migraphx::gpu::from_gpu(result));
}
else
{
......
#include <migraph/program.hpp>
#include <migraph/operators.hpp>
#include <migraph/generate.hpp>
#include <migraph/cpu/target.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/miopen.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/manage_ptr.hpp>
#include <migraph/type_name.hpp>
#include <migraph/verify_args.hpp>
#include <migraph/instruction.hpp>
#include <migraphx/program.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/type_name.hpp>
#include <migraphx/verify_args.hpp>
#include <migraphx/instruction.hpp>
#include <miopen/miopen.h>
......@@ -81,12 +81,12 @@ auto get_hash(const T& x)
return std::hash<T>{}(x);
}
void compile_check(migraph::program& p, const migraph::target& t)
void compile_check(migraphx::program& p, const migraphx::target& t)
{
auto name = t.name();
auto s = p.get_shape();
std::stringstream ss;
p.compile(t, migraph::tracer{ss});
p.compile(t, migraphx::tracer{ss});
if(p.get_shape() != s)
{
std::cout << ss.str() << std::endl;
......@@ -95,47 +95,55 @@ void compile_check(migraph::program& p, const migraph::target& t)
}
template <class V>
migraph::argument run_cpu(migraph::program& p)
migraphx::argument run_cpu(migraphx::program& p)
{
V v;
p = v.create_program();
auto_print pp{p, 0};
compile_check(p, migraph::cpu::target{});
migraph::program::parameter_map m;
compile_check(p, migraphx::cpu::target{});
migraphx::program::parameter_map m;
for(auto&& x : p.get_parameter_shapes())
{
m[x.first] = migraph::generate_argument(x.second, get_hash(x.first));
m[x.first] = migraphx::generate_argument(x.second, get_hash(x.first));
}
return p.eval(m);
}
template <class V>
migraph::argument run_gpu(migraph::program& p)
migraphx::argument run_gpu(migraphx::program& p)
{
V v;
p = v.create_program();
auto_print pp{p, 1};
compile_check(p, migraph::gpu::target{});
migraph::program::parameter_map m;
compile_check(p, migraphx::gpu::target{});
migraphx::program::parameter_map m;
for(auto&& x : p.get_parameter_shapes())
{
m[x.first] = migraph::gpu::to_gpu(migraph::generate_argument(x.second, get_hash(x.first)));
m[x.first] =
migraphx::gpu::to_gpu(migraphx::generate_argument(x.second, get_hash(x.first)));
}
// Program should have an output parameter
EXPECT(bool{m.find("output") != m.end()});
return migraph::gpu::from_gpu(p.eval(m));
// Ensure the program doesn't modify the context in a dry run
auto ctx = p.get_context();
assert(&ctx != &p.get_context());
EXPECT(is_shared(ctx, p.get_context()));
p.dry_run(m);
EXPECT(is_shared(ctx, p.get_context()));
return migraphx::gpu::from_gpu(p.eval(m));
}
template <class V>
void verify_program()
{
auto_print::set_terminate_handler(migraph::get_type_name<V>());
// std::cout << migraph::get_type_name<V>() << std::endl;
migraph::program cpu_prog;
migraph::program gpu_prog;
auto_print::set_terminate_handler(migraphx::get_type_name<V>());
// std::cout << migraphx::get_type_name<V>() << std::endl;
migraphx::program cpu_prog;
migraphx::program gpu_prog;
auto cpu_arg_f = detach_async([&] { return run_cpu<V>(cpu_prog); });
auto gpu_arg = run_gpu<V>(gpu_prog);
auto cpu_arg = cpu_arg_f.get();
bool passed = verify_args(migraph::get_type_name<V>(), cpu_arg, gpu_arg);
bool passed = verify_args(migraphx::get_type_name<V>(), cpu_arg, gpu_arg);
if(not passed)
{
V v;
......@@ -150,82 +158,215 @@ void verify_program()
struct test_literals
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
auto input = p.add_literal(
generate_literal(migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}}));
generate_literal(migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}));
auto weights = p.add_literal(
generate_literal(migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}}));
auto conv = p.add_instruction(migraph::op::convolution{}, input, weights);
p.add_instruction(migraph::op::relu{}, conv);
generate_literal(migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}));
auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
p.add_instruction(migraphx::op::relu{}, conv);
return p;
}
};
struct test_add
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
p.add_instruction(migraph::op::add{}, x, y);
p.add_instruction(migraphx::op::add{}, x, y);
return p;
}
};
struct test_add_half
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::half_type, {3}};
migraphx::program p;
migraphx::shape s{migraphx::shape::half_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
p.add_instruction(migraph::op::add{}, x, y);
p.add_instruction(migraphx::op::add{}, x, y);
return p;
}
};
struct test_mul
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
p.add_instruction(migraph::op::mul{}, x, y);
p.add_instruction(migraphx::op::mul{}, x, y);
return p;
}
};
struct test_exp
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {6}};
std::vector<float> data{0.1f, 0.2f, 1.f, 2.f, 0.6f, 10.f};
auto x = p.add_literal(s, data);
p.add_instruction(migraphx::op::exp{}, x);
return p;
}
};
struct test_log
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {6}};
std::vector<float> data{0.1f, 0.2f, 1.f, 2.f, 0.6f, 100.f};
auto x = p.add_literal(s, data);
p.add_instruction(migraphx::op::log{}, x);
return p;
}
};
struct test_sin
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {10}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::sin{}, x);
return p;
}
};
struct test_cos
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {8}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::cos{}, x);
return p;
}
};
struct test_tan
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::tan{}, x);
return p;
}
};
struct test_sinh
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::sinh{}, x);
return p;
}
};
struct test_cosh
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::cosh{}, x);
return p;
}
};
struct test_tanh
{
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::tanh{}, x);
return p;
}
};
struct test_asin
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::asin{}, x);
return p;
}
};
struct test_acos
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::acos{}, x);
return p;
}
};
struct test_atan
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::atan{}, x);
return p;
}
};
struct test_scale
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", migraph::shape::float_type);
auto scale = p.add_instruction(migraph::op::scalar{s}, y);
p.add_instruction(migraph::op::mul{}, x, scale);
auto y = p.add_parameter("y", migraphx::shape::float_type);
auto scale = p.add_instruction(migraphx::op::scalar{s}, y);
p.add_instruction(migraphx::op::mul{}, x, scale);
return p;
}
};
struct test_slice
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::int32_type, {2, 2, 4}};
migraphx::program p;
migraphx::shape s{migraphx::shape::int32_type, {2, 2, 4}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", {migraph::shape::int32_type, {2, 2, 2}});
auto slice0 = p.add_instruction(migraph::op::slice{{2}, {0}, {2}}, x);
p.add_instruction(migraph::op::add{}, y, slice0);
auto y = p.add_parameter("y", {migraphx::shape::int32_type, {2, 2, 2}});
auto slice0 = p.add_instruction(migraphx::op::slice{{2}, {0}, {2}}, x);
p.add_instruction(migraphx::op::add{}, y, slice0);
return p;
}
......@@ -233,247 +374,344 @@ struct test_slice
struct test_triadd
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
auto z = p.add_parameter("z", s);
auto sum = p.add_instruction(migraph::op::add{}, x, y);
p.add_instruction(migraph::op::add{}, sum, z);
auto sum = p.add_instruction(migraphx::op::add{}, x, y);
p.add_instruction(migraphx::op::add{}, sum, z);
return p;
}
};
struct test_triadd2
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {2, 3}};
migraph::shape b{migraph::shape::float_type, {3}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 3}};
migraphx::shape b{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
auto z = p.add_parameter("z", b);
auto zb = p.add_instruction(migraph::op::broadcast{1, s}, z);
auto sum = p.add_instruction(migraph::op::add{}, x, y);
p.add_instruction(migraph::op::add{}, sum, zb);
auto zb = p.add_instruction(migraphx::op::broadcast{1, s}, z);
auto sum = p.add_instruction(migraphx::op::add{}, x, y);
p.add_instruction(migraphx::op::add{}, sum, zb);
return p;
}
};
struct test_add_broadcast
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraph::shape::float_type, {2, 2, 3}});
auto y = p.add_parameter("y", {migraph::shape::float_type, {2, 2}});
auto by = p.add_instruction(migraph::op::broadcast{0, x->get_shape()}, y);
p.add_instruction(migraph::op::add{}, x, by);
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 2, 3}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {2, 2}});
auto by = p.add_instruction(migraphx::op::broadcast{0, x->get_shape()}, y);
p.add_instruction(migraphx::op::add{}, x, by);
return p;
}
};
struct test_add_broadcast2
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraph::shape::float_type, {2, 3, 4}});
auto y = p.add_parameter("y", {migraph::shape::float_type, {3}});
auto by = p.add_instruction(migraph::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraph::op::add{}, x, by);
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 3, 4}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {3}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraphx::op::add{}, x, by);
return p;
}
};
struct test_add_broadcast3
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraph::shape::float_type, {2, 4, 5}});
auto y = p.add_parameter("y", {migraph::shape::float_type, {4}});
auto by = p.add_instruction(migraph::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraph::op::add{}, x, by);
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 4, 5}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {4}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraphx::op::add{}, x, by);
return p;
}
};
struct test_add_broadcast4
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraph::shape::float_type, {2, 3, 5}});
auto y = p.add_parameter("y", {migraph::shape::float_type, {3}});
auto by = p.add_instruction(migraph::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraph::op::add{}, x, by);
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 3, 5}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {3}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraphx::op::add{}, x, by);
return p;
}
};
struct test_add_broadcast5
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraph::shape::float_type, {2, 4, 8}});
auto y = p.add_parameter("y", {migraph::shape::float_type, {4}});
auto by = p.add_instruction(migraph::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraph::op::add{}, x, by);
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 4, 8}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {4}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
p.add_instruction(migraphx::op::add{}, x, by);
return p;
}
};
struct test_triadd_broadcast
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 2, 3}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {2, 2}});
auto z = p.add_parameter("z", {migraphx::shape::float_type, {2, 2, 3}});
auto by = p.add_instruction(migraphx::op::broadcast{0, x->get_shape()}, y);
auto sum = p.add_instruction(migraphx::op::add{}, x, by);
p.add_instruction(migraphx::op::add{}, sum, z);
return p;
}
};
struct test_sub
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
auto z = p.add_parameter("z", s);
auto diff = p.add_instruction(migraphx::op::sub{}, x, y);
p.add_instruction(migraphx::op::sub{}, diff, z);
return p;
}
};
struct test_sub2
{
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraph::shape::float_type, {2, 2, 3}});
auto y = p.add_parameter("y", {migraph::shape::float_type, {2, 2}});
auto z = p.add_parameter("z", {migraph::shape::float_type, {2, 2, 3}});
auto by = p.add_instruction(migraph::op::broadcast{0, x->get_shape()}, y);
auto sum = p.add_instruction(migraph::op::add{}, x, by);
p.add_instruction(migraph::op::add{}, sum, z);
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {2, 3}};
migraphx::shape b{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
auto z = p.add_parameter("z", b);
auto zb = p.add_instruction(migraphx::op::broadcast{1, s}, z);
auto diff = p.add_instruction(migraphx::op::sub{}, x, y);
p.add_instruction(migraphx::op::sub{}, diff, zb);
return p;
}
};
struct test_softmax
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto x = p.add_parameter("x", migraph::shape{migraph::shape::float_type, {5, 3, 4, 2}});
p.add_instruction(migraph::op::softmax{}, x);
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {5, 3, 4, 2}});
p.add_instruction(migraphx::op::softmax{}, x);
return p;
}
};
struct test_softmax2
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto x = p.add_parameter("x", migraph::shape{migraph::shape::float_type, {1, 1000, 1, 1}});
p.add_instruction(migraph::op::softmax{}, x);
migraphx::program p;
auto x =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1000, 1, 1}});
p.add_instruction(migraphx::op::softmax{}, x);
return p;
}
};
struct test_conv
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto input = p.add_parameter("x", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
migraphx::program p;
auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto weights =
p.add_parameter("w", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraph::op::convolution{}, input, weights);
p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::convolution{}, input, weights);
return p;
}
};
struct test_conv2
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
auto input =
p.add_parameter("x", migraph::shape{migraph::shape::float_type, {1, 512, 28, 28}});
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 512, 28, 28}});
auto weights =
p.add_parameter("w", migraph::shape{migraph::shape::float_type, {256, 512, 1, 1}});
p.add_instruction(migraph::op::convolution{{0, 0}, {1, 1}, {1, 1}}, input, weights);
p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {256, 512, 1, 1}});
p.add_instruction(migraphx::op::convolution{{0, 0}, {1, 1}, {1, 1}}, input, weights);
return p;
}
};
struct test_group_conv
{
migraphx::program create_program() const
{
migraphx::program p;
auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 4, 16, 16}});
auto weights =
p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 1, 3, 3}});
migraphx::op::convolution op;
op.group = 4;
p.add_instruction(op, input, weights);
return p;
}
};
struct test_conv_relu
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto input = p.add_parameter("x", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
migraphx::program p;
auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto weights =
p.add_parameter("w", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
auto conv = p.add_instruction(migraph::op::convolution{}, input, weights);
p.add_instruction(migraph::op::relu{}, conv);
p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
p.add_instruction(migraphx::op::relu{}, conv);
return p;
}
};
struct test_conv_relu_half
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto input = p.add_parameter("x", migraph::shape{migraph::shape::half_type, {4, 3, 3, 3}});
migraphx::program p;
auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::half_type, {4, 3, 3, 3}});
auto weights =
p.add_parameter("w", migraph::shape{migraph::shape::half_type, {4, 3, 3, 3}});
auto conv = p.add_instruction(migraph::op::convolution{}, input, weights);
p.add_instruction(migraph::op::relu{}, conv);
p.add_parameter("w", migraphx::shape{migraphx::shape::half_type, {4, 3, 3, 3}});
auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
p.add_instruction(migraphx::op::relu{}, conv);
return p;
}
};
struct test_add_relu
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto y = p.add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = p.add_instruction(migraphx::op::add{}, x, y);
p.add_instruction(migraphx::op::relu{}, add);
return p;
}
};
struct test_sigmoid
{
migraphx::program create_program() const
{
migraph::program p;
auto x = p.add_parameter("x", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
auto y = p.add_parameter("y", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
auto add = p.add_instruction(migraph::op::add{}, x, y);
p.add_instruction(migraph::op::relu{}, add);
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::sigmoid{}, x);
return p;
}
};
struct test_abs
{
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::abs{}, x);
return p;
}
};
struct test_leaky_relu
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::leaky_relu{0.01}, x);
return p;
}
};
struct test_elu
{
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::leaky_relu{1.0}, x);
return p;
}
};
struct test_relu_lrn
{
migraphx::program create_program() const
{
migraph::program p;
auto x = p.add_parameter("x", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraph::op::leaky_relu{0.01}, x);
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 5, 2, 2}});
auto y = p.add_instruction(migraphx::op::relu{}, x);
p.add_instruction(migraphx::op::lrn{0.0001, 0.75, 1.0, 5}, y);
return p;
}
};
struct test_conv_pooling
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
auto input =
p.add_parameter("x", migraph::shape{migraph::shape::float_type, {4, 3, 32, 32}});
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 32, 32}});
auto weights =
p.add_parameter("w", migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
auto conv = p.add_instruction(migraph::op::convolution{}, input, weights);
auto pooling = p.add_instruction(migraph::op::pooling{"max"}, conv);
p.add_instruction(migraph::op::relu{}, pooling);
p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
auto pooling = p.add_instruction(migraphx::op::pooling{"max"}, conv);
p.add_instruction(migraphx::op::relu{}, pooling);
return p;
}
};
struct test_global_avg_pooling
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
auto input =
p.add_parameter("x", migraph::shape{migraph::shape::float_type, {1, 3, 16, 16}});
auto op = migraph::op::pooling{"average"};
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
auto op = migraphx::op::pooling{"average"};
auto lens = input->get_shape().lens();
op.lengths = {lens[2], lens[3]};
p.add_instruction(op, input);
......@@ -483,12 +721,12 @@ struct test_global_avg_pooling
struct test_global_max_pooling
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
auto input =
p.add_parameter("x", migraph::shape{migraph::shape::float_type, {1, 3, 16, 16}});
auto op = migraph::op::pooling{"max"};
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
auto op = migraphx::op::pooling{"max"};
auto lens = input->get_shape().lens();
op.lengths = {lens[2], lens[3]};
p.add_instruction(op, input);
......@@ -498,88 +736,90 @@ struct test_global_max_pooling
struct test_gemm
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto a = p.add_parameter("a", migraph::shape{migraph::shape::float_type, {4, 5}});
auto b = p.add_parameter("b", migraph::shape{migraph::shape::float_type, {5, 3}});
p.add_instruction(migraph::op::dot{}, a, b);
migraphx::program p;
auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {4, 5}});
auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {5, 3}});
p.add_instruction(migraphx::op::dot{}, a, b);
return p;
}
};
struct test_gemm_half
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto a = p.add_parameter("a", migraph::shape{migraph::shape::half_type, {4, 5}});
auto b = p.add_parameter("b", migraph::shape{migraph::shape::half_type, {5, 3}});
p.add_instruction(migraph::op::dot{}, a, b);
migraphx::program p;
auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::half_type, {4, 5}});
auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::half_type, {5, 3}});
p.add_instruction(migraphx::op::dot{}, a, b);
return p;
}
};
struct test_gemm_ld
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto a = p.add_parameter("a", migraph::shape{migraph::shape::float_type, {4, 5}, {10, 1}});
auto b = p.add_parameter("b", migraph::shape{migraph::shape::float_type, {5, 3}, {20, 1}});
p.add_instruction(migraph::op::dot{}, a, b);
migraphx::program p;
auto a =
p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {4, 5}, {10, 1}});
auto b =
p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {5, 3}, {20, 1}});
p.add_instruction(migraphx::op::dot{}, a, b);
return p;
}
};
struct test_gemm_transposeb
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto a = p.add_parameter("a", migraph::shape{migraph::shape::float_type, {4, 5}});
auto b = p.add_parameter("b", migraph::shape{migraph::shape::float_type, {3, 5}});
auto bt = p.add_instruction(migraph::op::transpose{{1, 0}}, b);
p.add_instruction(migraph::op::dot{}, a, bt);
migraphx::program p;
auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {4, 5}});
auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {3, 5}});
auto bt = p.add_instruction(migraphx::op::transpose{{1, 0}}, b);
p.add_instruction(migraphx::op::dot{}, a, bt);
return p;
}
};
struct test_gemm_transposea
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto a = p.add_parameter("a", migraph::shape{migraph::shape::float_type, {5, 4}});
auto b = p.add_parameter("b", migraph::shape{migraph::shape::float_type, {5, 3}});
auto at = p.add_instruction(migraph::op::transpose{{1, 0}}, a);
p.add_instruction(migraph::op::dot{}, at, b);
migraphx::program p;
auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {5, 4}});
auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {5, 3}});
auto at = p.add_instruction(migraphx::op::transpose{{1, 0}}, a);
p.add_instruction(migraphx::op::dot{}, at, b);
return p;
}
};
struct test_gemm_transposeab
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
auto a = p.add_parameter("a", migraph::shape{migraph::shape::float_type, {5, 4}});
auto b = p.add_parameter("b", migraph::shape{migraph::shape::float_type, {3, 5}});
auto at = p.add_instruction(migraph::op::transpose{{1, 0}}, a);
auto bt = p.add_instruction(migraph::op::transpose{{1, 0}}, b);
p.add_instruction(migraph::op::dot{}, at, bt);
migraphx::program p;
auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {5, 4}});
auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {3, 5}});
auto at = p.add_instruction(migraphx::op::transpose{{1, 0}}, a);
auto bt = p.add_instruction(migraphx::op::transpose{{1, 0}}, b);
p.add_instruction(migraphx::op::dot{}, at, bt);
return p;
}
};
struct test_contiguous
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {4, 4, 4, 3}, {48, 4, 1, 16}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {4, 4, 4, 3}, {48, 4, 1, 16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraph::op::contiguous{}, x);
p.add_instruction(migraphx::op::contiguous{}, x);
EXPECT(p.get_shape().standard());
return p;
}
......@@ -587,14 +827,14 @@ struct test_contiguous
struct test_transpose
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraph::shape s{migraph::shape::float_type, {4, 3, 4, 4}};
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {4, 3, 4, 4}};
auto x = p.add_parameter("x", s);
std::vector<int64_t> perm = {0, 2, 3, 1};
auto l = p.add_instruction(migraph::op::transpose{perm}, x);
p.add_instruction(migraph::op::contiguous{}, l);
auto l = p.add_instruction(migraphx::op::transpose{perm}, x);
p.add_instruction(migraphx::op::contiguous{}, l);
return p;
}
};
......@@ -606,18 +846,18 @@ struct test_batchnorm_inference_2
const size_t channels = 256;
const size_t batches = 1;
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
migraph::shape s{migraph::shape::float_type, {batches, channels, height, width}};
migraph::shape vars{migraph::shape::float_type, {channels}};
migraphx::shape s{migraphx::shape::float_type, {batches, channels, height, width}};
migraphx::shape vars{migraphx::shape::float_type, {channels}};
auto x = p.add_parameter("x", s);
auto scale = p.add_literal(migraph::abs(migraph::generate_literal(vars, 1)));
auto bias = p.add_literal(migraph::abs(migraph::generate_literal(vars, 2)));
auto mean = p.add_literal(migraph::abs(migraph::generate_literal(vars, 3)));
auto variance = p.add_literal(migraph::abs(migraph::generate_literal(vars, 4)));
p.add_instruction(migraph::op::batch_norm_inference{}, x, scale, bias, mean, variance);
auto scale = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
auto bias = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
p.add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
return p;
}
};
......@@ -629,212 +869,1274 @@ struct test_batchnorm_inference
const size_t channels = 3;
const size_t batches = 4;
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
migraph::shape s{migraph::shape::float_type, {batches, channels, height, width}};
migraph::shape vars{migraph::shape::float_type, {channels}};
migraphx::shape s{migraphx::shape::float_type, {batches, channels, height, width}};
migraphx::shape vars{migraphx::shape::float_type, {channels}};
auto x = p.add_parameter("x", s);
auto scale = p.add_literal(migraph::abs(migraph::generate_literal(vars, 1)));
auto bias = p.add_literal(migraph::abs(migraph::generate_literal(vars, 2)));
auto mean = p.add_literal(migraph::abs(migraph::generate_literal(vars, 3)));
auto variance = p.add_literal(migraph::abs(migraph::generate_literal(vars, 4)));
p.add_instruction(migraph::op::batch_norm_inference{}, x, scale, bias, mean, variance);
auto scale = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
auto bias = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
p.add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
return p;
}
};
struct test_conv_bn
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
migraph::shape xs{migraph::shape::float_type, {1, 3, 224, 224}};
migraph::shape ws{migraph::shape::float_type, {64, 3, 7, 7}};
migraph::shape vars{migraph::shape::float_type, {64}};
migraphx::shape xs{migraphx::shape::float_type, {1, 3, 224, 224}};
migraphx::shape ws{migraphx::shape::float_type, {64, 3, 7, 7}};
migraphx::shape vars{migraphx::shape::float_type, {64}};
auto x = p.add_parameter("x", xs);
auto w = p.add_parameter("w", ws);
auto conv = p.add_instruction(migraph::op::convolution{{3, 3}, {2, 2}, {1, 1}}, x, w);
auto scale = p.add_literal(migraph::abs(migraph::generate_literal(vars, 1)));
auto bias = p.add_literal(migraph::abs(migraph::generate_literal(vars, 2)));
auto mean = p.add_literal(migraph::abs(migraph::generate_literal(vars, 3)));
auto variance = p.add_literal(migraph::abs(migraph::generate_literal(vars, 4)));
p.add_instruction(migraph::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
auto conv = p.add_instruction(migraphx::op::convolution{{3, 3}, {2, 2}, {1, 1}}, x, w);
auto scale = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
auto bias = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
p.add_instruction(migraphx::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
return p;
}
};
struct test_conv_bn_relu_pooling
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
migraph::shape xs{migraph::shape::float_type, {1, 3, 224, 224}};
migraph::shape ws{migraph::shape::float_type, {64, 3, 7, 7}};
migraph::shape vars{migraph::shape::float_type, {64}};
migraphx::shape xs{migraphx::shape::float_type, {1, 3, 224, 224}};
migraphx::shape ws{migraphx::shape::float_type, {64, 3, 7, 7}};
migraphx::shape vars{migraphx::shape::float_type, {64}};
auto x = p.add_parameter("x", xs);
auto w = p.add_parameter("w", ws);
auto conv = p.add_instruction(migraph::op::convolution{{3, 3}, {2, 2}, {1, 1}}, x, w);
auto scale = p.add_literal(migraph::abs(migraph::generate_literal(vars, 1)));
auto bias = p.add_literal(migraph::abs(migraph::generate_literal(vars, 2)));
auto mean = p.add_literal(migraph::abs(migraph::generate_literal(vars, 3)));
auto variance = p.add_literal(migraph::abs(migraph::generate_literal(vars, 4)));
auto conv = p.add_instruction(migraphx::op::convolution{{3, 3}, {2, 2}, {1, 1}}, x, w);
auto scale = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
auto bias = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
auto bn = p.add_instruction(
migraph::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
auto relu = p.add_instruction(migraph::op::relu{}, bn);
p.add_instruction(migraph::op::pooling{"average", {1, 1}, {2, 2}, {3, 3}}, relu);
migraphx::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
auto relu = p.add_instruction(migraphx::op::relu{}, bn);
p.add_instruction(migraphx::op::pooling{"average", {1, 1}, {2, 2}, {3, 3}}, relu);
return p;
}
};
struct test_concat
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
std::size_t axis = 1;
migraph::shape s0{migraph::shape::int32_type, {2, 2}};
migraph::shape s1{migraph::shape::int32_type, {2, 3}};
migraph::shape s2{migraph::shape::int32_type, {2, 1}};
migraphx::shape s0{migraphx::shape::int32_type, {2, 2}};
migraphx::shape s1{migraphx::shape::int32_type, {2, 3}};
migraphx::shape s2{migraphx::shape::int32_type, {2, 1}};
auto l0 = p.add_parameter("x", s0);
auto l1 = p.add_parameter("y", s1);
auto l2 = p.add_parameter("z", s2);
p.add_instruction(migraph::op::concat{axis}, l0, l1, l2);
p.add_instruction(migraphx::op::concat{axis}, l0, l1, l2);
return p;
}
};
struct test_concat2
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
std::size_t axis = 0;
migraph::shape s0{migraph::shape::int32_type, {2, 2}};
migraph::shape s1{migraph::shape::int32_type, {3, 2}};
migraph::shape s2{migraph::shape::int32_type, {1, 2}};
migraphx::shape s0{migraphx::shape::int32_type, {2, 2}};
migraphx::shape s1{migraphx::shape::int32_type, {3, 2}};
migraphx::shape s2{migraphx::shape::int32_type, {1, 2}};
auto l0 = p.add_parameter("x", s0);
auto l1 = p.add_parameter("y", s1);
auto l2 = p.add_parameter("z", s2);
p.add_instruction(migraph::op::concat{axis}, l0, l1, l2);
p.add_instruction(migraphx::op::concat{axis}, l0, l1, l2);
return p;
}
};
struct test_concat_relu
{
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
std::size_t axis = 0;
migraph::shape s0{migraph::shape::float_type, {2, 2}};
migraph::shape s1{migraph::shape::float_type, {3, 2}};
migraph::shape s2{migraph::shape::float_type, {1, 2}};
migraphx::shape s0{migraphx::shape::float_type, {2, 2}};
migraphx::shape s1{migraphx::shape::float_type, {3, 2}};
migraphx::shape s2{migraphx::shape::float_type, {1, 2}};
auto l0 = p.add_parameter("x", s0);
auto l1 = p.add_parameter("y", s1);
auto l2 = p.add_parameter("z", s2);
auto r0 = p.add_instruction(migraph::op::relu{}, l0);
auto r1 = p.add_instruction(migraph::op::relu{}, l1);
auto r2 = p.add_instruction(migraph::op::relu{}, l2);
auto c0 = p.add_instruction(migraph::op::concat{axis}, r0, r1, r2);
p.add_instruction(migraph::op::relu{}, c0);
auto r0 = p.add_instruction(migraphx::op::relu{}, l0);
auto r1 = p.add_instruction(migraphx::op::relu{}, l1);
auto r2 = p.add_instruction(migraphx::op::relu{}, l2);
auto c0 = p.add_instruction(migraphx::op::concat{axis}, r0, r1, r2);
p.add_instruction(migraphx::op::relu{}, c0);
return p;
}
};
struct test_pad
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s0{migraphx::shape::int32_type, {1, 96, 165, 165}};
std::vector<int64_t> pads0 = {0, 0, 0, 0, 0, 0, 1, 1};
std::vector<int64_t> pads1 = {0, 0, 0, 0, 1, 1, 1, 1};
std::vector<int64_t> pads2 = {1, 1, 1, 1, 0, 0, 0, 0};
std::vector<int64_t> pads3 = {1, 0, 1, 0, 1, 0, 2, 0};
auto l0 = p.add_parameter("x", s0);
p.add_instruction(migraphx::op::pad{pads0}, l0);
p.add_instruction(migraphx::op::pad{pads1}, l0);
p.add_instruction(migraphx::op::pad{pads2}, l0);
p.add_instruction(migraphx::op::pad{pads3}, l0);
return p;
}
};
struct test_pooling_autopad
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s0{migraphx::shape::float_type, {1, 3, 63, 63}};
auto l0 = p.add_parameter("x", s0);
migraphx::op::pooling op{"max"};
op.padding_mode = migraphx::op::padding_mode_t::same;
op.lengths = {2, 2};
op.stride = {2, 2};
p.add_instruction(op, l0);
return p;
}
};
struct test_gather
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3, 3}};
migraphx::shape s_indices{migraphx::shape::int32_type, {2, 2}};
std::vector<int> indices{1, 2, 2, 1};
auto a0 = p.add_parameter("data", s);
auto a1 = p.add_literal(migraphx::literal{s_indices, indices});
int axis = 0;
p.add_instruction(migraphx::op::gather{axis}, a0, a1);
return p;
}
};
struct test_gather_neg_axis
{
migraphx::program create_program() const
{
migraphx::program p;
migraphx::shape s{migraphx::shape::float_type, {3, 3}};
migraphx::shape s_indices{migraphx::shape::int32_type, {2, 2}};
std::vector<int> indices{1, 2, 2, 1};
auto a0 = p.add_parameter("data", s);
auto a1 = p.add_literal(migraphx::literal{s_indices, indices});
int axis = -1;
p.add_instruction(migraphx::op::gather{axis}, a0, a1);
return p;
}
};
void manual_identity()
{
migraph::program p;
migraphx::program p;
std::vector<float> data0 = {0, 1, 2, 3};
migraph::shape s0{migraph::shape::float_type, {2, 2}};
auto l0 = p.add_literal(migraph::literal{s0, data0});
p.add_instruction(migraph::op::identity{}, l0);
p.compile(migraph::gpu::target{});
migraph::program::parameter_map m;
migraphx::shape s0{migraphx::shape::float_type, {2, 2}};
auto l0 = p.add_literal(migraphx::literal{s0, data0});
p.add_instruction(migraphx::op::identity{}, l0);
p.compile(migraphx::gpu::target{});
migraphx::program::parameter_map m;
for(auto&& x : p.get_parameter_shapes())
{
m[x.first] = migraph::gpu::to_gpu(migraph::generate_argument(x.second));
m[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second));
}
auto result = migraph::gpu::from_gpu(p.eval(m));
auto result = migraphx::gpu::from_gpu(p.eval(m));
std::cout << result << std::endl;
}
void manual_test_concat_relu()
{
migraph::program p;
migraphx::program p;
std::size_t axis = 0;
std::vector<float> data0 = {0, 1, 2, 3};
std::vector<float> data1 = {4, 5, 6, 7, 8, 9};
std::vector<float> data2 = {10, 11};
migraph::shape s0{migraph::shape::float_type, {2, 2}};
migraph::shape s1{migraph::shape::float_type, {3, 2}};
migraph::shape s2{migraph::shape::float_type, {1, 2}};
auto l0 = p.add_literal(migraph::literal{s0, data0});
auto l1 = p.add_literal(migraph::literal{s1, data1});
auto l2 = p.add_literal(migraph::literal{s2, data2});
auto r0 = p.add_instruction(migraph::op::relu{}, l0);
auto r1 = p.add_instruction(migraph::op::relu{}, l1);
auto r2 = p.add_instruction(migraph::op::relu{}, l2);
auto c0 = p.add_instruction(migraph::op::concat{axis}, r0, r1, r2);
p.add_instruction(migraph::op::relu{}, c0);
p.compile(migraph::gpu::target{});
migraph::program::parameter_map m;
migraphx::shape s0{migraphx::shape::float_type, {2, 2}};
migraphx::shape s1{migraphx::shape::float_type, {3, 2}};
migraphx::shape s2{migraphx::shape::float_type, {1, 2}};
auto l0 = p.add_literal(migraphx::literal{s0, data0});
auto l1 = p.add_literal(migraphx::literal{s1, data1});
auto l2 = p.add_literal(migraphx::literal{s2, data2});
auto r0 = p.add_instruction(migraphx::op::relu{}, l0);
auto r1 = p.add_instruction(migraphx::op::relu{}, l1);
auto r2 = p.add_instruction(migraphx::op::relu{}, l2);
auto c0 = p.add_instruction(migraphx::op::concat{axis}, r0, r1, r2);
p.add_instruction(migraphx::op::relu{}, c0);
p.compile(migraphx::gpu::target{});
migraphx::program::parameter_map m;
for(auto&& x : p.get_parameter_shapes())
{
m[x.first] = migraph::gpu::to_gpu(migraph::generate_argument(x.second));
m[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second));
}
auto result = migraph::gpu::from_gpu(p.eval(m));
auto result = migraphx::gpu::from_gpu(p.eval(m));
std::cout << result << std::endl;
}
struct test_conv_bn_relu_pooling2
{
static migraph::instruction_ref
add_bn(migraph::program& p, migraph::instruction_ref x, std::size_t channels)
static migraphx::instruction_ref
add_bn(migraphx::program& p, migraphx::instruction_ref x, std::size_t channels)
{
migraph::shape vars{migraph::shape::float_type, {channels}};
auto scale = p.add_literal(migraph::abs(migraph::generate_literal(vars, 1 + channels)));
auto bias = p.add_literal(migraph::abs(migraph::generate_literal(vars, 2 + channels)));
auto mean = p.add_literal(migraph::abs(migraph::generate_literal(vars, 3 + channels)));
auto variance = p.add_literal(migraph::abs(migraph::generate_literal(vars, 4 + channels)));
migraphx::shape vars{migraphx::shape::float_type, {channels}};
auto scale = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1 + channels)));
auto bias = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2 + channels)));
auto mean = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3 + channels)));
auto variance =
p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4 + channels)));
return p.add_instruction(
migraph::op::batch_norm_inference{}, x, scale, bias, mean, variance);
migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
}
migraph::program create_program() const
migraphx::program create_program() const
{
migraph::program p;
migraphx::program p;
migraph::shape xs1{migraph::shape::float_type, {1, 512, 7, 7}};
migraph::shape xs2{migraph::shape::float_type, {1, 1024, 14, 14}};
migraph::shape ws1{migraph::shape::float_type, {2048, 512, 1, 1}};
migraph::shape ws2{migraph::shape::float_type, {2048, 1024, 1, 1}};
migraphx::shape xs1{migraphx::shape::float_type, {1, 512, 7, 7}};
migraphx::shape xs2{migraphx::shape::float_type, {1, 1024, 14, 14}};
migraphx::shape ws1{migraphx::shape::float_type, {2048, 512, 1, 1}};
migraphx::shape ws2{migraphx::shape::float_type, {2048, 1024, 1, 1}};
auto x1 = p.add_parameter("x1", xs1);
auto w1 = p.add_parameter("w1", ws1);
auto conv1 = p.add_instruction(migraph::op::convolution{{0, 0}, {1, 1}, {1, 1}}, x1, w1);
auto conv1 = p.add_instruction(migraphx::op::convolution{{0, 0}, {1, 1}, {1, 1}}, x1, w1);
auto bn1 = add_bn(p, conv1, 2048);
auto x2 = p.add_parameter("x2", xs2);
auto w2 = p.add_parameter("w2", ws2);
auto conv2 = p.add_instruction(migraph::op::convolution{{0, 0}, {2, 2}, {1, 1}}, x2, w2);
auto conv2 = p.add_instruction(migraphx::op::convolution{{0, 0}, {2, 2}, {1, 1}}, x2, w2);
auto bn2 = add_bn(p, conv2, 2048);
auto add = p.add_instruction(migraph::op::add{}, bn1, bn2);
auto relu = p.add_instruction(migraph::op::relu{}, add);
p.add_instruction(migraph::op::pooling{"average", {1, 1}, {2, 2}, {3, 3}}, relu);
auto add = p.add_instruction(migraphx::op::add{}, bn1, bn2);
auto relu = p.add_instruction(migraphx::op::relu{}, add);
p.add_instruction(migraphx::op::pooling{"average", {1, 1}, {2, 2}, {3, 3}}, relu);
return p;
}
};
struct test_rnn_forward
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_rnn_forward10
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 10;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_rnn_reverse
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip},
seq,
w,
r,
bias,
und,
ih);
return p;
}
};
struct test_rnn_reverse2
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 2;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip},
seq,
w,
r,
bias,
und,
ih);
return p;
}
};
struct test_rnn_3args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip},
seq,
w,
r);
return p;
}
};
struct test_rnn_4args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 5;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip},
seq,
w,
r,
bias);
return p;
}
};
struct test_rnn_5args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 10;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_rnn_bidirectional
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_rnn_bidirectional10
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 10;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_rnn_bi_3args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 10;
std::size_t hidden_size = 4;
std::size_t input_size = 3;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto output =
p.add_instruction(migraphx::op::rnn{hidden_size,
{migraphx::op::tanh{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_gru_forward_last
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_gru_forward_hs
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
bias,
und,
ih);
return p;
}
};
struct test_gru_forward_3args_und
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r,
und,
und,
und);
return p;
}
};
struct test_gru_forward_3args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r);
return p;
}
};
struct test_gru_forward_seq1
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::forward,
clip},
seq,
w,
r);
return p;
}
};
struct test_gru_forward_default_actv
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(
migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::forward, clip},
seq,
w,
r);
return p;
}
};
struct test_gru_forward_default_actv1
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(
migraphx::op::gru{
hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::forward, clip},
seq,
w,
r,
bias,
und,
ih);
return p;
}
};
struct test_gru_reverse_last
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_gru_reverse_3args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 1;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::reverse,
clip},
seq,
w,
r);
return p;
}
};
struct test_gru_bidirct_last
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
auto output =
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias,
und,
ih);
p.add_instruction(migraphx::op::rnn_last_output{}, output);
return p;
}
};
struct test_gru_bidirct_hs
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias,
und,
ih);
return p;
}
};
struct test_gru_bidirct_3args_und
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
und,
und,
und);
return p;
}
};
struct test_gru_bidirct_3args
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r);
return p;
}
};
struct test_gru_bidirct_seq1
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}, migraphx::op::tanh{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r);
return p;
}
};
struct test_gru_bidirct_default_actv
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 1;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
p.add_instruction(
migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip},
seq,
w,
r);
return p;
}
};
struct test_gru_bidirct_default_actv1
{
migraphx::program create_program() const
{
std::size_t batch_size = 2;
std::size_t seq_len = 3;
std::size_t hidden_size = 5;
std::size_t input_size = 8;
std::size_t num_dirct = 2;
float clip = 0.0f;
migraphx::program p;
migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
migraphx::shape w_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, input_size}};
migraphx::shape r_shape{migraphx::shape::float_type,
{num_dirct, 3 * hidden_size, hidden_size}};
migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
auto seq = p.add_parameter("seq", in_shape);
auto w = p.add_parameter("w", w_shape);
auto r = p.add_parameter("r", r_shape);
auto bias = p.add_parameter("bias", b_shape);
auto ih = p.add_parameter("ih", ih_shape);
auto und = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(migraphx::op::gru{hidden_size,
{migraphx::op::sigmoid{}},
migraphx::op::rnn_direction::bidirectional,
clip},
seq,
w,
r,
bias,
und,
ih);
return p;
}
};
int main()
{
verify_program<test_relu_lrn>();
verify_program<test_pooling_autopad>();
verify_program<test_abs>();
verify_program<test_concat>();
verify_program<test_concat2>();
verify_program<test_concat_relu>();
verify_program<test_pad>();
verify_program<test_add>();
verify_program<test_add_half>();
verify_program<test_mul>();
verify_program<test_exp>();
verify_program<test_log>();
verify_program<test_sin>();
verify_program<test_cos>();
verify_program<test_tan>();
verify_program<test_sinh>();
verify_program<test_cosh>();
verify_program<test_tanh>();
verify_program<test_asin>();
verify_program<test_acos>();
verify_program<test_atan>();
verify_program<test_scale>();
verify_program<test_triadd>();
verify_program<test_triadd2>();
......@@ -844,14 +2146,19 @@ int main()
verify_program<test_add_broadcast4>();
verify_program<test_add_broadcast5>();
verify_program<test_triadd_broadcast>();
verify_program<test_sub>();
verify_program<test_sub2>();
verify_program<test_softmax>();
verify_program<test_softmax2>();
verify_program<test_conv>();
verify_program<test_conv2>();
verify_program<test_group_conv>();
verify_program<test_conv_relu>();
verify_program<test_conv_relu_half>();
verify_program<test_add_relu>();
verify_program<test_leaky_relu>();
verify_program<test_sigmoid>();
verify_program<test_elu>();
verify_program<test_conv_pooling>();
verify_program<test_global_avg_pooling>();
verify_program<test_global_max_pooling>();
......@@ -869,4 +2176,32 @@ int main()
verify_program<test_conv_bn_relu_pooling>();
verify_program<test_conv_bn_relu_pooling2>();
verify_program<test_slice>();
verify_program<test_gather>();
verify_program<test_gather_neg_axis>();
verify_program<test_rnn_forward>();
verify_program<test_rnn_forward10>();
verify_program<test_rnn_reverse>();
verify_program<test_rnn_reverse2>();
verify_program<test_rnn_3args>();
verify_program<test_rnn_4args>();
verify_program<test_rnn_5args>();
verify_program<test_rnn_bidirectional>();
verify_program<test_rnn_bidirectional10>();
verify_program<test_rnn_bi_3args>();
verify_program<test_gru_forward_last>();
verify_program<test_gru_forward_hs>();
verify_program<test_gru_forward_3args_und>();
verify_program<test_gru_forward_3args>();
verify_program<test_gru_forward_seq1>();
verify_program<test_gru_forward_default_actv>();
verify_program<test_gru_forward_default_actv1>();
verify_program<test_gru_reverse_last>();
verify_program<test_gru_reverse_3args>();
verify_program<test_gru_bidirct_last>();
verify_program<test_gru_bidirct_hs>();
verify_program<test_gru_bidirct_3args_und>();
verify_program<test_gru_bidirct_3args>();
verify_program<test_gru_bidirct_seq1>();
verify_program<test_gru_bidirct_default_actv>();
verify_program<test_gru_bidirct_default_actv1>();
}
#include <migraph/program.hpp>
#include <migraph/argument.hpp>
#include <migraph/shape.hpp>
#include <migraphx/program.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/shape.hpp>
struct sum_op
{
std::string name() const { return "sum"; }
migraph::argument
compute(migraph::context&, const migraph::shape&, std::vector<migraph::argument> args) const
migraphx::argument
compute(migraphx::context&, const migraphx::shape&, std::vector<migraphx::argument> args) const
{
migraph::argument result;
migraphx::argument result;
if(args.size() != 2)
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape() != args[1].get_shape())
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape().lens().size() != 1)
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape().lens().front() != 1)
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
args[0].visit_at([&](auto x) {
args[1].visit_at([&](auto y) { result = migraph::literal{x + y}.get_argument(); });
args[1].visit_at([&](auto y) { result = migraphx::literal{x + y}.get_argument(); });
});
return result;
}
migraph::shape compute_shape(std::vector<migraph::shape> inputs) const
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.size() != 2)
MIGRAPH_THROW("Wrong inputs");
MIGRAPHX_THROW("Wrong inputs");
return inputs.front();
}
};
......@@ -35,29 +35,29 @@ struct sum_op
struct minus_op
{
std::string name() const { return "minus"; }
migraph::argument
compute(migraph::context&, const migraph::shape&, std::vector<migraph::argument> args) const
migraphx::argument
compute(migraphx::context&, const migraphx::shape&, std::vector<migraphx::argument> args) const
{
migraph::argument result;
migraphx::argument result;
if(args.size() != 2)
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape() != args[1].get_shape())
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape().lens().size() != 1)
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
if(args[0].get_shape().lens().front() != 1)
MIGRAPH_THROW("Wrong args");
MIGRAPHX_THROW("Wrong args");
args[0].visit_at([&](auto x) {
args[1].visit_at([&](auto y) { result = migraph::literal{x - y}.get_argument(); });
args[1].visit_at([&](auto y) { result = migraphx::literal{x - y}.get_argument(); });
});
return result;
}
migraph::shape compute_shape(std::vector<migraph::shape> inputs) const
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.size() != 2)
MIGRAPH_THROW("Wrong inputs");
MIGRAPHX_THROW("Wrong inputs");
return inputs.front();
}
};
......@@ -65,35 +65,35 @@ struct minus_op
struct pass_op
{
std::string name() const { return "pass"; }
migraph::argument
compute(migraph::context&, const migraph::shape&, std::vector<migraph::argument> args) const
migraphx::argument
compute(migraphx::context&, const migraphx::shape&, std::vector<migraphx::argument> args) const
{
if(args.empty())
return {};
return args.front();
}
migraph::shape compute_shape(std::vector<migraph::shape> inputs) const
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
if(inputs.empty())
return {};
return inputs.front();
}
int output_alias(const std::vector<migraph::shape>&) const { return 0; }
int output_alias(const std::vector<migraphx::shape>&) const { return 0; }
};
struct pass_standard_op
{
std::string name() const { return "pass"; }
migraph::argument
compute(migraph::context&, const migraph::shape&, std::vector<migraph::argument> args) const
migraphx::argument
compute(migraphx::context&, const migraphx::shape&, std::vector<migraphx::argument> args) const
{
if(args.empty())
return {};
return args.front();
}
migraph::shape compute_shape(std::vector<migraph::shape> inputs) const
migraphx::shape compute_shape(std::vector<migraphx::shape> inputs) const
{
for(auto&& input : inputs)
{
......@@ -104,37 +104,38 @@ struct pass_standard_op
return {};
return inputs.front();
}
int output_alias(const std::vector<migraph::shape>&) const { return 0; }
int output_alias(const std::vector<migraphx::shape>&) const { return 0; }
};
struct nop
{
std::string name() const { return "nop"; }
migraph::argument
compute(migraph::context&, const migraph::shape&, const std::vector<migraph::argument>&) const
migraphx::argument compute(migraphx::context&,
const migraphx::shape&,
const std::vector<migraphx::argument>&) const
{
return {};
}
migraph::shape compute_shape(const std::vector<migraph::shape>&) const { return {}; }
migraphx::shape compute_shape(const std::vector<migraphx::shape>&) const { return {}; }
};
inline migraph::literal get_2x2()
inline migraphx::literal get_2x2()
{
return migraph::literal{{migraph::shape::float_type, {2, 2}}, {1, 2, 3, 4}};
return migraphx::literal{{migraphx::shape::float_type, {2, 2}}, {1, 2, 3, 4}};
}
inline migraph::literal get_2x2_transposed()
inline migraphx::literal get_2x2_transposed()
{
return migraph::literal{{migraph::shape::float_type, {2, 2}, {1, 2}}, {1, 2, 3, 4}};
return migraphx::literal{{migraphx::shape::float_type, {2, 2}, {1, 2}}, {1, 2, 3, 4}};
}
inline migraph::literal get_2()
inline migraphx::literal get_2()
{
return migraph::literal{{migraph::shape::float_type, {2}}, {1, 2}};
return migraphx::literal{{migraphx::shape::float_type, {2}}, {1, 2}};
}
inline migraph::literal get_2_broadcasted()
inline migraphx::literal get_2_broadcasted()
{
return migraph::literal{{migraph::shape::float_type, {2, 1}, {1, 0}}, {1, 2}};
return migraphx::literal{{migraphx::shape::float_type, {2, 1}, {1, 0}}, {1, 2}};
}
#ifndef MIGRAPH_GUARD_ROB_HPP
#define MIGRAPH_GUARD_ROB_HPP
#ifndef MIGRAPHX_GUARD_ROB_HPP
#define MIGRAPHX_GUARD_ROB_HPP
#ifdef __clang__
#pragma clang diagnostic push
......@@ -30,7 +30,8 @@ struct mem_data_ptr
using type = T C::*;
};
#define MIGRAPH_ROB(name, Type, C, mem) \
// NOLINTNEXTLINE
#define MIGRAPHX_ROB(name, Type, C, mem) \
struct name##_tag : mem_data_ptr<C, Type> \
{ \
}; \
......
......@@ -7,8 +7,8 @@
#include <unordered_map>
#include <vector>
#ifndef MIGRAPH_GUARD_TEST_TEST_HPP
#define MIGRAPH_GUARD_TEST_TEST_HPP
#ifndef MIGRAPHX_GUARD_TEST_TEST_HPP
#define MIGRAPHX_GUARD_TEST_TEST_HPP
namespace test {
// NOLINTNEXTLINE
......@@ -111,7 +111,7 @@ struct lhs_expression
struct capture
{
template <class T>
auto operator->*(const T& x)
auto operator->*(const T& x) const
{
return make_lhs_expression(x);
}
......@@ -189,7 +189,7 @@ inline auto& get_test_cases()
inline void add_test_case(std::string name, std::function<void()> f)
{
get_test_cases().emplace_back(name, f);
get_test_cases().emplace_back(std::move(name), std::move(f));
}
struct auto_register
......@@ -224,7 +224,13 @@ inline void run(int argc, const char* argv[])
std::unordered_map<std::string, std::function<void()>> m(get_test_cases().begin(),
get_test_cases().end());
for(auto&& name : cases)
run_test_case(name, m[name]);
{
auto f = m.find(name);
if(f == m.end())
std::cout << "[ ERROR ] Test case '" << name << "' not found." << std::endl;
else
run_test_case(name, f->second);
}
}
}
......@@ -248,6 +254,7 @@ inline void run(int argc, const char* argv[])
// NOLINTNEXTLINE
#define TEST_CAT(x, ...) TEST_PRIMITIVE_CAT(x, __VA_ARGS__)
// NOLINTNEXTLINE
#define TEST_PRIMITIVE_CAT(x, ...) x##__VA_ARGS__
// NOLINTNEXTLINE
......
#include <migraph/literal.hpp>
#include <migraphx/literal.hpp>
#include <sstream>
#include <string>
#include "test.hpp"
TEST_CASE(literal_test)
{
EXPECT(migraph::literal{1} == migraph::literal{1});
EXPECT(migraph::literal{1} != migraph::literal{2});
EXPECT(migraph::literal{} == migraph::literal{});
EXPECT(migraph::literal{} != migraph::literal{2});
EXPECT(migraphx::literal{1} == migraphx::literal{1});
EXPECT(migraphx::literal{1} != migraphx::literal{2});
EXPECT(migraphx::literal{} == migraphx::literal{});
EXPECT(migraphx::literal{} != migraphx::literal{2});
migraph::literal l1{1};
migraph::literal l2 = l1; // NOLINT
migraphx::literal l1{1};
migraphx::literal l2 = l1; // NOLINT
EXPECT(l1 == l2);
EXPECT(l1.at<int>(0) == 1);
EXPECT(!l1.empty());
EXPECT(!l2.empty());
migraph::literal l3{};
migraph::literal l4{};
migraphx::literal l3{};
migraphx::literal l4{};
EXPECT(l3 == l4);
EXPECT(l3.empty());
EXPECT(l4.empty());
......@@ -27,7 +27,7 @@ TEST_CASE(literal_test)
TEST_CASE(literal_os1)
{
migraph::literal l{1};
migraphx::literal l{1};
std::stringstream ss;
ss << l;
EXPECT(ss.str() == "1");
......@@ -35,7 +35,7 @@ TEST_CASE(literal_os1)
TEST_CASE(literal_os2)
{
migraph::literal l{};
migraphx::literal l{};
std::stringstream ss;
ss << l;
EXPECT(ss.str().empty());
......@@ -43,8 +43,8 @@ TEST_CASE(literal_os2)
TEST_CASE(literal_os3)
{
migraph::shape s{migraph::shape::int64_type, {3}};
migraph::literal l{s, {1, 2, 3}};
migraphx::shape s{migraphx::shape::int64_type, {3}};
migraphx::literal l{s, {1, 2, 3}};
std::stringstream ss;
ss << l;
EXPECT(ss.str() == "1, 2, 3");
......
#include <migraph/matcher.hpp>
#include <migraph/iterator_for.hpp>
#include <migraphx/matcher.hpp>
#include <migraphx/iterator_for.hpp>
#include <test.hpp>
#include <basic_ops.hpp>
namespace match = migraph::match;
namespace match = migraphx::match;
template <class M>
migraph::match::matcher_result find_match(migraph::program& p, M&& m)
migraphx::match::matcher_result find_match(migraphx::program& p, M&& m)
{
migraph::match::matcher_result result;
for(auto ins : migraph::iterator_for(p))
migraphx::match::matcher_result result;
for(auto ins : migraphx::iterator_for(p))
{
result = migraph::match::match_instruction(p, ins, m);
result = migraphx::match::match_instruction(p, ins, m);
if(result.result != p.end())
return result;
}
......@@ -20,7 +20,7 @@ migraph::match::matcher_result find_match(migraph::program& p, M&& m)
void match1()
{
migraph::program p;
migraphx::program p;
auto l = p.add_literal(1);
auto m = match::standard_shape();
auto r = find_match(p, m);
......@@ -29,7 +29,7 @@ void match1()
TEST_CASE(match_name1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -41,7 +41,7 @@ TEST_CASE(match_name1)
TEST_CASE(match_name2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -53,7 +53,7 @@ TEST_CASE(match_name2)
TEST_CASE(match_name3)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -65,7 +65,7 @@ TEST_CASE(match_name3)
TEST_CASE(match_arg1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -77,7 +77,7 @@ TEST_CASE(match_arg1)
TEST_CASE(match_arg2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -89,7 +89,7 @@ TEST_CASE(match_arg2)
TEST_CASE(match_arg3)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -101,7 +101,7 @@ TEST_CASE(match_arg3)
TEST_CASE(match_arg4)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -113,7 +113,7 @@ TEST_CASE(match_arg4)
TEST_CASE(match_arg5)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -125,7 +125,7 @@ TEST_CASE(match_arg5)
TEST_CASE(match_arg6)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -137,7 +137,7 @@ TEST_CASE(match_arg6)
TEST_CASE(match_arg7)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -150,7 +150,7 @@ TEST_CASE(match_arg7)
TEST_CASE(match_args1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -163,7 +163,7 @@ TEST_CASE(match_args1)
TEST_CASE(match_args2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -176,7 +176,7 @@ TEST_CASE(match_args2)
TEST_CASE(match_args3)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -188,7 +188,7 @@ TEST_CASE(match_args3)
TEST_CASE(match_args4)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum1 = p.add_instruction(sum_op{}, one, two);
......@@ -202,7 +202,7 @@ TEST_CASE(match_args4)
TEST_CASE(match_args5)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -215,7 +215,7 @@ TEST_CASE(match_args5)
TEST_CASE(match_args6)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -227,7 +227,7 @@ TEST_CASE(match_args6)
TEST_CASE(match_args7)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -241,7 +241,7 @@ TEST_CASE(match_args7)
TEST_CASE(match_either_args1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum1 = p.add_instruction(sum_op{}, one, two);
......@@ -255,7 +255,7 @@ TEST_CASE(match_either_args1)
TEST_CASE(match_either_args2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum1 = p.add_instruction(sum_op{}, one, two);
......@@ -269,7 +269,7 @@ TEST_CASE(match_either_args2)
TEST_CASE(match_either_args3)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum1 = p.add_instruction(sum_op{}, one, two);
......@@ -283,7 +283,7 @@ TEST_CASE(match_either_args3)
TEST_CASE(match_all_of1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -296,7 +296,7 @@ TEST_CASE(match_all_of1)
TEST_CASE(match_all_of2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -309,7 +309,7 @@ TEST_CASE(match_all_of2)
TEST_CASE(match_any_of1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -322,7 +322,7 @@ TEST_CASE(match_any_of1)
TEST_CASE(match_any_of2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -335,7 +335,7 @@ TEST_CASE(match_any_of2)
TEST_CASE(match_none_of1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -348,7 +348,7 @@ TEST_CASE(match_none_of1)
TEST_CASE(match_none_of2)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -361,7 +361,7 @@ TEST_CASE(match_none_of2)
TEST_CASE(match_bind1)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......@@ -382,18 +382,21 @@ TEST_CASE(match_bind1)
struct match_find_sum
{
migraph::instruction_ref ins;
migraphx::instruction_ref ins;
auto matcher() const { return match::name("sum"); }
void apply(migraph::program&, match::matcher_result r) const { EXPECT(bool{r.result == ins}); }
void apply(migraphx::program&, const match::matcher_result& r) const
{
EXPECT(bool{r.result == ins});
}
};
struct match_find_literal
{
migraph::instruction_ref ins;
migraphx::instruction_ref ins;
auto matcher() const { return match::name("@literal"); }
void apply(migraph::program&, match::matcher_result r) const
void apply(migraphx::program&, const match::matcher_result& r) const
{
EXPECT(bool{r.result != ins});
EXPECT(r.result->name() == "@literal");
......@@ -402,7 +405,7 @@ struct match_find_literal
TEST_CASE(match_finder)
{
migraph::program p;
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
......
#include <migraph/memory_coloring.hpp>
#include <migraph/operators.hpp>
#include <migraph/generate.hpp>
#include <migraph/instruction.hpp>
#include <migraphx/memory_coloring.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/instruction.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct memory_coloring_target
{
std::string name() const { return "memory_coloring"; }
std::vector<migraph::pass> get_passes(migraph::context&) const
std::vector<migraphx::pass> get_passes(migraphx::context&) const
{
return {migraph::memory_coloring{"allocate", true}};
return {migraphx::memory_coloring{"allocate", true}};
}
migraph::context get_context() const { return {}; }
migraphx::context get_context() const { return {}; }
};
struct allocate
{
migraph::shape s{};
migraphx::shape s{};
std::string name() const { return "allocate"; }
migraph::shape compute_shape(const std::vector<migraph::shape>& inputs) const
migraphx::shape compute_shape(const std::vector<migraphx::shape>& inputs) const
{
migraph::check_shapes{inputs, *this}.has(0);
return s;
}
migraph::argument compute(migraph::context&,
const migraph::shape& output_shape,
const std::vector<migraph::argument>&) const
migraphx::argument compute(migraphx::context&,
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
}
};
migraph::instruction_ref add_alloc(migraph::program& p, const migraph::shape& s)
migraphx::instruction_ref add_alloc(migraphx::program& p, const migraphx::shape& s)
{
return p.add_instruction(allocate{s});
}
bool no_allocate(const migraph::program& p)
bool no_allocate(const migraphx::program& p)
{
return std::none_of(p.begin(), p.end(), [](auto&& ins) { return ins.name() == "allocate"; });
}
TEST_CASE(test1)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
......@@ -56,12 +56,12 @@ TEST_CASE(test1)
TEST_CASE(test2)
{
migraph::program p;
auto input = p.add_parameter("input", migraph::shape{migraph::shape::float_type, {16}});
migraphx::program p;
auto input = p.add_parameter("input", migraphx::shape{migraphx::shape::float_type, {16}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {128}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {128}});
auto p1 = p.add_instruction(pass_op{}, a1, input);
auto p2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 672);
......@@ -70,24 +70,24 @@ TEST_CASE(test2)
TEST_CASE(test3)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
auto p2 = add_alloc(p, {migraph::shape::float_type, {128}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {128}});
auto p1 = p.add_instruction(pass_op{}, p2, a1);
auto p3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, p3, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 704); // The optimal solution is actually 672
CHECK(p.get_parameter_shape("scratch").bytes() == 672);
CHECK(no_allocate(p));
}
TEST_CASE(test4)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {0}});
auto p2 = add_alloc(p, {migraph::shape::float_type, {128}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {128}});
auto p1 = p.add_instruction(pass_op{}, p2, a1);
auto p3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, p3, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 672);
......@@ -96,10 +96,10 @@ TEST_CASE(test4)
TEST_CASE(test5)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {40}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = add_alloc(p, {migraph::shape::float_type, {8}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
......@@ -108,11 +108,11 @@ TEST_CASE(test5)
TEST_CASE(test6)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, p3, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 352);
......@@ -121,11 +121,11 @@ TEST_CASE(test6)
TEST_CASE(test7)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraph::shape::float_type, {8}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, p3, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 224);
......@@ -134,11 +134,11 @@ TEST_CASE(test7)
TEST_CASE(test8)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraph::shape::float_type, {192}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p3 = add_alloc(p, {migraphx::shape::float_type, {192}});
p.add_instruction(pass_op{}, p3, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 960);
......@@ -147,11 +147,11 @@ TEST_CASE(test8)
TEST_CASE(test9)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = add_alloc(p, {migraph::shape::float_type, {8}});
auto p3 = add_alloc(p, {migraph::shape::float_type, {8}});
auto p2 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p3 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, p3, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 96);
......@@ -160,8 +160,8 @@ TEST_CASE(test9)
TEST_CASE(test10)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 32);
......@@ -170,11 +170,11 @@ TEST_CASE(test10)
TEST_CASE(test11)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.add_instruction(pass_op{}, a3, p2);
p.compile(memory_coloring_target{});
......@@ -184,11 +184,11 @@ TEST_CASE(test11)
TEST_CASE(test12)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {40}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.add_instruction(pass_op{}, a3, p2);
p.compile(memory_coloring_target{});
......@@ -198,11 +198,11 @@ TEST_CASE(test12)
TEST_CASE(test13)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.add_instruction(pass_op{}, a3, p2);
p.compile(memory_coloring_target{});
......@@ -212,10 +212,10 @@ TEST_CASE(test13)
TEST_CASE(test14)
{
migraph::program p;
auto a3 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a3 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.add_instruction(pass_op{}, a3, p2);
......@@ -226,12 +226,12 @@ TEST_CASE(test14)
TEST_CASE(test15)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2);
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a3, p1, p2);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 352);
......@@ -240,12 +240,12 @@ TEST_CASE(test15)
TEST_CASE(test16)
{
migraph::program p;
auto a1 = p.add_literal(migraph::generate_literal({migraph::shape::float_type, {8}}));
migraphx::program p;
auto a1 = p.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {8}}));
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = p.add_literal(migraph::generate_literal({migraph::shape::float_type, {40}}));
auto a2 = p.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {40}}));
auto p2 = p.add_instruction(pass_op{}, a2);
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a3, p1, p2);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 160);
......@@ -254,11 +254,11 @@ TEST_CASE(test16)
TEST_CASE(test17)
{
migraph::program p;
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a1 = p.add_literal(migraph::generate_literal({migraph::shape::float_type, {8}}));
migraphx::program p;
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a1 = p.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {8}}));
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = p.add_literal(migraph::generate_literal({migraph::shape::float_type, {40}}));
auto a2 = p.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {40}}));
auto p2 = p.add_instruction(pass_op{}, a2);
p.add_instruction(pass_op{}, a3, p1, p2);
p.compile(memory_coloring_target{});
......@@ -268,12 +268,12 @@ TEST_CASE(test17)
TEST_CASE(test18)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto p2 = p.add_instruction(pass_op{}, a1, p1);
auto p3 = p.add_instruction(pass_op{}, p2, p1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a2, p1, p2, p3);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
......@@ -282,12 +282,12 @@ TEST_CASE(test18)
TEST_CASE(test19)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a3, p2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 352);
......@@ -296,12 +296,12 @@ TEST_CASE(test19)
TEST_CASE(test20)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {32}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto p1 = p.add_instruction(pass_op{}, a1, a2, a3);
auto a4 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {32}});
p.add_instruction(pass_op{}, a4, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 384);
......@@ -310,12 +310,12 @@ TEST_CASE(test20)
TEST_CASE(test21)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {32}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto p1 = p.add_instruction(pass_op{}, a1, a2, a3);
auto a4 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a4, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 288);
......@@ -324,12 +324,12 @@ TEST_CASE(test21)
TEST_CASE(test22)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1, a2, a3);
auto a4 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a4, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 288);
......@@ -338,12 +338,12 @@ TEST_CASE(test22)
TEST_CASE(test23)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {32}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto p1 = p.add_instruction(pass_op{}, a1, a2, a3);
auto a4 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a4, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 288);
......@@ -352,12 +352,12 @@ TEST_CASE(test23)
TEST_CASE(test24)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {32}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {32}});
auto p1 = p.add_instruction(pass_op{}, a1, a2, a3);
auto a4 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a4, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 384);
......@@ -366,12 +366,12 @@ TEST_CASE(test24)
TEST_CASE(test25)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(nop{});
auto p1 = p.add_instruction(pass_op{}, a1);
p.add_instruction(nop{});
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
......@@ -380,12 +380,12 @@ TEST_CASE(test25)
TEST_CASE(test26)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(nop{}, a1);
auto p1 = p.add_instruction(pass_op{}, a1);
p.add_instruction(nop{}, a1, p1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
......@@ -394,10 +394,10 @@ TEST_CASE(test26)
TEST_CASE(test27)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(nop{}, a2, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
......@@ -406,11 +406,11 @@ TEST_CASE(test27)
TEST_CASE(test28)
{
migraph::program p;
auto output = p.add_parameter("output", {migraph::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto output = p.add_parameter("output", {migraphx::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.add_instruction(pass_op{}, p2, output);
p.compile(memory_coloring_target{});
......@@ -420,11 +420,11 @@ TEST_CASE(test28)
TEST_CASE(test29)
{
migraph::program p;
auto output = p.add_parameter("output", {migraph::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto output = p.add_parameter("output", {migraphx::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.move_instruction(output, p2);
p.add_instruction(pass_op{}, p2, output);
......@@ -435,11 +435,11 @@ TEST_CASE(test29)
TEST_CASE(test30)
{
migraph::program p;
auto output = p.add_parameter("x", {migraph::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto output = p.add_parameter("x", {migraphx::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a2, p1);
p.move_instruction(output, p2);
p.add_instruction(pass_op{}, p2, output);
......@@ -450,11 +450,11 @@ TEST_CASE(test30)
TEST_CASE(test31)
{
migraph::program p;
auto output = p.add_parameter("output", {migraph::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto output = p.add_parameter("output", {migraphx::shape::float_type, {8}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a1);
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.move_instruction(output, a2);
p.add_instruction(pass_op{}, a2, p1);
p.compile(memory_coloring_target{});
......@@ -464,12 +464,12 @@ TEST_CASE(test31)
TEST_CASE(test32)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p1 = p.add_instruction(pass_op{}, a2, a1, a3);
auto a5 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a5 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a5, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 352);
......@@ -478,26 +478,26 @@ TEST_CASE(test32)
TEST_CASE(test33)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a2, a1, a3);
auto a5 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a5 = add_alloc(p, {migraphx::shape::float_type, {40}});
p.add_instruction(pass_op{}, a5, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 224);
CHECK(p.get_parameter_shape("scratch").bytes() == 192);
CHECK(no_allocate(p));
}
TEST_CASE(test34)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p1 = p.add_instruction(pass_op{}, a2, a1, a3);
auto a5 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a5 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a5, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 480);
......@@ -506,12 +506,12 @@ TEST_CASE(test34)
TEST_CASE(test35)
{
migraph::program p;
auto a1 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraph::shape::float_type, {8}});
migraphx::program p;
auto a1 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {8}});
auto p1 = p.add_instruction(pass_op{}, a2, a1, a3);
auto a5 = add_alloc(p, {migraph::shape::float_type, {8}});
auto a5 = add_alloc(p, {migraphx::shape::float_type, {8}});
p.add_instruction(pass_op{}, a5, p1);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 224);
......@@ -520,14 +520,14 @@ TEST_CASE(test35)
TEST_CASE(test36)
{
migraph::program p;
auto output = p.add_parameter("output", {migraph::shape::float_type, {20}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {0}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
migraphx::program p;
auto output = p.add_parameter("output", {migraphx::shape::float_type, {20}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p1 = p.add_instruction(pass_op{}, a2, a1);
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a3, p1);
auto a4 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p3 = p.add_instruction(pass_op{}, a4, p2);
p.add_instruction(pass_op{}, output, p3);
p.compile(memory_coloring_target{});
......@@ -537,14 +537,14 @@ TEST_CASE(test36)
TEST_CASE(test37)
{
migraph::program p;
auto output = p.add_parameter("output", {migraph::shape::float_type, {20}});
auto a1 = add_alloc(p, {migraph::shape::float_type, {4}});
auto a2 = add_alloc(p, {migraph::shape::float_type, {40}});
migraphx::program p;
auto output = p.add_parameter("output", {migraphx::shape::float_type, {20}});
auto a1 = add_alloc(p, {migraphx::shape::float_type, {4}});
auto a2 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p1 = p.add_instruction(pass_op{}, a2, a1);
auto a3 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a3 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p2 = p.add_instruction(pass_op{}, a3, p1);
auto a4 = add_alloc(p, {migraph::shape::float_type, {40}});
auto a4 = add_alloc(p, {migraphx::shape::float_type, {40}});
auto p3 = p.add_instruction(pass_op{}, a4, p2);
p.add_instruction(pass_op{}, output, p3);
p.compile(memory_coloring_target{});
......@@ -554,53 +554,53 @@ TEST_CASE(test37)
TEST_CASE(test38)
{
migraph::program p;
auto output = p.add_parameter("output", {migraph::shape::float_type, {1, 64, 56, 56}});
auto p29 = add_alloc(p, {migraph::shape::float_type, {0}});
auto p30 = add_alloc(p, {migraph::shape::float_type, {1, 64, 112, 112}});
migraphx::program p;
auto output = p.add_parameter("output", {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p29 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto p30 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 112, 112}});
auto p31 = p.add_instruction(pass_op{}, p30, p29);
auto p32 = add_alloc(p, {migraph::shape::float_type, {1, 64, 112, 112}});
auto p32 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 112, 112}});
auto p37 = p.add_instruction(pass_op{}, p32, p31);
auto p38 = add_alloc(p, {migraph::shape::float_type, {1, 64, 112, 112}});
auto p38 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 112, 112}});
auto p39 = p.add_instruction(pass_op{}, p38, p37);
auto p40 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p40 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p41 = p.add_instruction(pass_op{}, p40, p39);
auto p42 = add_alloc(p, {migraph::shape::float_type, {0}});
auto p43 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p42 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto p43 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p44 = p.add_instruction(pass_op{}, p43, p41, p42);
auto p45 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p45 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p50 = p.add_instruction(pass_op{}, p45, p44);
auto p51 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p51 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p52 = p.add_instruction(pass_op{}, p51, p50);
auto p53 = add_alloc(p, {migraph::shape::float_type, {0}});
auto p54 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p53 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto p54 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p55 = p.add_instruction(pass_op{}, p54, p52, p53);
auto p56 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p56 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p61 = p.add_instruction(pass_op{}, p56, p55);
auto p62 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p62 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p63 = p.add_instruction(pass_op{}, p62, p61, p41);
auto p64 = add_alloc(p, {migraph::shape::float_type, {0}});
auto p65 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p64 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto p65 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p66 = p.add_instruction(pass_op{}, p65, p63, p64);
auto p67 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p67 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p72 = p.add_instruction(pass_op{}, p67, p66);
auto p73 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p73 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p74 = p.add_instruction(pass_op{}, p73, p72);
auto p75 = add_alloc(p, {migraph::shape::float_type, {0}});
auto p76 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p75 = add_alloc(p, {migraphx::shape::float_type, {0}});
auto p76 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p77 = p.add_instruction(pass_op{}, p76, p74, p75);
auto p78 = add_alloc(p, {migraph::shape::float_type, {1, 64, 56, 56}});
auto p78 = add_alloc(p, {migraphx::shape::float_type, {1, 64, 56, 56}});
auto p83 = p.add_instruction(pass_op{}, p78, p77);
p.add_instruction(pass_op{}, output, p83, p63);
p.compile(memory_coloring_target{});
CHECK(p.get_parameter_shape("scratch").bytes() == 6422528);
CHECK(p.get_parameter_shape("scratch").bytes() == 7225344); // Optimal solution is 6422528
CHECK(no_allocate(p));
}
TEST_CASE(literal_test)
{
migraph::program p;
auto lit = generate_literal(migraph::shape{migraph::shape::float_type, {4, 3, 3, 3}});
migraphx::program p;
auto lit = generate_literal(migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_literal(lit);
p.compile(memory_coloring_target{});
auto result = p.eval({});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment