diff options
author | A. Unique TensorFlower <nobody@tensorflow.org> | 2016-03-24 08:44:27 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-03-24 10:02:49 -0700 |
commit | 821920c1f25968f5dfcd2f8999b293ebedf85957 (patch) | |
tree | b4dce0285bac385630f658582bf27558f80cac51 /tensorflow/core/framework/node_def_util.cc | |
parent | 5b5b8412f0684a548e1e9001421e5d095cda0142 (diff) |
Several changes to reduce TensorFlow code size (especially important
for mobile apps):
(1) Change many interfaces in node_def_builder.h, node_def_util.h,
op_kernel.h, node_builder.h, mirror_pad_mode.h, padding.h to use
'StringPiece', rather than 'const string&'. The interfaces that
were changed tend to be heavily used in the registration of ops and
kernels, and often caused extra string construction code to be emitted
in the macro expansion of each op or kernel registration.
(2) Move some repetitive CHECK operations into non-inlined routines in
tensor.cc, rather than having them in inlined or templated routines in
tensor.h (new Tensor::CheckDataType, Tensor::CheckTypeAndIsAligned,
and Tensor::CheckIsAlignedAndSingleElement routines)
(3) Factored out internal template<size_t NDIMS>
Tensor::FillDimsAndValidateCompatibleShape routine, to be shared
across more specialized templated routines (typically specialized on
both DataType and NDIMS).
(4) Added new non-inlined TensorShape::CheckDimsMatch(int NDIMS) routine in
tensor_shape.cc, that can be called from various TensorShape routines templated
on NDIMS.
(5) Don't inline single-argument StrCat, since it involves a string
creation, etc.
(6) Remove inline keyword from template <typename... AV> StrCat
version that handles 5 or more arguments.
Reduces text size for
third_party/tensorflow/core/libandroid_tensorflow_lib.so built in
Google build environment by 1.43%, as
measured by:
% blaze build -c opt --config=android_arm \
third_party/tensorflow/core:android_tensorflow_lib
% size blaze-bin/third_party/tensorflow/core/libandroid_tensorflow_lib.so
Change: 118036659
Diffstat (limited to 'tensorflow/core/framework/node_def_util.cc')
-rw-r--r-- | tensorflow/core/framework/node_def_util.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tensorflow/core/framework/node_def_util.cc b/tensorflow/core/framework/node_def_util.cc index 641411892d..002adfc250 100644 --- a/tensorflow/core/framework/node_def_util.cc +++ b/tensorflow/core/framework/node_def_util.cc @@ -72,13 +72,13 @@ string SummarizeNodeDef(const NodeDef& node_def) { return ret; } -const AttrValue* AttrSlice::Find(const string& attr_name) const { - auto iter = attrs_->find(attr_name); +const AttrValue* AttrSlice::Find(StringPiece attr_name) const { + auto iter = attrs_->find(attr_name.ToString()); if (iter == attrs_->end()) return nullptr; return &iter->second; } -Status AttrSlice::Find(const string& attr_name, +Status AttrSlice::Find(StringPiece attr_name, const AttrValue** attr_value) const { *attr_value = Find(attr_name); if (*attr_value != nullptr) { @@ -97,7 +97,7 @@ Status AttrSlice::Find(const string& attr_name, // The ... is to allow the caller to inject some value validation code. Use // just ; if no additional validation code is needed. #define DEFINE_GET_ATTR(TYPE, FIELD, ATTR_TYPE, APPEND_OP, CAST, ...) \ - Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, \ + Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, \ TYPE* value) { \ const AttrValue* attr_value; \ TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); \ @@ -107,7 +107,7 @@ Status AttrSlice::Find(const string& attr_name, *value = CAST; \ return Status::OK(); \ } \ - Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, \ + Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, \ std::vector<TYPE>* value) { \ const AttrValue* attr_value; \ TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); \ @@ -149,7 +149,7 @@ DEFINE_GET_ATTR(Tensor, tensor, "tensor", emplace_back, t, Tensor t; #undef DEFINE_GET_ATTR -Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, DataTypeVector* value) { const AttrValue* attr_value; TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); @@ -160,7 +160,7 @@ Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, return Status::OK(); } -Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, const TensorProto** value) { const AttrValue* attr_value; TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); @@ -169,7 +169,7 @@ Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, return Status::OK(); } -Status GetNodeAttr(const AttrSlice& attrs, const string& attr_name, +Status GetNodeAttr(const AttrSlice& attrs, StringPiece attr_name, const NameAttrList** value) { const AttrValue* attr_value; TF_RETURN_IF_ERROR(attrs.Find(attr_name, &attr_value)); |