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

Method dump_tensor

src/core/impl/utils/debug.cpp:436–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434}
435
436std::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
460void debug::write_to_file(
461 const char* filename, const std::string& content, const char* mode) {

Callers 11

dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45
dumpMethod · 0.45

Calls 8

dist_byteMethod · 0.80
spanMethod · 0.80
is_contiguousMethod · 0.45
layoutMethod · 0.45
sizeMethod · 0.45
enumvMethod · 0.45
dtypeMethod · 0.45
raw_ptrMethod · 0.45

Tested by

no test coverage detected