Commit 57d000b2 authored by Brian Pickrell's avatar Brian Pickrell
Browse files

add support for dynamic reduce ops in Onnx parsing

parent 6be7f1fb
......@@ -136,6 +136,12 @@ struct shape
const std::vector<std::size_t>& lens() const;
const std::vector<std::size_t>& strides() const;
/*!
* The number of dimensions in the shape.
* Same as the number of indices required to get a data value.
*/
std::size_t ndim() const;
/*!
* Return the number of elements in the tensor.
*/
......
......@@ -68,8 +68,7 @@ instruction_ref parse_reduce_oper(const std::string& op_name,
}
else
{
std::size_t n_dim = args.front()->get_shape().lens().size();
axes.resize(n_dim);
axes.resize(args.front()->get_shape().ndim());
std::iota(axes.begin(), axes.end(), 0);
}
}
......
......@@ -244,6 +244,15 @@ const std::vector<std::size_t>& shape::lens() const { return impl->m_lens; }
const std::vector<std::size_t>& shape::strides() const { return impl->m_strides; }
std::size_t shape::ndim() const
{
if(this->dynamic())
{
return dyn_dims().size();
}
return lens().size();
}
std::size_t shape::elements() const { return impl->elements(); }
std::size_t shape::bytes() const
......
......@@ -4241,6 +4241,21 @@ TEST_CASE(reducel1_test)
EXPECT(p == prog);
}
TEST_CASE(reducel1_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
// a shape with 4 dynamic dimensions
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {{3,3,0}, {3, 5, 0}, {4, 6, 5}, {5, 7, 6}}});
auto abs_l0 = mm->add_instruction(migraphx::make_op("abs"), l0);
auto sum_l0 = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {-2}}}), abs_l0);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {-2}}}), sum_l0);
auto prog = optimize_onnx("reducel1_dyn_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(reducel2_test)
{
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