| 434 | } |
| 435 | |
| 436 | std::string debug::dump_tensor(const HostTensorND& value, const std::string& name) { |
| 437 | struct Header { |
| 438 | uint32_t name_len; |
| 439 | uint32_t dtype; |
| 440 | uint32_t max_ndim; |
| 441 | uint32_t shape[TensorShape::MAX_NDIM]; |
| 442 | char name[0]; |
| 443 | }; |
| 444 | mgb_assert(value.layout().is_contiguous()); |
| 445 | auto value_bytes = value.layout().span().dist_byte(); |
| 446 | std::string ret(name.size() + value_bytes + sizeof(Header), '\0'); |
| 447 | auto header = reinterpret_cast<Header*>(&ret[0]); |
| 448 | memset(header, 0, sizeof(Header)); |
| 449 | header->name_len = name.length(); |
| 450 | header->dtype = static_cast<uint32_t>(value.dtype().enumv()); |
| 451 | header->max_ndim = TensorShape::MAX_NDIM; |
| 452 | for (size_t i = 0; i < value.layout().ndim; ++i) { |
| 453 | header->shape[i] = value.layout()[i]; |
| 454 | } |
| 455 | memcpy(header->name, name.c_str(), header->name_len); |
| 456 | memcpy(header->name + name.size(), value.raw_ptr(), value_bytes); |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | void debug::write_to_file( |
| 461 | const char* filename, const std::string& content, const char* mode) { |
no test coverage detected