Unverified Commit 77e80b8e authored by Ted Themistokleous's avatar Ted Themistokleous Committed by GitHub
Browse files

Add onnx mod operator (#1302)

* Add in changes for onnx Mod operator

Initial operator for mod implementation and test cases for integer and floating based types.

Need to use fmod from stdlib for floating point types. half_float::half thankfully is specced to the use the existing std::fmod() call when looking at the half.hpp implementation.

fmod_flag should mirror the onnx fmod attribute. Right now using a floating point type without setting that on the user side to true will result in an exception.

Ref ticket #1283 
parent 8a30d698
...@@ -134,6 +134,7 @@ register_migraphx_ops( ...@@ -134,6 +134,7 @@ register_migraphx_ops(
exp exp
flatten flatten
floor floor
fmod
gather gather
gathernd gathernd
get_tuple_elem get_tuple_elem
...@@ -156,6 +157,7 @@ register_migraphx_ops( ...@@ -156,6 +157,7 @@ register_migraphx_ops(
lstm lstm
max max
min min
mod
mul mul
multibroadcast multibroadcast
multinomial multinomial
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_OPERATORS_FMOD_HPP
#define MIGRAPHX_GUARD_OPERATORS_FMOD_HPP
#include <array>
#include <migraphx/op/binary.hpp>
#include <migraphx/check_shapes.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/streamutils.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <cmath>
#include <utility>
#include <type_traits>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace op {
struct fmod : binary<fmod>
{
std::string name() const { return "fmod"; }
value attributes() const
{
auto a = base_attributes();
a["commutative"] = false;
return a;
}
std::string point_function() const { return "fmod"; }
auto apply() const
{
return [](auto x, auto y) { return std::fmod(x, y); };
}
};
} // namespace op
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_OPERATORS_MOD_HPP
#define MIGRAPHX_GUARD_OPERATORS_MOD_HPP
#include <array>
#include <migraphx/op/binary.hpp>
#include <migraphx/check_shapes.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/streamutils.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <cmath>
#include <utility>
#include <type_traits>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace op {
struct mod : binary<mod>
{
std::string name() const { return "mod"; }
value attributes() const
{
auto a = base_attributes();
a["commutative"] = false;
return a;
}
std::string point_function() const { return "mod"; }
auto apply() const
{
return [](auto x, auto y) { return std::fmod((std::remainder(x, y)) + y, y); };
}
};
} // namespace op
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <migraphx/op/exp.hpp> #include <migraphx/op/exp.hpp>
#include <migraphx/op/flatten.hpp> #include <migraphx/op/flatten.hpp>
#include <migraphx/op/floor.hpp> #include <migraphx/op/floor.hpp>
#include <migraphx/op/fmod.hpp>
#include <migraphx/op/gather.hpp> #include <migraphx/op/gather.hpp>
#include <migraphx/op/gathernd.hpp> #include <migraphx/op/gathernd.hpp>
#include <migraphx/op/get_tuple_elem.hpp> #include <migraphx/op/get_tuple_elem.hpp>
...@@ -79,6 +80,7 @@ ...@@ -79,6 +80,7 @@
#include <migraphx/op/lstm.hpp> #include <migraphx/op/lstm.hpp>
#include <migraphx/op/max.hpp> #include <migraphx/op/max.hpp>
#include <migraphx/op/min.hpp> #include <migraphx/op/min.hpp>
#include <migraphx/op/mod.hpp>
#include <migraphx/op/mul.hpp> #include <migraphx/op/mul.hpp>
#include <migraphx/op/multibroadcast.hpp> #include <migraphx/op/multibroadcast.hpp>
#include <migraphx/op/neg.hpp> #include <migraphx/op/neg.hpp>
......
...@@ -119,6 +119,7 @@ struct onnx_parser ...@@ -119,6 +119,7 @@ struct onnx_parser
}; };
shape::type_t get_type(int dtype); shape::type_t get_type(int dtype);
bool is_type_float(shape::type_t dtype);
} // namespace onnx } // namespace onnx
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
......
...@@ -514,6 +514,16 @@ shape::type_t get_type(int dtype) ...@@ -514,6 +514,16 @@ shape::type_t get_type(int dtype)
} }
} }
bool is_type_float(shape::type_t dtype)
{
bool r = false;
if(dtype == shape::float_type || dtype == shape::double_type || dtype == shape::half_type)
{
r = true;
}
return r;
}
} // namespace onnx } // namespace onnx
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx } // namespace migraphx
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/onnx/op_parser.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/make_op.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace onnx {
struct parse_mod : op_parser<parse_mod>
{
std::vector<op_desc> operators() const { return {{"Mod"}}; }
instruction_ref parse(const op_desc& /*opd*/,
const onnx_parser& parser,
onnx_parser::node_info info,
std::vector<instruction_ref> args) const
{
std::string mod = "mod";
if(is_type_float(args[0]->get_shape().type()) || is_type_float(args[1]->get_shape().type()))
{
if(!contains(info.attributes, "fmod"))
{
MIGRAPHX_THROW("Mod operator with float args and fmod=0 invalid");
}
}
if(contains(info.attributes, "fmod"))
{
if(parser.parse_value(info.attributes.at("fmod")).at<int>() == 1)
{
mod = "fmod";
}
}
return info.add_common_op(mod, args[0], args[1]);
}
};
} // namespace onnx
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
...@@ -138,6 +138,8 @@ struct pointwise_compiler : compiler<pointwise_compiler> ...@@ -138,6 +138,8 @@ struct pointwise_compiler : compiler<pointwise_compiler>
g.add_point_op("less", "migraphx::abs(${0} < ${1})"); g.add_point_op("less", "migraphx::abs(${0} < ${1})");
g.add_point_op("greater", "migraphx::abs(${0} > ${1})"); g.add_point_op("greater", "migraphx::abs(${0} > ${1})");
g.add_point_op("not", "migraphx::abs(not ${0})"); g.add_point_op("not", "migraphx::abs(not ${0})");
g.add_point_op("mod", "migraphx::mod(${0}, ${1})");
g.add_point_op("fmod", "migraphx::fmod(${0}, ${1})");
// Add explict conversions // Add explict conversions
g.fresult([](const shape& s) { g.fresult([](const shape& s) {
return "migraphx::convert<" + shape::cpp_type(s.type()) + ">"; return "migraphx::convert<" + shape::cpp_type(s.type()) + ">";
......
...@@ -3231,6 +3231,89 @@ def min_test(): ...@@ -3231,6 +3231,89 @@ def min_test():
return ([node], [a, b, c], [y]) return ([node], [a, b, c], [y])
@onnx_test
def mod_test():
a = helper.make_tensor_value_info('0', TensorProto.INT32, [3, 3, 3])
b = helper.make_tensor_value_info('1', TensorProto.INT32, [3, 3, 3])
y = helper.make_tensor_value_info('2', TensorProto.INT32, [3, 3, 3])
node = onnx.helper.make_node('Mod', inputs=['0', '1'], outputs=['2'])
return ([node], [a, b], [y])
@onnx_test
def mod_test_half():
a = helper.make_tensor_value_info('0', TensorProto.FLOAT16, [3, 3, 3])
b = helper.make_tensor_value_info('1', TensorProto.FLOAT16, [3, 3, 3])
y = helper.make_tensor_value_info('2', TensorProto.FLOAT16, [3, 3, 3])
node = onnx.helper.make_node('Mod', inputs=['0', '1'], outputs=['2'])
return ([node], [a, b], [y])
@onnx_test
def mod_test_different_dtypes():
a = helper.make_tensor_value_info('0', TensorProto.INT16, [3, 3, 3])
b = helper.make_tensor_value_info('1', TensorProto.INT32, [3, 3, 3])
y = helper.make_tensor_value_info('2', TensorProto.INT32, [3, 3, 3])
node = onnx.helper.make_node(
'Mod',
inputs=['0', '1'],
outputs=['2'],
)
return ([node], [a, b], [y])
@onnx_test
def mod_test_fmod():
a = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3, 3, 3])
b = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 3, 3])
y = helper.make_tensor_value_info('2', TensorProto.FLOAT, [3, 3, 3])
node = onnx.helper.make_node(
'Mod',
inputs=['0', '1'],
outputs=['2'],
fmod=1 #fmod flag = 1
)
return ([node], [a, b], [y])
@onnx_test
def mod_test_fmod_half():
a = helper.make_tensor_value_info('0', TensorProto.FLOAT16, [3, 3, 3])
b = helper.make_tensor_value_info('1', TensorProto.FLOAT16, [3, 3, 3])
y = helper.make_tensor_value_info('2', TensorProto.FLOAT16, [3, 3, 3])
node = onnx.helper.make_node('Mod',
inputs=['0', '1'],
outputs=['2'],
fmod=1)
return ([node], [a, b], [y])
@onnx_test
def mod_test_fmod_different_dtypes():
a = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3, 3, 3])
b = helper.make_tensor_value_info('1', TensorProto.INT32, [3, 3, 3])
y = helper.make_tensor_value_info('2', TensorProto.FLOAT, [3, 3, 3])
node = onnx.helper.make_node(
'Mod',
inputs=['0', '1'],
outputs=['2'],
fmod=1 #fmod flag = 1
)
return ([node], [a, b], [y])
@onnx_test @onnx_test
def multinomial_test(): def multinomial_test():
sample_size = 10 sample_size = 10
......
mod_test:e

