| 938 | } |
| 939 | |
| 940 | std::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 | |
| 996 | std::shared_ptr<json::Value> OprFootprint::get_opr_fp_graph_exec( |
| 997 | cg::ComputingGraph& graph, const SymbolVarArray& outputs) { |
no test coverage detected