1/* Copyright 2015 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_FUNCTION_H_
17#define TENSORFLOW_CORE_COMMON_RUNTIME_FUNCTION_H_
18
19#include <functional>
20#include <memory>
21
22#include "absl/types/optional.h"
23#include "tensorflow/core/common_runtime/device.h"
24#include "tensorflow/core/common_runtime/device_mgr.h"
25#include "tensorflow/core/common_runtime/function_body.h"
26#include "tensorflow/core/common_runtime/function_def_utils.h"
27#include "tensorflow/core/common_runtime/function_utils.h"
28#include "tensorflow/core/common_runtime/graph_optimizer.h"
29#include "tensorflow/core/common_runtime/inline_function_utils.h"
30#include "tensorflow/core/common_runtime/process_function_library_runtime.h"
31#include "tensorflow/core/framework/function.h"
32#include "tensorflow/core/graph/graph.h"
33#include "tensorflow/core/protobuf/config.pb.h"
34
35namespace tensorflow {
36
37// Get default customizable kernel creator if set
38const CustomKernelCreator* GetDefaultCustomKernelCreator();
39
40// Registers a default customizable kernel creator for a function call.
41//
42// If c->CanCreateKernel returns false, we still fall back to an executor-based
43// interpreter op kernel to execute a function. Else c->CreateKernel() can be
44// used to create a kernel that will compile the function with XLA and run the
45// resulting program.
46void RegisterDefaultCustomKernelCreator(CustomKernelCreator* c);
47
48// Creates a FunctionLibraryRuntime, which instantiates functions
49// defined in "lib_def" and executes functions on the "device".
50// "device_mgr" must contain the "device".
51//
52// The returned object does not take ownerships of "device" or
53// "lib_def". The caller must ensure "device" and "lib_def" outlives
54// the returned object.
55//
56// The "parent" is a pointer to the ProcessFunctionLibraryRuntime object that
57// typically owns the created FunctionLibraryRuntime object. The parent pointer
58// is not owned by the FunctionLibraryRuntime object.
59std::unique_ptr<FunctionLibraryRuntime> NewFunctionLibraryRuntime(
60 const DeviceMgr* device_mgr, Env* env, const ConfigProto* config,
61 Device* device, int graph_def_version,
62 const FunctionLibraryDefinition* lib_def, thread::ThreadPool* thread_pool,
63 const OptimizerOptions& optimizer_options,
64 const SessionMetadata* session_metadata,
65 ProcessFunctionLibraryRuntime* parent);
66
67// Given a numerical function "f", returns another numerical function
68// "g", such that if "f" takes N inputs and produces M outputs, "g"
69// takes N + M inputs and produces N outputs. I.e., if
70// (y1, y2, ..., y_M) = f(x1, x2, ..., x_N),
71// g is a function which is
72// (dL/dx1, dL/dx2, ..., dL/dx_N) = g(x1, x2, ..., x_N,
73// dL/dy1, dL/dy2, ..., dL/dy_M),
74// where L is a scalar-value function of (...x_i...).
75//
76// TODO(zhifengc): Asks math expert to say the comment again.
77std::unique_ptr<FunctionBody> SymbolicGradient(const FunctionBody& f);
78
79} // end namespace tensorflow
80
81#endif // TENSORFLOW_CORE_COMMON_RUNTIME_FUNCTION_H_
82