|
17 | 17 |
|
18 | 18 | namespace vkcompute { |
19 | 19 |
|
| 20 | +std::ostream& operator<<(std::ostream& os, const std::vector<int64_t>& sizes) { |
| 21 | + if (sizes.size() == 0) { |
| 22 | + os << "[]"; |
| 23 | + return os; |
| 24 | + } |
| 25 | + os << "["; |
| 26 | + for (int i = 0; i < sizes.size() - 1; ++i) { |
| 27 | + os << sizes.at(i) << ", "; |
| 28 | + } |
| 29 | + os << sizes.at(sizes.size() - 1); |
| 30 | + os << "]"; |
| 31 | + return os; |
| 32 | +} |
| 33 | + |
| 34 | +std::string make_arg_json(ComputeGraph* const compute_graph, ValueRef arg) { |
| 35 | + std::stringstream ss; |
| 36 | + ss << "{\"type\": \"" << compute_graph->get_val_type(arg) << "\", "; |
| 37 | + ss << "\"value_ref\": " << arg; |
| 38 | + if (compute_graph->val_is_tensor(arg)) { |
| 39 | + ss << ", \"dtype\": \""; |
| 40 | + ss << compute_graph->dtype_of(arg) << "\""; |
| 41 | + ss << ", \"sizes\": "; |
| 42 | + ss << compute_graph->sizes_of(arg); |
| 43 | + ss << ", \"storage\": \""; |
| 44 | + ss << compute_graph->storage_type_of(arg) << "\""; |
| 45 | + ss << ", \"packed_dim\": "; |
| 46 | + ss << compute_graph->packed_dim_of(arg); |
| 47 | + } else if (compute_graph->val_is_tref(arg)) { |
| 48 | + ss << ", \"sizes\": "; |
| 49 | + ss << compute_graph->sizes_of(arg); |
| 50 | + ss << ", \"dtype\": \""; |
| 51 | + ss << compute_graph->dtype_of(arg) << "\""; |
| 52 | + } else if (compute_graph->val_is_value_list(arg)) { |
| 53 | + ValueListPtr val_list = compute_graph->get_value_list(arg); |
| 54 | + ss << ", \"values\": ["; |
| 55 | + for (const ValueRef& value : *val_list) { |
| 56 | + ss << value << ", "; |
| 57 | + } |
| 58 | + ss << "]"; |
| 59 | + } else if (compute_graph->val_is_int_list(arg)) { |
| 60 | + ss << ", \"values\": "; |
| 61 | + ss << *compute_graph->get_int_list(arg); |
| 62 | + } else if (compute_graph->val_is_int(arg)) { |
| 63 | + ss << ", \"value\": "; |
| 64 | + ss << compute_graph->get_int(arg); |
| 65 | + } else if (compute_graph->val_is_double(arg)) { |
| 66 | + ss << ", \"value\": "; |
| 67 | + ss << compute_graph->get_double(arg); |
| 68 | + } else if (compute_graph->val_is_bool(arg)) { |
| 69 | + ss << ", \"value\": "; |
| 70 | + ss << compute_graph->get_bool(arg); |
| 71 | + } else if (compute_graph->val_is_symint(arg)) { |
| 72 | + ss << ", \"value\": "; |
| 73 | + ss << compute_graph->read_symint(arg); |
| 74 | + } |
| 75 | + ss << "}"; |
| 76 | + |
| 77 | + return ss.str(); |
| 78 | +} |
| 79 | + |
| 80 | +std::string make_operator_json( |
| 81 | + ComputeGraph* const compute_graph, |
| 82 | + std::string& op_name, |
| 83 | + std::vector<ValueRef>& args) { |
| 84 | + std::stringstream ss; |
| 85 | + ss << "\"name\": \"" << op_name << "\", \"args\": ["; |
| 86 | + for (size_t i = 0; i < args.size(); ++i) { |
| 87 | + ss << make_arg_json(compute_graph, args[i]); |
| 88 | + if (i + 1 < args.size()) { |
| 89 | + ss << ", "; |
| 90 | + } |
| 91 | + } |
| 92 | + ss << "]"; |
| 93 | + return ss.str(); |
| 94 | +} |
| 95 | + |
20 | 96 | void ComputeGraph::print_readable() { |
21 | 97 | std::set<ValueRef> input_set; |
22 | 98 | for (const IOValueRef& io_val : inputs()) { |
|
0 commit comments