1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EXECUTE_H_ 16 #define TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EXECUTE_H_ 17 18 #include "absl/types/span.h" 19 #include "tensorflow/core/common_runtime/device.h" 20 #include "tensorflow/core/common_runtime/eager/context.h" 21 #include "tensorflow/core/common_runtime/eager/eager_operation.h" 22 #include "tensorflow/core/common_runtime/eager/kernel_and_device.h" 23 #include "tensorflow/core/common_runtime/eager/tensor_handle.h" 24 #include "tensorflow/core/framework/step_stats.pb.h" 25 #include "tensorflow/core/lib/core/status.h" 26 #include "tensorflow/core/lib/gtl/inlined_vector.h" 27 28 namespace tensorflow { 29 30 // Utility function that executes a fully constructed EagerOperation. 31 // There are a few possible different combinations of how things can be 32 // executed: 33 // - Async (the op context is configured to schedule asynchronously) 34 // Eager execute should return quickly after scheduling this operation to 35 // execute. 36 // - Remote (the op device is on a remote task) 37 // Eager execute will send an RPC to execute the op on a remote device. 38 // Note that in the Async + Remote case, EagerExecute should still return 39 // quickly, but it will schedule the op to be executed remotely. 40 // 41 // 'retvals' must point to a pre-allocated array of TensorHandle* and 42 // '*num_retvals' should be set to the size of this array. It is an error if 43 // the size of 'retvals' is less than the number of outputs. This call sets 44 // *num_retvals to the number of outputs. 45 Status EagerExecute(EagerOperation* op, TensorHandle** retvals, 46 int* num_retvals); 47 48 // Low-level utility to execute the kernel specified by `kernel` on 49 // `kernel->device()`, with the inputs op_inputs, in the context 'ctx'. 50 Status EagerKernelExecute( 51 EagerContext* ctx, const gtl::InlinedVector<TensorHandle*, 4>& op_inputs, 52 const absl::optional<EagerRemoteFunctionParams>& remote_func_params, 53 const core::RefCountPtr<KernelAndDevice>& kernel, 54 GraphCollector* graph_collector, CancellationManager* cancellation_manager, 55 absl::Span<TensorHandle*> retvals); 56 57 // Low-level utility to copy a tensor handle from one device to another. If 58 // successful, result TensorHandle will be populated. If the caller requests for 59 // the mirror flag, EagerCopyToDevice will attempt to add a mirror to the 60 // original handle and update *result to point to h. Since this is not 61 // guaranteed, callers should always use the value in *result. 62 Status EagerCopyToDevice(TensorHandle* h, EagerContext* ctx, 63 EagerExecutor* executor, Device* device, bool mirror, 64 TensorHandle** result); 65 66 } // namespace tensorflow 67 68 #endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EXECUTE_H_ 69