aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/c/eager
diff options
context:
space:
mode:
authorGravatar Akshay Modi <nareshmodi@google.com>2018-04-17 10:32:47 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-17 10:35:11 -0700
commit69f392fab1445f18dbd31dcd0e97f1f65eeb68e0 (patch)
tree219a5504dc9eea9fbf2bd1fe1a083ef7e3a05e7d /tensorflow/c/eager
parent56026690cd4a5587670047dc89aaad7b09853f87 (diff)
Avoid ToString() in Eager's TFE_Execute.
Also use InlinedVector instead of std::vector for non-async path Before: Benchmark Time(ns) CPU(ns) Iterations ------------------------------------------------------------- BM_Execute/0 1895 1898 360200 Execute BM_Execute/1 1193 1942 358322 ExecuteAsync BM_ExecuteFunction/0 5812 5825 100000 ExecuteFunction BM_ExecuteFunction/1 5015 5374 100000 ExecuteFunctionAsync After: Benchmark Time(ns) CPU(ns) Iterations ------------------------------------------------------------- BM_Execute/0 1604 1607 428262 Execute BM_Execute/1 1150 1765 404821 ExecuteAsync BM_ExecuteFunction/0 5615 5626 100000 ExecuteFunction BM_ExecuteFunction/1 5111 5476 100000 ExecuteFunctionAsync PiperOrigin-RevId: 193218331
Diffstat (limited to 'tensorflow/c/eager')
-rw-r--r--tensorflow/c/eager/c_api.cc14
-rw-r--r--tensorflow/c/eager/runtime.cc9
2 files changed, 7 insertions, 16 deletions
diff --git a/tensorflow/c/eager/c_api.cc b/tensorflow/c/eager/c_api.cc
index c96a38dec3..393851d13c 100644
--- a/tensorflow/c/eager/c_api.cc
+++ b/tensorflow/c/eager/c_api.cc
@@ -116,9 +116,7 @@ TFE_Context* TFE_NewContext(const TFE_ContextOptions* opts, TF_Status* status) {
opts->async, std::move(device_mgr), r);
}
-void TFE_DeleteContext(TFE_Context* ctx, TF_Status* status) {
- delete ctx;
-}
+void TFE_DeleteContext(TFE_Context* ctx, TF_Status* status) { delete ctx; }
TF_DeviceList* TFE_ContextListDevices(TFE_Context* ctx, TF_Status* status) {
TF_DeviceList* list = new TF_DeviceList;
@@ -581,7 +579,6 @@ tensorflow::Device* SelectDevice(const tensorflow::NodeDef& ndef,
return nullptr;
}
-
#ifdef TENSORFLOW_EAGER_USE_XLA
// Synthesizes and returns a wrapper function over `op`, which must be a
// primitive op (e.g. matmul).
@@ -725,9 +722,7 @@ std::unique_ptr<TFE_Op> BuildXlaLaunch(TFE_Op* op, TF_Status* status) {
}
const tensorflow::FunctionDef* fdef;
- {
- fdef = op->ctx->context.FindFunctionDef(op->name);
- }
+ { fdef = op->ctx->context.FindFunctionDef(op->name); }
std::vector<TF_DataType> const_input_types;
std::vector<TF_DataType> arg_input_types;
tensorflow::gtl::FlatMap<int, int> op_input_to_func_input;
@@ -940,8 +935,8 @@ void TFE_Execute(TFE_Op* op, TFE_TensorHandle** retvals, int* num_retvals,
} else {
// Execute checks if retvals[i] is nullptr or not to figure if it needs to
// allocate it.
- std::vector<tensorflow::TensorHandle*> handle_retvals(*num_retvals,
- nullptr);
+ tensorflow::gtl::InlinedVector<tensorflow::TensorHandle*, 2> handle_retvals(
+ *num_retvals);
status->status = tensorflow::EagerExecute(
&op->ctx->context, op->device, op->inputs, kernel, maybe_stats.get(),
handle_retvals.data(), *num_retvals);
@@ -1091,7 +1086,6 @@ void SetOpAttrValueScalar(TFE_Context* ctx, TFE_Op* op,
}
} // namespace tensorflow
-
TFE_Op::~TFE_Op() {
for (tensorflow::TensorHandle* h : inputs) {
h->Unref();
diff --git a/tensorflow/c/eager/runtime.cc b/tensorflow/c/eager/runtime.cc
index abe2793ce8..e6c51ab17a 100644
--- a/tensorflow/c/eager/runtime.cc
+++ b/tensorflow/c/eager/runtime.cc
@@ -184,8 +184,7 @@ void CombineUnordered(const tensorflow::Fprint128& a,
inline tensorflow::Fprint128 CacheKeyHelper(StringPiece s,
const tensorflow::Fprint128& b) {
- // TODO(agarwal): avoid ToString().
- tensorflow::Fprint128 a = tensorflow::Fingerprint128(s.ToString());
+ tensorflow::Fprint128 a = tensorflow::Fingerprint128(s);
return FingerprintCat128(a, b);
}
@@ -213,10 +212,8 @@ tensorflow::Fprint128 AttrBuilder::CacheKey(const string& device) const {
if (node_def_finalized_) return f;
}
for (const auto& p : string_attrs_) {
- // TODO(agarwal): avoid ToString().
- CombineUnordered(CacheKeyHelper(p.first, tensorflow::Fingerprint128(
- p.second.ToString())),
- &f);
+ CombineUnordered(
+ CacheKeyHelper(p.first, tensorflow::Fingerprint128(p.second)), &f);
}
for (const auto& p : int_attrs_) {
CombineUnordered(CacheKeyHelper(p.first, static_cast<uint64>(p.second)),