MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / compute_shapes

Method compute_shapes

src/module.cpp:751–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

749}
750
751std::vector<shape> module::compute_shapes(const std::vector<shape>& inputs,
752 compute_shapes_options options) const
753{
754 auto params = this->get_parameter_names();
755 std::sort(params.begin(), params.end());
756 std::unordered_map<instruction_ref, shape> ins_shapes;
757 std::unordered_map<std::string, shape> adjusted_param_shapes;
758 std::transform(inputs.begin(),
759 inputs.end(),
760 params.begin(),
761 std::inserter(adjusted_param_shapes, adjusted_param_shapes.end()),
762 [](auto ps, const auto& name) { return std::make_pair(name, ps); });
763 for(auto ins : iterator_for(*this))
764 {
765 if(ins->name() == "@param")
766 {
767 ins_shapes[ins] =
768 adjusted_param_shapes[any_cast<builtin::param>(ins->get_operator()).parameter];
769 if(options.strict_type and ins->get_shape().type() != ins_shapes[ins].type())
770 {
771 MIGRAPHX_THROW(options.name + ": Mismatched type: expected " +
772 ins->get_shape().type_string() + " but passed " +
773 ins_shapes[ins].type_string());
774 }
775 if(options.strict_lens and ins->get_shape().lens() != ins_shapes[ins].lens())
776 {
777 MIGRAPHX_THROW(options.name + ": Mismatched lens: expected {" +
778 to_string_range(ins->get_shape().lens()) + "} but passed {" +
779 to_string_range(ins_shapes[ins].lens()) + "}");
780 }
781 }
782 else if(ins->name() == "@literal")
783 {
784 if(not options.scalar_const_out_lens.empty() and ins->get_shape().scalar())
785 {
786 std::vector<std::size_t> strides(options.scalar_const_out_lens.size());
787 ins_shapes[ins] =
788 shape{ins->get_shape().type(), options.scalar_const_out_lens, strides};
789 }
790 else
791 {
792 ins_shapes[ins] = ins->get_shape();
793 }
794 }
795 else
796 {
797 std::vector<shape> input_shapes;
798 input_shapes.resize(ins->inputs().size());
799 std::transform(ins->inputs().begin(),
800 ins->inputs().end(),
801 input_shapes.begin(),
802 [&](auto in) { return ins_shapes.at(in); });
803 if(ins->name() == "@return")
804 return input_shapes;
805 ins_shapes[ins] = ins->get_operator().compute_shape(input_shapes, ins->module_inputs());
806 }
807 }
808 MIGRAPHX_THROW("No return found in the submodule");

Callers 4

compute_shapeMethod · 0.80
compute_shapeMethod · 0.80
compute_shapeMethod · 0.80
compute_shapeMethod · 0.80

Calls 15

get_parameter_namesMethod · 0.95
iterator_forFunction · 0.85
to_string_rangeFunction · 0.85
type_stringMethod · 0.80
lensMethod · 0.80
scalarMethod · 0.80
resizeMethod · 0.80
atMethod · 0.80
sortFunction · 0.50
transformFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected