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

Method write_tensor_to_file

test/src/helper.cpp:408–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408void mgb::write_tensor_to_file(const HostTensorND& hv, const char* fname, char mode) {
409 mgb_assert(hv.layout().is_contiguous());
410 char modefull[] = {mode, 'b', '\x00'};
411 FILE* fout = fopen(fname, modefull);
412 mgb_assert(fout, "failed to open %s: %s", fname, strerror(errno));
413 fprintf(fout, "%s %zu", hv.dtype().name(), hv.shape().ndim);
414 for (size_t i = 0; i < hv.shape().ndim; ++i) {
415 fprintf(fout, " %zu", hv.shape(i));
416 }
417 fprintf(fout, "\n");
418 auto size = hv.layout().span().dist_byte();
419 auto wr = fwrite(hv.raw_ptr(), 1, size, fout);
420 mgb_assert(size == wr);
421 mgb_log("write tensor: %zu bytes (%s) to %s", size, hv.shape().to_string().c_str(),
422 fname);
423 fclose(fout);
424}
425
426cg::ComputingGraph::OutputSpecItem mgb::make_callback_copy(
427 SymbolVar dev, HostTensorND& host, bool sync) {

Callers

nothing calls this directly

Calls 9

dist_byteMethod · 0.80
spanMethod · 0.80
is_contiguousMethod · 0.45
layoutMethod · 0.45
nameMethod · 0.45
dtypeMethod · 0.45
shapeMethod · 0.45
raw_ptrMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected