| 406 | } |
| 407 | |
| 408 | void 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 | |
| 426 | cg::ComputingGraph::OutputSpecItem mgb::make_callback_copy( |
| 427 | SymbolVar dev, HostTensorND& host, bool sync) { |