1/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_SINGLE_THREADED_EXECUTOR_H_
17#define TENSORFLOW_CORE_COMMON_RUNTIME_SINGLE_THREADED_EXECUTOR_H_
18
19#include "tensorflow/core/common_runtime/executor.h"
20
21namespace tensorflow {
22
23// Creates a new `Executor` for executing `graph` synchronously on the caller
24// thread.
25//
26// NOTE(mrry): The returned executor is optimized to impose low overhead on
27// graphs that perform a small amount of work (e.g. <15us of work per graph on
28// present architectures). It eschews concurrency, because issuing work to
29// multiple threads can dominate the cost of executing small ops synchronously,
30// and because contention in the executor data structures can reduce throughput
31// (in terms of ops executed per unit time).
32//
33// However, the current implementation has the following limitations:
34//
35// 1. Reference-typed tensors are not supported and will not be supported in
36// future.
37// 2. Graphs with control flow (containing "Switch" and "Merge" nodes) are not
38// currently supported. The current plan is to extend support to "functional"
39// control flow after the TensorFlow APIs transition to building graphs in
40// that form (e.g. `tf.cond_v2()`).
41// 3. Partitioned graphs (containing "_Recv" nodes) are not currently supported.
42// The present implementation executes kernels one at a time in topological
43// order, and cannot currently distinguish between disconnected subgraphs
44// that are logically connected by subgraphs on a different device.
45// 4. Memory logging is not currently supported.
46// 5. Allocation forwarding is not currently supported.
47// 6. Non-default device contexts are not currently supported. In effect, this
48// limits the executor to CPU devices.
49// 7. Ops that rely on `OpKernelContext::slice_reader_cache()` being non-null
50// are not currently supported.
51//
52// The single-threaded executor is primarily suitable for executing simple
53// TensorFlow functions, such as one might find in a `tf.data` pipeline.
54Status NewSingleThreadedExecutor(const LocalExecutorParams& params,
55 const Graph& graph, Executor** executor);
56
57// Returns OkStatus() for ops which are compatible with synchronous execution,
58// and otherwise returns an error message appropriate for propagation if needed.
59// If `allow_control_flow_sync_execution` is set to `true` control
60// nodes are marked as safe for execution on the SingleThreadedExecutor.
61Status ValidateOpIsSafeForSyncExecution(const Node& n,
62 bool allow_control_flow_sync_execution);
63
64} // namespace tensorflow
65
66#endif // TENSORFLOW_CORE_COMMON_RUNTIME_SINGLE_THREADED_EXECUTOR_H_
67