[info] type_name = "caffe2::Blob" ctype = "CAFFE2_BLOB_TYPE" header = "caffe2/core/blob.h" # Old: typeName = "caffe2::Blob" matcher = "^caffe2::Blob$" ns = ["caffe2::Blob", "caffe2::Tensor"] numTemplateParams = 0 replaceTemplateParamIndex = [] [codegen] decl = """ void getSizeType(const %1% &container, size_t& returnArg); """ func = """ size_t getTensorItemSize(const Tensor& t, size_t& returnArg) { const caffe2::TypeMeta& tm = t.dtype(); if (!tm.isScalarType()) { // For non-scalar types, the pre-defined static array is not accessed return tm.itemsize(); } else { // For scalar types, static array is accessed which does not undergo // relocattion and causes segfaults. Would be nice to have a better // way to do this. if (tm.Match()) { return sizeof(uint8_t); } else if (tm.Match()) { return sizeof(int8_t); } else if (tm.Match()) { return sizeof(uint16_t); } else if (tm.Match()) { return sizeof(int); } else if (tm.Match()) { return sizeof(int64_t); } else if (tm.Match()) { return sizeof(at::Half); } else if (tm.Match()) { return sizeof(float); } else if (tm.Match()) { return sizeof(double); } else if (tm.Match>()) { return sizeof(c10::complex); } else if (tm.Match>()) { return sizeof(c10::complex); } else if (tm.Match>()) { return sizeof(c10::complex); } else if (tm.Match()) { return sizeof(bool); } else if (tm.Match()) { return sizeof(c10::qint8); } else if (tm.Match()) { return sizeof(c10::quint8); } else if (tm.Match()) { return sizeof(c10::qint32); } else if (tm.Match()) { return sizeof(at::BFloat16); } else if (tm.Match()) { return sizeof(c10::quint4x2); } } return 0; } size_t getTensorSize(const Tensor& t, size_t& returnArg) { size_t p1 = t.numel(); size_t p2 = getTensorItemSize(t, returnArg); return p1 * p2; } void getSizeType(const %1% &blob, size_t& returnArg) { // TODO: We should have a way to assert at compile time if Blob struct changes // TODO: Log the type of Blob i.e. Tensor/string // TODO: Capture the capacity if blob is of string type if (blob.IsType()) { const auto& tensor = blob.Get(); // tensor.nbytes() cannot be directly called since it accesses a static // array SAVE_DATA((uintptr_t)getTensorSize(tensor)); } else if (blob.IsType()) { const auto& s = blob.Get(); SAVE_DATA((uintptr_t)s.size()); /* } else if (blob.IsType()) { SAVE_DATA((uintptr_t)sizeof(caffe2::db::DBReader)); */ } else { SAVE_DATA((uintptr_t)0); } } """