MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / to_json

Method to_json

src/plugin/impl/opr_footprint.cpp:940–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

938}
939
940std::shared_ptr<json::Value> OprFootprint::Result::to_json() const {
941 using namespace json;
942 std::shared_ptr<Value> comp;
943 if (computation) {
944 comp = NumberInt::make(computation);
945 } else {
946 comp = Null::make();
947 }
948 auto format_shape_arr = [](const TensorShapeArray& arr) {
949 auto ret = Array::make();
950 for (auto&& shp : arr) {
951 auto cur = Array::make();
952 for (size_t i = 0; i < shp.ndim; ++i) {
953 cur->add(NumberInt::make(shp[i]));
954 }
955 ret->add(std::move(cur));
956 }
957 return ret;
958 };
959 auto format_layout_arr =
960 [](const TensorLayoutArray& arr) -> std::shared_ptr<Value> {
961 auto ret = Array::make();
962 bool have_non_contig = false;
963 for (auto&& item : arr) {
964 if (item.is_contiguous()) {
965 ret->add(json::Null::make());
966 } else {
967 have_non_contig = true;
968 auto cur = Array::make();
969 for (size_t i = 0; i < item.ndim; ++i) {
970 cur->add(NumberInt::make(item.stride[i]));
971 }
972 ret->add(std::move(cur));
973 }
974 }
975 if (!have_non_contig) {
976 ret.reset();
977 }
978 return ret;
979 };
980
981 TensorShapeArray inp_shape;
982 for (auto&& i : inp_layout)
983 inp_shape.push_back(i);
984 auto ret = Object::make(
985 {{"computation", std::move(comp)},
986 {"memory", NumberInt::make(memory)},
987 {"in_shapes", format_shape_arr(inp_shape)},
988 {"out_shapes", format_shape_arr(out_shape)},
989 {"param", param}});
990 if (auto inp_layout_json = format_layout_arr(inp_layout)) {
991 ret->operator[]("in_layouts") = std::move(inp_layout_json);
992 }
993 return ret;
994}
995
996std::shared_ptr<json::Value> OprFootprint::get_opr_fp_graph_exec(
997 cg::ComputingGraph& graph, const SymbolVarArray& outputs) {

Callers 1

get_opr_fp_graph_execMethod · 0.45

Calls 6

makeFunction · 0.50
addMethod · 0.45
is_contiguousMethod · 0.45
resetMethod · 0.45
push_backMethod · 0.45
operator[]Method · 0.45

Tested by

no test coverage detected