0
12"Modmod_testZ
0



Z
1



b
2



B
\ No newline at end of file
mod_test_different_dtypes:v

0
12"Modmod_test_different_dtypesZ
0



Z
1



b
2



B
\ No newline at end of file
 mod_test_fmod:w

0
12"Mod*
fmod mod_test_fmodZ
0



Z
1



b
2



B
\ No newline at end of file
mod_test_fmod_different_dtypes:

0
12"Mod*
fmodmod_test_fmod_different_dtypesZ
0



Z
1



b
2



B
\ No newline at end of file
mod_test_fmod_half:|

0
12"Mod*
fmodmod_test_fmod_halfZ
0




Z
1




b
2




B
\ No newline at end of file
 mod_test_half:j

0
12"Mod mod_test_halfZ
0




Z
1




b
2




B
\ No newline at end of file
...@@ -2954,6 +2954,76 @@ TEST_CASE(min_test) ...@@ -2954,6 +2954,76 @@ TEST_CASE(min_test)
EXPECT(p == prog); EXPECT(p == prog);
} }
TEST_CASE(mod_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::int32_type, {3, 3, 3}});
auto input1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::int32_type, {3, 3, 3}});
mm->add_instruction(migraphx::make_op("mod"), input0, input1);
auto prog = optimize_onnx("mod_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(mod_test_half)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("mod_test_half.onnx"); }));
}
TEST_CASE(mod_test_different_dtypes)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::int16_type, {3, 3, 3}});
auto input1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::int32_type, {3, 3, 3}});
add_common_op(*mm, migraphx::make_op("mod"), {input0, input1});
auto prog = optimize_onnx("mod_test_different_dtypes.onnx");
EXPECT(p == prog);
}
TEST_CASE(mod_test_fmod)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3, 3, 3}});
auto input1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {3, 3, 3}});
mm->add_instruction(migraphx::make_op("fmod"), input0, input1);
auto prog = optimize_onnx("mod_test_fmod.onnx");
EXPECT(p == prog);
}
TEST_CASE(mod_test_fmod_half)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::half_type, {3, 3, 3}});
auto input1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::half_type, {3, 3, 3}});
mm->add_instruction(migraphx::make_op("fmod"), input0, input1);
auto prog = optimize_onnx("mod_test_fmod_half.onnx");
EXPECT(p == prog);
}
TEST_CASE(mod_test_fmod_different_dtypes)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3, 3, 3}});
auto input1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::int32_type, {3, 3, 3}});
add_common_op(*mm, migraphx::make_op("fmod"), {input0, input1});
auto prog = optimize_onnx("mod_test_fmod_different_dtypes.onnx");
EXPECT(p == prog);
}
TEST_CASE(multinomial_test) TEST_CASE(multinomial_test)
{ {
migraphx::program p; migraphx::program p;
......
...@@ -631,6 +631,120 @@ TEST_CASE(mean_integral_test) ...@@ -631,6 +631,120 @@ TEST_CASE(mean_integral_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(mod_test)
{
migraphx::program p = migraphx::parse_onnx("mod_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::int32_type, {3, 3, 3}};
std::vector<int32_t> a = {-4, 7, 5, 4, -7, 8, -4, 7, 5, 4, -7, 8, -4, 7,
5, 4, -7, 8, -4, 7, 5, 4, -7, 8, -4, 7, 5};
std::vector<int32_t> b = {2, -3, 8, -2, 3, 5, 2, -3, 8, -2, 3, 5, 2, -3,
8, -2, 3, 5, 2, -3, 8, -2, 3, 5, 2, -3, 8};
migraphx::parameter_map p_map;
p_map["0"] = migraphx::argument(s, a.data());
p_map["1"] = migraphx::argument(s, b.data());
auto result = p.eval(p_map).back();
std::vector<int32_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int32_t> gold = {0, -2, 5, 0, 2, 3, 0, -2, 5, 0, 2, 3, 0, -2,
5, 0, 2, 3, 0, -2, 5, 0, 2, 3, 0, -2, 5};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(mod_test_different_types)
{
migraphx::program p = migraphx::parse_onnx("mod_test_different_dtypes.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s_int16{migraphx::shape::int16_type, {3, 3, 3}};
migraphx::shape s_int32{migraphx::shape::int32_type, {3, 3, 3}};
std::vector<int16_t> a = {-4, 7, 5, 4, -7, 8, -4, 7, 5, 4, -7, 8, -4, 7,
5, 4, -7, 8, -4, 7, 5, 4, -7, 8, -4, 7, 5};
std::vector<int32_t> b = {2, -3, 8, -2, 3, 5, 2, -3, 8, -2, 3, 5, 2, -3,
8, -2, 3, 5, 2, -3, 8, -2, 3, 5, 2, -3, 8};
migraphx::parameter_map p_map;
p_map["0"] = migraphx::argument(s_int16, a.data());
p_map["1"] = migraphx::argument(s_int32, b.data());
auto result = p.eval(p_map).back();
std::vector<int32_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int32_t> gold = {0, -2, 5, 0, 2, 3, 0, -2, 5, 0, 2, 3, 0, -2,
5, 0, 2, 3, 0, -2, 5, 0, 2, 3, 0, -2, 5};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(mod_test_fmod)
{
migraphx::program p = migraphx::parse_onnx("mod_test_fmod.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::float_type, {3, 3, 3}};
std::vector<float> a = {1.2, -2.2, 3.3, 4.1, -5.4, 6.7, 7.8, -8.4, 9.9,
10.7, 11.2, 12.3, 13.9, -14.2, 15.8, 16.6, 17.9, 18.2,
19.0, 20.0, 21.0, -22.0, 23.0, -24.0, 25.2, 26.3, 27.1};
std::vector<float> b = {30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4};
migraphx::parameter_map p_map;
p_map["0"] = migraphx::argument(s, a.data());
p_map["1"] = migraphx::argument(s, b.data());
auto result = p.eval(p_map).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1.2, -2.2, 3.3, 4.1, -5.4, 6.7, 7.8, -8.4, 9.9,
10.7, 11.2, 12.3, 13.9, -14.2, 15.8, 1.6, 3.9, 5.2,
7.0, 9.0, 1.0, -4.0, 7.0, -3.0, 1.2, 1.3, 3.1};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(mod_test_fmod_different_types)
{
migraphx::program p = migraphx::parse_onnx("mod_test_fmod_different_dtypes.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s_float{migraphx::shape::float_type, {3, 3, 3}};
migraphx::shape s_int{migraphx::shape::int32_type, {3, 3, 3}};
std::vector<float> a = {1.2, -2.2, 3.3, 4.1, -5.4, 6.7, 7.8, -8.4, 9.9,
10.7, 11.2, 12.3, 13.9, -14.2, 15.8, 16.6, 17.9, 18.2,
19.0, 20.0, 21.0, -22.0, 23.0, -24.0, 25.2, 26.3, 27.1};
std::vector<int32_t> b = {30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4};
migraphx::parameter_map p_map;
p_map["0"] = migraphx::argument(s_float, a.data());
p_map["1"] = migraphx::argument(s_int, b.data());
auto result = p.eval(p_map).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1.2, -2.2, 3.3, 4.1, -5.4, 6.7, 7.8, -8.4, 9.9,
10.7, 11.2, 12.3, 13.9, -14.2, 15.8, 1.6, 3.9, 5.2,
7.0, 9.0, 1.0, -4.0, 7.0, -3.0, 1.2, 1.3, 3.1};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(nonzero_test) TEST_CASE(nonzero_test)
{ {
migraphx::program p = migraphx::parse_onnx("nonzero_dynamic_test.onnx"); migraphx::program p = migraphx::parse_onnx("nonzero_dynamic_test.onnx");
......
...@@ -3030,6 +3030,80 @@ TEST_CASE(min_test) ...@@ -3030,6 +3030,80 @@ TEST_CASE(min_test)
EXPECT(migraphx::verify_range(results_vector, gold)); EXPECT(migraphx::verify_range(results_vector, gold));
} }
TEST_CASE(fmod_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int32_type, {3}};
auto l0 = mm->add_literal(migraphx::literal{s, {-7, 8, -3}});
auto l1 = mm->add_literal(migraphx::literal{s, {2, 4, 6}});
auto l2 = mm->add_literal(migraphx::literal{s, {7, 5, 9}});
auto curr_mod = mm->add_instruction(migraphx::make_op("fmod"), l0, l1);
mm->add_instruction(migraphx::make_op("fmod"), curr_mod, l2);
p.compile(migraphx::ref::target{});
auto result = p.eval({}).back();
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{-1, 0, -3};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(fmod_float_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l0 = mm->add_literal(migraphx::literal{s, {-7.2f, 8.5f, -3.3f}});
auto l1 = mm->add_literal(migraphx::literal{s, {2.0f, 4.0f, 6.0f}});
auto l2 = mm->add_literal(migraphx::literal{s, {7.0f, 5.0f, 9.0f}});
auto curr_mod = mm->add_instruction(migraphx::make_op("fmod"), l0, l1);
mm->add_instruction(migraphx::make_op("fmod"), curr_mod, l2);
p.compile(migraphx::ref::target{});
auto result = p.eval({}).back();
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{-1.2f, 0.5f, -3.3f};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(mod_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int32_type, {3}};
auto l0 = mm->add_literal(migraphx::literal{s, {-3, 8, -7}});
auto l1 = mm->add_literal(migraphx::literal{s, {3, 3, 3}});
auto l2 = mm->add_literal(migraphx::literal{s, {10, 2, 9}});
auto curr_mod = mm->add_instruction(migraphx::make_op("mod"), l0, l1);
mm->add_instruction(migraphx::make_op("mod"), curr_mod, l2);
p.compile(migraphx::ref::target{});
auto result = p.eval({}).back();
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{0, 0, 2};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(mod_float_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}};
auto l0 = mm->add_literal(migraphx::literal{s, {-3.0f, 8.5f, -7.0f}});
auto l1 = mm->add_literal(migraphx::literal{s, {2.0f, 3.0f, 3.0f}});
auto l2 = mm->add_literal(migraphx::literal{s, {3.0f, 3.0f, 4.0f}});
auto curr_mod = mm->add_instruction(migraphx::make_op("mod"), l0, l1);
mm->add_instruction(migraphx::make_op("mod"), curr_mod, l2);
p.compile(migraphx::ref::target{});
auto result = p.eval({}).back();
std::vector<float> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1.0f, 2.5f, 2.0f};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(mul_test) TEST_CASE(mul_test)
{ {
migraphx::program p; migraphx::program p;
......
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