1 #ifndef CAFFE2_CORE_QTENSOR_SERIALIZATION_H_ 2 #define CAFFE2_CORE_QTENSOR_SERIALIZATION_H_ 4 #include "caffe2/core/blob_serialization.h" 5 #include "caffe2/core/qtensor.h" 9 constexpr
auto kQTensorBlobQType =
"QTensor";
11 template <
class Context>
23 SerializationAcceptor acceptor)
override;
29 template <
class Context>
32 void Deserialize(
const BlobProto& proto,
Blob* blob)
override;
36 template <
class Context>
41 BlobSerializerBase::SerializationAcceptor acceptor) {
45 blob_proto.set_name(name);
46 blob_proto.set_type(kQTensorBlobQType);
47 QTensorProto& proto = *blob_proto.mutable_qtensor();
49 for (
int i = 0; i < qtensor.ndim(); ++i) {
50 proto.add_dims(qtensor.dim32(i));
52 proto.set_precision(qtensor.precision());
53 proto.set_scale(qtensor.scale());
54 proto.set_bias(qtensor.bias());
55 proto.set_is_signed(qtensor.is_signed());
56 detail::CopyToProtoWithCast(
57 qtensor.nbytes(), qtensor.data(), proto.mutable_data(), &this->context_);
58 acceptor(name, SerializeBlobProtoAsString_EnforceCheck(blob_proto));
61 template <
class Context>
63 const BlobProto& blob_proto,
68 template <
class Context>
70 const QTensorProto& proto,
74 for (
const int d : proto.dims()) {
77 qtensor->Resize(dims);
78 qtensor->SetPrecision(proto.precision());
79 qtensor->SetScale(proto.scale());
80 qtensor->SetBias(proto.bias());
81 qtensor->SetSigned(proto.is_signed());
83 detail::CopyFromProtoWithCast(
84 qtensor->nbytes(), proto.data(), qtensor->mutable_data(), &context);
89 #endif // CAFFE2_CORE_QTENSOR_SERIALIZATION_H_ Blob is a general container that hosts a typed pointer.
BlobDeserializerBase is an abstract class that deserializes a blob from a BlobProto or a TensorProto...
void Serialize(const void *pointer, TypeMeta typeMeta, const string &name, SerializationAcceptor acceptor) override
Serializes a Blob.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
T * GetMutable()
Gets a mutable pointer to the stored object.
BlobSerializerBase is an abstract class that serializes a blob to a string.