44 virtual size_t Read(
void *ptr,
size_t size) = 0;
50 virtual void Write(
const void *ptr,
size_t size) = 0;
63 template<
int dim,
typename DType,
typename TStream>
73 template<
int dim,
typename DType,
typename TStream>
86 template<
int dim,
typename DType,
typename TStream>
101 template<
int dim,
typename DType,
typename TStream>
106 template<
int dim,
typename DType,
typename TStream>
111 fo.Write(src[i].dptr_,
sizeof(DType) * src.
size(1));
114 template<
int dim,
typename DType,
typename TStream>
120 Copy(tmp, src, &stream);
124 template<
int dim,
typename DType,
typename TStream>
128 CHECK_NE(fi.Read(&shape,
sizeof(shape)), 0) <<
"mshadow::LoadBinary";
130 CHECK_EQ(shape, dst_->
shape_) <<
"LoadBinary, shape do not match pre-allocated shape";
135 if (dst.
size(0) == 0)
return;
137 CHECK_NE(fi.Read(dst[i].
dptr_,
sizeof(DType) * dst.
size(1)), 0) <<
"mshadow::LoadBinary";
140 template<
int dim,
typename DType,
typename TStream>
146 CHECK_EQ(tmp.shape, dst->
shape_) <<
"LoadBinary, shape do not match pre-allocated shape";
151 Copy(*dst, tmp, &stream);
155 #endif // MSHADOW_IO_H_ void FreeSpace(Tensor< cpu, dim, DType > *obj)
CPU/GPU: free the space of tensor, will set obj.dptr to NULL.
Definition: tensor_cpu-inl.h:140
DType * dptr_
pointer to the data
Definition: tensor.h:434
virtual size_t Read(void *ptr, size_t size)=0
read data from stream
void LoadBinary(TStream &fi, Tensor< cpu, dim, DType > *dst, bool pre_alloc)
CPU/GPU: load a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: io.h:125
void Copy(Tensor< cpu, dim, DType > dst, const Tensor< cpu, dim, DType > &src, Stream< cpu > *stream=NULL)
copy data from one tensor to another, with same shape
Definition: tensor_cpu-inl.h:145
Definition: stream_gpu-inl.h:37
Shape< dimension > shape_
shape of the tensor
Definition: tensor.h:436
header file of tensor data structure and functions This lib requires explicit memory allocation and d...
int32_t index_t
type that will be used for index
Definition: base.h:343
void AllocSpace(Tensor< cpu, dim, DType > *obj, bool pad=MSHADOW_ALLOC_PAD)
CPU/CPU: allocate space for CTensor, according to the shape in the obj this function is responsible t...
Definition: tensor_cpu-inl.h:116
MSHADOW_XINLINE Tensor< Device, 2, DType > FlatTo2D(void) const
flatten the tensor to 2 dimension, collapse the higher dimensions together
Definition: tensor.h:519
MSHADOW_XINLINE index_t size(int idx) const
return size of i-th dimension, start counting from highest dimension
Definition: tensor.h:505
overloaded + operator between half_t and bf16_t
Definition: base.h:334
interface of stream I/O, used to serialize data, mshadow does not restricted to only this interface i...
Definition: io.h:36
void SaveBinary(TStream &fo, const Tensor< cpu, dim, DType > &src)
CPU/GPU: save a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: io.h:107
virtual ~IStream(void)
virtual destructor
Definition: io.h:52
general tensor
Definition: tensor.h:420
virtual void Write(const void *ptr, size_t size)=0
write data to stream