| 151 | |
| 152 | #if MGB_ENABLE_JSON |
| 153 | std::shared_ptr<json::Value> MemAllocPlan::to_json() const { |
| 154 | auto cvt_layout = [](const TensorLayout& layout) { |
| 155 | auto shape = json::Array::make(), stride = json::Array::make(); |
| 156 | for (size_t i = 0; i < layout.ndim; i++) { |
| 157 | shape->add(json::Number::make(layout.shape[i])); |
| 158 | stride->add(json::Number::make(layout.stride[i])); |
| 159 | } |
| 160 | return json::Object::make( |
| 161 | {{"shape", shape}, |
| 162 | {"stride", stride}, |
| 163 | {"dtype", json::String::make(layout.dtype.name())}}); |
| 164 | }; |
| 165 | |
| 166 | return json::Object::make( |
| 167 | {{"mem_chunk_id", json::String::make(m_chunk->id_str())}, |
| 168 | {"layout", cvt_layout(m_layout)}, |
| 169 | {"offset_byte", json::Number::make(m_offset_byte)}}); |
| 170 | } |
| 171 | #endif |
| 172 | |
| 173 | std::string MemAllocPlan::Chunk::id_str() const { |