Unverified Commit 234cf5a4 authored by Shucai Xiao's avatar Shucai Xiao Committed by GitHub
Browse files

Resize op (#656)



* code backup for upsample op

* clang format

* fixed a bug

* fix a bug

* clang format

* add unit tests for upsample

* clang format

* code backup for resize

* clang format

* code backup

* clang format

* add unit test for resize operator

* clang format

* fix cppcheck error

* fix cppcheck error

* clang format

* fix a typo

* refine unit tests for better code coverage

* remove unnecessary python binary file

* fix review comments

* clang format

* change two functions to static
Co-authored-by: default avatarPaul Fultz II <pfultz2@yahoo.com>
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
parent 2ea40daa
...@@ -167,6 +167,7 @@ struct onnx_parser ...@@ -167,6 +167,7 @@ struct onnx_parser
add_mem_op("ReduceSum", "reduce_sum", &onnx_parser::parse_reduce_oper); add_mem_op("ReduceSum", "reduce_sum", &onnx_parser::parse_reduce_oper);
add_mem_op("ReduceSumSquare", &onnx_parser::parse_reduce_sum_square); add_mem_op("ReduceSumSquare", &onnx_parser::parse_reduce_sum_square);
add_mem_op("Reshape", &onnx_parser::parse_reshape); add_mem_op("Reshape", &onnx_parser::parse_reshape);
add_mem_op("Resize", &onnx_parser::parse_resize);
add_mem_op("RNN", &onnx_parser::parse_rnn); add_mem_op("RNN", &onnx_parser::parse_rnn);
add_mem_op("Selu", &onnx_parser::parse_selu); add_mem_op("Selu", &onnx_parser::parse_selu);
add_mem_op("Shape", &onnx_parser::parse_shape); add_mem_op("Shape", &onnx_parser::parse_shape);
...@@ -1067,6 +1068,187 @@ struct onnx_parser ...@@ -1067,6 +1068,187 @@ struct onnx_parser
return prog.add_instruction(op, make_contiguous(args[0])); return prog.add_instruction(op, make_contiguous(args[0]));
} }
static const auto& get_nearest_op(const std::string& mode)
{
using nearest_op = std::function<std::size_t(std::size_t, double)>;
static std::unordered_map<std::string, nearest_op> const nearest_ops = {
{"round_prefer_floor",
[=](std::size_t d_in, double val) {
val = std::max(0.0, std::min(d_in - 1.0, val));
return static_cast<std::size_t>(std::ceil((val - 0.5)));
}},
{"round_prefer_ceil",
[=](std::size_t d_in, double val) {
val = std::max(0.0, std::min(d_in - 1.0, val));
return static_cast<std::size_t>(std::round((val)));
}},
{"floor",
[=](std::size_t d_in, double val) {
val = std::max(0.0, std::min(d_in - 1.0, val));
return static_cast<std::size_t>(std::floor((val)));
}},
{"ceil", [=](std::size_t d_in, double val) {
val = std::max(0.0, std::min(d_in - 1.0, val));
return static_cast<std::size_t>(std::ceil((val)));
}}};
if(!contains(nearest_ops, mode))
{
MIGRAPHX_THROW("PARSE_RESIZE: nearest_mode " + mode + " not supported!");
}
return nearest_ops.at(mode);
}
static const auto& get_original_idx_op(const std::string& mode)
{
using original_idx_op =
std::function<double(std::size_t, std::size_t, std::size_t, double)>;
static std::unordered_map<std::string, original_idx_op> const idx_ops = {
{"half_pixel",
[=](std::size_t, std::size_t, std::size_t idx, double scale) {
return (idx + 0.5) / scale - 0.5;
}},
{"pytorch_half_pixel",
[=](std::size_t, std::size_t l_out, std::size_t idx, double scale) {
return l_out > 1 ? (idx + 0.5) / scale - 0.5 : 0.0;
}},
{"align_corners",
[=](std::size_t l_in, std::size_t l_out, std::size_t idx, double) {
return 1.0 * idx * (l_in - 1.0) / (l_out - 1.0);
}},
{"asymmetric",
[=](std::size_t, std::size_t, std::size_t idx, double scale) { return idx / scale; }},
{"tf_half_pixel_for_nn", [=](std::size_t, std::size_t, std::size_t idx, double scale) {
return (idx + 0.5) / scale;
}}};
if(!contains(idx_ops, mode))
{
MIGRAPHX_THROW("PARSE_RESIZE: coordinate_transformation_mode " + mode +
" not supported!");
}
return idx_ops.at(mode);
}
instruction_ref
parse_resize(const std::string&, const node_info& info, std::vector<instruction_ref> args)
{
std::string coord_trans_mode = "half_pixel";
if(contains(info.attributes, "coordinate_transformation_mode"))
{
coord_trans_mode = info.attributes.at("coordinate_transformation_mode").s();
// does not support transformation mode "tf_crop_and_resize"
if(coord_trans_mode == "tf_crop_and_resize")
{
MIGRAPHX_THROW("PARSE_RESIZE: \"tf_crop_and_resize\" mode is not supported!");
}
}
// mode: only nearest mode is supported for now
if(contains(info.attributes, "mode"))
{
auto mode = info.attributes.at("mode").s();
if(mode != "nearest")
{
MIGRAPHX_THROW("PARSE_RESIZE: only nearest mode is supported!");
}
}
// nearest mode
std::string nearest_mode = "round_prefer_floor";
if(contains(info.attributes, "nearest_mode"))
{
nearest_mode = info.attributes.at("nearest_mode").s();
}
// check exclude_outside, only support 0
if(contains(info.attributes, "exclude_outside"))
{
int exclude_outside = info.attributes.at("exclude_outside").i();
if(exclude_outside == 1)
{
MIGRAPHX_THROW("PARSE_RESIZE: exclude_outside 1 is not supported!");
}
}
// input data shape info
auto in_s = args[0]->get_shape();
auto in_lens = in_s.lens();
// output shape is explicitly specified
std::vector<std::size_t> out_lens(in_lens.size());
// scale
std::vector<double> vec_scale;
// output size is specified in input, so use it as output size
if(args.size() == 4 and args.back()->name() != "undefined")
{
auto arg_out_s = args[3]->eval();
check_arg_empty(arg_out_s, "PARSE_RESIZE: dynamic output size is not supported!");
arg_out_s.visit([&](auto ol) { out_lens.assign(ol.begin(), ol.end()); });
if(out_lens.size() != in_lens.size())
{
MIGRAPHX_THROW("PARSE_RESIZE: specified output size does not match input size");
}
// compute the scale
vec_scale.resize(in_lens.size());
std::transform(in_lens.begin(),
in_lens.end(),
out_lens.begin(),
vec_scale.begin(),
[](auto iss, auto oss) { return 1.0 * oss / iss; });
}
// need to compute the output lens from input
else
{
auto arg_scale = args[2]->eval();
check_arg_empty(arg_scale, "PARSE_RESIZE: dynamic input scale is not supported!");
arg_scale.visit([&](auto v) { vec_scale.assign(v.begin(), v.end()); });
if(in_lens.size() != vec_scale.size())
{
MIGRAPHX_THROW("PARSE_RESIZE: ranks of input and scale are different!");
}
std::transform(
in_lens.begin(),
in_lens.end(),
vec_scale.begin(),
out_lens.begin(),
[&](auto idx, auto scale) { return static_cast<std::size_t>(idx * scale); });
}
shape out_s{in_s.type(), out_lens};
std::vector<int> ind(out_s.elements());
// map out_idx to in_idx
auto nearest_op = get_nearest_op(nearest_mode);
auto idx_op = get_original_idx_op(coord_trans_mode);
shape_for_each(out_s, [&](auto idx) {
auto in_idx = idx;
for(auto ii = 0; ii < in_lens.size(); ++ii)
{
auto idx_val = idx_op(in_lens[ii], out_lens[ii], in_idx[ii], vec_scale[ii]);
in_idx[ii] = nearest_op(in_lens[ii], idx_val);
}
ind[out_s.index(idx)] = static_cast<int64_t>(in_s.index(in_idx));
});
// reshape input to one-dimension
std::vector<int64_t> rsp_lens = {static_cast<int64_t>(in_s.elements())};
shape ind_s{shape::int32_type, out_lens};
auto rsp = prog.add_instruction(make_op("reshape", {{"dims", rsp_lens}}), args[0]);
auto ins_ind = prog.add_literal(literal(ind_s, ind));
return prog.add_instruction(make_op("gather", {{"axis", 0}}), rsp, ins_ind);
}
instruction_ref instruction_ref
parse_gather_elements(const std::string&, node_info info, std::vector<instruction_ref> args) parse_gather_elements(const std::string&, node_info info, std::vector<instruction_ref> args)
{ {
......
...@@ -2466,6 +2466,113 @@ def reshape_non_standard_test(): ...@@ -2466,6 +2466,113 @@ def reshape_non_standard_test():
return ([trans, res], [x], [y]) return ([trans, res], [x], [y])
@onnx_test
def resize_downsample_f_test():
scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)
scale_tensor = helper.make_tensor(name='scales',
data_type=TensorProto.FLOAT,
dims=scales.shape,
vals=scales.flatten().astype(np.float32))
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 2, 4])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 1, 2])
node = onnx.helper.make_node(
'Resize',
inputs=['X', '', 'scales'],
outputs=['Y'],
coordinate_transformation_mode='align_corners',
mode='nearest',
nearest_mode='floor')
return ([node], [X], [Y], [scale_tensor])
@onnx_test
def resize_downsample_c_test():
scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)
scale_tensor = helper.make_tensor(name='scales',
data_type=TensorProto.FLOAT,
dims=scales.shape,
vals=scales.flatten().astype(np.float32))
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 2, 4])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 1, 2])
node = onnx.helper.make_node('Resize',
inputs=['X', '', 'scales'],
outputs=['Y'],
coordinate_transformation_mode='asymmetric',
mode='nearest',
nearest_mode='ceil')
return ([node], [X], [Y], [scale_tensor])
@onnx_test
def resize_outsize_test():
out_lens = np.array([1, 1, 4, 6], dtype=np.int64)
out_lens_tensor = helper.make_tensor(name='out_lens',
data_type=TensorProto.INT64,
dims=out_lens.shape,
vals=out_lens.flatten().astype(
np.int64))
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 2, 2])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 4, 6])
node = onnx.helper.make_node(
'Resize',
inputs=['X', '', '', 'out_lens'],
outputs=['Y'],
coordinate_transformation_mode='tf_half_pixel_for_nn',
mode='nearest',
nearest_mode='round_prefer_floor')
return ([node], [X], [Y], [out_lens_tensor])
@onnx_test
def resize_upsample_pf_test():
scales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)
scale_tensor = helper.make_tensor(name='scales',
data_type=TensorProto.FLOAT,
dims=scales.shape,
vals=scales.flatten().astype(np.float32))
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 2, 2])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 4, 6])
node = onnx.helper.make_node('Resize',
inputs=['X', '', 'scales'],
outputs=['Y'],
mode='nearest')
return ([node], [X], [Y], [scale_tensor])
def resize_upsample_pc_test():
scales = np.array([1.0, 1.0, 2.0, 1.5], dtype=np.float32)
scale_tensor = helper.make_tensor(name='scales',
data_type=TensorProto.FLOAT,
dims=scales.shape,
vals=scales.flatten().astype(np.float32))
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 2, 4])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 4, 6])
node = onnx.helper.make_node(
'Resize',
inputs=['X', '', 'scales'],
outputs=['Y'],
coordinate_transformation_mode='pytorch_half_pixel',
mode='nearest',
exclude_outside=0,
nearest_mode='round_prefer_ceil')
return ([node], [X], [Y], [scale_tensor])
@onnx_test @onnx_test
def selu_test(): def selu_test():
x = helper.make_tensor_value_info('x', TensorProto.DOUBLE, [2, 3]) x = helper.make_tensor_value_info('x', TensorProto.DOUBLE, [2, 3])
......
...@@ -1821,6 +1821,136 @@ TEST_CASE(reshape_non_standard_test) ...@@ -1821,6 +1821,136 @@ TEST_CASE(reshape_non_standard_test)
EXPECT(p == prog); EXPECT(p == prog);
} }
TEST_CASE(resize_downsample_f_test)
{
migraphx::program p;
std::vector<float> ds = {1.0f, 1.0f, 0.6f, 0.6f};
migraphx::shape ss{migraphx::shape::float_type, {4}};
p.add_literal(migraphx::literal{ss, ds});
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 4}};
auto inx = p.add_parameter("X", sx);
p.add_instruction(migraphx::op::undefined{});
migraphx::shape si{migraphx::shape::int32_type, {1, 1, 1, 2}};
std::vector<int> ind = {4, 7};
auto li = p.add_literal(migraphx::literal(si, ind));
auto lrsp = p.add_instruction(migraphx::op::reshape{{8}}, inx);
auto r = p.add_instruction(migraphx::op::gather{0}, lrsp, li);
p.add_return({r});
auto prog = migraphx::parse_onnx("resize_downsample_f_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(resize_downsample_c_test)
{
migraphx::program p;
std::vector<float> ds = {1.0f, 1.0f, 0.6f, 0.6f};
migraphx::shape ss{migraphx::shape::float_type, {4}};
p.add_literal(migraphx::literal{ss, ds});
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 4}};
auto inx = p.add_parameter("X", sx);
p.add_instruction(migraphx::op::undefined{});
migraphx::shape si{migraphx::shape::int32_type, {1, 1, 1, 2}};
std::vector<int> ind = {0, 2};
auto li = p.add_literal(migraphx::literal(si, ind));
auto lrsp = p.add_instruction(migraphx::op::reshape{{8}}, inx);
auto r = p.add_instruction(migraphx::op::gather{0}, lrsp, li);
p.add_return({r});
auto prog = migraphx::parse_onnx("resize_downsample_c_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(resize_outsize_test)
{
migraphx::program p;
std::vector<int64_t> out_len = {1, 1, 4, 6};
migraphx::shape so{migraphx::shape::int64_type, {4}};
p.add_literal(migraphx::literal(so, out_len));
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 2}};
auto inx = p.add_parameter("X", sx);
p.add_instruction(migraphx::op::undefined{});
migraphx::shape si{migraphx::shape::int32_type, {1, 1, 4, 6}};
std::vector<int> ind = {0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 2, 2, 3, 3, 3, 3, 2, 2, 3, 3, 3, 3};
auto li = p.add_literal(migraphx::literal(si, ind));
auto lrsp = p.add_instruction(migraphx::op::reshape{{4}}, inx);
auto r = p.add_instruction(migraphx::op::gather{0}, lrsp, li);
p.add_return({r});
auto prog = migraphx::parse_onnx("resize_outsize_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(resize_upsample_pc_test)
{
migraphx::program p;
std::vector<float> ds = {1.0f, 1.0f, 2.0f, 1.5f};
migraphx::shape ss{migraphx::shape::float_type, {4}};
p.add_literal(migraphx::literal{ss, ds});
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 4}};
auto inx = p.add_parameter("X", sx);
p.add_instruction(migraphx::op::undefined{});
migraphx::shape si{migraphx::shape::int32_type, {1, 1, 4, 6}};
std::vector<int> ind = {0, 1, 1, 2, 3, 3, 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 4, 5, 5, 6, 7, 7};
auto li = p.add_literal(migraphx::literal(si, ind));
auto lrsp = p.add_instruction(migraphx::op::reshape{{8}}, inx);
auto r = p.add_instruction(migraphx::op::gather{0}, lrsp, li);
p.add_return({r});
auto prog = migraphx::parse_onnx("resize_upsample_pc_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(resize_upsample_pf_test)
{
migraphx::program p;
std::vector<float> ds = {1.0f, 1.0f, 2.0f, 3.0f};
migraphx::shape ss{migraphx::shape::float_type, {4}};
p.add_literal(migraphx::literal{ss, ds});
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 2}};
auto inx = p.add_parameter("X", sx);
p.add_instruction(migraphx::op::undefined{});
migraphx::shape si{migraphx::shape::int32_type, {1, 1, 4, 6}};
std::vector<int> ind = {0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3};
auto li = p.add_literal(migraphx::literal(si, ind));
auto lrsp = p.add_instruction(migraphx::op::reshape{{4}}, inx);
auto r = p.add_instruction(migraphx::op::gather{0}, lrsp, li);
p.add_return({r});
auto prog = migraphx::parse_onnx("resize_upsample_pf_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(round_test) TEST_CASE(round_test)
{ {
migraphx::program p; migraphx::program p;
......
...@@ -9,6 +9,65 @@ ...@@ -9,6 +9,65 @@
#include <migraphx/onnx.hpp> #include <migraphx/onnx.hpp>
#include "test.hpp" #include "test.hpp"
TEST_CASE(averagepool_notset_test)
{
auto p = migraphx::parse_onnx("averagepool_notset_test.onnx");
p.compile(migraphx::cpu::target{});
std::vector<float> data_x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
migraphx::shape s_x{migraphx::shape::float_type, {1, 1, 5, 5}};
migraphx::program::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {12};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(averagepool_nt_cip_test)
{
auto p = migraphx::parse_onnx("averagepool_nt_cip_test.onnx");
p.compile(migraphx::cpu::target{});
std::vector<float> data_x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
migraphx::shape s_x{migraphx::shape::float_type, {1, 1, 5, 5}};
migraphx::program::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {8.33333};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(gather_elements)
{
migraphx::program p = migraphx::parse_onnx("gather_elements_axis0_test.onnx");
p.compile(migraphx::cpu::target{});
migraphx::shape s_data{migraphx::shape::float_type, {3, 4}};
std::vector<float> data = {
0.25, 0.75, 0.9375, 0.4375, 0.6875, 0.5625, -0.875, 0.1875, -0.125, 0.5, -0.9375, -0.0625};
migraphx::shape s_ind{migraphx::shape::int32_type, {2, 3}};
std::vector<int> ind = {2, 1, 2, 0, 1, 0};
migraphx::program::parameter_map pp;
pp["data"] = migraphx::argument(s_data, data.data());
pp["indices"] = migraphx::argument(s_ind, ind.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.125, 0.5625, -0.9375, 0.25, 0.5625, 0.9375};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(instance_norm_test) TEST_CASE(instance_norm_test)
{ {
migraphx::program p = migraphx::parse_onnx("instance_norm_val_test.onnx"); migraphx::program p = migraphx::parse_onnx("instance_norm_val_test.onnx");
...@@ -68,62 +127,44 @@ TEST_CASE(instance_norm_3d_test) ...@@ -68,62 +127,44 @@ TEST_CASE(instance_norm_3d_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(averagepool_notset_test) TEST_CASE(resize_test)
{ {
auto p = migraphx::parse_onnx("averagepool_notset_test.onnx"); migraphx::program p = migraphx::parse_onnx("resize_upsample_pf_test.onnx");
p.compile(migraphx::cpu::target{}); p.compile(migraphx::cpu::target{});
std::vector<float> data_x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
migraphx::shape s_x{migraphx::shape::float_type, {1, 1, 5, 5}};
migraphx::program::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {12}; migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 2}};
EXPECT(migraphx::verify_range(result_vector, gold)); std::vector<float> dx = {1.0f, 2.0f, 3.0f, 4.0f};
}
TEST_CASE(averagepool_nt_cip_test)
{
auto p = migraphx::parse_onnx("averagepool_nt_cip_test.onnx");
p.compile(migraphx::cpu::target{});
std::vector<float> data_x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
migraphx::shape s_x{migraphx::shape::float_type, {1, 1, 5, 5}};
migraphx::program::parameter_map pp; migraphx::program::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data()); pp["X"] = migraphx::argument(sx, dx.data());
auto result = p.eval(pp).back(); auto result = p.eval(pp).back();
std::vector<float> result_vector; std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {8.33333}; std::vector<float> gold = {1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4, 3, 3, 3, 4, 4, 4};
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(gather_elements) TEST_CASE(selu_test)
{ {
migraphx::program p = migraphx::parse_onnx("gather_elements_axis0_test.onnx"); migraphx::program p = migraphx::parse_onnx("selu_test.onnx");
p.compile(migraphx::cpu::target{}); p.compile(migraphx::cpu::target{});
migraphx::shape s_data{migraphx::shape::float_type, {3, 4}};
std::vector<float> data = {
0.25, 0.75, 0.9375, 0.4375, 0.6875, 0.5625, -0.875, 0.1875, -0.125, 0.5, -0.9375, -0.0625};
migraphx::shape s_ind{migraphx::shape::int32_type, {2, 3}}; migraphx::shape xs{migraphx::shape::double_type, {2, 3}};
std::vector<int> ind = {2, 1, 2, 0, 1, 0}; std::vector<double> x_data = {1.1, 2.1, 0.0, -1.3, -5.3, 12.0};
migraphx::program::parameter_map pp; migraphx::program::parameter_map pp;
pp["data"] = migraphx::argument(s_data, data.data()); pp["x"] = migraphx::argument(xs, x_data.data());
pp["indices"] = migraphx::argument(s_ind, ind.data());
auto result = p.eval(pp).back(); auto result = p.eval(pp).back();
std::vector<float> result_vector; std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.125, 0.5625, -0.9375, 0.25, 0.5625, 0.9375}; std::vector<float> gold = {0.55, 1.05, 0, -0.10912, -0.149251, 6};
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
...@@ -146,25 +187,6 @@ TEST_CASE(upsample_test) ...@@ -146,25 +187,6 @@ TEST_CASE(upsample_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(selu_test)
{
migraphx::program p = migraphx::parse_onnx("selu_test.onnx");
p.compile(migraphx::cpu::target{});
migraphx::shape xs{migraphx::shape::double_type, {2, 3}};
std::vector<double> x_data = {1.1, 2.1, 0.0, -1.3, -5.3, 12.0};
migraphx::program::parameter_map pp;
pp["x"] = migraphx::argument(xs, x_data.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.55, 1.05, 0, -0.10912, -0.149251, 6};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(where_test) TEST_CASE(where_test)
{ {
migraphx::program p = migraphx::parse_onnx("where_test.onnx"); migraphx::program p = migraphx::parse_onnx("where_test.onnx");
......
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