This commit is contained in:
Kevin Darby committed 2019-01-02 17:04:10 -05:00
1 parent eb1b42a5e8
commit 458eb2aef1
1283 files changed
+323373

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,190 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_C_C_API_EXPERIMENTAL_H_
#define TENSORFLOW_C_C_API_EXPERIMENTAL_H_
#include <stddef.h>
#include <stdint.h>
#include "tensorflow/c/c_api.h"
#include "tensorflow/c/eager/c_api.h"
// --------------------------------------------------------------------------
// Experimental C API for TensorFlow.
//
// The API here is subject to changes in the future.
// --------------------------------------------------------------------------
// Macro to control visibility of exported symbols in the shared library (.so,
// .dylib, .dll).
// This duplicates the TF_EXPORT macro definition in
// tensorflow/core/platform/macros.h in order to keep this .h file independent
// of any other includes.$a
#ifdef SWIG
#define TF_CAPI_EXPORT
#else
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
#define TF_CAPI_EXPORT __declspec(dllimport)
#endif // TF_COMPILE_LIBRARY
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // _WIN32
#endif // SWIG
#ifdef __cplusplus
extern "C" {
#endif
// When `enable` is true, set
// tensorflow.ConfigProto.OptimizerOptions.global_jit_level to ON_1, and also
// set XLA flag values to prepare for XLA compilation. Otherwise set
// global_jit_level to OFF.
//
// This and the next API are syntax sugar over TF_SetConfig(), and is used by
// clients that cannot read/write the tensorflow.ConfigProto proto.
// TODO: Migrate to TF_CreateConfig() below.
TF_CAPI_EXPORT extern void TF_EnableXLACompilation(TF_SessionOptions* options,
unsigned char enable);
// Create a serialized tensorflow.ConfigProto proto, where:
//
// a) ConfigProto.optimizer_options.global_jit_level is set to to ON_1 if
// `enable_xla_compilation` is non-zero, and OFF otherwise.
// b) ConfigProto.gpu_options.allow_growth is set to `gpu_memory_allow_growth`.
TF_CAPI_EXPORT extern TF_Buffer* TF_CreateConfig(
unsigned char enable_xla_compilation,
unsigned char gpu_memory_allow_growth);
// Create a serialized tensorflow.RunOptions proto, where RunOptions.trace_level
// is set to FULL_TRACE if `enable_full_trace` is non-zero, and NO_TRACE
// otherwise.
TF_CAPI_EXPORT extern TF_Buffer* TF_CreateRunOptions(
unsigned char enable_full_trace);
// Returns the graph content in a human-readable format, with length set in
// `len`. The format is subject to change in the future.
// The returned string is heap-allocated, and caller should call free() on it.
TF_CAPI_EXPORT extern const char* TF_GraphDebugString(TF_Graph* graph,
size_t* len);
// Creates a stack of data set + iterator nodes, currently hard-coded to return
// a sequence of 3 float values <42.0, 43.0, 44.0> over 3 calls. On success,
// returns the IteratorGetNext node, which caller can run or feed into an node.
//
// TODO(hongm): Extend the API to allow customization of the nodes created.
TF_CAPI_EXPORT extern TF_Operation* TF_MakeFakeIteratorGetNextWithDatasets(
TF_Graph* graph, TF_Status* status);
// Similar to the above API, except that the returned iterator reads the
// file based dataset from `file_path`.
// If `is_mnist` is 0, the dataset corresponds to ImageNet.
// The iterators outputs 2 tensors:
// - A float tensor of shape `batch_size` X 784 when `is_mnist` is non-zero, or
// `batch_size` X 224 X 224 X 3 otherwise.
// - An int32 tensor of shape `batch_size`
// TODO(hongm): Extend the API to allow customization of the nodes created.
TF_CAPI_EXPORT extern TF_Operation* TF_MakeFileBasedIteratorGetNextWithDatasets(
TF_Graph* graph, const char* file_path, int batch_size,
unsigned char is_mnist, TF_Status* status);
// On success, dequeues a tensor from a TF-managed FifoQueue given by
// `tensor_id`, associated with `session`. There must be a graph node named
// "fifo_queue_dequeue_<tensor_id>", to be executed by this API call.
// Caller must call TF_DeleteTensor() over the returned tensor. If the queue is
// empty, this call is blocked.
//
// Tensors are enqueued via the corresponding TF enqueue op.
// TODO(hongm): Add support for `timeout_ms`.
TF_CAPI_EXPORT extern TF_Tensor* TF_DequeueNamedTensor(TF_Session* session,
int tensor_id,
TF_Status* status);
// On success, enqueues `tensor` into a TF-managed FifoQueue given by
// `tensor_id`, associated with `session`. There must be a graph node named
// "fifo_queue_enqueue_<tensor_id>", to be executed by this API call. It reads
// from a placeholder node "arg_tensor_enqueue_<tensor_id>".
//
// `tensor` is still owned by the caller. This call will be blocked if the queue
// has reached its capacity, and will be unblocked when the queued tensors again
// drop below the capacity due to dequeuing.
//
// Tensors are dequeued via the corresponding TF dequeue op.
// TODO(hongm): Add support for `timeout_ms`.
TF_CAPI_EXPORT extern void TF_EnqueueNamedTensor(TF_Session* session,
int tensor_id,
TF_Tensor* tensor,
TF_Status* status);
// Create a serialized tensorflow.ServerDef proto.
TF_Buffer* TFE_GetServerDef(const char* text_proto, TF_Status* status);
// TODO: remove this API in favor of the next one.
TF_CAPI_EXPORT extern TFE_Context* TFE_NewContextFromSession(
const TFE_ContextOptions* opts, TF_Session* sess, TF_Status* status);
// Creates from `session` a new eager context to run a graph function or
// sends/recvs, so that these concurrent TFE executions can share (via
// `session` and its associated device mgr) the same set of fifo queue resource
// ops, used for host<->TF tensor transfers. This way the sends/recvs calls and
// graph function execution can access the same fifo queue resource handles
// (associated with devices managed by the device manager, which can be obtained
// from `session`).
//
// TODO: Remove this function once we migrate away from using session.
TF_CAPI_EXPORT extern TFE_Context* TFE_CreateContextFromSession(
TF_Session* session, TF_Status* status);
// TODO: Retire this API in favor of the next one.
TF_CAPI_EXPORT extern TFE_TensorHandle* TFE_DequeueNamedTensor(
TF_Session* session, int tensor_id, TF_DataType inputType,
TF_Status* status);
TF_CAPI_EXPORT extern TFE_TensorHandle* TFE_DequeueNamedTensorFromCtx(
TFE_Context* ctx, int tensor_id, TF_DataType inputType, TF_Status* status);
TF_CAPI_EXPORT extern void TFE_EnqueueNamedTensor(TF_Session* session,
int tensor_id,
TFE_TensorHandle* tensor,
TF_Status* status);
TF_CAPI_EXPORT extern void TFE_EnqueueNamedTensorFromCtx(
TFE_Context* ctx, int tensor_id, TFE_TensorHandle* tensor,
TF_Status* status);
// TODO: consider folding the 2 APIs below into the ones above.
TF_CAPI_EXPORT extern void TFE_EnqueueVariantTensor(TF_Session* session,
int tensor_id,
TFE_TensorHandle* tensor,
TF_Status* status);
TF_CAPI_EXPORT extern TFE_TensorHandle* TFE_DequeueVariantTensor(
TF_Session* session, int tensor_id, TF_Status* status);
// Prints `handle` in a human readable format to standard output for debugging.
TF_CAPI_EXPORT extern void TFE_TensorHandlePrintDebugString(
TFE_TensorHandle* handle);
TF_CAPI_EXPORT extern void TF_MakeInternalErrorStatus(TF_Status* status,
const char* errMsg);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif // TENSORFLOW_C_C_API_EXPERIMENTAL_H_
+223
View File
@@ -0,0 +1,223 @@
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_C_C_API_INTERNAL_H_
#define TENSORFLOW_C_C_API_INTERNAL_H_
#include "tensorflow/c/c_api.h"
#include <list>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#ifndef __ANDROID__
#include "tensorflow/core/framework/op_gen_lib.h"
#endif
#include "tensorflow/core/common_runtime/shape_refiner.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session.h"
namespace tensorflow {
class Device;
class DeviceMgr;
} // namespace tensorflow
// Internal structures used by the C API. These are likely to change and should
// not be depended on.
struct TF_Status {
tensorflow::Status status;
};
struct TF_Tensor {
~TF_Tensor();
TF_DataType dtype;
tensorflow::TensorShape shape;
tensorflow::TensorBuffer* buffer;
};
struct TF_SessionOptions {
tensorflow::SessionOptions options;
};
struct TF_DeprecatedSession {
tensorflow::Session* session;
};
struct TF_Library {
void* lib_handle;
TF_Buffer op_list;
};
struct TF_Graph {
TF_Graph();
tensorflow::mutex mu;
tensorflow::Graph graph GUARDED_BY(mu);
// Runs shape inference.
tensorflow::ShapeRefiner refiner GUARDED_BY(mu);
// Maps from name of an operation to the Node* in 'graph'.
std::unordered_map<tensorflow::string, tensorflow::Node*> name_map
GUARDED_BY(mu);
// The keys of this map are all the active sessions using this graph. Each
// value records whether the graph has been mutated since the corresponding
// session has been run (this is detected in RecordMutation function). If the
// string is empty, no mutation has occurred. Otherwise the string is a
// description of the mutation suitable for returning to the user.
//
// Sessions are added to this map in TF_NewSession, and removed in
// TF_DeleteSession.
// TF_Graph may only / must be deleted when
// sessions.size() == 0 && delete_requested == true
//
// TODO(b/74949947): mutations currently trigger a warning instead of a bad
// status, this should be reverted when possible.
tensorflow::gtl::FlatMap<TF_Session*, tensorflow::string> sessions
GUARDED_BY(mu);
bool delete_requested GUARDED_BY(mu); // set true by TF_DeleteGraph
// Used to link graphs contained in TF_WhileParams to the parent graph that
// will eventually contain the full while loop.
TF_Graph* parent;
TF_Output* parent_inputs;
};
struct TF_OperationDescription {
TF_OperationDescription(TF_Graph* g, const char* op_type,
const char* node_name)
: node_builder(node_name, op_type, g->graph.op_registry()), graph(g) {}
tensorflow::NodeBuilder node_builder;
TF_Graph* graph;
std::set<tensorflow::string> colocation_constraints;
};
struct TF_Operation {
tensorflow::Node node;
};
struct TF_Session {
TF_Session(tensorflow::Session* s, TF_Graph* g);
tensorflow::Session* session;
TF_Graph* const graph;
tensorflow::mutex mu ACQUIRED_AFTER(TF_Graph::mu);
int last_num_graph_nodes;
// If true, TF_SessionRun and similar methods will call
// ExtendSessionGraphHelper before running the graph (this is the default
// public behavior). Can be set to false if the caller needs to call
// ExtendSessionGraphHelper manually.
std::atomic<bool> extend_before_run;
};
struct TF_ImportGraphDefOptions {
tensorflow::ImportGraphDefOptions opts;
// Backing memory for TensorId fields in opts.
// TODO(skyewm): it'd be better if ImportGraphDefOptions owned this.
std::list<tensorflow::string> tensor_id_data;
};
struct TF_ImportGraphDefResults {
std::vector<TF_Output> return_tensors;
std::vector<TF_Operation*> return_nodes;
std::vector<const char*> missing_unused_key_names;
std::vector<int> missing_unused_key_indexes;
// Backing memory for missing_unused_key_names values.
std::list<tensorflow::string> missing_unused_key_names_data;
};
struct TF_DeviceList {
std::vector<tensorflow::DeviceAttributes> response;
};
struct TF_Function {
tensorflow::FunctionDef fdef;
};
struct TF_ApiDefMap {
explicit TF_ApiDefMap(const tensorflow::OpList& op_list)
:
#ifndef __ANDROID__
api_def_map(op_list),
#endif
update_docs_called(false) {
}
#ifndef __ANDROID__
tensorflow::ApiDefMap api_def_map GUARDED_BY(lock);
#endif
bool update_docs_called GUARDED_BY(lock);
tensorflow::mutex lock;
};
namespace tensorflow {
class TensorCApi {
public:
static TensorBuffer* Buffer(const Tensor& tensor) { return tensor.buf_; }
static Tensor MakeTensor(TF_DataType type, const TensorShape& shape,
TensorBuffer* buf) {
return Tensor(static_cast<DataType>(type), shape, buf);
}
};
Status TF_TensorToTensor(const TF_Tensor* src, Tensor* dst);
TF_Tensor* TF_TensorFromTensor(const Tensor& src, TF_Status* status);
Status MessageToBuffer(const tensorflow::protobuf::Message& in, TF_Buffer* out);
// Set the shapes and types of the output's handle.
//
// The lengths of the arrays pointed to by `shapes`, `ranks`, and `types` must
// all be equal to `num_shapes_and_types`. If `ranks[i] != -1`, (i.e., if the
// rank is known), then it must be equal to the length of `shapes[i]`; if
// `ranks[i] == 1`, then `shapes[i]` may be nullptr.
//
// TODO(akshayka): Implement a corresponding getter method.
void TF_GraphSetOutputHandleShapesAndTypes(TF_Graph* graph, TF_Output output,
int num_shapes_and_types,
const int64_t** shapes,
const int* ranks,
const TF_DataType* types,
TF_Status* status);
void RecordMutation(TF_Graph* graph, const TF_Operation& op,
const char* mutation_type)
EXCLUSIVE_LOCKS_REQUIRED(graph->mu);
bool ExtendSessionGraphHelper(TF_Session* session, TF_Status* status)
LOCKS_EXCLUDED(session->graph->mu, session->mu);
} // end namespace tensorflow
#endif // TENSORFLOW_C_C_API_INTERNAL_H_
@@ -0,0 +1,82 @@
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_C_CHECKPOINT_READER_H_
#define TENSORFLOW_C_CHECKPOINT_READER_H_
#include <memory>
#include <string>
#include "tensorflow/c/tf_status_helper.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/tensor_bundle/tensor_bundle.h"
#include "tensorflow/core/util/tensor_slice_reader.h"
namespace tensorflow {
namespace checkpoint {
class TensorSliceReader;
// A wrapper around BundleReader (for V2 checkpoints) and
// checkpoint::TensorSliceReader (for V1), that is more easily SWIG wrapped for
// other languages.
//
// The class currently only interacts with single-slice (i.e., non-partitioned)
// variables.
class CheckpointReader {
public:
CheckpointReader(const string& filepattern, TF_Status* out_status);
bool HasTensor(const string& name) const;
const string DebugString() const;
// Returns a map from variable names to their shapes. Slices of a partitioned
// tensor are combined into a single entry.
const TensorSliceReader::VarToShapeMap& GetVariableToShapeMap() const;
// Returns a map from variable names to their data types. Slices of a
// partitioned tensor are combined into a single entry.
const TensorSliceReader::VarToDataTypeMap& GetVariableToDataTypeMap() const;
// Attempts to look up the tensor named "name" and stores the found result in
// "out_tensor".
void GetTensor(const string& name,
std::unique_ptr<tensorflow::Tensor>* out_tensor,
TF_Status* out_status) const;
private:
// Uses "v2_reader_" to build "var name -> shape" and "var name -> data type"
// maps; both owned by caller.
// REQUIRES: "v2_reader_ != nullptr && v2_reader_.status().ok()".
std::pair<std::unique_ptr<TensorSliceReader::VarToShapeMap>,
std::unique_ptr<TensorSliceReader::VarToDataTypeMap> >
BuildV2VarMaps();
// Invariant: exactly one of "reader_" and "v2_reader_" is non-null.
std::unique_ptr<TensorSliceReader> reader_;
std::unique_ptr<BundleReader> v2_reader_;
std::unique_ptr<TensorSliceReader::VarToShapeMap> var_to_shape_map_;
std::unique_ptr<TensorSliceReader::VarToDataTypeMap> var_to_data_type_map_;
TF_DISALLOW_COPY_AND_ASSIGN(CheckpointReader);
};
} // namespace checkpoint
} // namespace tensorflow
#endif // TENSORFLOW_C_CHECKPOINT_READER_H_
+429
View File
@@ -0,0 +1,429 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_C_EAGER_C_API_H_
#define TENSORFLOW_C_EAGER_C_API_H_
// C API extensions to experiment with eager execution of kernels.
// WARNING: Unlike tensorflow/c/c_api.h, the API here is not guaranteed to be
// stable and can change without notice.
#include "tensorflow/c/c_api.h"
// Macro to control visibility of exported symbols in the shared library (.so,
// .dylib, .dll).
// This duplicates the TF_EXPORT macro definition in
// tensorflow/core/platform/macros.h in order to keep this .h file independent
// of any other includes.$a
#ifdef SWIG
#define TF_CAPI_EXPORT
#else
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
#define TF_CAPI_EXPORT __declspec(dllimport)
#endif // TF_COMPILE_LIBRARY
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // _WIN32
#endif // SWIG
#ifdef __cplusplus
extern "C" {
#endif
typedef struct TFE_ContextOptions TFE_ContextOptions;
// Return a new options object.
TF_CAPI_EXPORT extern TFE_ContextOptions* TFE_NewContextOptions();
// Set the config in TF_ContextOptions.options.
// config should be a serialized tensorflow.ConfigProto proto.
// If config was not parsed successfully as a ConfigProto, record the
// error information in *status.
TF_CAPI_EXPORT extern void TFE_ContextOptionsSetConfig(
TFE_ContextOptions* options, const void* proto, size_t proto_len,
TF_Status* status);
// Controls how to act when we try to run an operation on a given device but
// some input tensors are not on that device.
typedef enum TFE_ContextDevicePlacementPolicy {
// Running operations with input tensors on the wrong device will fail.
TFE_DEVICE_PLACEMENT_EXPLICIT = 0,
// Copy the tensor to the right device but log a warning.
TFE_DEVICE_PLACEMENT_WARN = 1,
// Silently copy the tensor, which has a performance cost since the operation
// will be blocked till the copy completes. This is the default placement
// policy.
TFE_DEVICE_PLACEMENT_SILENT = 2,
// Placement policy which silently copies int32 tensors but not other dtypes.
TFE_DEVICE_PLACEMENT_SILENT_FOR_INT32 = 3,
} TFE_ContextDevicePlacementPolicy;
// Sets the default execution mode (sync/async). Note that this can be
// overridden per thread using TFE_ContextSetAsyncForThread.
TF_CAPI_EXPORT extern void TFE_ContextOptionsSetAsync(TFE_ContextOptions*,
unsigned char enable);
TF_CAPI_EXPORT extern void TFE_ContextOptionsSetDevicePlacementPolicy(
TFE_ContextOptions*, TFE_ContextDevicePlacementPolicy);
// Destroy an options object.
TF_CAPI_EXPORT extern void TFE_DeleteContextOptions(TFE_ContextOptions*);
// "Context" under which operations/functions are executed. It encapsulates
// things like the available devices, resource manager etc.
//
// TODO(ashankar): Merge with TF_Session?
typedef struct TFE_Context TFE_Context;
TF_CAPI_EXPORT extern TFE_Context* TFE_NewContext(
const TFE_ContextOptions* opts, TF_Status* status);
TF_CAPI_EXPORT extern void TFE_DeleteContext(TFE_Context* ctx);
TF_CAPI_EXPORT extern TF_DeviceList* TFE_ContextListDevices(TFE_Context* ctx,
TF_Status* status);
// Clears the internal caches in the TFE context. Useful when reseeding random
// ops.
TF_CAPI_EXPORT extern void TFE_ContextClearCaches(TFE_Context* ctx);
// Sets a thread-local device placement policy. After this call, other calls to
// TFE_Execute in the same thread will use the device policy specified here
// instead of the device policy used to construct the context. This has no
// effect on the device policy used by other program threads.
TF_CAPI_EXPORT extern void TFE_ContextSetThreadLocalDevicePlacementPolicy(
TFE_Context*, TFE_ContextDevicePlacementPolicy);
// Returns the device placement policy to be used by this context in the current
// thread.
TF_CAPI_EXPORT extern TFE_ContextDevicePlacementPolicy
TFE_ContextGetDevicePlacementPolicy(TFE_Context*);
// Overrides the execution mode (sync/async) for the current thread.
TF_CAPI_EXPORT extern void TFE_ContextSetAsyncForThread(TFE_Context*,
unsigned char enable,
TF_Status* status);
// A tensorflow.ServerDef specifies remote workers (in addition to the current
// workers name). Operations created on this context can then be executed on
// any of these remote workers by setting an appropriate device.
//
// If the following is set, all servers identified by the
// ServerDef must be up when the context is created.
TF_CAPI_EXPORT extern void TFE_ContextSetServerDef(TFE_Context* ctx,
int keep_alive_secs,
const void* proto,
size_t proto_len,
TF_Status* status);
// Causes the calling thread to block till all ops dispatched in async mode
// have been executed. Note that "execution" here refers to kernel execution /
// scheduling of copies, etc. Similar to sync execution, it doesn't guarantee
// that lower level device queues (like GPU streams) have been flushed.
//
// This call may not block for execution of ops enqueued concurrently with this
// call.
TF_CAPI_EXPORT extern void TFE_ContextAsyncWait(TFE_Context*,
TF_Status* status);
// When an error happens, any pending operations are discarded and newly issued
// ops return an error. This call clears the error state and re-enables
// execution of newly issued ops.
//
// Note that outputs of discarded ops remain in a corrupt state and should not
// be used for future calls.
// TODO(agarwal): mark the affected handles and raise errors if they are used.
TF_CAPI_EXPORT extern void TFE_ContextAsyncClearError(TFE_Context*);
// A handle to a tensor on a device.
//
// Like a TF_Tensor, a TFE_TensorHandle refers to a tensor with a value, shape,
// type etc. Unlike a TF_Tensor, a TFE_TensorHandle may refer to such tensors
// placed in memory of different devices or remote address spaces.
typedef struct TFE_TensorHandle TFE_TensorHandle;
TF_CAPI_EXPORT extern TFE_TensorHandle* TFE_NewTensorHandle(TF_Tensor* t,
TF_Status* status);
// Indicates that the caller will not be using `h` any more.
TF_CAPI_EXPORT extern void TFE_DeleteTensorHandle(TFE_TensorHandle* h);
TF_CAPI_EXPORT extern TF_DataType TFE_TensorHandleDataType(TFE_TensorHandle* h);
// This function will block till the operation that produces `h` has completed.
TF_CAPI_EXPORT extern int TFE_TensorHandleNumDims(TFE_TensorHandle* h,
TF_Status* status);
TF_CAPI_EXPORT extern int64_t TFE_TensorHandleNumElements(TFE_TensorHandle* h,
TF_Status* status);
// This function will block till the operation that produces `h` has completed.
TF_CAPI_EXPORT extern int64_t TFE_TensorHandleDim(TFE_TensorHandle* h,
int dim_index,
TF_Status* status);
// This function will block till the operation that produces `h` has completed.
TF_CAPI_EXPORT extern const char* TFE_TensorHandleDeviceName(
TFE_TensorHandle* h, TF_Status* status);
// Return a pointer to a new TFE_TensorHandle that shares the underlying tensor
// with `h`. On success, `status` is set to OK. On failure, `status` reflects
// the error and a nullptr is returned.
TF_CAPI_EXPORT extern TFE_TensorHandle* TFE_TensorHandleCopySharingTensor(
TFE_TensorHandle* h, TF_Status* status);
// This function will block till the operation that produces `h` has
// completed. The memory returned might alias the internal memory used by
// TensorFlow. Hence, callers should not mutate this memory (for example by
// modifying the memory region pointed to by TF_TensorData() on the returned
// TF_Tensor).
TF_CAPI_EXPORT extern TF_Tensor* TFE_TensorHandleResolve(TFE_TensorHandle* h,
TF_Status* status);
// Create a new TFE_TensorHandle with the same contents as 'h' but placed
// in the memory of the device name 'device_name'.
// If source and destination are the same device, then this creates a new handle
// that shares the underlying buffer. Otherwise, it currently requires at least
// one of the source or destination devices to be CPU (i.e., for the source or
// destination tensor to be placed in host memory).
// If async execution is enabled, the copy may be enqueued and the call will
// return "non-ready" handle. Else, this function returns after the copy has
// been done.
TF_CAPI_EXPORT extern TFE_TensorHandle* TFE_TensorHandleCopyToDevice(
TFE_TensorHandle* h, TFE_Context* ctx, const char* device_name,
TF_Status* status);
// Debugging/Profiling information for TFE_TensorHandle
//
// TFE_TensorDebugInfo contains information useful for debugging and
// profiling tensors.
typedef struct TFE_TensorDebugInfo TFE_TensorDebugInfo;
// Retrieves TFE_TensorDebugInfo for `handle`.
// If TFE_TensorHandleTensorDebugInfo succeeds, `status` is set to OK and caller
// is responsible for deleting returned TFE_TensorDebugInfo.
// If TFE_TensorHandleTensorDebugInfo fails, `status` is set to appropriate
// error and nullptr is returned. This function can block till the operation
// that produces `handle` has completed.
TF_CAPI_EXPORT extern TFE_TensorDebugInfo* TFE_TensorHandleTensorDebugInfo(
TFE_TensorHandle* handle, TF_Status* status);
// Deletes `debug_info`.
TF_CAPI_EXPORT extern void TFE_DeleteTensorDebugInfo(
TFE_TensorDebugInfo* debug_info);
// Returns the number of dimensions used to represent the tensor on its device.
// The number of dimensions used to reprensent the tensor on device can be
// different from the number returned by TFE_TensorHandleNumDims.
// The return value was current at the time of TFE_TensorDebugInfo creation.
TF_CAPI_EXPORT extern int TFE_TensorDebugInfoOnDeviceNumDims(
TFE_TensorDebugInfo* debug_info);
// Returns the number of elements in dimension `dim_index`.
// Tensor representation on device can be transposed from its representation
// on host. The data contained in dimension `dim_index` on device
// can correspond to the data contained in another dimension in on-host
// representation. The dimensions are indexed using the standard TensorFlow
// major-to-minor order (slowest varying dimension first),
// not the XLA's minor-to-major order.
// On-device dimensions can be padded. TFE_TensorDebugInfoOnDeviceDim returns
// the number of elements in a dimension after padding.
// The return value was current at the time of TFE_TensorDebugInfo creation.
TF_CAPI_EXPORT extern int64_t TFE_TensorDebugInfoOnDeviceDim(
TFE_TensorDebugInfo* debug_info, int dim_index);
// Description of the TensorFlow op to execute.
//
// Assumes that the provided 'ctx' outlives the returned TFE_Op, i.e.,
// TFE_DeleteOp() is called before TFE_DeleteContext().
//
// Very similar to TF_OperationDescription with some differences:
// (1) TF_Output or TFE_TensorHandle* as arguments to TF_AddInput,
// TF_AddInputList
// (2) TF_ColocateWith, TF_AddControlInput etc. do not make sense.
// (3) Implementation detail: Avoid use of NodeBuilder/NodeDefBuilder since
// the additional sanity checks there seem unnecessary;
typedef struct TFE_Op TFE_Op;
TF_CAPI_EXPORT extern TFE_Op* TFE_NewOp(TFE_Context* ctx,
const char* op_or_function_name,
TF_Status* status);
TF_CAPI_EXPORT extern void TFE_DeleteOp(TFE_Op* op);
TF_CAPI_EXPORT extern void TFE_OpSetDevice(TFE_Op* op, const char* device_name,
TF_Status* status);
// The returned string remains valid throughout the lifetime of 'op'.
TF_CAPI_EXPORT extern const char* TFE_OpGetDevice(TFE_Op* op,
TF_Status* status);
// When 'enable' is set to 1, and if TensorFlow library is built with XLA
// support, a subsequent TFE_Execute() call on `op` will run the op via XLA.
//
// If the library is not built with XLA support, this call would be a no-op.
TF_CAPI_EXPORT extern void TFE_OpSetXLACompilation(TFE_Op* op,
unsigned char enable);
TF_CAPI_EXPORT extern void TFE_OpAddInput(TFE_Op* op, TFE_TensorHandle* h,
TF_Status* status);
TF_CAPI_EXPORT extern TF_AttrType TFE_OpGetAttrType(TFE_Op* op,
const char* attr_name,
unsigned char* is_list,
TF_Status* status);
// Get an attribute type given an op name; a fusion of TFE_NewOp and
// TFE_OpGetAttrType for use from Python without the overhead of the individual
// calls and memory management of TFE_Op.
TF_CAPI_EXPORT extern TF_AttrType TFE_OpNameGetAttrType(
TFE_Context* ctx, const char* op_or_function_name, const char* attr_name,
unsigned char* is_list, TF_Status* status);
TF_CAPI_EXPORT extern void TFE_OpSetAttrString(TFE_Op* op,
const char* attr_name,
const void* value,
size_t length);
TF_CAPI_EXPORT extern void TFE_OpSetAttrInt(TFE_Op* op, const char* attr_name,
int64_t value);
TF_CAPI_EXPORT extern void TFE_OpSetAttrFloat(TFE_Op* op, const char* attr_name,
float value);
TF_CAPI_EXPORT extern void TFE_OpSetAttrBool(TFE_Op* op, const char* attr_name,
unsigned char value);
TF_CAPI_EXPORT extern void TFE_OpSetAttrType(TFE_Op* op, const char* attr_name,
TF_DataType value);
// If the number of dimensions is unknown, `num_dims` must be set to
// -1 and `dims` can be null. If a dimension is unknown, the
// corresponding entry in the `dims` array must be -1.
TF_CAPI_EXPORT extern void TFE_OpSetAttrShape(TFE_Op* op, const char* attr_name,
const int64_t* dims,
const int num_dims,
TF_Status* out_status);
// Sets the attribute attr_name to be a function specified by 'function'.
//
// TODO(ashankar,iga): Add this functionality to the C API for graph
// construction. Perhaps we want an AttrValueMap equivalent in the C API?
TF_CAPI_EXPORT extern void TFE_OpSetAttrFunction(TFE_Op* op,
const char* attr_name,
const TFE_Op* value);
TF_CAPI_EXPORT void TFE_OpSetAttrFunctionName(TFE_Op* op, const char* attr_name,
const char* data, size_t length);
TF_CAPI_EXPORT extern void TFE_OpSetAttrTensor(TFE_Op* op,
const char* attr_name,
TF_Tensor* tensor,
TF_Status* status);
TF_CAPI_EXPORT extern void TFE_OpSetAttrStringList(TFE_Op* op,
const char* attr_name,
const void* const* values,
const size_t* lengths,
int num_values);
TF_CAPI_EXPORT extern void TFE_OpSetAttrIntList(TFE_Op* op,
const char* attr_name,
const int64_t* values,
int num_values);
TF_CAPI_EXPORT extern void TFE_OpSetAttrFloatList(TFE_Op* op,
const char* attr_name,
const float* values,
int num_values);
TF_CAPI_EXPORT extern void TFE_OpSetAttrBoolList(TFE_Op* op,
const char* attr_name,
const unsigned char* values,
int num_values);
TF_CAPI_EXPORT extern void TFE_OpSetAttrTypeList(TFE_Op* op,
const char* attr_name,
const TF_DataType* values,
int num_values);
TF_CAPI_EXPORT extern void TFE_OpSetAttrShapeList(
TFE_Op* op, const char* attr_name, const int64_t** dims,
const int* num_dims, int num_values, TF_Status* out_status);
TF_CAPI_EXPORT extern void TFE_OpSetAttrFunctionList(TFE_Op* op,
const char* attr_name,
const TFE_Op** value,
int num_values);
// Execute the operation defined by 'op' and return handles to computed
// tensors in `retvals`.
//
// 'retvals' must point to a pre-allocated array of TFE_TensorHandle* and
// '*num_retvals' should be set to the size of this array. It is an error if
// the size of 'retvals' is less than the number of outputs. This call sets
// *num_retvals to the number of outputs.
//
// If async execution is enabled, the call may simply enqueue the execution
// and return "non-ready" handles in `retvals`. Note that any handles contained
// in 'op' should not be mutated till the kernel execution actually finishes.
//
// For sync execution, if any of the inputs to `op` are not ready, this call
// will block till they become ready and then return when the kernel execution
// is done.
// TODO(agarwal): change num_retvals to int from int*.
TF_CAPI_EXPORT extern void TFE_Execute(TFE_Op* op, TFE_TensorHandle** retvals,
int* num_retvals, TF_Status* status);
// Add a function (serialized FunctionDef protocol buffer) to ctx so
// that it can be invoked using TFE_Execute.
TF_CAPI_EXPORT extern void TFE_ContextAddFunctionDef(
TFE_Context* ctx, const char* serialized_function_def, size_t size,
TF_Status* status);
// Adds a function (created from TF_GraphToFunction or
// TF_FunctionImportFunctionDef) to the context, allowing it to be executed with
// TFE_Execute by creating an op with the same name as the function.
TF_CAPI_EXPORT extern void TFE_ContextAddFunction(TFE_Context* ctx,
TF_Function* function,
TF_Status* status);
// Enables tracing of RunMetadata on the ops executed from this context.
TF_CAPI_EXPORT extern void TFE_ContextEnableRunMetadata(TFE_Context* ctx);
// Disables tracing of RunMetadata on the ops executed from this context.
TF_CAPI_EXPORT extern void TFE_ContextDisableRunMetadata(TFE_Context* ctx);
// Populates the passed-in buffer with a serialized RunMetadata protocol buffer
// containing any run metadata information accumulated so far and clears this
// information.
// If async mode is enabled, this call blocks till all currently pending ops are
// done.
TF_CAPI_EXPORT extern void TFE_ContextExportRunMetadata(TFE_Context* ctx,
TF_Buffer* buf,
TF_Status* status);
// Some TF ops need a step container to be set to limit the lifetime of some
// resources (mostly TensorArray and Stack, used in while loop gradients in
// graph mode). Calling this on a context tells it to start a step.
TF_CAPI_EXPORT extern void TFE_ContextStartStep(TFE_Context* ctx);
// Ends a step. When there is no active step (that is, every started step has
// been ended) step containers will be cleared. Note: it is not safe to call
// TFE_ContextEndStep while ops which rely on the step container may be running.
TF_CAPI_EXPORT extern void TFE_ContextEndStep(TFE_Context* ctx);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#ifdef __cplusplus
// A workaround to ease conversion to and from numpy objects and
// TFE_TensorHandle's.
//
// TODO(ashankar): Figure out an alternative scheme that precludes the need for
// these API-boundary breaking methods.
namespace tensorflow {
class Tensor;
} // namespace tensorflow
const tensorflow::Tensor* TFE_TensorHandleUnderlyingTensorInHostMemory(
TFE_TensorHandle* h, TF_Status* status);
TFE_TensorHandle* TFE_NewTensorHandle(const tensorflow::Tensor& t);
#endif
#endif // TENSORFLOW_C_EAGER_C_API_H_
@@ -0,0 +1,32 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_C_TF_STATUS_HELPER_H_
#define TENSORFLOW_C_TF_STATUS_HELPER_H_
#include "tensorflow/c/c_api.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// Set the attribute of "tf_status" from the attributes of "status".
void Set_TF_Status_from_Status(TF_Status* tf_status, const Status& status);
// Returns a "status" from "tf_status".
Status StatusFromTF_Status(const TF_Status* tf_status);
} // namespace tensorflow
#endif // TENSORFLOW_C_TF_STATUS_HELPER_H_
@@ -0,0 +1,129 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_CLIENT_CLIENT_SESSION_H_
#define TENSORFLOW_CC_CLIENT_CLIENT_SESSION_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/public/session_options.h"
namespace tensorflow {
/// @addtogroup core
/// @{
/// A `ClientSession` object lets the caller drive the evaluation of the
/// TensorFlow graph constructed with the C++ API.
///
/// Example:
///
/// Scope root = Scope::NewRootScope();
/// auto a = Placeholder(root, DT_INT32);
/// auto c = Add(root, a, {41});
///
/// ClientSession session(root);
/// std::vector<Tensor> outputs;
///
/// Status s = session.Run({ {a, {1}} }, {c}, &outputs);
/// if (!s.ok()) { ... }
class ClientSession {
public:
/// A data type to represent feeds to a Run call.
///
/// This is a map of `Output` objects returned by op-constructors to the value
/// to feed them with. See `Input::Initializer` for details on what can be
/// used as feed values.
typedef std::unordered_map<Output, Input::Initializer, OutputHash> FeedType;
/// Create a new session to evaluate the graph contained in `scope` by
/// connecting to the TensorFlow runtime specified by `target`.
ClientSession(const Scope& scope, const string& target);
/// Same as above, but use the empty string ("") as the target specification.
ClientSession(const Scope& scope);
/// Create a new session, configuring it with `session_options`.
ClientSession(const Scope& scope, const SessionOptions& session_options);
~ClientSession();
/// Evaluate the tensors in `fetch_outputs`. The values are returned as
/// `Tensor` objects in `outputs`. The number and order of `outputs` will
/// match `fetch_outputs`.
Status Run(const std::vector<Output>& fetch_outputs,
std::vector<Tensor>* outputs) const;
/// Same as above, but use the mapping in `inputs` as feeds.
Status Run(const FeedType& inputs, const std::vector<Output>& fetch_outputs,
std::vector<Tensor>* outputs) const;
/// Same as above. Additionally runs the operations ins `run_outputs`.
Status Run(const FeedType& inputs, const std::vector<Output>& fetch_outputs,
const std::vector<Operation>& run_outputs,
std::vector<Tensor>* outputs) const;
/// Use `run_options` to turn on performance profiling. `run_metadata`, if not
/// null, is filled in with the profiling results.
Status Run(const RunOptions& run_options, const FeedType& inputs,
const std::vector<Output>& fetch_outputs,
const std::vector<Operation>& run_outputs,
std::vector<Tensor>* outputs, RunMetadata* run_metadata) const;
/// \brief A handle to a subgraph, created with
/// `ClientSession::MakeCallable()`.
typedef int64 CallableHandle;
/// \brief Creates a `handle` for invoking the subgraph defined by
/// `callable_options`.
/// NOTE: This API is still experimental and may change.
Status MakeCallable(const CallableOptions& callable_options,
CallableHandle* out_handle);
/// \brief Invokes the subgraph named by `handle` with the given options and
/// input tensors.
///
/// The order of tensors in `feed_tensors` must match the order of names in
/// `CallableOptions::feed()` and the order of tensors in `fetch_tensors` will
/// match the order of names in `CallableOptions::fetch()` when this subgraph
/// was created.
/// NOTE: This API is still experimental and may change.
Status RunCallable(CallableHandle handle,
const std::vector<Tensor>& feed_tensors,
std::vector<Tensor>* fetch_tensors,
RunMetadata* run_metadata);
/// \brief Releases resources associated with the given `handle` in this
/// session.
/// NOTE: This API is still experimental and may change.
Status ReleaseCallable(CallableHandle handle);
private:
class Impl;
std::unique_ptr<Impl> impl_;
Impl* impl() { return impl_.get(); }
const Impl* impl() const { return impl_.get(); }
};
/// @}
} // end namespace tensorflow
#endif // TENSORFLOW_CC_CLIENT_CLIENT_SESSION_H_
@@ -0,0 +1,75 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_GRAD_OP_REGISTRY_H_
#define TENSORFLOW_CC_FRAMEWORK_GRAD_OP_REGISTRY_H_
#include <unordered_map>
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
namespace tensorflow {
namespace ops {
/// GradFunc is the signature for all gradient functions in GradOpRegistry.
/// Implementations should add operations to compute the gradient outputs of
/// 'op' (returned in 'grad_outputs') using 'scope' and 'grad_inputs'.
typedef Status (*GradFunc)(const Scope& scope, const Operation& op,
const std::vector<Output>& grad_inputs,
std::vector<Output>* grad_outputs);
/// GradOpRegistry maintains a static registry of gradient functions.
/// Gradient functions are indexed in the registry by the forward op name (i.e.
/// "MatMul" -> MatMulGrad func).
class GradOpRegistry {
public:
/// Registers 'func' as the gradient function for 'op'.
/// Returns true if registration was successful, check fails otherwise.
bool Register(const string& op, GradFunc func);
/// Sets 'func' to the gradient function for 'op' and returns Status OK if
/// the gradient function for 'op' exists in the registry.
/// Note that 'func' can be null for ops that have registered no-gradient with
/// the registry.
/// Returns error status otherwise.
Status Lookup(const string& op, GradFunc* func) const;
/// Returns a pointer to the global gradient function registry.
static GradOpRegistry* Global();
private:
std::unordered_map<string, GradFunc> registry_;
};
} // namespace ops
// Macros used to define gradient functions for ops.
#define REGISTER_GRADIENT_OP(name, fn) \
REGISTER_GRADIENT_OP_UNIQ_HELPER(__COUNTER__, name, fn)
#define REGISTER_NO_GRADIENT_OP(name) \
REGISTER_GRADIENT_OP_UNIQ_HELPER(__COUNTER__, name, nullptr)
#define REGISTER_GRADIENT_OP_UNIQ_HELPER(ctr, name, fn) \
REGISTER_GRADIENT_OP_UNIQ(ctr, name, fn)
#define REGISTER_GRADIENT_OP_UNIQ(ctr, name, fn) \
static bool unused_ret_val_##ctr = \
::tensorflow::ops::GradOpRegistry::Global()->Register(name, fn)
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_GRAD_OP_REGISTRY_H_
@@ -0,0 +1,63 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_GRADIENT_CHECKER_H_
#define TENSORFLOW_CC_FRAMEWORK_GRADIENT_CHECKER_H_
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
namespace tensorflow {
/// Returns in 'max_error' the maximum element-wise error for dy/dx between the
/// computed and numeric Jacobian matrices where 'xs' and 'ys' are tensors.
/// X_T and Y_T are the c++ types for the x and y tensors, and JAC_T is a
/// real-valued type to store the Jacobian derivatives dy/dx.
/// This function adds operations to the graph associated with 'scope'.
///
/// Examples:
/// if y = Square(x), where x (and so y) are DT_FLOAT,
/// <X_T, Y_T, JAC_T> should be <float, float, float>
///
/// if y = Square(x), where x (and so y) are DT_DOUBLE,
/// <X_T, Y_T, JAC_T> should be <double, double, double>
///
/// if y = Square(x), where x (and so y) are DT_COMPLEX64,
/// <X_T, Y_T, JAC_T> should be <complex64, complex64, float>
/// Note that JAC_T is always real-valued, and should be an appropriate
/// precision to host the partial derivatives for dy/dx
///
/// if y = ComplexAbs(x) where x is DT_COMPLEX64 (so y is DT_FLOAT)
/// <X_T, Y_T, JAC_T> should be <complex64, float, float>
///
/// if y = Complex(x, x) where x is DT_FLOAT (so y is DT_COMPLEX64)
/// <X_T, Y_T, JAC_T> should be <float, complex64, float>
template <typename X_T, typename Y_T, typename JAC_T>
Status ComputeGradientError(const Scope& scope, const OutputList& xs,
const std::vector<TensorShape>& x_shapes,
const OutputList& ys,
const std::vector<TensorShape>& y_shapes,
JAC_T* max_error);
/// Overload of ComputeGradientError which takes an initial value for 'x'.
template <typename X_T, typename Y_T, typename JAC_T>
Status ComputeGradientError(const Scope& scope, const Output& x,
const Tensor& x_init_value, const Output& y,
const TensorShape& y_shape, JAC_T* max_error);
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_GRADIENT_CHECKER_H_
@@ -0,0 +1,52 @@
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_GRADIENTS_H_
#define TENSORFLOW_CC_FRAMEWORK_GRADIENTS_H_
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
namespace tensorflow {
/// NOTE: This API is a work in progress and will likely be changing frequently.
///
/// Given initial gradients 'grad_inputs' (which represent the symbolic partial
/// derivatives of some loss function 'L' w.r.t 'outputs'), adds gradient nodes
/// to the graph associated with 'scope', which compute (and return in
/// 'grad_outputs') the symbolic partial derivatives of 'L' w.r.t 'inputs'.
Status AddSymbolicGradients(const Scope& scope,
const std::vector<Output>& outputs,
const std::vector<Output>& inputs,
const std::vector<Output>& grad_inputs,
std::vector<Output>* grad_outputs);
// Same as above, but uses 'OnesLike' for all shapes in
// 'outputs' as grad_inputs.
Status AddSymbolicGradients(const Scope& scope,
const std::vector<Output>& outputs,
const std::vector<Output>& inputs,
std::vector<Output>* grad_outputs);
/// Returns a sentinel Output that represents 'no gradient' (i.e. no gradient
/// flows along some graph edge during backpropagation).
/// Can be returned in 'grad_outputs' by an invocation of 'AddSymbolicGradients'
/// (note that gradient flow through an Output can be stopped through the use of
/// the StopGradient node).
Output NoGradient();
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_GRADIENTS_H_
+299
View File
@@ -0,0 +1,299 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_OPS_H_
#define TENSORFLOW_CC_FRAMEWORK_OPS_H_
#include <type_traits>
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/lib/strings/strcat.h"
namespace tensorflow {
/// @defgroup core Core Tensorflow API
class Output;
/// @addtogroup core
/// @{
/// Represents a node in the computation graph.
class Operation {
public:
Operation() : node_(nullptr) {}
explicit Operation(Node* n);
int32 num_inputs() const { return node_->num_inputs(); }
DataType input_type(int32 o) const { return node_->input_type(o); }
Output input(int32 i) const;
int32 num_outputs() const { return node_->num_outputs(); }
DataType output_type(int32 o) const { return node_->output_type(o); }
Output output(int32 i) const;
Node* node() const { return node_; }
uint64 hash(int32 index) const;
bool operator==(const Operation& other) const { return node_ == other.node_; }
private:
typedef std::vector<std::pair<Node*, int32>> Inputs;
static Inputs GetInputs(Node* node);
Inputs inputs_;
Node* node_;
};
/// Represents a tensor value produced by an Operation.
class Output {
public:
Output() = default;
explicit Output(Node* n) : op_(n) {}
Output(Node* n, int32 index) : op_(n), index_(index) {}
Output(const Operation& op, int32 index) : op_(op), index_(index) {}
Operation op() const { return op_; }
Node* node() const { return op().node(); }
int32 index() const { return index_; }
DataType type() const { return op_.output_type(index_); }
string name() const { return strings::StrCat(node()->name(), ":", index()); }
bool operator==(const Output& other) const {
return op_ == other.op_ && index_ == other.index_;
}
uint64 hash() const { return op_.hash(index_); }
private:
Operation op_ = Operation(nullptr);
int32 index_ = 0;
};
/// Hash class that can be used for e.g. storing Outputs in an unordered_map
struct OutputHash {
std::size_t operator()(const Output& output) const {
return Hash64Combine(std::hash<Node*>()(output.node()),
std::hash<int32>()(output.index()));
}
};
/// Represents a tensor value that can be used as an operand to an Operation.
class Input {
public:
/// Initializer enables constructing an Input object from various kinds of C++
/// constants such as simple primitive constants and nested initializer lists
/// representing a multi-dimensional array. Initializer constructors are all
/// templates, so the aforementioned kinds of C++ constants can be used to
/// construct an Initializer. Initializer stores the value it got constructed
/// with in a Tensor object.
struct Initializer {
/// Construct from a scalar value of an arithmetic type or a type that can
/// be converted to a string (eg. a string literal).
template <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value ||
std::is_convertible<T, string>::value>::type>
Initializer(const T& v) { // NOLINT(runtime/explicit)
typedef typename RealType<T>::type RealT;
Tensor t(DataTypeToEnum<RealT>::v(), TensorShape());
t.flat<T>()(0) = RealT(v);
tensor = t;
}
Initializer(const Tensor& t) : tensor(t) {} // NOLINT(runtime/explicit)
/// Construct from a scalar value and an explicit shape
template <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value ||
std::is_convertible<T, string>::value>::type>
Initializer(const T& v, const TensorShape& shape) {
typedef typename RealType<T>::type RealT;
Tensor t(DataTypeToEnum<RealT>::v(), shape);
for (int64 i = 0; i < t.NumElements(); ++i) {
t.flat<T>()(i) = RealT(v);
}
tensor = t;
}
/// Construct from a initializer list of scalars (a one-dimensional tensor).
template <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value ||
std::is_convertible<T, string>::value>::type>
Initializer(
const std::initializer_list<T>& v) { // NOLINT(runtime/explicit)
typedef typename RealType<T>::type RealT;
Tensor t(DataTypeToEnum<RealT>::v(),
TensorShape{static_cast<int>(v.size())});
std::copy_n(v.begin(), v.size(), t.flat<RealT>().data());
tensor = t;
}
/// Construct from a initializer list of scalars and an explicit shape.
template <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value ||
std::is_convertible<T, string>::value>::type>
Initializer(const std::initializer_list<T>& v, const TensorShape& shape) {
typedef typename RealType<T>::type RealT;
Tensor t(DataTypeToEnum<RealT>::v(), shape);
if (t.NumElements() != static_cast<int64>(v.size())) {
status = errors::InvalidArgument(
"Cannot construct a tensor with ", t.NumElements(),
" from an initializer list with ", v.size(), " elements");
return;
}
std::copy_n(v.begin(), v.size(), t.flat<RealT>().data());
tensor = t;
}
/// Construct a multi-dimensional tensor from a nested initializer
/// list. Note that C++ syntax allows nesting of arbitrarily typed
/// initializer lists, so such invalid initializers cannot be disallowed at
/// compile time. This function performs checks to make sure that the nested
/// initializer list is indeed a valid multi-dimensional tensor.
Initializer(const std::initializer_list<Initializer>& v);
// START_SKIP_DOXYGEN
template <typename T, bool = std::is_convertible<T, string>::value>
struct RealType {
typedef string type;
};
template <typename T>
struct RealType<T, false> {
typedef T type;
};
// END_SKIP_DOXYGEN
TensorProto AsTensorProto() {
TensorProto tensor_proto;
if (tensor.NumElements() > 1) {
tensor.AsProtoTensorContent(&tensor_proto);
} else {
tensor.AsProtoField(&tensor_proto);
}
return tensor_proto;
}
Status status;
Tensor tensor;
};
/// All of Input's constructors are implicit. Input can be implicitly
/// constructed from the following objects :
/// * Output: This is so that the output of an Operation can be directly used
/// as the input to a op wrapper, which takes Inputs.
/// * A scalar, or a multi-dimensional tensor specified as a recursive
/// initializer list. This enables directly passing constants as
/// inputs to op wrappers.
/// * A Tensor object.
Input(const Output& o) : output_(o) {} // NOLINT(runtime/explicit)
template <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value ||
std::is_convertible<T, string>::value>::type>
Input(const T& v) // NOLINT(runtime/explicit)
: Input(Initializer(v)) {}
Input(const Initializer& init) // NOLINT(runtime/explicit)
: status_(init.status),
tensor_(init.tensor) {}
Input(const Tensor& t) // NOLINT(runtime/explicit)
: status_(Status::OK()),
tensor_(t) {}
Input(const std::initializer_list<Initializer>&
init) { // NOLINT(runtime/explicit)
for (const auto& i : init) {
if (!i.status.ok()) {
status_ = i.status;
return;
}
}
tensor_ = Initializer(init).tensor;
}
/// Constructor specifying a node name, index and datatype. This should only
/// be used for specifying a backward edge, needed by control flow.
Input(const string& name, int32 i, DataType dt)
: node_name_(name), index_(i), data_type_(dt) {}
Node* node() const { return output_.node(); }
string node_name() const { return node_name_; }
int32 index() const { return node_name_.empty() ? output_.index() : index_; }
DataType data_type() const { return data_type_; }
Status status() const { return status_; }
const Tensor& tensor() const { return tensor_; }
private:
Status status_;
Output output_ = Output(Operation(nullptr), 0);
Tensor tensor_;
const string node_name_ = "";
int32 index_ = 0;
DataType data_type_ = DT_INVALID;
};
/// A type for representing the output of ops that produce more than one output,
/// or a list of tensors.
typedef std::vector<Output> OutputList;
/// A type for representing the input to ops that require a list of tensors.
class InputList {
public:
/// Implicitly convert a list of outputs to a list of inputs. This is useful
/// to write code such as ops::Concat(ops::Split(x, 4)).
InputList(const OutputList& out) { // NOLINT(runtime/explicit)
for (auto const& x : out) {
inputs_.push_back(x);
}
}
InputList(
const std::initializer_list<Input>& inputs) // NOLINT(runtime/explicit)
: inputs_(inputs.begin(), inputs.end()) {}
InputList(const tensorflow::gtl::ArraySlice<Input>&
inputs) // NOLINT(runtime/explicit)
: inputs_(inputs.begin(), inputs.end()) {}
InputList(
const std::initializer_list<Output>& out) { // NOLINT(runtime/explicit)
for (auto const& x : out) {
inputs_.push_back(x);
}
}
typename std::vector<Input>::iterator begin() { return inputs_.begin(); }
typename std::vector<Input>::iterator end() { return inputs_.end(); }
typename std::vector<Input>::const_iterator begin() const {
return inputs_.begin();
}
typename std::vector<Input>::const_iterator end() const {
return inputs_.end();
}
private:
std::vector<Input> inputs_;
};
/// @}
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_OPS_H_
@@ -0,0 +1,249 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_SCOPE_H_
#define TENSORFLOW_CC_FRAMEWORK_SCOPE_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
class Graph;
class GraphDef;
class NodeBuilder;
struct CompositeOpScopes;
/// @addtogroup core
/// @{
/// A `Scope` object represents a set of related TensorFlow ops that have the
/// same properties such as a common name prefix.
///
/// A Scope object is a container for TensorFlow Op properties. Op constructors
/// get a Scope object as a mandatory first argument and the constructed op
/// acquires the properties in the object.
///
/// A simple example:
///
/// using namespace ops;
/// Scope root = Scope::NewRootScope();
/// auto c1 = Const(root, { {1, 1} });
/// auto m = MatMul(root, c1, { {41}, {1} });
/// GraphDef gdef;
/// Status s = root.ToGraphDef(&gdef);
/// if (!s.ok()) { ... }
///
/// Scope hierarchy:
///
/// The Scope class provides various With<> functions that create a new scope.
/// The new scope typically has one property changed while other properties are
/// inherited from the parent scope.
/// NewSubScope(name) method appends `name` to the prefix of names for ops
/// created within the scope, and WithOpName() changes the suffix which
/// otherwise defaults to the type of the op.
///
/// Name examples:
///
/// Scope root = Scope::NewRootScope();
/// Scope linear = root.NewSubScope("linear");
/// // W will be named "linear/W"
/// auto W = Variable(linear.WithOpName("W"),
/// {2, 2}, DT_FLOAT);
/// // b will be named "linear/b"
/// auto b = Variable(linear.WithOpName("b"),
/// {2}, DT_FLOAT);
/// auto x = Const(linear, {...}); // name: "linear/Const"
/// auto m = MatMul(linear, x, W); // name: "linear/MatMul"
/// auto r = BiasAdd(linear, m, b); // name: "linear/BiasAdd"
///
/// Scope lifetime:
///
/// A new scope is created by calling Scope::NewRootScope. This creates some
/// resources that are shared by all the child scopes that inherit from this
/// scope, directly or transitively. For instance, a new scope creates a new
/// Graph object to which operations are added when the new scope or its
/// children are used by an Op constructor. The new scope also has a Status
/// object which will be used to indicate errors by Op-constructor functions
/// called on any child scope. The Op-constructor functions have to check the
/// scope's status by calling the ok() method before proceeding to construct the
/// op.
///
/// Thread safety:
///
/// A `Scope` object is NOT thread-safe. Threads cannot concurrently call
/// op-constructor functions on the same `Scope` object.
class Scope {
public:
Scope(const Scope& other);
~Scope();
Scope& operator=(const Scope& other);
// The following functions are for users making graphs. They return brand new
// scopes, or scopes derived from an existing scope object.
/// Return a new scope.
/// This creates a new graph and all operations constructed in this graph
/// should use the returned object as the "root" scope.
static Scope NewRootScope();
/// Return a new scope. Ops created with this scope will have
/// `name/child_scope_name` as the prefix. The actual name will be unique
/// in the current scope. All other properties are inherited from the current
/// scope. If `child_scope_name` is empty, the `/` is elided.
Scope NewSubScope(const string& child_scope_name) const;
/// Return a new scope. All ops created within the returned scope will have
/// names of the form `name/op_name[_suffix]`.
Scope WithOpName(const string& op_name) const;
/// Return a new scope. All ops created within the returned scope will have as
/// control dependencies the union of operations in the control_deps vector
/// and the control dependencies of the current scope.
Scope WithControlDependencies(
const gtl::ArraySlice<Operation>& control_deps) const;
/// Same as above, but convenient to add control dependency on the operation
/// producing the control_dep output.
Scope WithControlDependencies(const Output& control_dep) const;
/// Return a new scope. All ops created within the returned scope will have no
/// control dependencies on other operations.
Scope WithNoControlDependencies() const;
/// Return a new scope. All ops created within the returned scope will have
/// the device field set to 'device'.
Scope WithDevice(const string& device) const;
/// Returns a new scope. All ops created within the returned scope will have
/// their assigned device set to `assigned_device`.
Scope WithAssignedDevice(const string& assigned_device) const;
/// Return a new scope. All ops created within the returned scope will be
/// co-located on the device where op is placed.
/// NOTE: This function is intended to be use internal libraries only for
/// controlling placement of ops on to devices. Public use is not encouraged
/// because the implementation of device placement is subject to change.
Scope ColocateWith(const Operation& op) const;
/// Convenience function for above.
Scope ColocateWith(const Output& out) const { return ColocateWith(out.op()); }
/// Clear all colocation constraints.
Scope ClearColocation() const;
/// Return a new scope. The op-constructor functions taking the returned scope
/// as the scope argument will exit as soon as an error is detected, instead
/// of setting the status on the scope.
Scope ExitOnError() const;
/// Return a new scope. All ops created with the new scope will have
/// kernel_label as the value for their '_kernel' attribute;
Scope WithKernelLabel(const string& kernel_label) const;
// The following functions are for scope object consumers.
/// Return a unique name, using default_name if an op name has not been
/// specified.
string GetUniqueNameForOp(const string& default_name) const;
/// Update the status on this scope.
/// Note: The status object is shared between all children of this scope.
/// If the resulting status is not Status::OK() and exit_on_error_ is set on
/// this scope, this function exits by calling LOG(FATAL).
void UpdateStatus(const Status s) const;
// START_SKIP_DOXYGEN
/// Update the builder with properties accumulated in this scope. Does not set
/// status().
// TODO(skyewm): NodeBuilder is not part of public API
void UpdateBuilder(NodeBuilder* builder) const;
// END_SKIP_DOXYGEN
CompositeOpScopes GetCompositeOpScopes(const string& composite_op_name) const;
bool ok() const;
// TODO(skyewm): Graph is not part of public API
Graph* graph() const;
// TODO(skyewm): Graph is not part of public API
std::shared_ptr<Graph> graph_as_shared_ptr() const;
Status status() const;
/// If status() is Status::OK(), convert the Graph object stored in this scope
/// to a GraphDef proto and return Status::OK(). Otherwise, return the error
/// status as is without performing GraphDef conversion.
Status ToGraphDef(GraphDef* gdef) const;
// START_SKIP_DOXYGEN
/// If status() is Status::OK(), construct a Graph object using the default
/// GraphConstructorOptions, and return Status::OK if graph construction was
/// successful. Otherwise, return the error status.
// TODO(josh11b, keveman): Make this faster; right now it converts
// Graph->GraphDef->Graph. This cleans up the graph (e.g. adds
// edges from the source and to the sink node, resolves back edges
// by name), and makes sure the resulting graph is valid.
Status ToGraph(Graph* g) const;
// Calls AddNode() using this scope's ShapeRefiner. This exists in the public
// API to prevent custom op wrappers from needing access to shape_refiner.h or
// scope_internal.h.
// TODO(skyewm): remove this from public API
Status DoShapeInference(Node* node) const;
// Creates a new root scope that causes all DoShapeInference() calls to return
// Status::OK() (on the returned scope and any subscopes). Used for testing.
// TODO(skyewm): fix tests that still require this and eventually remove, or
// at least remove from public API
static Scope DisabledShapeInferenceScope();
// END_SKIP_DOXYGEN
const std::vector<Operation>& control_deps() const;
// START_SKIP_DOXYGEN
class Impl;
Impl* impl() { return impl_.get(); }
const Impl* impl() const { return impl_.get(); }
// END_SKIP_DOXYGEN
private:
friend class InternalScope;
std::unique_ptr<Impl> impl_;
explicit Scope(Impl*);
};
/// A helper struct to hold the scopes that would be used by a function
/// constructing a composite op.
struct CompositeOpScopes {
/// Scope to be used for creating the local ops (primitive or other composite
/// ops).
Scope child;
/// Scope to be used for creating the last op.
Scope last;
};
/// @}
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_SCOPE_H_
@@ -0,0 +1,124 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_SCOPE_INTERNAL_H_
#define TENSORFLOW_CC_FRAMEWORK_SCOPE_INTERNAL_H_
#include "tensorflow/cc/framework/scope.h"
namespace tensorflow {
class ShapeRefiner;
// NewInternalScope returns a new scope which doesn't take ownership of
// graph, status, name_map, and refiner.
// This is intended to enable the C API (which are used by other language
// bindings) to create a Scope and access C++ functionality (i.e. gradients).
//
// Shape inference is disabled if `refiner` is nullptr.
Scope NewInternalScope(Graph* graph, Status* status, ShapeRefiner* refiner);
class Scope::Impl {
public:
// A NameMap is used to keep track of suffixes for names used in a scope. A
// name that has not been used so far in a scope will get no suffix. Later
// uses of the same name will get suffixes _1, _2, _3, etc. Multiple scopes
// can share the same NameMap. For instance, a new scope created using
// WithControlDependencies() would share the same NameMap with the parent.
typedef std::unordered_map<string, int> NameMap;
Impl(const std::shared_ptr<Graph>& graph,
const std::shared_ptr<Status>& status,
const std::shared_ptr<NameMap>& name_map,
const std::shared_ptr<ShapeRefiner>& refiner);
const string& name() const { return name_; }
const std::vector<Operation>& control_deps() const { return control_deps_; }
private:
friend class Scope;
// Tag types to choose the constructor to dispatch.
struct Tags {
enum class ScopeName;
enum class OpName;
enum class ControlDeps;
enum class Device;
enum class SingleUseScope;
enum class ExitOnError;
enum class KernelLabel;
enum class Colocate;
enum class AssignedDevice;
};
Impl(Graph* graph, Status* status, NameMap* name_map, ShapeRefiner* refiner,
bool disable_shape_inference);
Impl(const Scope& other, Tags::ScopeName, const string& name,
bool copy_names);
Impl(const Scope& other, Tags::OpName, const string& name,
const string& op_name);
Impl(const Scope& other, Tags::ControlDeps,
std::vector<Operation> control_deps, bool clear_control_deps);
Impl(const Scope& other, Tags::Device, const string& device);
Impl(const Scope& other, Tags::SingleUseScope, const string& op_name);
Impl(const Scope& other, Tags::ExitOnError);
Impl(const Scope& other, Tags::KernelLabel, const string& kernel_label);
Impl(const Scope& other, Tags::Colocate, const Operation& colocate_with_op,
bool clear_colocations);
Impl(const Scope& other, Tags::AssignedDevice, const string& assigned_device);
std::unordered_set<string> GetColocationConstraints(
const Operation& colocate_with_op) const;
// Helper functions to get a unique names.
string GetUniqueName(const string& prefix, bool check_single_use) const;
string GetNameForOp(const string& default_name) const;
bool single_use_scope() const { return scope_used_ != nullptr; }
// The graph, status, and name maps are shared by all child scopes
// created from a single 'root' scope. A root scope is created by calling the
// Scope::NewRootScope function, which creates a new graph, a new status and
// the name maps.
std::shared_ptr<Graph> graph_ = nullptr;
std::shared_ptr<Status> status_ = nullptr;
std::shared_ptr<NameMap> name_map_ = nullptr;
std::shared_ptr<ShapeRefiner> refiner_ = nullptr;
// If scope_used_ is not nullptr, op_name_ should be empty and
// GetUniqueNameForOp can only be called once on this scope. More calls to
// GetUniqueNameForOp will cause an error status to be set on this scope.
std::shared_ptr<bool> scope_used_ = nullptr;
const std::vector<Operation> control_deps_;
// The fully-qualified name of this scope (i.e. includes any parent scope
// names).
const string name_ = "";
const string op_name_ = "";
const bool exit_on_error_ = false;
const string kernel_label_ = "";
const string device_ = "";
const string assigned_device_ = "";
const std::unordered_set<string> colocation_constraints_;
// If true, Scope::DoShapeInference() always returns Status:OK().
// TODO(skyewm): remove this when possible
const bool disable_shape_inference_;
};
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_SCOPE_INTERNAL_H_
@@ -0,0 +1,40 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_FRAMEWORK_WHILE_GRADIENTS_H_
#define TENSORFLOW_CC_FRAMEWORK_WHILE_GRADIENTS_H_
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/graph/while_context.h"
// Utility functions for constructing while loop gradients
namespace tensorflow {
// Adds the gradient computation for the while loop associated with
// `while_ctx`. `grad_inputs` are the partial derivatives w.r.t. the loop
// outputs, i.e. the exit nodes. The partial derivatives w.r.t. the loop
// inputs, i.e. the input loop vars, are returned in `grad_outputs`.
// `grad_inputs` and `grad_outputs` are both in loop-variable order, as defined
// by the original inputs to BuildWhileLoop().
// TODO(skyewm): maybe comment on NoGradient once it's supported
Status AddWhileLoopGradient(WhileContext* while_ctx, const Scope& scope,
const std::vector<Output>& grad_inputs,
std::vector<Output>* grad_outputs);
} // namespace tensorflow
#endif // TENSORFLOW_CC_FRAMEWORK_WHILE_GRADIENTS_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,226 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_ARRAY_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_ARRAY_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup array_ops_internal Array Ops Internal
/// @{
/// Return the reduction indices for computing gradients of s0 op s1 with broadcast.
///
/// This is typically used by gradient computations for a broadcasting operation.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output` r0
/// * `Output` r1
class BroadcastGradientArgs {
public:
BroadcastGradientArgs(const ::tensorflow::Scope& scope, ::tensorflow::Input s0,
::tensorflow::Input s1);
Operation operation;
::tensorflow::Output r0;
::tensorflow::Output r1;
};
/// Applies lower_bound(sorted_search_values, values) along each row.
///
/// Each set of rows with the same index in (sorted_inputs, values) is treated
/// independently. The resulting row is the equivalent of calling
/// `np.searchsorted(sorted_inputs, values, side='left')`.
///
/// The result is not a global index to the entire
/// `Tensor`, but rather just the index in the last dimension.
///
/// A 2-D example:
/// sorted_sequence = [[0, 3, 9, 9, 10],
/// [1, 2, 3, 4, 5]]
/// values = [[2, 4, 9],
/// [0, 2, 6]]
///
/// result = LowerBound(sorted_sequence, values)
///
/// result == [[1, 2, 2],
/// [0, 1, 5]]
///
/// Arguments:
/// * scope: A Scope object
/// * sorted_inputs: 2-D Tensor where each row is ordered.
/// * values: 2-D Tensor with the same numbers of rows as `sorted_search_values`. Contains
/// the values that will be searched for in `sorted_search_values`.
///
/// Returns:
/// * `Output`: A `Tensor` with the same shape as `values`. It contains the first scalar index
/// into the last dimension where values can be inserted without changing the
/// ordered property.
class LowerBound {
public:
/// Optional attribute setters for LowerBound
struct Attrs {
/// Defaults to DT_INT32
TF_MUST_USE_RESULT Attrs OutType(DataType x) {
Attrs ret = *this;
ret.out_type_ = x;
return ret;
}
DataType out_type_ = DT_INT32;
};
LowerBound(const ::tensorflow::Scope& scope, ::tensorflow::Input sorted_inputs,
::tensorflow::Input values);
LowerBound(const ::tensorflow::Scope& scope, ::tensorflow::Input sorted_inputs,
::tensorflow::Input values, const LowerBound::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs OutType(DataType x) {
return Attrs().OutType(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Gradient op for `MirrorPad` op. This op folds a mirror-padded tensor.
///
/// This operation folds the padded areas of `input` by `MirrorPad` according to the
/// `paddings` you specify. `paddings` must be the same as `paddings` argument
/// given to the corresponding `MirrorPad` op.
///
/// The folded size of each dimension D of the output is:
///
/// `input.dim_size(D) - paddings(D, 0) - paddings(D, 1)`
///
/// For example:
///
/// ```
/// # 't' is [[1, 2, 3], [4, 5, 6], [7, 8, 9]].
/// # 'paddings' is [[0, 1]], [0, 1]].
/// # 'mode' is SYMMETRIC.
/// # rank of 't' is 2.
/// pad(t, paddings) ==> [[ 1, 5]
/// [11, 28]]
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * input: The input tensor to be folded.
/// * paddings: A two-column matrix specifying the padding sizes. The number of
/// rows must be the same as the rank of `input`.
/// * mode: The mode used in the `MirrorPad` op.
///
/// Returns:
/// * `Output`: The folded tensor.
class MirrorPadGrad {
public:
MirrorPadGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input paddings, StringPiece mode);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Return the same ref tensor as the input ref tensor.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The output tensor.
class RefIdentity {
public:
RefIdentity(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Applies upper_bound(sorted_search_values, values) along each row.
///
/// Each set of rows with the same index in (sorted_inputs, values) is treated
/// independently. The resulting row is the equivalent of calling
/// `np.searchsorted(sorted_inputs, values, side='right')`.
///
/// The result is not a global index to the entire
/// `Tensor`, but rather just the index in the last dimension.
///
/// A 2-D example:
/// sorted_sequence = [[0, 3, 9, 9, 10],
/// [1, 2, 3, 4, 5]]
/// values = [[2, 4, 9],
/// [0, 2, 6]]
///
/// result = UpperBound(sorted_sequence, values)
///
/// result == [[1, 2, 4],
/// [0, 2, 5]]
///
/// Arguments:
/// * scope: A Scope object
/// * sorted_inputs: 2-D Tensor where each row is ordered.
/// * values: 2-D Tensor with the same numbers of rows as `sorted_search_values`. Contains
/// the values that will be searched for in `sorted_search_values`.
///
/// Returns:
/// * `Output`: A `Tensor` with the same shape as `values`. It contains the last scalar index
/// into the last dimension where values can be inserted without changing the
/// ordered property.
class UpperBound {
public:
/// Optional attribute setters for UpperBound
struct Attrs {
/// Defaults to DT_INT32
TF_MUST_USE_RESULT Attrs OutType(DataType x) {
Attrs ret = *this;
ret.out_type_ = x;
return ret;
}
DataType out_type_ = DT_INT32;
};
UpperBound(const ::tensorflow::Scope& scope, ::tensorflow::Input sorted_inputs,
::tensorflow::Input values);
UpperBound(const ::tensorflow::Scope& scope, ::tensorflow::Input sorted_inputs,
::tensorflow::Input values, const UpperBound::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs OutType(DataType x) {
return Attrs().OutType(x);
}
Operation operation;
::tensorflow::Output output;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_ARRAY_OPS_INTERNAL_H_
+295
View File
@@ -0,0 +1,295 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_AUDIO_OPS_H_
#define TENSORFLOW_CC_OPS_AUDIO_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup audio_ops Audio Ops
/// @{
/// Produces a visualization of audio data over time.
///
/// Spectrograms are a standard way of representing audio information as a series of
/// slices of frequency information, one slice for each window of time. By joining
/// these together into a sequence, they form a distinctive fingerprint of the sound
/// over time.
///
/// This op expects to receive audio data as an input, stored as floats in the range
/// -1 to 1, together with a window width in samples, and a stride specifying how
/// far to move the window between slices. From this it generates a three
/// dimensional output. The lowest dimension has an amplitude value for each
/// frequency during that time slice. The next dimension is time, with successive
/// frequency slices. The final dimension is for the channels in the input, so a
/// stereo audio input would have two here for example.
///
/// This means the layout when converted and saved as an image is rotated 90 degrees
/// clockwise from a typical spectrogram. Time is descending down the Y axis, and
/// the frequency decreases from left to right.
///
/// Each value in the result represents the square root of the sum of the real and
/// imaginary parts of an FFT on the current window of samples. In this way, the
/// lowest dimension represents the power of each frequency in the current window,
/// and adjacent windows are concatenated in the next dimension.
///
/// To get a more intuitive and visual look at what this operation does, you can run
/// tensorflow/examples/wav_to_spectrogram to read in an audio file and save out the
/// resulting spectrogram as a PNG image.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Float representation of audio data.
/// * window_size: How wide the input window is in samples. For the highest efficiency
/// this should be a power of two, but other values are accepted.
/// * stride: How widely apart the center of adjacent sample windows should be.
///
/// Optional attributes (see `Attrs`):
/// * magnitude_squared: Whether to return the squared magnitude or just the
/// magnitude. Using squared magnitude can avoid extra calculations.
///
/// Returns:
/// * `Output`: 3D representation of the audio frequencies as an image.
class AudioSpectrogram {
public:
/// Optional attribute setters for AudioSpectrogram
struct Attrs {
/// Whether to return the squared magnitude or just the
/// magnitude. Using squared magnitude can avoid extra calculations.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs MagnitudeSquared(bool x) {
Attrs ret = *this;
ret.magnitude_squared_ = x;
return ret;
}
bool magnitude_squared_ = false;
};
AudioSpectrogram(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
int64 window_size, int64 stride);
AudioSpectrogram(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
int64 window_size, int64 stride, const
AudioSpectrogram::Attrs& attrs);
operator ::tensorflow::Output() const { return spectrogram; }
operator ::tensorflow::Input() const { return spectrogram; }
::tensorflow::Node* node() const { return spectrogram.node(); }
static Attrs MagnitudeSquared(bool x) {
return Attrs().MagnitudeSquared(x);
}
Operation operation;
::tensorflow::Output spectrogram;
};
/// Decode a 16-bit PCM WAV file to a float tensor.
///
/// The -32768 to 32767 signed 16-bit values will be scaled to -1.0 to 1.0 in float.
///
/// When desired_channels is set, if the input contains fewer channels than this
/// then the last channel will be duplicated to give the requested number, else if
/// the input has more channels than requested then the additional channels will be
/// ignored.
///
/// If desired_samples is set, then the audio will be cropped or padded with zeroes
/// to the requested length.
///
/// The first output contains a Tensor with the content of the audio samples. The
/// lowest dimension will be the number of channels, and the second will be the
/// number of samples. For example, a ten-sample-long stereo WAV file should give an
/// output shape of [10, 2].
///
/// Arguments:
/// * scope: A Scope object
/// * contents: The WAV-encoded audio, usually from a file.
///
/// Optional attributes (see `Attrs`):
/// * desired_channels: Number of sample channels wanted.
/// * desired_samples: Length of audio requested.
///
/// Returns:
/// * `Output` audio: 2-D with shape `[length, channels]`.
/// * `Output` sample_rate: Scalar holding the sample rate found in the WAV header.
class DecodeWav {
public:
/// Optional attribute setters for DecodeWav
struct Attrs {
/// Number of sample channels wanted.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs DesiredChannels(int64 x) {
Attrs ret = *this;
ret.desired_channels_ = x;
return ret;
}
/// Length of audio requested.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs DesiredSamples(int64 x) {
Attrs ret = *this;
ret.desired_samples_ = x;
return ret;
}
int64 desired_channels_ = -1;
int64 desired_samples_ = -1;
};
DecodeWav(const ::tensorflow::Scope& scope, ::tensorflow::Input contents);
DecodeWav(const ::tensorflow::Scope& scope, ::tensorflow::Input contents, const
DecodeWav::Attrs& attrs);
static Attrs DesiredChannels(int64 x) {
return Attrs().DesiredChannels(x);
}
static Attrs DesiredSamples(int64 x) {
return Attrs().DesiredSamples(x);
}
Operation operation;
::tensorflow::Output audio;
::tensorflow::Output sample_rate;
};
/// Encode audio data using the WAV file format.
///
/// This operation will generate a string suitable to be saved out to create a .wav
/// audio file. It will be encoded in the 16-bit PCM format. It takes in float
/// values in the range -1.0f to 1.0f, and any outside that value will be clamped to
/// that range.
///
/// `audio` is a 2-D float Tensor of shape `[length, channels]`.
/// `sample_rate` is a scalar Tensor holding the rate to use (e.g. 44100).
///
/// Arguments:
/// * scope: A Scope object
/// * audio: 2-D with shape `[length, channels]`.
/// * sample_rate: Scalar containing the sample frequency.
///
/// Returns:
/// * `Output`: 0-D. WAV-encoded file contents.
class EncodeWav {
public:
EncodeWav(const ::tensorflow::Scope& scope, ::tensorflow::Input audio,
::tensorflow::Input sample_rate);
operator ::tensorflow::Output() const { return contents; }
operator ::tensorflow::Input() const { return contents; }
::tensorflow::Node* node() const { return contents.node(); }
Operation operation;
::tensorflow::Output contents;
};
/// Transforms a spectrogram into a form that's useful for speech recognition.
///
/// Mel Frequency Cepstral Coefficients are a way of representing audio data that's
/// been effective as an input feature for machine learning. They are created by
/// taking the spectrum of a spectrogram (a 'cepstrum'), and discarding some of the
/// higher frequencies that are less significant to the human ear. They have a long
/// history in the speech recognition world, and https://en.wikipedia.org/wiki/Mel-frequency_cepstrum
/// is a good resource to learn more.
///
/// Arguments:
/// * scope: A Scope object
/// * spectrogram: Typically produced by the Spectrogram op, with magnitude_squared
/// set to true.
/// * sample_rate: How many samples per second the source audio used.
///
/// Optional attributes (see `Attrs`):
/// * upper_frequency_limit: The highest frequency to use when calculating the
/// ceptstrum.
/// * lower_frequency_limit: The lowest frequency to use when calculating the
/// ceptstrum.
/// * filterbank_channel_count: Resolution of the Mel bank used internally.
/// * dct_coefficient_count: How many output channels to produce per time slice.
///
/// Returns:
/// * `Output`: The output tensor.
class Mfcc {
public:
/// Optional attribute setters for Mfcc
struct Attrs {
/// The highest frequency to use when calculating the
/// ceptstrum.
///
/// Defaults to 4000
TF_MUST_USE_RESULT Attrs UpperFrequencyLimit(float x) {
Attrs ret = *this;
ret.upper_frequency_limit_ = x;
return ret;
}
/// The lowest frequency to use when calculating the
/// ceptstrum.
///
/// Defaults to 20
TF_MUST_USE_RESULT Attrs LowerFrequencyLimit(float x) {
Attrs ret = *this;
ret.lower_frequency_limit_ = x;
return ret;
}
/// Resolution of the Mel bank used internally.
///
/// Defaults to 40
TF_MUST_USE_RESULT Attrs FilterbankChannelCount(int64 x) {
Attrs ret = *this;
ret.filterbank_channel_count_ = x;
return ret;
}
/// How many output channels to produce per time slice.
///
/// Defaults to 13
TF_MUST_USE_RESULT Attrs DctCoefficientCount(int64 x) {
Attrs ret = *this;
ret.dct_coefficient_count_ = x;
return ret;
}
float upper_frequency_limit_ = 4000.0f;
float lower_frequency_limit_ = 20.0f;
int64 filterbank_channel_count_ = 40;
int64 dct_coefficient_count_ = 13;
};
Mfcc(const ::tensorflow::Scope& scope, ::tensorflow::Input spectrogram,
::tensorflow::Input sample_rate);
Mfcc(const ::tensorflow::Scope& scope, ::tensorflow::Input spectrogram,
::tensorflow::Input sample_rate, const Mfcc::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs UpperFrequencyLimit(float x) {
return Attrs().UpperFrequencyLimit(x);
}
static Attrs LowerFrequencyLimit(float x) {
return Attrs().LowerFrequencyLimit(x);
}
static Attrs FilterbankChannelCount(int64 x) {
return Attrs().FilterbankChannelCount(x);
}
static Attrs DctCoefficientCount(int64 x) {
return Attrs().DctCoefficientCount(x);
}
Operation operation;
::tensorflow::Output output;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_AUDIO_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_AUDIO_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_AUDIO_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup audio_ops_internal Audio Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_AUDIO_OPS_INTERNAL_H_
@@ -0,0 +1,657 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_CANDIDATE_SAMPLING_OPS_H_
#define TENSORFLOW_CC_OPS_CANDIDATE_SAMPLING_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup candidate_sampling_ops Candidate Sampling Ops
/// @{
/// Generates labels for candidate sampling with a learned unigram distribution.
///
/// See explanations of candidate sampling and the data formats at
/// go/candidate-sampling.
///
/// For each batch, this op picks a single set of sampled candidate labels.
///
/// The advantages of sampling candidates per-batch are simplicity and the
/// possibility of efficient dense matrix multiplication. The disadvantage is that
/// the sampled candidates must be chosen independently of the context and of the
/// true labels.
///
/// Arguments:
/// * scope: A Scope object
/// * true_classes: A batch_size * num_true matrix, in which each row contains the
/// IDs of the num_true target_classes in the corresponding original label.
/// * num_true: Number of true labels per context.
/// * num_sampled: Number of candidates to produce.
/// * unique: If unique is true, we sample with rejection, so that all sampled
/// candidates in a batch are unique. This requires some approximation to
/// estimate the post-rejection sampling probabilities.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: An second seed to avoid seed collision.
///
/// Returns:
/// * `Output` sampled_candidates: A vector of length num_sampled, in which each element is
/// the ID of a sampled candidate.
/// * `Output` true_expected_count: A batch_size * num_true matrix, representing
/// the number of times each candidate is expected to occur in a batch
/// of sampled candidates. If unique=true, then this is a probability.
/// * `Output` sampled_expected_count: A vector of length num_sampled, for each sampled
/// candidate representing the number of times the candidate is expected
/// to occur in a batch of sampled candidates. If unique=true, then this is a
/// probability.
class AllCandidateSampler {
public:
/// Optional attribute setters for AllCandidateSampler
struct Attrs {
/// If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// An second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
AllCandidateSampler(const ::tensorflow::Scope& scope, ::tensorflow::Input
true_classes, int64 num_true, int64 num_sampled, bool
unique);
AllCandidateSampler(const ::tensorflow::Scope& scope, ::tensorflow::Input
true_classes, int64 num_true, int64 num_sampled, bool
unique, const AllCandidateSampler::Attrs& attrs);
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output sampled_candidates;
::tensorflow::Output true_expected_count;
::tensorflow::Output sampled_expected_count;
};
/// Computes the ids of the positions in sampled_candidates that match true_labels.
///
/// When doing log-odds NCE, the result of this op should be passed through a
/// SparseToDense op, then added to the logits of the sampled candidates. This has
/// the effect of 'removing' the sampled labels that match the true labels by
/// making the classifier sure that they are sampled labels.
///
/// Arguments:
/// * scope: A Scope object
/// * true_classes: The true_classes output of UnpackSparseLabels.
/// * sampled_candidates: The sampled_candidates output of CandidateSampler.
/// * num_true: Number of true labels per context.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: An second seed to avoid seed collision.
///
/// Returns:
/// * `Output` indices: A vector of indices corresponding to rows of true_candidates.
/// * `Output` ids: A vector of IDs of positions in sampled_candidates that match a true_label
/// for the row with the corresponding index in indices.
/// * `Output` weights: A vector of the same length as indices and ids, in which each element
/// is -FLOAT_MAX.
class ComputeAccidentalHits {
public:
/// Optional attribute setters for ComputeAccidentalHits
struct Attrs {
/// If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// An second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
ComputeAccidentalHits(const ::tensorflow::Scope& scope, ::tensorflow::Input
true_classes, ::tensorflow::Input sampled_candidates,
int64 num_true);
ComputeAccidentalHits(const ::tensorflow::Scope& scope, ::tensorflow::Input
true_classes, ::tensorflow::Input sampled_candidates,
int64 num_true, const ComputeAccidentalHits::Attrs&
attrs);
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output indices;
::tensorflow::Output ids;
::tensorflow::Output weights;
};
/// Generates labels for candidate sampling with a learned unigram distribution.
///
/// A unigram sampler could use a fixed unigram distribution read from a
/// file or passed in as an in-memory array instead of building up the distribution
/// from data on the fly. There is also an option to skew the distribution by
/// applying a distortion power to the weights.
///
/// The vocabulary file should be in CSV-like format, with the last field
/// being the weight associated with the word.
///
/// For each batch, this op picks a single set of sampled candidate labels.
///
/// The advantages of sampling candidates per-batch are simplicity and the
/// possibility of efficient dense matrix multiplication. The disadvantage is that
/// the sampled candidates must be chosen independently of the context and of the
/// true labels.
///
/// Arguments:
/// * scope: A Scope object
/// * true_classes: A batch_size * num_true matrix, in which each row contains the
/// IDs of the num_true target_classes in the corresponding original label.
/// * num_true: Number of true labels per context.
/// * num_sampled: Number of candidates to randomly sample.
/// * unique: If unique is true, we sample with rejection, so that all sampled
/// candidates in a batch are unique. This requires some approximation to
/// estimate the post-rejection sampling probabilities.
/// * range_max: The sampler will sample integers from the interval [0, range_max).
///
/// Optional attributes (see `Attrs`):
/// * vocab_file: Each valid line in this file (which should have a CSV-like format)
/// corresponds to a valid word ID. IDs are in sequential order, starting from
/// num_reserved_ids. The last entry in each line is expected to be a value
/// corresponding to the count or relative probability. Exactly one of vocab_file
/// and unigrams needs to be passed to this op.
/// * distortion: The distortion is used to skew the unigram probability distribution.
/// Each weight is first raised to the distortion's power before adding to the
/// internal unigram distribution. As a result, distortion = 1.0 gives regular
/// unigram sampling (as defined by the vocab file), and distortion = 0.0 gives
/// a uniform distribution.
/// * num_reserved_ids: Optionally some reserved IDs can be added in the range [0,
/// ..., num_reserved_ids) by the users. One use case is that a special unknown
/// word token is used as ID 0. These IDs will have a sampling probability of 0.
/// * num_shards: A sampler can be used to sample from a subset of the original range
/// in order to speed up the whole computation through parallelism. This parameter
/// (together with 'shard') indicates the number of partitions that are being
/// used in the overall computation.
/// * shard: A sampler can be used to sample from a subset of the original range
/// in order to speed up the whole computation through parallelism. This parameter
/// (together with 'num_shards') indicates the particular partition number of a
/// sampler op, when partitioning is being used.
/// * unigrams: A list of unigram counts or probabilities, one per ID in sequential
/// order. Exactly one of vocab_file and unigrams should be passed to this op.
/// * seed: If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: An second seed to avoid seed collision.
///
/// Returns:
/// * `Output` sampled_candidates: A vector of length num_sampled, in which each element is
/// the ID of a sampled candidate.
/// * `Output` true_expected_count: A batch_size * num_true matrix, representing
/// the number of times each candidate is expected to occur in a batch
/// of sampled candidates. If unique=true, then this is a probability.
/// * `Output` sampled_expected_count: A vector of length num_sampled, for each sampled
/// candidate representing the number of times the candidate is expected
/// to occur in a batch of sampled candidates. If unique=true, then this is a
/// probability.
class FixedUnigramCandidateSampler {
public:
/// Optional attribute setters for FixedUnigramCandidateSampler
struct Attrs {
/// Each valid line in this file (which should have a CSV-like format)
/// corresponds to a valid word ID. IDs are in sequential order, starting from
/// num_reserved_ids. The last entry in each line is expected to be a value
/// corresponding to the count or relative probability. Exactly one of vocab_file
/// and unigrams needs to be passed to this op.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs VocabFile(StringPiece x) {
Attrs ret = *this;
ret.vocab_file_ = x;
return ret;
}
/// The distortion is used to skew the unigram probability distribution.
/// Each weight is first raised to the distortion's power before adding to the
/// internal unigram distribution. As a result, distortion = 1.0 gives regular
/// unigram sampling (as defined by the vocab file), and distortion = 0.0 gives
/// a uniform distribution.
///
/// Defaults to 1
TF_MUST_USE_RESULT Attrs Distortion(float x) {
Attrs ret = *this;
ret.distortion_ = x;
return ret;
}
/// Optionally some reserved IDs can be added in the range [0,
/// ..., num_reserved_ids) by the users. One use case is that a special unknown
/// word token is used as ID 0. These IDs will have a sampling probability of 0.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs NumReservedIds(int64 x) {
Attrs ret = *this;
ret.num_reserved_ids_ = x;
return ret;
}
/// A sampler can be used to sample from a subset of the original range
/// in order to speed up the whole computation through parallelism. This parameter
/// (together with 'shard') indicates the number of partitions that are being
/// used in the overall computation.
///
/// Defaults to 1
TF_MUST_USE_RESULT Attrs NumShards(int64 x) {
Attrs ret = *this;
ret.num_shards_ = x;
return ret;
}
/// A sampler can be used to sample from a subset of the original range
/// in order to speed up the whole computation through parallelism. This parameter
/// (together with 'num_shards') indicates the particular partition number of a
/// sampler op, when partitioning is being used.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Shard(int64 x) {
Attrs ret = *this;
ret.shard_ = x;
return ret;
}
/// A list of unigram counts or probabilities, one per ID in sequential
/// order. Exactly one of vocab_file and unigrams should be passed to this op.
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs Unigrams(const gtl::ArraySlice<float>& x) {
Attrs ret = *this;
ret.unigrams_ = x;
return ret;
}
/// If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// An second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
StringPiece vocab_file_ = "";
float distortion_ = 1.0f;
int64 num_reserved_ids_ = 0;
int64 num_shards_ = 1;
int64 shard_ = 0;
gtl::ArraySlice<float> unigrams_ = {};
int64 seed_ = 0;
int64 seed2_ = 0;
};
FixedUnigramCandidateSampler(const ::tensorflow::Scope& scope,
::tensorflow::Input true_classes, int64 num_true,
int64 num_sampled, bool unique, int64 range_max);
FixedUnigramCandidateSampler(const ::tensorflow::Scope& scope,
::tensorflow::Input true_classes, int64 num_true,
int64 num_sampled, bool unique, int64 range_max,
const FixedUnigramCandidateSampler::Attrs& attrs);
static Attrs VocabFile(StringPiece x) {
return Attrs().VocabFile(x);
}
static Attrs Distortion(float x) {
return Attrs().Distortion(x);
}
static Attrs NumReservedIds(int64 x) {
return Attrs().NumReservedIds(x);
}
static Attrs NumShards(int64 x) {
return Attrs().NumShards(x);
}
static Attrs Shard(int64 x) {
return Attrs().Shard(x);
}
static Attrs Unigrams(const gtl::ArraySlice<float>& x) {
return Attrs().Unigrams(x);
}
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output sampled_candidates;
::tensorflow::Output true_expected_count;
::tensorflow::Output sampled_expected_count;
};
/// Generates labels for candidate sampling with a learned unigram distribution.
///
/// See explanations of candidate sampling and the data formats at
/// go/candidate-sampling.
///
/// For each batch, this op picks a single set of sampled candidate labels.
///
/// The advantages of sampling candidates per-batch are simplicity and the
/// possibility of efficient dense matrix multiplication. The disadvantage is that
/// the sampled candidates must be chosen independently of the context and of the
/// true labels.
///
/// Arguments:
/// * scope: A Scope object
/// * true_classes: A batch_size * num_true matrix, in which each row contains the
/// IDs of the num_true target_classes in the corresponding original label.
/// * num_true: Number of true labels per context.
/// * num_sampled: Number of candidates to randomly sample.
/// * unique: If unique is true, we sample with rejection, so that all sampled
/// candidates in a batch are unique. This requires some approximation to
/// estimate the post-rejection sampling probabilities.
/// * range_max: The sampler will sample integers from the interval [0, range_max).
///
/// Optional attributes (see `Attrs`):
/// * seed: If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: An second seed to avoid seed collision.
///
/// Returns:
/// * `Output` sampled_candidates: A vector of length num_sampled, in which each element is
/// the ID of a sampled candidate.
/// * `Output` true_expected_count: A batch_size * num_true matrix, representing
/// the number of times each candidate is expected to occur in a batch
/// of sampled candidates. If unique=true, then this is a probability.
/// * `Output` sampled_expected_count: A vector of length num_sampled, for each sampled
/// candidate representing the number of times the candidate is expected
/// to occur in a batch of sampled candidates. If unique=true, then this is a
/// probability.
class LearnedUnigramCandidateSampler {
public:
/// Optional attribute setters for LearnedUnigramCandidateSampler
struct Attrs {
/// If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// An second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
LearnedUnigramCandidateSampler(const ::tensorflow::Scope& scope,
::tensorflow::Input true_classes, int64
num_true, int64 num_sampled, bool unique, int64
range_max);
LearnedUnigramCandidateSampler(const ::tensorflow::Scope& scope,
::tensorflow::Input true_classes, int64
num_true, int64 num_sampled, bool unique, int64
range_max, const
LearnedUnigramCandidateSampler::Attrs& attrs);
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output sampled_candidates;
::tensorflow::Output true_expected_count;
::tensorflow::Output sampled_expected_count;
};
/// Generates labels for candidate sampling with a log-uniform distribution.
///
/// See explanations of candidate sampling and the data formats at
/// go/candidate-sampling.
///
/// For each batch, this op picks a single set of sampled candidate labels.
///
/// The advantages of sampling candidates per-batch are simplicity and the
/// possibility of efficient dense matrix multiplication. The disadvantage is that
/// the sampled candidates must be chosen independently of the context and of the
/// true labels.
///
/// Arguments:
/// * scope: A Scope object
/// * true_classes: A batch_size * num_true matrix, in which each row contains the
/// IDs of the num_true target_classes in the corresponding original label.
/// * num_true: Number of true labels per context.
/// * num_sampled: Number of candidates to randomly sample.
/// * unique: If unique is true, we sample with rejection, so that all sampled
/// candidates in a batch are unique. This requires some approximation to
/// estimate the post-rejection sampling probabilities.
/// * range_max: The sampler will sample integers from the interval [0, range_max).
///
/// Optional attributes (see `Attrs`):
/// * seed: If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: An second seed to avoid seed collision.
///
/// Returns:
/// * `Output` sampled_candidates: A vector of length num_sampled, in which each element is
/// the ID of a sampled candidate.
/// * `Output` true_expected_count: A batch_size * num_true matrix, representing
/// the number of times each candidate is expected to occur in a batch
/// of sampled candidates. If unique=true, then this is a probability.
/// * `Output` sampled_expected_count: A vector of length num_sampled, for each sampled
/// candidate representing the number of times the candidate is expected
/// to occur in a batch of sampled candidates. If unique=true, then this is a
/// probability.
class LogUniformCandidateSampler {
public:
/// Optional attribute setters for LogUniformCandidateSampler
struct Attrs {
/// If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// An second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
LogUniformCandidateSampler(const ::tensorflow::Scope& scope,
::tensorflow::Input true_classes, int64 num_true,
int64 num_sampled, bool unique, int64 range_max);
LogUniformCandidateSampler(const ::tensorflow::Scope& scope,
::tensorflow::Input true_classes, int64 num_true,
int64 num_sampled, bool unique, int64 range_max,
const LogUniformCandidateSampler::Attrs& attrs);
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output sampled_candidates;
::tensorflow::Output true_expected_count;
::tensorflow::Output sampled_expected_count;
};
/// Generates labels for candidate sampling with a uniform distribution.
///
/// See explanations of candidate sampling and the data formats at
/// go/candidate-sampling.
///
/// For each batch, this op picks a single set of sampled candidate labels.
///
/// The advantages of sampling candidates per-batch are simplicity and the
/// possibility of efficient dense matrix multiplication. The disadvantage is that
/// the sampled candidates must be chosen independently of the context and of the
/// true labels.
///
/// Arguments:
/// * scope: A Scope object
/// * true_classes: A batch_size * num_true matrix, in which each row contains the
/// IDs of the num_true target_classes in the corresponding original label.
/// * num_true: Number of true labels per context.
/// * num_sampled: Number of candidates to randomly sample.
/// * unique: If unique is true, we sample with rejection, so that all sampled
/// candidates in a batch are unique. This requires some approximation to
/// estimate the post-rejection sampling probabilities.
/// * range_max: The sampler will sample integers from the interval [0, range_max).
///
/// Optional attributes (see `Attrs`):
/// * seed: If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: An second seed to avoid seed collision.
///
/// Returns:
/// * `Output` sampled_candidates: A vector of length num_sampled, in which each element is
/// the ID of a sampled candidate.
/// * `Output` true_expected_count: A batch_size * num_true matrix, representing
/// the number of times each candidate is expected to occur in a batch
/// of sampled candidates. If unique=true, then this is a probability.
/// * `Output` sampled_expected_count: A vector of length num_sampled, for each sampled
/// candidate representing the number of times the candidate is expected
/// to occur in a batch of sampled candidates. If unique=true, then this is a
/// probability.
class UniformCandidateSampler {
public:
/// Optional attribute setters for UniformCandidateSampler
struct Attrs {
/// If either seed or seed2 are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// An second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
UniformCandidateSampler(const ::tensorflow::Scope& scope, ::tensorflow::Input
true_classes, int64 num_true, int64 num_sampled, bool
unique, int64 range_max);
UniformCandidateSampler(const ::tensorflow::Scope& scope, ::tensorflow::Input
true_classes, int64 num_true, int64 num_sampled, bool
unique, int64 range_max, const
UniformCandidateSampler::Attrs& attrs);
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output sampled_candidates;
::tensorflow::Output true_expected_count;
::tensorflow::Output sampled_expected_count;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_CANDIDATE_SAMPLING_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_CANDIDATE_SAMPLING_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_CANDIDATE_SAMPLING_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup candidate_sampling_ops_internal Candidate Sampling Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_CANDIDATE_SAMPLING_OPS_INTERNAL_H_
@@ -0,0 +1,85 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_OPS_CONST_OP_H_
#define TENSORFLOW_CC_OPS_CONST_OP_H_
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/graph/node_builder.h"
namespace tensorflow {
namespace ops {
/// @defgroup const_op Const Op
/// @{
Output Const(const Scope& scope, const Input::Initializer& val);
Output ConstFromProto(const Scope& scope, const TensorProto& proto);
NodeBuilder::NodeOut AsNodeOut(const Scope& scope, const Input& inp);
template <typename T>
Output Const(const Scope& scope, const Input::Initializer& val) {
auto orig_const_output = Const(scope, val);
if (!scope.ok()) return Output();
typedef typename Input::Initializer::RealType<T>::type DstT;
if (val.tensor.dtype() == DataTypeToEnum<DstT>::v()) {
return orig_const_output;
}
if (val.tensor.NumElements() == 0) {
Tensor t(DataTypeToEnum<DstT>::v(), val.tensor.shape());
return Const(scope, Input::Initializer(t));
}
// TODO(keveman): Refactor Cast op's kernel implementation such that the code
// can be directly called here instead of adding the Cast op to the graph.
auto orig_const = AsNodeOut(scope, orig_const_output);
const auto cast_op_name = scope.GetUniqueNameForOp("Cast");
auto cast_builder = NodeBuilder(cast_op_name, "Cast")
.Input(orig_const)
.Attr("DstT", DataTypeToEnum<DstT>::v());
scope.UpdateBuilder(&cast_builder);
Node* ret;
scope.UpdateStatus(cast_builder.Finalize(scope.graph(), &ret));
if (!scope.ok()) return Output();
scope.UpdateStatus(scope.DoShapeInference(ret));
return Output(ret, 0);
}
template <typename T>
Output Const(const Scope& scope, const T& v, const TensorShape shape) {
return Const(scope, Input::Initializer(v, shape));
}
template <typename T>
Output Const(const Scope& scope, const std::initializer_list<T>& v,
const TensorShape shape) {
return Const(scope, Input::Initializer(v, shape));
}
std::vector<NodeBuilder::NodeOut> AsNodeOutList(const Scope& scope,
const InputList& inp);
/// }@
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_CONST_OP_H_
@@ -0,0 +1,250 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_CONTROL_FLOW_OPS_H_
#define TENSORFLOW_CC_OPS_CONTROL_FLOW_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup control_flow_ops Control Flow Ops
/// @{
/// Raise a exception to abort the process when called.
///
/// If exit_without_error is true, the process will exit normally,
/// otherwise it will exit with a SIGABORT signal.
///
/// Returns nothing but an exception.
///
/// Arguments:
/// * scope: A Scope object
///
/// Optional attributes (see `Attrs`):
/// * error_msg: A string which is the message associated with the exception.
///
/// Returns:
/// * the created `Operation`
class Abort {
public:
/// Optional attribute setters for Abort
struct Attrs {
/// A string which is the message associated with the exception.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs ErrorMsg(StringPiece x) {
Attrs ret = *this;
ret.error_msg_ = x;
return ret;
}
/// Defaults to false
TF_MUST_USE_RESULT Attrs ExitWithoutError(bool x) {
Attrs ret = *this;
ret.exit_without_error_ = x;
return ret;
}
StringPiece error_msg_ = "";
bool exit_without_error_ = false;
};
Abort(const ::tensorflow::Scope& scope);
Abort(const ::tensorflow::Scope& scope, const Abort::Attrs& attrs);
operator ::tensorflow::Operation() const { return operation; }
static Attrs ErrorMsg(StringPiece x) {
return Attrs().ErrorMsg(x);
}
static Attrs ExitWithoutError(bool x) {
return Attrs().ExitWithoutError(x);
}
Operation operation;
};
/// Does nothing. Serves as a control trigger for scheduling.
///
/// Only useful as a placeholder for control edges.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * the created `Operation`
class ControlTrigger {
public:
ControlTrigger(const ::tensorflow::Scope& scope);
operator ::tensorflow::Operation() const { return operation; }
Operation operation;
};
/// Forwards the input to the output.
///
/// This operator represents the loop termination condition used by the
/// "pivot" switches of a loop.
///
/// Arguments:
/// * scope: A Scope object
/// * input: A boolean scalar, representing the branch predicate of the Switch op.
///
/// Returns:
/// * `Output`: The same tensor as `input`.
class LoopCond {
public:
LoopCond(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Forwards the value of an available tensor from `inputs` to `output`.
///
/// `Merge` waits for at least one of the tensors in `inputs` to become available.
/// It is usually combined with `Switch` to implement branching.
///
/// `Merge` forwards the first tensor to become available to `output`, and sets
/// `value_index` to its index in `inputs`.
///
/// Arguments:
/// * scope: A Scope object
/// * inputs: The input tensors, exactly one of which will become available.
///
/// Returns:
/// * `Output` output: Will be set to the available input tensor.
/// * `Output` value_index: The index of the chosen input tensor in `inputs`.
class Merge {
public:
Merge(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs);
Operation operation;
::tensorflow::Output output;
::tensorflow::Output value_index;
};
/// Makes its input available to the next iteration.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be made available to the next iteration.
///
/// Returns:
/// * `Output`: The same tensor as `data`.
class NextIteration {
public:
NextIteration(const ::tensorflow::Scope& scope, ::tensorflow::Input data);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Makes its input available to the next iteration.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be made available to the next iteration.
///
/// Returns:
/// * `Output`: The same tensor as `data`.
class RefNextIteration {
public:
RefNextIteration(const ::tensorflow::Scope& scope, ::tensorflow::Input data);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Forwards the `index`th element of `inputs` to `output`.
///
/// Arguments:
/// * scope: A Scope object
/// * index: A scalar that determines the input that gets selected.
/// * inputs: A list of ref tensors, one of which will be forwarded to `output`.
///
/// Returns:
/// * `Output`: The forwarded tensor.
class RefSelect {
public:
RefSelect(const ::tensorflow::Scope& scope, ::tensorflow::Input index,
::tensorflow::InputList inputs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Forwards the ref tensor `data` to the output port determined by `pred`.
///
/// If `pred` is true, the `data` input is forwarded to `output_true`. Otherwise,
/// the data goes to `output_false`.
///
/// See also `Switch` and `Merge`.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The ref tensor to be forwarded to the appropriate output.
/// * pred: A scalar that specifies which output port will receive data.
///
/// Returns:
/// * `Output` output_false: If `pred` is false, data will be forwarded to this output.
/// * `Output` output_true: If `pred` is true, data will be forwarded to this output.
class RefSwitch {
public:
RefSwitch(const ::tensorflow::Scope& scope, ::tensorflow::Input data,
::tensorflow::Input pred);
Operation operation;
::tensorflow::Output output_false;
::tensorflow::Output output_true;
};
/// Forwards `data` to the output port determined by `pred`.
///
/// If `pred` is true, the `data` input is forwarded to `output_true`. Otherwise,
/// the data goes to `output_false`.
///
/// See also `RefSwitch` and `Merge`.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be forwarded to the appropriate output.
/// * pred: A scalar that specifies which output port will receive data.
///
/// Returns:
/// * `Output` output_false: If `pred` is false, data will be forwarded to this output.
/// * `Output` output_true: If `pred` is true, data will be forwarded to this output.
class Switch {
public:
Switch(const ::tensorflow::Scope& scope, ::tensorflow::Input data,
::tensorflow::Input pred);
Operation operation;
::tensorflow::Output output_false;
::tensorflow::Output output_true;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_CONTROL_FLOW_OPS_H_
@@ -0,0 +1,219 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_CONTROL_FLOW_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_CONTROL_FLOW_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup control_flow_ops_internal Control Flow Ops Internal
/// @{
/// Creates or finds a child frame, and makes `data` available to the child frame.
///
/// This op is used together with `Exit` to create loops in the graph.
/// The unique `frame_name` is used by the `Executor` to identify frames. If
/// `is_constant` is true, `output` is a constant in the child frame; otherwise
/// it may be changed in the child frame. At most `parallel_iterations` iterations
/// are run in parallel in the child frame.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be made available to the child frame.
/// * frame_name: The name of the child frame.
///
/// Optional attributes (see `Attrs`):
/// * is_constant: If true, the output is constant within the child frame.
/// * parallel_iterations: The number of iterations allowed to run in parallel.
///
/// Returns:
/// * `Output`: The same tensor as `data`.
class Enter {
public:
/// Optional attribute setters for Enter
struct Attrs {
/// If true, the output is constant within the child frame.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs IsConstant(bool x) {
Attrs ret = *this;
ret.is_constant_ = x;
return ret;
}
/// The number of iterations allowed to run in parallel.
///
/// Defaults to 10
TF_MUST_USE_RESULT Attrs ParallelIterations(int64 x) {
Attrs ret = *this;
ret.parallel_iterations_ = x;
return ret;
}
bool is_constant_ = false;
int64 parallel_iterations_ = 10;
};
Enter(const ::tensorflow::Scope& scope, ::tensorflow::Input data, StringPiece
frame_name);
Enter(const ::tensorflow::Scope& scope, ::tensorflow::Input data, StringPiece
frame_name, const Enter::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs IsConstant(bool x) {
return Attrs().IsConstant(x);
}
static Attrs ParallelIterations(int64 x) {
return Attrs().ParallelIterations(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Exits the current frame to its parent frame.
///
/// Exit makes its input `data` available to the parent frame.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be made available to the parent frame.
///
/// Returns:
/// * `Output`: The same tensor as `data`.
class Exit {
public:
Exit(const ::tensorflow::Scope& scope, ::tensorflow::Input data);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Creates or finds a child frame, and makes `data` available to the child frame.
///
/// The unique `frame_name` is used by the `Executor` to identify frames. If
/// `is_constant` is true, `output` is a constant in the child frame; otherwise
/// it may be changed in the child frame. At most `parallel_iterations` iterations
/// are run in parallel in the child frame.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be made available to the child frame.
/// * frame_name: The name of the child frame.
///
/// Optional attributes (see `Attrs`):
/// * is_constant: If true, the output is constant within the child frame.
/// * parallel_iterations: The number of iterations allowed to run in parallel.
///
/// Returns:
/// * `Output`: The same tensor as `data`.
class RefEnter {
public:
/// Optional attribute setters for RefEnter
struct Attrs {
/// If true, the output is constant within the child frame.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs IsConstant(bool x) {
Attrs ret = *this;
ret.is_constant_ = x;
return ret;
}
/// The number of iterations allowed to run in parallel.
///
/// Defaults to 10
TF_MUST_USE_RESULT Attrs ParallelIterations(int64 x) {
Attrs ret = *this;
ret.parallel_iterations_ = x;
return ret;
}
bool is_constant_ = false;
int64 parallel_iterations_ = 10;
};
RefEnter(const ::tensorflow::Scope& scope, ::tensorflow::Input data,
StringPiece frame_name);
RefEnter(const ::tensorflow::Scope& scope, ::tensorflow::Input data,
StringPiece frame_name, const RefEnter::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs IsConstant(bool x) {
return Attrs().IsConstant(x);
}
static Attrs ParallelIterations(int64 x) {
return Attrs().ParallelIterations(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Exits the current frame to its parent frame.
///
/// Exit makes its input `data` available to the parent frame.
///
/// Arguments:
/// * scope: A Scope object
/// * data: The tensor to be made available to the parent frame.
///
/// Returns:
/// * `Output`: The same tensor as `data`.
class RefExit {
public:
RefExit(const ::tensorflow::Scope& scope, ::tensorflow::Input data);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Forwards the value of an available tensor from `inputs` to `output`.
///
/// `Merge` waits for at least one of the tensors in `inputs` to become available.
/// It is usually combined with `Switch` to implement branching.
///
/// `Merge` forwards the first tensor for become available to `output`, and sets
/// `value_index` to its index in `inputs`.
///
/// Arguments:
/// * scope: A Scope object
/// * inputs: The input tensors, exactly one of which will become available.
///
/// Returns:
/// * `Output` output: Will be set to the available input tensor.
/// * `Output` value_index: The index of the chosen input tensor in `inputs`.
class RefMerge {
public:
RefMerge(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs);
Operation operation;
::tensorflow::Output output;
::tensorflow::Output value_index;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_CONTROL_FLOW_OPS_INTERNAL_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_DATA_FLOW_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_DATA_FLOW_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup data_flow_ops_internal Data Flow Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_DATA_FLOW_OPS_INTERNAL_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,174 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_IMAGE_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_IMAGE_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup image_ops_internal Image Ops Internal
/// @{
/// Computes the gradient of bicubic interpolation.
///
/// Arguments:
/// * scope: A Scope object
/// * grads: 4-D with shape `[batch, height, width, channels]`.
/// * original_image: 4-D with shape `[batch, orig_height, orig_width, channels]`,
/// The image tensor that was resized.
///
/// Optional attributes (see `Attrs`):
/// * align_corners: If true, the centers of the 4 corner pixels of the input and grad tensors are
/// aligned. Defaults to false.
///
/// Returns:
/// * `Output`: 4-D with shape `[batch, orig_height, orig_width, channels]`.
/// Gradients with respect to the input image. Input image must have been
/// float or double.
class ResizeBicubicGrad {
public:
/// Optional attribute setters for ResizeBicubicGrad
struct Attrs {
/// If true, the centers of the 4 corner pixels of the input and grad tensors are
/// aligned. Defaults to false.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs AlignCorners(bool x) {
Attrs ret = *this;
ret.align_corners_ = x;
return ret;
}
bool align_corners_ = false;
};
ResizeBicubicGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input grads,
::tensorflow::Input original_image);
ResizeBicubicGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input grads,
::tensorflow::Input original_image, const
ResizeBicubicGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs AlignCorners(bool x) {
return Attrs().AlignCorners(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes the gradient of bilinear interpolation.
///
/// Arguments:
/// * scope: A Scope object
/// * grads: 4-D with shape `[batch, height, width, channels]`.
/// * original_image: 4-D with shape `[batch, orig_height, orig_width, channels]`,
/// The image tensor that was resized.
///
/// Optional attributes (see `Attrs`):
/// * align_corners: If true, the centers of the 4 corner pixels of the input and grad tensors are
/// aligned. Defaults to false.
///
/// Returns:
/// * `Output`: 4-D with shape `[batch, orig_height, orig_width, channels]`.
/// Gradients with respect to the input image. Input image must have been
/// float or double.
class ResizeBilinearGrad {
public:
/// Optional attribute setters for ResizeBilinearGrad
struct Attrs {
/// If true, the centers of the 4 corner pixels of the input and grad tensors are
/// aligned. Defaults to false.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs AlignCorners(bool x) {
Attrs ret = *this;
ret.align_corners_ = x;
return ret;
}
bool align_corners_ = false;
};
ResizeBilinearGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input grads,
::tensorflow::Input original_image);
ResizeBilinearGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input grads,
::tensorflow::Input original_image, const
ResizeBilinearGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs AlignCorners(bool x) {
return Attrs().AlignCorners(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes the gradient of nearest neighbor interpolation.
///
/// Arguments:
/// * scope: A Scope object
/// * grads: 4-D with shape `[batch, height, width, channels]`.
/// * size: = A 1-D int32 Tensor of 2 elements: `orig_height, orig_width`. The
/// original input size.
///
/// Optional attributes (see `Attrs`):
/// * align_corners: If true, the centers of the 4 corner pixels of the input and grad tensors are
/// aligned. Defaults to false.
///
/// Returns:
/// * `Output`: 4-D with shape `[batch, orig_height, orig_width, channels]`. Gradients
/// with respect to the input image.
class ResizeNearestNeighborGrad {
public:
/// Optional attribute setters for ResizeNearestNeighborGrad
struct Attrs {
/// If true, the centers of the 4 corner pixels of the input and grad tensors are
/// aligned. Defaults to false.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs AlignCorners(bool x) {
Attrs ret = *this;
ret.align_corners_ = x;
return ret;
}
bool align_corners_ = false;
};
ResizeNearestNeighborGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
grads, ::tensorflow::Input size);
ResizeNearestNeighborGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
grads, ::tensorflow::Input size, const
ResizeNearestNeighborGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs AlignCorners(bool x) {
return Attrs().AlignCorners(x);
}
Operation operation;
::tensorflow::Output output;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_IMAGE_OPS_INTERNAL_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_IO_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_IO_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup io_ops_internal Io Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_IO_OPS_INTERNAL_H_
@@ -0,0 +1,601 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_LINALG_OPS_H_
#define TENSORFLOW_CC_OPS_LINALG_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup linalg_ops Linalg Ops
/// @{
/// Computes the Cholesky decomposition of one or more square matrices.
///
/// The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
/// form square matrices.
///
/// The input has to be symmetric and positive definite. Only the lower-triangular
/// part of the input will be used for this operation. The upper-triangular part
/// will not be read.
///
/// The output is a tensor of the same shape as the input
/// containing the Cholesky decompositions for all input submatrices `[..., :, :]`.
///
/// **Note**: The gradient computation on GPU is faster for large matrices but
/// not for large batch dimensions when the submatrices are small. In this
/// case it might be faster to use the CPU.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Shape is `[..., M, M]`.
///
/// Returns:
/// * `Output`: Shape is `[..., M, M]`.
class Cholesky {
public:
Cholesky(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Computes the reverse mode backpropagated gradient of the Cholesky algorithm.
///
/// For an explanation see "Differentiation of the Cholesky algorithm" by
/// Iain Murray http://arxiv.org/abs/1602.07527.
///
/// Arguments:
/// * scope: A Scope object
/// * l: Output of batch Cholesky algorithm l = cholesky(A). Shape is `[..., M, M]`.
/// Algorithm depends only on lower triangular part of the innermost matrices of
/// this tensor.
/// * grad: df/dl where f is some scalar function. Shape is `[..., M, M]`.
/// Algorithm depends only on lower triangular part of the innermost matrices of
/// this tensor.
///
/// Returns:
/// * `Output`: Symmetrized version of df/dA . Shape is `[..., M, M]`
class CholeskyGrad {
public:
CholeskyGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input l,
::tensorflow::Input grad);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Computes the sign and the log of the absolute value of the determinant of
///
/// one or more square matrices.
///
/// The input is a tensor of shape `[N, M, M]` whose inner-most 2 dimensions
/// form square matrices. The outputs are two tensors containing the signs and
/// absolute values of the log determinants for all N input submatrices
/// `[..., :, :]` such that the determinant = sign*exp(log_abs_determinant).
/// The log_abs_determinant is computed as det(P)*sum(log(diag(LU))) where LU
/// is the LU decomposition of the input and P is the corresponding
/// permutation matrix.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Shape is `[N, M, M]`.
///
/// Returns:
/// * `Output` sign: The signs of the log determinants of the inputs. Shape is `[N]`.
/// * `Output` log_abs_determinant: The logs of the absolute values of the determinants
/// of the N input matrices. Shape is `[N]`.
class LogMatrixDeterminant {
public:
LogMatrixDeterminant(const ::tensorflow::Scope& scope, ::tensorflow::Input
input);
Operation operation;
::tensorflow::Output sign;
::tensorflow::Output log_abs_determinant;
};
/// Computes the determinant of one or more square matrices.
///
/// The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
/// form square matrices. The output is a tensor containing the determinants
/// for all input submatrices `[..., :, :]`.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Shape is `[..., M, M]`.
///
/// Returns:
/// * `Output`: Shape is `[...]`.
class MatrixDeterminant {
public:
MatrixDeterminant(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Computes the inverse of one or more square invertible matrices or their
///
/// adjoints (conjugate transposes).
///
/// The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
/// form square matrices. The output is a tensor of the same shape as the input
/// containing the inverse for all input submatrices `[..., :, :]`.
///
/// The op uses LU decomposition with partial pivoting to compute the inverses.
///
/// If a matrix is not invertible there is no guarantee what the op does. It
/// may detect the condition and raise an exception or it may simply return a
/// garbage result.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Shape is `[..., M, M]`.
///
/// Returns:
/// * `Output`: Shape is `[..., M, M]`.
///
/// @compatibility(numpy)
/// Equivalent to np.linalg.inv
/// @end_compatibility
class MatrixInverse {
public:
/// Optional attribute setters for MatrixInverse
struct Attrs {
/// Defaults to false
TF_MUST_USE_RESULT Attrs Adjoint(bool x) {
Attrs ret = *this;
ret.adjoint_ = x;
return ret;
}
bool adjoint_ = false;
};
MatrixInverse(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
MatrixInverse(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
const MatrixInverse::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Adjoint(bool x) {
return Attrs().Adjoint(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Solves systems of linear equations.
///
/// `Matrix` is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
/// form square matrices. `Rhs` is a tensor of shape `[..., M, K]`. The `output` is
/// a tensor shape `[..., M, K]`. If `adjoint` is `False` then each output matrix
/// satisfies `matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]`.
/// If `adjoint` is `True` then each output matrix satisfies
/// `adjoint(matrix[..., :, :]) * output[..., :, :] = rhs[..., :, :]`.
///
/// Arguments:
/// * scope: A Scope object
/// * matrix: Shape is `[..., M, M]`.
/// * rhs: Shape is `[..., M, K]`.
///
/// Optional attributes (see `Attrs`):
/// * adjoint: Boolean indicating whether to solve with `matrix` or its (block-wise)
/// adjoint.
///
/// Returns:
/// * `Output`: Shape is `[..., M, K]`.
class MatrixSolve {
public:
/// Optional attribute setters for MatrixSolve
struct Attrs {
/// Boolean indicating whether to solve with `matrix` or its (block-wise)
/// adjoint.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Adjoint(bool x) {
Attrs ret = *this;
ret.adjoint_ = x;
return ret;
}
bool adjoint_ = false;
};
MatrixSolve(const ::tensorflow::Scope& scope, ::tensorflow::Input matrix,
::tensorflow::Input rhs);
MatrixSolve(const ::tensorflow::Scope& scope, ::tensorflow::Input matrix,
::tensorflow::Input rhs, const MatrixSolve::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Adjoint(bool x) {
return Attrs().Adjoint(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Solves one or more linear least-squares problems.
///
/// `matrix` is a tensor of shape `[..., M, N]` whose inner-most 2 dimensions
/// form real or complex matrices of size `[M, N]`. `Rhs` is a tensor of the same
/// type as `matrix` and shape `[..., M, K]`.
/// The output is a tensor shape `[..., N, K]` where each output matrix solves
/// each of the equations
/// `matrix[..., :, :]` * `output[..., :, :]` = `rhs[..., :, :]`
/// in the least squares sense.
///
/// We use the following notation for (complex) matrix and right-hand sides
/// in the batch:
///
/// `matrix`=\\(A \in \mathbb{C}^{m \times n}\\),
/// `rhs`=\\(B \in \mathbb{C}^{m \times k}\\),
/// `output`=\\(X \in \mathbb{C}^{n \times k}\\),
/// `l2_regularizer`=\\(\lambda \in \mathbb{R}\\).
///
/// If `fast` is `True`, then the solution is computed by solving the normal
/// equations using Cholesky decomposition. Specifically, if \\(m \ge n\\) then
/// \\(X = (A^H A + \lambda I)^{-1} A^H B\\), which solves the least-squares
/// problem \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k} } ||A Z - B||_F^2 + \lambda ||Z||_F^2\\).
/// If \\(m \lt n\\) then `output` is computed as
/// \\(X = A^H (A A^H + \lambda I)^{-1} B\\), which (for \\(\lambda = 0\\)) is the
/// minimum-norm solution to the under-determined linear system, i.e.
/// \\(X = \mathrm{argmin}_{Z \in \mathbb{C}^{n \times k} } ||Z||_F^2 \\),
/// subject to \\(A Z = B\\). Notice that the fast path is only numerically stable
/// when \\(A\\) is numerically full rank and has a condition number
/// \\(\mathrm{cond}(A) \lt \frac{1}{\sqrt{\epsilon_{mach} } }\\) or \\(\lambda\\) is
/// sufficiently large.
///
/// If `fast` is `False` an algorithm based on the numerically robust complete
/// orthogonal decomposition is used. This computes the minimum-norm
/// least-squares solution, even when \\(A\\) is rank deficient. This path is
/// typically 6-7 times slower than the fast path. If `fast` is `False` then
/// `l2_regularizer` is ignored.
///
/// Arguments:
/// * scope: A Scope object
/// * matrix: Shape is `[..., M, N]`.
/// * rhs: Shape is `[..., M, K]`.
/// * l2_regularizer: Scalar tensor.
///
/// @compatibility(numpy)
/// Equivalent to np.linalg.lstsq
/// @end_compatibility
///
/// Returns:
/// * `Output`: Shape is `[..., N, K]`.
class MatrixSolveLs {
public:
/// Optional attribute setters for MatrixSolveLs
struct Attrs {
/// Defaults to true
TF_MUST_USE_RESULT Attrs Fast(bool x) {
Attrs ret = *this;
ret.fast_ = x;
return ret;
}
bool fast_ = true;
};
MatrixSolveLs(const ::tensorflow::Scope& scope, ::tensorflow::Input matrix,
::tensorflow::Input rhs, ::tensorflow::Input l2_regularizer);
MatrixSolveLs(const ::tensorflow::Scope& scope, ::tensorflow::Input matrix,
::tensorflow::Input rhs, ::tensorflow::Input l2_regularizer,
const MatrixSolveLs::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Fast(bool x) {
return Attrs().Fast(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Solves systems of linear equations with upper or lower triangular matrices by
///
/// backsubstitution.
///
/// `matrix` is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions form
/// square matrices. If `lower` is `True` then the strictly upper triangular part
/// of each inner-most matrix is assumed to be zero and not accessed.
/// If `lower` is False then the strictly lower triangular part of each inner-most
/// matrix is assumed to be zero and not accessed.
/// `rhs` is a tensor of shape `[..., M, K]`.
///
/// The output is a tensor of shape `[..., M, K]`. If `adjoint` is
/// `True` then the innermost matrices in `output` satisfy matrix equations
/// `matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]`.
/// If `adjoint` is `False` then the strictly then the innermost matrices in
/// `output` satisfy matrix equations
/// `adjoint(matrix[..., i, k]) * output[..., k, j] = rhs[..., i, j]`.
///
/// Arguments:
/// * scope: A Scope object
/// * matrix: Shape is `[..., M, M]`.
/// * rhs: Shape is `[..., M, K]`.
///
/// Optional attributes (see `Attrs`):
/// * lower: Boolean indicating whether the innermost matrices in `matrix` are
/// lower or upper triangular.
/// * adjoint: Boolean indicating whether to solve with `matrix` or its (block-wise)
/// adjoint.
///
/// @compatibility(numpy)
/// Equivalent to scipy.linalg.solve_triangular
/// @end_compatibility
///
/// Returns:
/// * `Output`: Shape is `[..., M, K]`.
class MatrixTriangularSolve {
public:
/// Optional attribute setters for MatrixTriangularSolve
struct Attrs {
/// Boolean indicating whether the innermost matrices in `matrix` are
/// lower or upper triangular.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs Lower(bool x) {
Attrs ret = *this;
ret.lower_ = x;
return ret;
}
/// Boolean indicating whether to solve with `matrix` or its (block-wise)
/// adjoint.
///
/// @compatibility(numpy)
/// Equivalent to scipy.linalg.solve_triangular
/// @end_compatibility
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Adjoint(bool x) {
Attrs ret = *this;
ret.adjoint_ = x;
return ret;
}
bool lower_ = true;
bool adjoint_ = false;
};
MatrixTriangularSolve(const ::tensorflow::Scope& scope, ::tensorflow::Input
matrix, ::tensorflow::Input rhs);
MatrixTriangularSolve(const ::tensorflow::Scope& scope, ::tensorflow::Input
matrix, ::tensorflow::Input rhs, const
MatrixTriangularSolve::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Lower(bool x) {
return Attrs().Lower(x);
}
static Attrs Adjoint(bool x) {
return Attrs().Adjoint(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes the QR decompositions of one or more matrices.
///
/// Computes the QR decomposition of each inner matrix in `tensor` such that
/// `tensor[..., :, :] = q[..., :, :] * r[..., :,:])`
///
/// ```python
/// # a is a tensor.
/// # q is a tensor of orthonormal matrices.
/// # r is a tensor of upper triangular matrices.
/// q, r = qr(a)
/// q_full, r_full = qr(a, full_matrices=True)
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * input: A tensor of shape `[..., M, N]` whose inner-most 2 dimensions
/// form matrices of size `[M, N]`. Let `P` be the minimum of `M` and `N`.
///
/// Optional attributes (see `Attrs`):
/// * full_matrices: If true, compute full-sized `q` and `r`. If false
/// (the default), compute only the leading `P` columns of `q`.
///
/// Returns:
/// * `Output` q: Orthonormal basis for range of `a`. If `full_matrices` is `False` then
/// shape is `[..., M, P]`; if `full_matrices` is `True` then shape is
/// `[..., M, M]`.
/// * `Output` r: Triangular factor. If `full_matrices` is `False` then shape is
/// `[..., P, N]`. If `full_matrices` is `True` then shape is `[..., M, N]`.
class Qr {
public:
/// Optional attribute setters for Qr
struct Attrs {
/// If true, compute full-sized `q` and `r`. If false
/// (the default), compute only the leading `P` columns of `q`.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs FullMatrices(bool x) {
Attrs ret = *this;
ret.full_matrices_ = x;
return ret;
}
bool full_matrices_ = false;
};
Qr(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
Qr(const ::tensorflow::Scope& scope, ::tensorflow::Input input, const
Qr::Attrs& attrs);
static Attrs FullMatrices(bool x) {
return Attrs().FullMatrices(x);
}
Operation operation;
::tensorflow::Output q;
::tensorflow::Output r;
};
/// Computes the eigen decomposition of one or more square self-adjoint matrices.
///
/// Computes the eigenvalues and (optionally) eigenvectors of each inner matrix in
/// `input` such that `input[..., :, :] = v[..., :, :] * diag(e[..., :])`. The eigenvalues
/// are sorted in non-decreasing order.
///
/// ```python
/// # a is a tensor.
/// # e is a tensor of eigenvalues.
/// # v is a tensor of eigenvectors.
/// e, v = self_adjoint_eig(a)
/// e = self_adjoint_eig(a, compute_v=False)
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * input: `Tensor` input of shape `[N, N]`.
///
/// Optional attributes (see `Attrs`):
/// * compute_v: If `True` then eigenvectors will be computed and returned in `v`.
/// Otherwise, only the eigenvalues will be computed.
///
/// Returns:
/// * `Output` e: Eigenvalues. Shape is `[N]`.
/// * `Output` v: Eigenvectors. Shape is `[N, N]`.
class SelfAdjointEig {
public:
/// Optional attribute setters for SelfAdjointEig
struct Attrs {
/// If `True` then eigenvectors will be computed and returned in `v`.
/// Otherwise, only the eigenvalues will be computed.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs ComputeV(bool x) {
Attrs ret = *this;
ret.compute_v_ = x;
return ret;
}
bool compute_v_ = true;
};
SelfAdjointEig(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
SelfAdjointEig(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
const SelfAdjointEig::Attrs& attrs);
static Attrs ComputeV(bool x) {
return Attrs().ComputeV(x);
}
Operation operation;
::tensorflow::Output e;
::tensorflow::Output v;
};
/// Computes the singular value decompositions of one or more matrices.
///
/// Computes the SVD of each inner matrix in `input` such that
/// `input[..., :, :] = u[..., :, :] * diag(s[..., :, :]) * transpose(v[..., :, :])`
///
/// ```python
/// # a is a tensor containing a batch of matrices.
/// # s is a tensor of singular values for each matrix.
/// # u is the tensor containing of left singular vectors for each matrix.
/// # v is the tensor containing of right singular vectors for each matrix.
/// s, u, v = svd(a)
/// s, _, _ = svd(a, compute_uv=False)
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * input: A tensor of shape `[..., M, N]` whose inner-most 2 dimensions
/// form matrices of size `[M, N]`. Let `P` be the minimum of `M` and `N`.
///
/// Optional attributes (see `Attrs`):
/// * compute_uv: If true, left and right singular vectors will be
/// computed and returned in `u` and `v`, respectively.
/// If false, `u` and `v` are not set and should never referenced.
/// * full_matrices: If true, compute full-sized `u` and `v`. If false
/// (the default), compute only the leading `P` singular vectors.
/// Ignored if `compute_uv` is `False`.
///
/// Returns:
/// * `Output` s: Singular values. Shape is `[..., P]`.
/// * `Output` u: Left singular vectors. If `full_matrices` is `False` then shape is
/// `[..., M, P]`; if `full_matrices` is `True` then shape is
/// `[..., M, M]`. Undefined if `compute_uv` is `False`.
/// * `Output` v: Left singular vectors. If `full_matrices` is `False` then shape is
/// `[..., N, P]`. If `full_matrices` is `True` then shape is `[..., N, N]`.
/// Undefined if `compute_uv` is false.
class Svd {
public:
/// Optional attribute setters for Svd
struct Attrs {
/// If true, left and right singular vectors will be
/// computed and returned in `u` and `v`, respectively.
/// If false, `u` and `v` are not set and should never referenced.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs ComputeUv(bool x) {
Attrs ret = *this;
ret.compute_uv_ = x;
return ret;
}
/// If true, compute full-sized `u` and `v`. If false
/// (the default), compute only the leading `P` singular vectors.
/// Ignored if `compute_uv` is `False`.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs FullMatrices(bool x) {
Attrs ret = *this;
ret.full_matrices_ = x;
return ret;
}
bool compute_uv_ = true;
bool full_matrices_ = false;
};
Svd(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
Svd(const ::tensorflow::Scope& scope, ::tensorflow::Input input, const
Svd::Attrs& attrs);
static Attrs ComputeUv(bool x) {
return Attrs().ComputeUv(x);
}
static Attrs FullMatrices(bool x) {
return Attrs().FullMatrices(x);
}
Operation operation;
::tensorflow::Output s;
::tensorflow::Output u;
::tensorflow::Output v;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_LINALG_OPS_H_
@@ -0,0 +1,67 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_LINALG_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_LINALG_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup linalg_ops_internal Linalg Ops Internal
/// @{
/// Computes the matrix logarithm of one or more square matrices:
///
///
/// \\(log(exp(A)) = A\\)
///
/// This op is only defined for complex matrices. If A is positive-definite and
/// real, then casting to a complex matrix, taking the logarithm and casting back
/// to a real matrix will give the correct result.
///
/// This function computes the matrix logarithm using the Schur-Parlett algorithm.
/// Details of the algorithm can be found in Section 11.6.2 of:
/// Nicholas J. Higham, Functions of Matrices: Theory and Computation, SIAM 2008.
/// ISBN 978-0-898716-46-7.
///
/// The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
/// form square matrices. The output is a tensor of the same shape as the input
/// containing the exponential for all input submatrices `[..., :, :]`.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Shape is `[..., M, M]`.
///
/// Returns:
/// * `Output`: Shape is `[..., M, M]`.
///
/// @compatibility(scipy)
/// Equivalent to scipy.linalg.logm
/// @end_compatibility
class MatrixLogarithm {
public:
MatrixLogarithm(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_LINALG_OPS_INTERNAL_H_
@@ -0,0 +1,530 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_LOGGING_OPS_H_
#define TENSORFLOW_CC_OPS_LOGGING_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup logging_ops Logging Ops
/// @{
/// Asserts that the given condition is true.
///
/// If `condition` evaluates to false, print the list of tensors in `data`.
/// `summarize` determines how many entries of the tensors to print.
///
/// Arguments:
/// * scope: A Scope object
/// * condition: The condition to evaluate.
/// * data: The tensors to print out when condition is false.
///
/// Optional attributes (see `Attrs`):
/// * summarize: Print this many entries of each tensor.
///
/// Returns:
/// * the created `Operation`
class Assert {
public:
/// Optional attribute setters for Assert
struct Attrs {
/// Print this many entries of each tensor.
///
/// Defaults to 3
TF_MUST_USE_RESULT Attrs Summarize(int64 x) {
Attrs ret = *this;
ret.summarize_ = x;
return ret;
}
int64 summarize_ = 3;
};
Assert(const ::tensorflow::Scope& scope, ::tensorflow::Input condition,
::tensorflow::InputList data);
Assert(const ::tensorflow::Scope& scope, ::tensorflow::Input condition,
::tensorflow::InputList data, const Assert::Attrs& attrs);
operator ::tensorflow::Operation() const { return operation; }
static Attrs Summarize(int64 x) {
return Attrs().Summarize(x);
}
Operation operation;
};
/// Outputs a `Summary` protocol buffer with audio.
///
/// The summary has up to `max_outputs` summary values containing audio. The
/// audio is built from `tensor` which must be 3-D with shape `[batch_size,
/// frames, channels]` or 2-D with shape `[batch_size, frames]`. The values are
/// assumed to be in the range of `[-1.0, 1.0]` with a sample rate of `sample_rate`.
///
/// The `tag` argument is a scalar `Tensor` of type `string`. It is used to
/// build the `tag` of the summary values:
///
/// * If `max_outputs` is 1, the summary value tag is '*tag*/audio'.
/// * If `max_outputs` is greater than 1, the summary value tags are
/// generated sequentially as '*tag*/audio/0', '*tag*/audio/1', etc.
///
/// Arguments:
/// * scope: A Scope object
/// * tag: Scalar. Used to build the `tag` attribute of the summary values.
/// * tensor: 2-D of shape `[batch_size, frames]`.
/// * sample_rate: The sample rate of the signal in hertz.
///
/// Optional attributes (see `Attrs`):
/// * max_outputs: Max number of batch elements to generate audio for.
///
/// Returns:
/// * `Output`: Scalar. Serialized `Summary` protocol buffer.
class AudioSummary {
public:
/// Optional attribute setters for AudioSummary
struct Attrs {
/// Max number of batch elements to generate audio for.
///
/// Defaults to 3
TF_MUST_USE_RESULT Attrs MaxOutputs(int64 x) {
Attrs ret = *this;
ret.max_outputs_ = x;
return ret;
}
int64 max_outputs_ = 3;
};
AudioSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tag,
::tensorflow::Input tensor, ::tensorflow::Input sample_rate);
AudioSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tag,
::tensorflow::Input tensor, ::tensorflow::Input sample_rate, const
AudioSummary::Attrs& attrs);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
static Attrs MaxOutputs(int64 x) {
return Attrs().MaxOutputs(x);
}
Operation operation;
::tensorflow::Output summary;
};
/// Outputs a `Summary` protocol buffer with a histogram.
///
/// The generated
/// [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
/// has one summary value containing a histogram for `values`.
///
/// This op reports an `InvalidArgument` error if any value is not finite.
///
/// Arguments:
/// * scope: A Scope object
/// * tag: Scalar. Tag to use for the `Summary.Value`.
/// * values: Any shape. Values to use to build the histogram.
///
/// Returns:
/// * `Output`: Scalar. Serialized `Summary` protocol buffer.
class HistogramSummary {
public:
HistogramSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tag,
::tensorflow::Input values);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
Operation operation;
::tensorflow::Output summary;
};
/// Outputs a `Summary` protocol buffer with images.
///
/// The summary has up to `max_images` summary values containing images. The
/// images are built from `tensor` which must be 4-D with shape `[batch_size,
/// height, width, channels]` and where `channels` can be:
///
/// * 1: `tensor` is interpreted as Grayscale.
/// * 3: `tensor` is interpreted as RGB.
/// * 4: `tensor` is interpreted as RGBA.
///
/// The images have the same number of channels as the input tensor. For float
/// input, the values are normalized one image at a time to fit in the range
/// `[0, 255]`. `uint8` values are unchanged. The op uses two different
/// normalization algorithms:
///
/// * If the input values are all positive, they are rescaled so the largest one
/// is 255.
///
/// * If any input value is negative, the values are shifted so input value 0.0
/// is at 127. They are then rescaled so that either the smallest value is 0,
/// or the largest one is 255.
///
/// The `tag` argument is a scalar `Tensor` of type `string`. It is used to
/// build the `tag` of the summary values:
///
/// * If `max_images` is 1, the summary value tag is '*tag*/image'.
/// * If `max_images` is greater than 1, the summary value tags are
/// generated sequentially as '*tag*/image/0', '*tag*/image/1', etc.
///
/// The `bad_color` argument is the color to use in the generated images for
/// non-finite input values. It is a `uint8` 1-D tensor of length `channels`.
/// Each element must be in the range `[0, 255]` (It represents the value of a
/// pixel in the output image). Non-finite values in the input tensor are
/// replaced by this tensor in the output image. The default value is the color
/// red.
///
/// Arguments:
/// * scope: A Scope object
/// * tag: Scalar. Used to build the `tag` attribute of the summary values.
/// * tensor: 4-D of shape `[batch_size, height, width, channels]` where
/// `channels` is 1, 3, or 4.
///
/// Optional attributes (see `Attrs`):
/// * max_images: Max number of batch elements to generate images for.
/// * bad_color: Color to use for pixels with non-finite values.
///
/// Returns:
/// * `Output`: Scalar. Serialized `Summary` protocol buffer.
class ImageSummary {
public:
/// Optional attribute setters for ImageSummary
struct Attrs {
/// Max number of batch elements to generate images for.
///
/// Defaults to 3
TF_MUST_USE_RESULT Attrs MaxImages(int64 x) {
Attrs ret = *this;
ret.max_images_ = x;
return ret;
}
/// Color to use for pixels with non-finite values.
///
/// Defaults to Tensor<type: uint8 shape: [4] values: 255 0 0...>
TF_MUST_USE_RESULT Attrs BadColor(const TensorProto& x) {
Attrs ret = *this;
ret.bad_color_ = x;
return ret;
}
int64 max_images_ = 3;
TensorProto bad_color_ = Input::Initializer({255, 0, 0, 255}, {4}).AsTensorProto();
};
ImageSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tag,
::tensorflow::Input tensor);
ImageSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tag,
::tensorflow::Input tensor, const ImageSummary::Attrs& attrs);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
static Attrs MaxImages(int64 x) {
return Attrs().MaxImages(x);
}
static Attrs BadColor(const TensorProto& x) {
return Attrs().BadColor(x);
}
Operation operation;
::tensorflow::Output summary;
};
/// Merges summaries.
///
/// This op creates a
/// [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
/// protocol buffer that contains the union of all the values in the input
/// summaries.
///
/// When the Op is run, it reports an `InvalidArgument` error if multiple values
/// in the summaries to merge use the same tag.
///
/// Arguments:
/// * scope: A Scope object
/// * inputs: Can be of any shape. Each must contain serialized `Summary` protocol
/// buffers.
///
/// Returns:
/// * `Output`: Scalar. Serialized `Summary` protocol buffer.
class MergeSummary {
public:
MergeSummary(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
Operation operation;
::tensorflow::Output summary;
};
/// Prints a list of tensors.
///
/// Passes `input` through to `output` and prints `data` when evaluating.
///
/// Arguments:
/// * scope: A Scope object
/// * input: The tensor passed to `output`
/// * data: A list of tensors to print out when op is evaluated.
///
/// Optional attributes (see `Attrs`):
/// * message: A string, prefix of the error message.
/// * first_n: Only log `first_n` number of times. -1 disables logging.
/// * summarize: Only print this many entries of each tensor.
///
/// Returns:
/// * `Output`: = The unmodified `input` tensor
class Print {
public:
/// Optional attribute setters for Print
struct Attrs {
/// A string, prefix of the error message.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Message(StringPiece x) {
Attrs ret = *this;
ret.message_ = x;
return ret;
}
/// Only log `first_n` number of times. -1 disables logging.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs FirstN(int64 x) {
Attrs ret = *this;
ret.first_n_ = x;
return ret;
}
/// Only print this many entries of each tensor.
///
/// Defaults to 3
TF_MUST_USE_RESULT Attrs Summarize(int64 x) {
Attrs ret = *this;
ret.summarize_ = x;
return ret;
}
StringPiece message_ = "";
int64 first_n_ = -1;
int64 summarize_ = 3;
};
Print(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::InputList data);
Print(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::InputList data, const Print::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Message(StringPiece x) {
return Attrs().Message(x);
}
static Attrs FirstN(int64 x) {
return Attrs().FirstN(x);
}
static Attrs Summarize(int64 x) {
return Attrs().Summarize(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Prints a string scalar.
///
/// Prints a string scalar to the desired output_stream.
///
/// Arguments:
/// * scope: A Scope object
/// * input: The string scalar to print.
///
/// Optional attributes (see `Attrs`):
/// * output_stream: A string specifying the output stream or logging level to print to.
///
/// Returns:
/// * the created `Operation`
class PrintV2 {
public:
/// Optional attribute setters for PrintV2
struct Attrs {
/// A string specifying the output stream or logging level to print to.
///
/// Defaults to "stderr"
TF_MUST_USE_RESULT Attrs OutputStream(StringPiece x) {
Attrs ret = *this;
ret.output_stream_ = x;
return ret;
}
StringPiece output_stream_ = "stderr";
};
PrintV2(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
PrintV2(const ::tensorflow::Scope& scope, ::tensorflow::Input input, const
PrintV2::Attrs& attrs);
operator ::tensorflow::Operation() const { return operation; }
static Attrs OutputStream(StringPiece x) {
return Attrs().OutputStream(x);
}
Operation operation;
};
/// Outputs a `Summary` protocol buffer with scalar values.
///
/// The input `tags` and `values` must have the same shape. The generated summary
/// has a summary value for each tag-value pair in `tags` and `values`.
///
/// Arguments:
/// * scope: A Scope object
/// * tags: Tags for the summary.
/// * values: Same shape as `tags. Values for the summary.
///
/// Returns:
/// * `Output`: Scalar. Serialized `Summary` protocol buffer.
class ScalarSummary {
public:
ScalarSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tags,
::tensorflow::Input values);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
Operation operation;
::tensorflow::Output summary;
};
/// Outputs a `Summary` protocol buffer with a tensor.
///
/// This op is being phased out in favor of TensorSummaryV2, which lets callers pass
/// a tag as well as a serialized SummaryMetadata proto string that contains
/// plugin-specific data. We will keep this op to maintain backwards compatibility.
///
/// Arguments:
/// * scope: A Scope object
/// * tensor: A tensor to serialize.
///
/// Optional attributes (see `Attrs`):
/// * description: A json-encoded SummaryDescription proto.
/// * labels: An unused list of strings.
/// * display_name: An unused string.
///
/// Returns:
/// * `Output`: The summary tensor.
class TensorSummary {
public:
/// Optional attribute setters for TensorSummary
struct Attrs {
/// A json-encoded SummaryDescription proto.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Description(StringPiece x) {
Attrs ret = *this;
ret.description_ = x;
return ret;
}
/// An unused list of strings.
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs Labels(const gtl::ArraySlice<string>& x) {
Attrs ret = *this;
ret.labels_ = x;
return ret;
}
/// An unused string.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs DisplayName(StringPiece x) {
Attrs ret = *this;
ret.display_name_ = x;
return ret;
}
StringPiece description_ = "";
gtl::ArraySlice<string> labels_ = {};
StringPiece display_name_ = "";
};
TensorSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tensor);
TensorSummary(const ::tensorflow::Scope& scope, ::tensorflow::Input tensor,
const TensorSummary::Attrs& attrs);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
static Attrs Description(StringPiece x) {
return Attrs().Description(x);
}
static Attrs Labels(const gtl::ArraySlice<string>& x) {
return Attrs().Labels(x);
}
static Attrs DisplayName(StringPiece x) {
return Attrs().DisplayName(x);
}
Operation operation;
::tensorflow::Output summary;
};
/// Outputs a `Summary` protocol buffer with a tensor and per-plugin data.
///
/// Arguments:
/// * scope: A Scope object
/// * tag: A string attached to this summary. Used for organization in TensorBoard.
/// * tensor: A tensor to serialize.
/// * serialized_summary_metadata: A serialized SummaryMetadata proto. Contains plugin
/// data.
///
/// Returns:
/// * `Output`: The summary tensor.
class TensorSummaryV2 {
public:
TensorSummaryV2(const ::tensorflow::Scope& scope, ::tensorflow::Input tag,
::tensorflow::Input tensor, ::tensorflow::Input
serialized_summary_metadata);
operator ::tensorflow::Output() const { return summary; }
operator ::tensorflow::Input() const { return summary; }
::tensorflow::Node* node() const { return summary.node(); }
Operation operation;
::tensorflow::Output summary;
};
/// Provides the time since epoch in seconds.
///
/// Returns the timestamp as a `float64` for seconds since the Unix epoch.
///
/// Note: the timestamp is computed when the op is executed, not when it is added
/// to the graph.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The ts tensor.
class Timestamp {
public:
Timestamp(const ::tensorflow::Scope& scope);
operator ::tensorflow::Output() const { return ts; }
operator ::tensorflow::Input() const { return ts; }
::tensorflow::Node* node() const { return ts.node(); }
Operation operation;
::tensorflow::Output ts;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_LOGGING_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_LOGGING_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_LOGGING_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup logging_ops_internal Logging Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_LOGGING_OPS_INTERNAL_H_
@@ -0,0 +1,610 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_LOOKUP_OPS_H_
#define TENSORFLOW_CC_OPS_LOOKUP_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup lookup_ops Lookup Ops
/// @{
/// Creates a non-initialized hash table.
///
/// This op creates a hash table, specifying the type of its keys and values.
/// Before using the table you will have to initialize it. After initialization the
/// table will be immutable.
///
/// Arguments:
/// * scope: A Scope object
/// * key_dtype: Type of the table keys.
/// * value_dtype: Type of the table values.
///
/// Optional attributes (see `Attrs`):
/// * container: If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
/// * shared_name: If non-empty, this table is shared under the given name across
/// multiple sessions.
/// * use_node_name_sharing: If true and shared_name is empty, the table is shared
/// using the node name.
///
/// Returns:
/// * `Output`: Handle to a table.
class HashTable {
public:
/// Optional attribute setters for HashTable
struct Attrs {
/// If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Container(StringPiece x) {
Attrs ret = *this;
ret.container_ = x;
return ret;
}
/// If non-empty, this table is shared under the given name across
/// multiple sessions.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs SharedName(StringPiece x) {
Attrs ret = *this;
ret.shared_name_ = x;
return ret;
}
/// If true and shared_name is empty, the table is shared
/// using the node name.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs UseNodeNameSharing(bool x) {
Attrs ret = *this;
ret.use_node_name_sharing_ = x;
return ret;
}
StringPiece container_ = "";
StringPiece shared_name_ = "";
bool use_node_name_sharing_ = false;
};
HashTable(const ::tensorflow::Scope& scope, DataType key_dtype, DataType
value_dtype);
HashTable(const ::tensorflow::Scope& scope, DataType key_dtype, DataType
value_dtype, const HashTable::Attrs& attrs);
operator ::tensorflow::Output() const { return table_handle; }
operator ::tensorflow::Input() const { return table_handle; }
::tensorflow::Node* node() const { return table_handle.node(); }
static Attrs Container(StringPiece x) {
return Attrs().Container(x);
}
static Attrs SharedName(StringPiece x) {
return Attrs().SharedName(x);
}
static Attrs UseNodeNameSharing(bool x) {
return Attrs().UseNodeNameSharing(x);
}
Operation operation;
::tensorflow::Output table_handle;
};
/// Initializes a table from a text file.
///
/// It inserts one key-value pair into the table for each line of the file.
/// The key and value is extracted from the whole line content, elements from the
/// split line based on `delimiter` or the line number (starting from zero).
/// Where to extract the key and value from a line is specified by `key_index` and
/// `value_index`.
///
/// - A value of -1 means use the line number(starting from zero), expects `int64`.
/// - A value of -2 means use the whole line content, expects `string`.
/// - A value >= 0 means use the index (starting at zero) of the split line based
/// on `delimiter`.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to a table which will be initialized.
/// * filename: Filename of a vocabulary text file.
/// * key_index: Column index in a line to get the table `key` values from.
/// * value_index: Column index that represents information of a line to get the table
/// `value` values from.
///
/// Optional attributes (see `Attrs`):
/// * vocab_size: Number of elements of the file, use -1 if unknown.
/// * delimiter: Delimiter to separate fields in a line.
///
/// Returns:
/// * the created `Operation`
class InitializeTableFromTextFile {
public:
/// Optional attribute setters for InitializeTableFromTextFile
struct Attrs {
/// Number of elements of the file, use -1 if unknown.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs VocabSize(int64 x) {
Attrs ret = *this;
ret.vocab_size_ = x;
return ret;
}
/// Delimiter to separate fields in a line.
///
/// Defaults to "\t"
TF_MUST_USE_RESULT Attrs Delimiter(StringPiece x) {
Attrs ret = *this;
ret.delimiter_ = x;
return ret;
}
int64 vocab_size_ = -1;
StringPiece delimiter_ = "\t";
};
InitializeTableFromTextFile(const ::tensorflow::Scope& scope,
::tensorflow::Input table_handle,
::tensorflow::Input filename, int64 key_index,
int64 value_index);
InitializeTableFromTextFile(const ::tensorflow::Scope& scope,
::tensorflow::Input table_handle,
::tensorflow::Input filename, int64 key_index,
int64 value_index, const
InitializeTableFromTextFile::Attrs& attrs);
operator ::tensorflow::Operation() const { return operation; }
static Attrs VocabSize(int64 x) {
return Attrs().VocabSize(x);
}
static Attrs Delimiter(StringPiece x) {
return Attrs().Delimiter(x);
}
Operation operation;
};
/// Table initializer that takes two tensors for keys and values respectively.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to a table which will be initialized.
/// * keys: Keys of type Tkey.
/// * values: Values of type Tval.
///
/// Returns:
/// * the created `Operation`
class InitializeTable {
public:
InitializeTable(const ::tensorflow::Scope& scope, ::tensorflow::Input
table_handle, ::tensorflow::Input keys, ::tensorflow::Input
values);
operator ::tensorflow::Operation() const { return operation; }
Operation operation;
};
/// Outputs all keys and values in the table.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to the table.
///
/// Returns:
/// * `Output` keys: Vector of all keys present in the table.
/// * `Output` values: Tensor of all values in the table. Indexed in parallel with `keys`.
class LookupTableExport {
public:
LookupTableExport(const ::tensorflow::Scope& scope, ::tensorflow::Input
table_handle, DataType Tkeys, DataType Tvalues);
Operation operation;
::tensorflow::Output keys;
::tensorflow::Output values;
};
/// Looks up keys in a table, outputs the corresponding values.
///
/// The tensor `keys` must of the same type as the keys of the table.
/// The output `values` is of the type of the table values.
///
/// The scalar `default_value` is the value output for keys not present in the
/// table. It must also be of the same type as the table values.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to the table.
/// * keys: Any shape. Keys to look up.
///
/// Returns:
/// * `Output`: Same shape as `keys`. Values found in the table, or `default_values`
/// for missing keys.
class LookupTableFind {
public:
LookupTableFind(const ::tensorflow::Scope& scope, ::tensorflow::Input
table_handle, ::tensorflow::Input keys, ::tensorflow::Input
default_value);
operator ::tensorflow::Output() const { return values; }
operator ::tensorflow::Input() const { return values; }
::tensorflow::Node* node() const { return values.node(); }
Operation operation;
::tensorflow::Output values;
};
/// Replaces the contents of the table with the specified keys and values.
///
/// The tensor `keys` must be of the same type as the keys of the table.
/// The tensor `values` must be of the type of the table values.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to the table.
/// * keys: Any shape. Keys to look up.
/// * values: Values to associate with keys.
///
/// Returns:
/// * the created `Operation`
class LookupTableImport {
public:
LookupTableImport(const ::tensorflow::Scope& scope, ::tensorflow::Input
table_handle, ::tensorflow::Input keys, ::tensorflow::Input
values);
operator ::tensorflow::Operation() const { return operation; }
Operation operation;
};
/// Updates the table to associates keys with values.
///
/// The tensor `keys` must be of the same type as the keys of the table.
/// The tensor `values` must be of the type of the table values.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to the table.
/// * keys: Any shape. Keys to look up.
/// * values: Values to associate with keys.
///
/// Returns:
/// * the created `Operation`
class LookupTableInsert {
public:
LookupTableInsert(const ::tensorflow::Scope& scope, ::tensorflow::Input
table_handle, ::tensorflow::Input keys, ::tensorflow::Input
values);
operator ::tensorflow::Operation() const { return operation; }
Operation operation;
};
/// Computes the number of elements in the given table.
///
/// Arguments:
/// * scope: A Scope object
/// * table_handle: Handle to the table.
///
/// Returns:
/// * `Output`: Scalar that contains number of elements in the table.
class LookupTableSize {
public:
LookupTableSize(const ::tensorflow::Scope& scope, ::tensorflow::Input
table_handle);
operator ::tensorflow::Output() const { return size; }
operator ::tensorflow::Input() const { return size; }
::tensorflow::Node* node() const { return size.node(); }
Operation operation;
::tensorflow::Output size;
};
/// Creates an empty hash table that uses tensors as the backing store.
///
/// It uses "open addressing" with quadratic reprobing to resolve
/// collisions.
///
/// This op creates a mutable hash table, specifying the type of its keys and
/// values. Each value must be a scalar. Data can be inserted into the table using
/// the insert operations. It does not support the initialization operation.
///
/// Arguments:
/// * scope: A Scope object
/// * empty_key: The key used to represent empty key buckets internally. Must not
/// be used in insert or lookup operations.
/// * value_dtype: Type of the table values.
///
/// Optional attributes (see `Attrs`):
/// * container: If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
/// * shared_name: If non-empty, this table is shared under the given name across
/// multiple sessions.
/// * value_shape: The shape of each value.
/// * initial_num_buckets: The initial number of hash table buckets. Must be a power
/// to 2.
/// * max_load_factor: The maximum ratio between number of entries and number of
/// buckets before growing the table. Must be between 0 and 1.
///
/// Returns:
/// * `Output`: Handle to a table.
class MutableDenseHashTable {
public:
/// Optional attribute setters for MutableDenseHashTable
struct Attrs {
/// If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Container(StringPiece x) {
Attrs ret = *this;
ret.container_ = x;
return ret;
}
/// If non-empty, this table is shared under the given name across
/// multiple sessions.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs SharedName(StringPiece x) {
Attrs ret = *this;
ret.shared_name_ = x;
return ret;
}
/// Defaults to false
TF_MUST_USE_RESULT Attrs UseNodeNameSharing(bool x) {
Attrs ret = *this;
ret.use_node_name_sharing_ = x;
return ret;
}
/// The shape of each value.
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs ValueShape(PartialTensorShape x) {
Attrs ret = *this;
ret.value_shape_ = x;
return ret;
}
/// The initial number of hash table buckets. Must be a power
/// to 2.
///
/// Defaults to 131072
TF_MUST_USE_RESULT Attrs InitialNumBuckets(int64 x) {
Attrs ret = *this;
ret.initial_num_buckets_ = x;
return ret;
}
/// The maximum ratio between number of entries and number of
/// buckets before growing the table. Must be between 0 and 1.
///
/// Defaults to 0.8
TF_MUST_USE_RESULT Attrs MaxLoadFactor(float x) {
Attrs ret = *this;
ret.max_load_factor_ = x;
return ret;
}
StringPiece container_ = "";
StringPiece shared_name_ = "";
bool use_node_name_sharing_ = false;
PartialTensorShape value_shape_ = {};
int64 initial_num_buckets_ = 131072;
float max_load_factor_ = 0.8f;
};
MutableDenseHashTable(const ::tensorflow::Scope& scope, ::tensorflow::Input
empty_key, DataType value_dtype);
MutableDenseHashTable(const ::tensorflow::Scope& scope, ::tensorflow::Input
empty_key, DataType value_dtype, const
MutableDenseHashTable::Attrs& attrs);
operator ::tensorflow::Output() const { return table_handle; }
operator ::tensorflow::Input() const { return table_handle; }
::tensorflow::Node* node() const { return table_handle.node(); }
static Attrs Container(StringPiece x) {
return Attrs().Container(x);
}
static Attrs SharedName(StringPiece x) {
return Attrs().SharedName(x);
}
static Attrs UseNodeNameSharing(bool x) {
return Attrs().UseNodeNameSharing(x);
}
static Attrs ValueShape(PartialTensorShape x) {
return Attrs().ValueShape(x);
}
static Attrs InitialNumBuckets(int64 x) {
return Attrs().InitialNumBuckets(x);
}
static Attrs MaxLoadFactor(float x) {
return Attrs().MaxLoadFactor(x);
}
Operation operation;
::tensorflow::Output table_handle;
};
/// Creates an empty hash table.
///
/// This op creates a mutable hash table, specifying the type of its keys and
/// values. Each value must be a vector. Data can be inserted into the table using
/// the insert operations. It does not support the initialization operation.
///
/// Arguments:
/// * scope: A Scope object
/// * key_dtype: Type of the table keys.
/// * value_dtype: Type of the table values.
///
/// Optional attributes (see `Attrs`):
/// * container: If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
/// * shared_name: If non-empty, this table is shared under the given name across
/// multiple sessions.
///
/// Returns:
/// * `Output`: Handle to a table.
class MutableHashTableOfTensors {
public:
/// Optional attribute setters for MutableHashTableOfTensors
struct Attrs {
/// If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Container(StringPiece x) {
Attrs ret = *this;
ret.container_ = x;
return ret;
}
/// If non-empty, this table is shared under the given name across
/// multiple sessions.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs SharedName(StringPiece x) {
Attrs ret = *this;
ret.shared_name_ = x;
return ret;
}
/// Defaults to false
TF_MUST_USE_RESULT Attrs UseNodeNameSharing(bool x) {
Attrs ret = *this;
ret.use_node_name_sharing_ = x;
return ret;
}
/// Defaults to []
TF_MUST_USE_RESULT Attrs ValueShape(PartialTensorShape x) {
Attrs ret = *this;
ret.value_shape_ = x;
return ret;
}
StringPiece container_ = "";
StringPiece shared_name_ = "";
bool use_node_name_sharing_ = false;
PartialTensorShape value_shape_ = {};
};
MutableHashTableOfTensors(const ::tensorflow::Scope& scope, DataType key_dtype,
DataType value_dtype);
MutableHashTableOfTensors(const ::tensorflow::Scope& scope, DataType key_dtype,
DataType value_dtype, const
MutableHashTableOfTensors::Attrs& attrs);
operator ::tensorflow::Output() const { return table_handle; }
operator ::tensorflow::Input() const { return table_handle; }
::tensorflow::Node* node() const { return table_handle.node(); }
static Attrs Container(StringPiece x) {
return Attrs().Container(x);
}
static Attrs SharedName(StringPiece x) {
return Attrs().SharedName(x);
}
static Attrs UseNodeNameSharing(bool x) {
return Attrs().UseNodeNameSharing(x);
}
static Attrs ValueShape(PartialTensorShape x) {
return Attrs().ValueShape(x);
}
Operation operation;
::tensorflow::Output table_handle;
};
/// Creates an empty hash table.
///
/// This op creates a mutable hash table, specifying the type of its keys and
/// values. Each value must be a scalar. Data can be inserted into the table using
/// the insert operations. It does not support the initialization operation.
///
/// Arguments:
/// * scope: A Scope object
/// * key_dtype: Type of the table keys.
/// * value_dtype: Type of the table values.
///
/// Optional attributes (see `Attrs`):
/// * container: If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
/// * shared_name: If non-empty, this table is shared under the given name across
/// multiple sessions.
/// * use_node_name_sharing: If true and shared_name is empty, the table is shared
/// using the node name.
///
/// Returns:
/// * `Output`: Handle to a table.
class MutableHashTable {
public:
/// Optional attribute setters for MutableHashTable
struct Attrs {
/// If non-empty, this table is placed in the given container.
/// Otherwise, a default container is used.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Container(StringPiece x) {
Attrs ret = *this;
ret.container_ = x;
return ret;
}
/// If non-empty, this table is shared under the given name across
/// multiple sessions.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs SharedName(StringPiece x) {
Attrs ret = *this;
ret.shared_name_ = x;
return ret;
}
/// If true and shared_name is empty, the table is shared
/// using the node name.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs UseNodeNameSharing(bool x) {
Attrs ret = *this;
ret.use_node_name_sharing_ = x;
return ret;
}
StringPiece container_ = "";
StringPiece shared_name_ = "";
bool use_node_name_sharing_ = false;
};
MutableHashTable(const ::tensorflow::Scope& scope, DataType key_dtype, DataType
value_dtype);
MutableHashTable(const ::tensorflow::Scope& scope, DataType key_dtype, DataType
value_dtype, const MutableHashTable::Attrs& attrs);
operator ::tensorflow::Output() const { return table_handle; }
operator ::tensorflow::Input() const { return table_handle; }
::tensorflow::Node* node() const { return table_handle.node(); }
static Attrs Container(StringPiece x) {
return Attrs().Container(x);
}
static Attrs SharedName(StringPiece x) {
return Attrs().SharedName(x);
}
static Attrs UseNodeNameSharing(bool x) {
return Attrs().UseNodeNameSharing(x);
}
Operation operation;
::tensorflow::Output table_handle;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_LOOKUP_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_LOOKUP_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_LOOKUP_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup lookup_ops_internal Lookup Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_LOOKUP_OPS_INTERNAL_H_
@@ -0,0 +1,76 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_MANIP_OPS_H_
#define TENSORFLOW_CC_OPS_MANIP_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup manip_ops Manip Ops
/// @{
/// Rolls the elements of a tensor along an axis.
///
/// The elements are shifted positively (towards larger indices) by the offset of
/// `shift` along the dimension of `axis`. Negative `shift` values will shift
/// elements in the opposite direction. Elements that roll passed the last position
/// will wrap around to the first and vice versa. Multiple shifts along multiple
/// axes may be specified.
///
/// For example:
///
/// ```
/// # 't' is [0, 1, 2, 3, 4]
/// roll(t, shift=2, axis=0) ==> [3, 4, 0, 1, 2]
///
/// # shifting along multiple dimensions
/// # 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
/// roll(t, shift=[1, -2], axis=[0, 1]) ==> [[7, 8, 9, 5, 6], [2, 3, 4, 0, 1]]
///
/// # shifting along the same axis multiple times
/// # 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
/// roll(t, shift=[2, -3], axis=[1, 1]) ==> [[1, 2, 3, 4, 0], [6, 7, 8, 9, 5]]
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * shift: Dimension must be 0-D or 1-D. `shift[i]` specifies the number of places by which
/// elements are shifted positively (towards larger indices) along the dimension
/// specified by `axis[i]`. Negative shifts will roll the elements in the opposite
/// direction.
/// * axis: Dimension must be 0-D or 1-D. `axis[i]` specifies the dimension that the shift
/// `shift[i]` should occur. If the same axis is referenced more than once, the
/// total shift for that axis will be the sum of all the shifts that belong to that
/// axis.
///
/// Returns:
/// * `Output`: Has the same shape and size as the input. The elements are shifted
/// positively (towards larger indices) by the offsets of `shift` along the
/// dimensions of `axis`.
class Roll {
public:
Roll(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input shift, ::tensorflow::Input axis);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_MANIP_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_MANIP_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_MANIP_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup manip_ops_internal Manip Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_MANIP_OPS_INTERNAL_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,179 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_MATH_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_MATH_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup math_ops_internal Math Ops Internal
/// @{
/// Computes the gradient of `igamma(a, x)` wrt `a`.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class IgammaGradA {
public:
IgammaGradA(const ::tensorflow::Scope& scope, ::tensorflow::Input a,
::tensorflow::Input x);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
/// Computes the gradient for the inverse of `x` wrt its input.
///
/// Specifically, `grad = -dy * y*y`, where `y = 1/x`, and `dy`
/// is the corresponding input gradient.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class InvGrad {
public:
InvGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input y,
::tensorflow::Input dy);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
/// Computes the gradient for the inverse of `x` wrt its input.
///
/// Specifically, `grad = -dy * y*y`, where `y = 1/x`, and `dy`
/// is the corresponding input gradient.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class ReciprocalGrad {
public:
ReciprocalGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input y,
::tensorflow::Input dy);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
/// Computes the gradient for the rsqrt of `x` wrt its input.
///
/// Specifically, `grad = dy * -0.5 * y^3`, where `y = rsqrt(x)`, and `dy`
/// is the corresponding input gradient.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class RsqrtGrad {
public:
RsqrtGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input y,
::tensorflow::Input dy);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
/// Computes the gradient of the sigmoid of `x` wrt its input.
///
/// Specifically, `grad = dy * y * (1 - y)`, where `y = sigmoid(x)`, and
/// `dy` is the corresponding input gradient.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class SigmoidGrad {
public:
SigmoidGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input y,
::tensorflow::Input dy);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
/// Computes the gradient for the sqrt of `x` wrt its input.
///
/// Specifically, `grad = dy * 0.5 / y`, where `y = sqrt(x)`, and `dy`
/// is the corresponding input gradient.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class SqrtGrad {
public:
SqrtGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input y,
::tensorflow::Input dy);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
/// Computes the gradient for the tanh of `x` wrt its input.
///
/// Specifically, `grad = dy * (1 - y*y)`, where `y = tanh(x)`, and `dy`
/// is the corresponding input gradient.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The z tensor.
class TanhGrad {
public:
TanhGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input y,
::tensorflow::Input dy);
operator ::tensorflow::Output() const { return z; }
operator ::tensorflow::Input() const { return z; }
::tensorflow::Node* node() const { return z.node(); }
Operation operation;
::tensorflow::Output z;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_MATH_OPS_INTERNAL_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,541 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_NN_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_NN_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup nn_ops_internal Nn Ops Internal
/// @{
/// Computes gradients of the average pooling function.
///
/// Arguments:
/// * scope: A Scope object
/// * orig_input_shape: 1-D. Shape of the original input to `avg_pool`.
/// * grad: 4-D with shape `[batch, height, width, channels]`. Gradients w.r.t.
/// the output of `avg_pool`.
/// * ksize: The size of the sliding window for each dimension of the input.
/// * strides: The stride of the sliding window for each dimension of the input.
/// * padding: The type of padding algorithm to use.
///
/// Optional attributes (see `Attrs`):
/// * data_format: Specify the data format of the input and output data. With the
/// default format "NHWC", the data is stored in the order of:
/// [batch, in_height, in_width, in_channels].
/// Alternatively, the format could be "NCHW", the data storage order of:
/// [batch, in_channels, in_height, in_width].
///
/// Returns:
/// * `Output`: 4-D. Gradients w.r.t. the input of `avg_pool`.
class AvgPoolGrad {
public:
/// Optional attribute setters for AvgPoolGrad
struct Attrs {
/// Specify the data format of the input and output data. With the
/// default format "NHWC", the data is stored in the order of:
/// [batch, in_height, in_width, in_channels].
/// Alternatively, the format could be "NCHW", the data storage order of:
/// [batch, in_channels, in_height, in_width].
///
/// Defaults to "NHWC"
TF_MUST_USE_RESULT Attrs DataFormat(StringPiece x) {
Attrs ret = *this;
ret.data_format_ = x;
return ret;
}
StringPiece data_format_ = "NHWC";
};
AvgPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
orig_input_shape, ::tensorflow::Input grad, const
gtl::ArraySlice<int>& ksize, const gtl::ArraySlice<int>& strides,
StringPiece padding);
AvgPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
orig_input_shape, ::tensorflow::Input grad, const
gtl::ArraySlice<int>& ksize, const gtl::ArraySlice<int>& strides,
StringPiece padding, const AvgPoolGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs DataFormat(StringPiece x) {
return Attrs().DataFormat(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes gradients for the exponential linear (Elu) operation.
///
/// Arguments:
/// * scope: A Scope object
/// * gradients: The backpropagated gradients to the corresponding Elu operation.
/// * outputs: The outputs of the corresponding Elu operation.
///
/// Returns:
/// * `Output`: The gradients: `gradients * (outputs + 1)` if outputs < 0,
/// `gradients` otherwise.
class EluGrad {
public:
EluGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input gradients,
::tensorflow::Input outputs);
operator ::tensorflow::Output() const { return backprops; }
operator ::tensorflow::Input() const { return backprops; }
::tensorflow::Node* node() const { return backprops.node(); }
Operation operation;
::tensorflow::Output backprops;
};
/// Computes gradient of the FractionalAvgPool function.
///
/// Unlike FractionalMaxPoolGrad, we don't need to find arg_max for
/// FractionalAvgPoolGrad, we just need to evenly back-propagate each element of
/// out_backprop to those indices that form the same pooling cell. Therefore, we
/// just need to know the shape of original input tensor, instead of the whole
/// tensor.
///
/// Arguments:
/// * scope: A Scope object
/// * orig_input_tensor_shape: Original input tensor shape for `fractional_avg_pool`
/// * out_backprop: 4-D with shape `[batch, height, width, channels]`. Gradients
/// w.r.t. the output of `fractional_avg_pool`.
/// * row_pooling_sequence: row pooling sequence, form pooling region with
/// col_pooling_sequence.
/// * col_pooling_sequence: column pooling sequence, form pooling region with
/// row_pooling sequence.
///
/// Optional attributes (see `Attrs`):
/// * overlapping: When set to True, it means when pooling, the values at the boundary
/// of adjacent pooling cells are used by both cells. For example:
///
/// `index 0 1 2 3 4`
///
/// `value 20 5 16 3 7`
///
/// If the pooling sequence is [0, 2, 4], then 16, at index 2 will be used twice.
/// The result would be [41/3, 26/3] for fractional avg pooling.
///
/// Returns:
/// * `Output`: 4-D. Gradients w.r.t. the input of `fractional_avg_pool`.
class FractionalAvgPoolGrad {
public:
/// Optional attribute setters for FractionalAvgPoolGrad
struct Attrs {
/// When set to True, it means when pooling, the values at the boundary
/// of adjacent pooling cells are used by both cells. For example:
///
/// `index 0 1 2 3 4`
///
/// `value 20 5 16 3 7`
///
/// If the pooling sequence is [0, 2, 4], then 16, at index 2 will be used twice.
/// The result would be [41/3, 26/3] for fractional avg pooling.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Overlapping(bool x) {
Attrs ret = *this;
ret.overlapping_ = x;
return ret;
}
bool overlapping_ = false;
};
FractionalAvgPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
orig_input_tensor_shape, ::tensorflow::Input
out_backprop, ::tensorflow::Input row_pooling_sequence,
::tensorflow::Input col_pooling_sequence);
FractionalAvgPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
orig_input_tensor_shape, ::tensorflow::Input
out_backprop, ::tensorflow::Input row_pooling_sequence,
::tensorflow::Input col_pooling_sequence, const
FractionalAvgPoolGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Overlapping(bool x) {
return Attrs().Overlapping(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes gradient of the FractionalMaxPool function.
///
/// Arguments:
/// * scope: A Scope object
/// * orig_input: Original input for `fractional_max_pool`
/// * orig_output: Original output for `fractional_max_pool`
/// * out_backprop: 4-D with shape `[batch, height, width, channels]`. Gradients
/// w.r.t. the output of `fractional_max_pool`.
/// * row_pooling_sequence: row pooling sequence, form pooling region with
/// col_pooling_sequence.
/// * col_pooling_sequence: column pooling sequence, form pooling region with
/// row_pooling sequence.
///
/// Optional attributes (see `Attrs`):
/// * overlapping: When set to True, it means when pooling, the values at the boundary
/// of adjacent pooling cells are used by both cells. For example:
///
/// `index 0 1 2 3 4`
///
/// `value 20 5 16 3 7`
///
/// If the pooling sequence is [0, 2, 4], then 16, at index 2 will be used twice.
/// The result would be [20, 16] for fractional max pooling.
///
/// Returns:
/// * `Output`: 4-D. Gradients w.r.t. the input of `fractional_max_pool`.
class FractionalMaxPoolGrad {
public:
/// Optional attribute setters for FractionalMaxPoolGrad
struct Attrs {
/// When set to True, it means when pooling, the values at the boundary
/// of adjacent pooling cells are used by both cells. For example:
///
/// `index 0 1 2 3 4`
///
/// `value 20 5 16 3 7`
///
/// If the pooling sequence is [0, 2, 4], then 16, at index 2 will be used twice.
/// The result would be [20, 16] for fractional max pooling.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Overlapping(bool x) {
Attrs ret = *this;
ret.overlapping_ = x;
return ret;
}
bool overlapping_ = false;
};
FractionalMaxPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
orig_input, ::tensorflow::Input orig_output,
::tensorflow::Input out_backprop, ::tensorflow::Input
row_pooling_sequence, ::tensorflow::Input
col_pooling_sequence);
FractionalMaxPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input
orig_input, ::tensorflow::Input orig_output,
::tensorflow::Input out_backprop, ::tensorflow::Input
row_pooling_sequence, ::tensorflow::Input
col_pooling_sequence, const FractionalMaxPoolGrad::Attrs&
attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Overlapping(bool x) {
return Attrs().Overlapping(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Gradients for Local Response Normalization.
///
/// Arguments:
/// * scope: A Scope object
/// * input_grads: 4-D with shape `[batch, height, width, channels]`.
/// * input_image: 4-D with shape `[batch, height, width, channels]`.
/// * output_image: 4-D with shape `[batch, height, width, channels]`.
///
/// Optional attributes (see `Attrs`):
/// * depth_radius: A depth radius.
/// * bias: An offset (usually > 0 to avoid dividing by 0).
/// * alpha: A scale factor, usually positive.
/// * beta: An exponent.
///
/// Returns:
/// * `Output`: The gradients for LRN.
class LRNGrad {
public:
/// Optional attribute setters for LRNGrad
struct Attrs {
/// A depth radius.
///
/// Defaults to 5
TF_MUST_USE_RESULT Attrs DepthRadius(int64 x) {
Attrs ret = *this;
ret.depth_radius_ = x;
return ret;
}
/// An offset (usually > 0 to avoid dividing by 0).
///
/// Defaults to 1
TF_MUST_USE_RESULT Attrs Bias(float x) {
Attrs ret = *this;
ret.bias_ = x;
return ret;
}
/// A scale factor, usually positive.
///
/// Defaults to 1
TF_MUST_USE_RESULT Attrs Alpha(float x) {
Attrs ret = *this;
ret.alpha_ = x;
return ret;
}
/// An exponent.
///
/// Defaults to 0.5
TF_MUST_USE_RESULT Attrs Beta(float x) {
Attrs ret = *this;
ret.beta_ = x;
return ret;
}
int64 depth_radius_ = 5;
float bias_ = 1.0f;
float alpha_ = 1.0f;
float beta_ = 0.5f;
};
LRNGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input input_grads,
::tensorflow::Input input_image, ::tensorflow::Input output_image);
LRNGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input input_grads,
::tensorflow::Input input_image, ::tensorflow::Input output_image,
const LRNGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs DepthRadius(int64 x) {
return Attrs().DepthRadius(x);
}
static Attrs Bias(float x) {
return Attrs().Bias(x);
}
static Attrs Alpha(float x) {
return Attrs().Alpha(x);
}
static Attrs Beta(float x) {
return Attrs().Beta(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes gradients of the maxpooling function.
///
/// Arguments:
/// * scope: A Scope object
/// * orig_input: The original input tensor.
/// * orig_output: The original output tensor.
/// * grad: 4-D. Gradients w.r.t. the output of `max_pool`.
/// * ksize: The size of the window for each dimension of the input tensor.
/// * strides: The stride of the sliding window for each dimension of the
/// input tensor.
/// * padding: The type of padding algorithm to use.
///
/// Optional attributes (see `Attrs`):
/// * data_format: Specify the data format of the input and output data. With the
/// default format "NHWC", the data is stored in the order of:
/// [batch, in_height, in_width, in_channels].
/// Alternatively, the format could be "NCHW", the data storage order of:
/// [batch, in_channels, in_height, in_width].
///
/// Returns:
/// * `Output`: Gradients w.r.t. the input to `max_pool`.
class MaxPoolGrad {
public:
/// Optional attribute setters for MaxPoolGrad
struct Attrs {
/// Specify the data format of the input and output data. With the
/// default format "NHWC", the data is stored in the order of:
/// [batch, in_height, in_width, in_channels].
/// Alternatively, the format could be "NCHW", the data storage order of:
/// [batch, in_channels, in_height, in_width].
///
/// Defaults to "NHWC"
TF_MUST_USE_RESULT Attrs DataFormat(StringPiece x) {
Attrs ret = *this;
ret.data_format_ = x;
return ret;
}
StringPiece data_format_ = "NHWC";
};
MaxPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input orig_input,
::tensorflow::Input orig_output, ::tensorflow::Input grad, const
gtl::ArraySlice<int>& ksize, const gtl::ArraySlice<int>& strides,
StringPiece padding);
MaxPoolGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input orig_input,
::tensorflow::Input orig_output, ::tensorflow::Input grad, const
gtl::ArraySlice<int>& ksize, const gtl::ArraySlice<int>& strides,
StringPiece padding, const MaxPoolGrad::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs DataFormat(StringPiece x) {
return Attrs().DataFormat(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Computes gradients of the maxpooling function.
///
/// Arguments:
/// * scope: A Scope object
/// * input: The original input.
/// * grad: 4-D with shape `[batch, height, width, channels]`. Gradients w.r.t. the
/// output of `max_pool`.
/// * argmax: The indices of the maximum values chosen for each output of `max_pool`.
/// * ksize: The size of the window for each dimension of the input tensor.
/// * strides: The stride of the sliding window for each dimension of the
/// input tensor.
/// * padding: The type of padding algorithm to use.
///
/// Returns:
/// * `Output`: Gradients w.r.t. the input of `max_pool`.
class MaxPoolGradWithArgmax {
public:
MaxPoolGradWithArgmax(const ::tensorflow::Scope& scope, ::tensorflow::Input
input, ::tensorflow::Input grad, ::tensorflow::Input
argmax, const gtl::ArraySlice<int>& ksize, const
gtl::ArraySlice<int>& strides, StringPiece padding);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Computes rectified linear 6 gradients for a Relu6 operation.
///
/// Arguments:
/// * scope: A Scope object
/// * gradients: The backpropagated gradients to the corresponding Relu6 operation.
/// * features: The features passed as input to the corresponding Relu6 operation, or
/// its output; using either one produces the same result.
///
/// Returns:
/// * `Output`: The gradients:
/// `gradients * (features > 0) * (features < 6)`.
class Relu6Grad {
public:
Relu6Grad(const ::tensorflow::Scope& scope, ::tensorflow::Input gradients,
::tensorflow::Input features);
operator ::tensorflow::Output() const { return backprops; }
operator ::tensorflow::Input() const { return backprops; }
::tensorflow::Node* node() const { return backprops.node(); }
Operation operation;
::tensorflow::Output backprops;
};
/// Computes rectified linear gradients for a Relu operation.
///
/// Arguments:
/// * scope: A Scope object
/// * gradients: The backpropagated gradients to the corresponding Relu operation.
/// * features: The features passed as input to the corresponding Relu operation, OR
/// the outputs of that operation (both work equivalently).
///
/// Returns:
/// * `Output`: `gradients * (features > 0)`.
class ReluGrad {
public:
ReluGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input gradients,
::tensorflow::Input features);
operator ::tensorflow::Output() const { return backprops; }
operator ::tensorflow::Input() const { return backprops; }
::tensorflow::Node* node() const { return backprops.node(); }
Operation operation;
::tensorflow::Output backprops;
};
/// Computes gradients for the scaled exponential linear (Selu) operation.
///
/// Arguments:
/// * scope: A Scope object
/// * gradients: The backpropagated gradients to the corresponding Selu operation.
/// * outputs: The outputs of the corresponding Selu operation.
///
/// Returns:
/// * `Output`: The gradients: `gradients * (outputs + scale * alpha)`
/// if outputs < 0, `scale * gradients` otherwise.
class SeluGrad {
public:
SeluGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input gradients,
::tensorflow::Input outputs);
operator ::tensorflow::Output() const { return backprops; }
operator ::tensorflow::Input() const { return backprops; }
::tensorflow::Node* node() const { return backprops.node(); }
Operation operation;
::tensorflow::Output backprops;
};
/// Computes softplus gradients for a softplus operation.
///
/// Arguments:
/// * scope: A Scope object
/// * gradients: The backpropagated gradients to the corresponding softplus operation.
/// * features: The features passed as input to the corresponding softplus operation.
///
/// Returns:
/// * `Output`: The gradients: `gradients / (1 + exp(-features))`.
class SoftplusGrad {
public:
SoftplusGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input gradients,
::tensorflow::Input features);
operator ::tensorflow::Output() const { return backprops; }
operator ::tensorflow::Input() const { return backprops; }
::tensorflow::Node* node() const { return backprops.node(); }
Operation operation;
::tensorflow::Output backprops;
};
/// Computes softsign gradients for a softsign operation.
///
/// Arguments:
/// * scope: A Scope object
/// * gradients: The backpropagated gradients to the corresponding softsign operation.
/// * features: The features passed as input to the corresponding softsign operation.
///
/// Returns:
/// * `Output`: The gradients: `gradients / (1 + abs(features)) ** 2`.
class SoftsignGrad {
public:
SoftsignGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input gradients,
::tensorflow::Input features);
operator ::tensorflow::Output() const { return backprops; }
operator ::tensorflow::Input() const { return backprops; }
::tensorflow::Node* node() const { return backprops.node(); }
Operation operation;
::tensorflow::Output backprops;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_NN_OPS_INTERNAL_H_
+41
View File
@@ -0,0 +1,41 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_NO_OP_H_
#define TENSORFLOW_CC_OPS_NO_OP_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup no_op No Op
/// @{
/// Does nothing. Only useful as a placeholder for control edges.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * the created `Operation`
class NoOp {
public:
NoOp(const ::tensorflow::Scope& scope);
operator ::tensorflow::Operation() const { return operation; }
Operation operation;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_NO_OP_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_NO_OP_INTERNAL_H_
#define TENSORFLOW_CC_OPS_NO_OP_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup no_op_internal No Op Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_NO_OP_INTERNAL_H_
@@ -0,0 +1,854 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_PARSING_OPS_H_
#define TENSORFLOW_CC_OPS_PARSING_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup parsing_ops Parsing Ops
/// @{
/// Convert CSV records to tensors. Each column maps to one tensor.
///
/// RFC 4180 format is expected for the CSV records.
/// (https://tools.ietf.org/html/rfc4180)
/// Note that we allow leading and trailing spaces with int or float field.
///
/// Arguments:
/// * scope: A Scope object
/// * records: Each string is a record/row in the csv and all records should have
/// the same format.
/// * record_defaults: One tensor per column of the input record, with either a
/// scalar default value for that column or an empty vector if the column is
/// required.
///
/// Optional attributes (see `Attrs`):
/// * field_delim: char delimiter to separate fields in a record.
/// * use_quote_delim: If false, treats double quotation marks as regular
/// characters inside of the string fields (ignoring RFC 4180, Section 2,
/// Bullet 5).
/// * na_value: Additional string to recognize as NA/NaN.
///
/// Returns:
/// * `OutputList`: Each tensor will have the same shape as records.
class DecodeCSV {
public:
/// Optional attribute setters for DecodeCSV
struct Attrs {
/// char delimiter to separate fields in a record.
///
/// Defaults to ","
TF_MUST_USE_RESULT Attrs FieldDelim(StringPiece x) {
Attrs ret = *this;
ret.field_delim_ = x;
return ret;
}
/// If false, treats double quotation marks as regular
/// characters inside of the string fields (ignoring RFC 4180, Section 2,
/// Bullet 5).
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs UseQuoteDelim(bool x) {
Attrs ret = *this;
ret.use_quote_delim_ = x;
return ret;
}
/// Additional string to recognize as NA/NaN.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs NaValue(StringPiece x) {
Attrs ret = *this;
ret.na_value_ = x;
return ret;
}
/// Defaults to []
TF_MUST_USE_RESULT Attrs SelectCols(const gtl::ArraySlice<int>& x) {
Attrs ret = *this;
ret.select_cols_ = x;
return ret;
}
StringPiece field_delim_ = ",";
bool use_quote_delim_ = true;
StringPiece na_value_ = "";
gtl::ArraySlice<int> select_cols_ = {};
};
DecodeCSV(const ::tensorflow::Scope& scope, ::tensorflow::Input records,
::tensorflow::InputList record_defaults);
DecodeCSV(const ::tensorflow::Scope& scope, ::tensorflow::Input records,
::tensorflow::InputList record_defaults, const DecodeCSV::Attrs&
attrs);
::tensorflow::Output operator[](size_t index) const { return output[index]; }
static Attrs FieldDelim(StringPiece x) {
return Attrs().FieldDelim(x);
}
static Attrs UseQuoteDelim(bool x) {
return Attrs().UseQuoteDelim(x);
}
static Attrs NaValue(StringPiece x) {
return Attrs().NaValue(x);
}
static Attrs SelectCols(const gtl::ArraySlice<int>& x) {
return Attrs().SelectCols(x);
}
Operation operation;
::tensorflow::OutputList output;
};
/// Decompress strings.
///
/// This op decompresses each element of the `bytes` input `Tensor`, which
/// is assumed to be compressed using the given `compression_type`.
///
/// The `output` is a string `Tensor` of the same shape as `bytes`,
/// each element containing the decompressed data from the corresponding
/// element in `bytes`.
///
/// Arguments:
/// * scope: A Scope object
/// * bytes: A Tensor of string which is compressed.
///
/// Optional attributes (see `Attrs`):
/// * compression_type: A scalar containing either (i) the empty string (no
/// compression), (ii) "ZLIB", or (iii) "GZIP".
///
/// Returns:
/// * `Output`: A Tensor with the same shape as input `bytes`, uncompressed
/// from bytes.
class DecodeCompressed {
public:
/// Optional attribute setters for DecodeCompressed
struct Attrs {
/// A scalar containing either (i) the empty string (no
/// compression), (ii) "ZLIB", or (iii) "GZIP".
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs CompressionType(StringPiece x) {
Attrs ret = *this;
ret.compression_type_ = x;
return ret;
}
StringPiece compression_type_ = "";
};
DecodeCompressed(const ::tensorflow::Scope& scope, ::tensorflow::Input bytes);
DecodeCompressed(const ::tensorflow::Scope& scope, ::tensorflow::Input bytes,
const DecodeCompressed::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs CompressionType(StringPiece x) {
return Attrs().CompressionType(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Convert JSON-encoded Example records to binary protocol buffer strings.
///
/// This op translates a tensor containing Example records, encoded using
/// the [standard JSON
/// mapping](https://developers.google.com/protocol-buffers/docs/proto3#json),
/// into a tensor containing the same records encoded as binary protocol
/// buffers. The resulting tensor can then be fed to any of the other
/// Example-parsing ops.
///
/// Arguments:
/// * scope: A Scope object
/// * json_examples: Each string is a JSON object serialized according to the JSON
/// mapping of the Example proto.
///
/// Returns:
/// * `Output`: Each string is a binary Example protocol buffer corresponding
/// to the respective element of `json_examples`.
class DecodeJSONExample {
public:
DecodeJSONExample(const ::tensorflow::Scope& scope, ::tensorflow::Input
json_examples);
operator ::tensorflow::Output() const { return binary_examples; }
operator ::tensorflow::Input() const { return binary_examples; }
::tensorflow::Node* node() const { return binary_examples.node(); }
Operation operation;
::tensorflow::Output binary_examples;
};
/// Reinterpret the bytes of a string as a vector of numbers.
///
/// Arguments:
/// * scope: A Scope object
/// * bytes: All the elements must have the same length.
///
/// Optional attributes (see `Attrs`):
/// * little_endian: Whether the input `bytes` are in little-endian order.
/// Ignored for `out_type` values that are stored in a single byte like
/// `uint8`.
///
/// Returns:
/// * `Output`: A Tensor with one more dimension than the input `bytes`. The
/// added dimension will have size equal to the length of the elements
/// of `bytes` divided by the number of bytes to represent `out_type`.
class DecodeRaw {
public:
/// Optional attribute setters for DecodeRaw
struct Attrs {
/// Whether the input `bytes` are in little-endian order.
/// Ignored for `out_type` values that are stored in a single byte like
/// `uint8`.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs LittleEndian(bool x) {
Attrs ret = *this;
ret.little_endian_ = x;
return ret;
}
bool little_endian_ = true;
};
DecodeRaw(const ::tensorflow::Scope& scope, ::tensorflow::Input bytes, DataType
out_type);
DecodeRaw(const ::tensorflow::Scope& scope, ::tensorflow::Input bytes, DataType
out_type, const DecodeRaw::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs LittleEndian(bool x) {
return Attrs().LittleEndian(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Transforms a vector of brain.Example protos (as strings) into typed tensors.
///
/// Arguments:
/// * scope: A Scope object
/// * serialized: A vector containing a batch of binary serialized Example protos.
/// * names: A vector containing the names of the serialized protos.
/// May contain, for example, table key (descriptive) names for the
/// corresponding serialized protos. These are purely useful for debugging
/// purposes, and the presence of values here has no effect on the output.
/// May also be an empty vector if no names are available.
/// If non-empty, this vector must be the same length as "serialized".
/// * sparse_keys: A list of Nsparse string Tensors (scalars).
/// The keys expected in the Examples' features associated with sparse values.
/// * dense_keys: A list of Ndense string Tensors (scalars).
/// The keys expected in the Examples' features associated with dense values.
/// * dense_defaults: A list of Ndense Tensors (some may be empty).
/// dense_defaults[j] provides default values
/// when the example's feature_map lacks dense_key[j]. If an empty Tensor is
/// provided for dense_defaults[j], then the Feature dense_keys[j] is required.
/// The input type is inferred from dense_defaults[j], even when it's empty.
/// If dense_defaults[j] is not empty, and dense_shapes[j] is fully defined,
/// then the shape of dense_defaults[j] must match that of dense_shapes[j].
/// If dense_shapes[j] has an undefined major dimension (variable strides dense
/// feature), dense_defaults[j] must contain a single element:
/// the padding element.
/// * sparse_types: A list of Nsparse types; the data types of data in each Feature
/// given in sparse_keys.
/// Currently the ParseExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
/// * dense_shapes: A list of Ndense shapes; the shapes of data in each Feature
/// given in dense_keys.
/// The number of elements in the Feature corresponding to dense_key[j]
/// must always equal dense_shapes[j].NumEntries().
/// If dense_shapes[j] == (D0, D1, ..., DN) then the shape of output
/// Tensor dense_values[j] will be (|serialized|, D0, D1, ..., DN):
/// The dense outputs are just the inputs row-stacked by batch.
/// This works for dense_shapes[j] = (-1, D1, ..., DN). In this case
/// the shape of the output Tensor dense_values[j] will be
/// (|serialized|, M, D1, .., DN), where M is the maximum number of blocks
/// of elements of length D1 * .... * DN, across all minibatch entries
/// in the input. Any minibatch entry with less than M blocks of elements of
/// length D1 * ... * DN will be padded with the corresponding default_value
/// scalar element along the second dimension.
///
/// Returns:
/// * `OutputList` sparse_indices
/// * `OutputList` sparse_values
/// * `OutputList` sparse_shapes
/// * `OutputList` dense_values
class ParseExample {
public:
ParseExample(const ::tensorflow::Scope& scope, ::tensorflow::Input serialized,
::tensorflow::Input names, ::tensorflow::InputList sparse_keys,
::tensorflow::InputList dense_keys, ::tensorflow::InputList
dense_defaults, const DataTypeSlice& sparse_types, const
gtl::ArraySlice<PartialTensorShape>& dense_shapes);
Operation operation;
::tensorflow::OutputList sparse_indices;
::tensorflow::OutputList sparse_values;
::tensorflow::OutputList sparse_shapes;
::tensorflow::OutputList dense_values;
};
/// Transforms a vector of brain.SequenceExample protos (as strings) into typed tensors.
///
/// Arguments:
/// * scope: A Scope object
/// * serialized: A vector containing binary serialized SequenceExample protos.
/// * debug_name: A vector containing the names of the serialized protos.
/// May contain, for example, table key (descriptive) name for the
/// corresponding serialized proto. This is purely useful for debugging
/// purposes, and the presence of values here has no effect on the output.
/// May also be an empty vector if no name is available.
/// * context_dense_defaults: A list of Ncontext_dense Tensors (some may be empty).
/// context_dense_defaults[j] provides default values
/// when the SequenceExample's context map lacks context_dense_key[j].
/// If an empty Tensor is provided for context_dense_defaults[j],
/// then the Feature context_dense_keys[j] is required.
/// The input type is inferred from context_dense_defaults[j], even when it's
/// empty. If context_dense_defaults[j] is not empty, its shape must match
/// context_dense_shapes[j].
/// * feature_list_dense_missing_assumed_empty: A vector listing the
/// FeatureList keys which may be missing from the SequenceExamples. If the
/// associated FeatureList is missing, it is treated as empty. By default,
/// any FeatureList not listed in this vector must exist in the SequenceExamples.
/// * context_sparse_keys: A list of Ncontext_sparse string Tensors (scalars).
/// The keys expected in the Examples' features associated with context_sparse
/// values.
/// * context_dense_keys: A list of Ncontext_dense string Tensors (scalars).
/// The keys expected in the SequenceExamples' context features associated with
/// dense values.
/// * feature_list_sparse_keys: A list of Nfeature_list_sparse string Tensors
/// (scalars). The keys expected in the FeatureLists associated with sparse
/// values.
/// * feature_list_dense_keys: A list of Nfeature_list_dense string Tensors (scalars).
/// The keys expected in the SequenceExamples' feature_lists associated
/// with lists of dense values.
///
/// Optional attributes (see `Attrs`):
/// * context_sparse_types: A list of Ncontext_sparse types; the data types of data in
/// each context Feature given in context_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
/// * context_dense_shapes: A list of Ncontext_dense shapes; the shapes of data in
/// each context Feature given in context_dense_keys.
/// The number of elements in the Feature corresponding to context_dense_key[j]
/// must always equal context_dense_shapes[j].NumEntries().
/// The shape of context_dense_values[j] will match context_dense_shapes[j].
/// * feature_list_sparse_types: A list of Nfeature_list_sparse types; the data types
/// of data in each FeatureList given in feature_list_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
/// * feature_list_dense_shapes: A list of Nfeature_list_dense shapes; the shapes of
/// data in each FeatureList given in feature_list_dense_keys.
/// The shape of each Feature in the FeatureList corresponding to
/// feature_list_dense_key[j] must always equal
/// feature_list_dense_shapes[j].NumEntries().
///
/// Returns:
/// * `OutputList` context_sparse_indices
/// * `OutputList` context_sparse_values
/// * `OutputList` context_sparse_shapes
/// * `OutputList` context_dense_values
/// * `OutputList` feature_list_sparse_indices
/// * `OutputList` feature_list_sparse_values
/// * `OutputList` feature_list_sparse_shapes
/// * `OutputList` feature_list_dense_values
/// * `OutputList` feature_list_dense_lengths
class ParseSequenceExample {
public:
/// Optional attribute setters for ParseSequenceExample
struct Attrs {
/// Defaults to 0
TF_MUST_USE_RESULT Attrs NcontextSparse(int64 x) {
Attrs ret = *this;
ret.Ncontext_sparse_ = x;
return ret;
}
/// Defaults to 0
TF_MUST_USE_RESULT Attrs NcontextDense(int64 x) {
Attrs ret = *this;
ret.Ncontext_dense_ = x;
return ret;
}
/// Defaults to 0
TF_MUST_USE_RESULT Attrs NfeatureListSparse(int64 x) {
Attrs ret = *this;
ret.Nfeature_list_sparse_ = x;
return ret;
}
/// Defaults to 0
TF_MUST_USE_RESULT Attrs NfeatureListDense(int64 x) {
Attrs ret = *this;
ret.Nfeature_list_dense_ = x;
return ret;
}
/// A list of Ncontext_sparse types; the data types of data in
/// each context Feature given in context_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs ContextSparseTypes(const DataTypeSlice& x) {
Attrs ret = *this;
ret.context_sparse_types_ = x;
return ret;
}
/// Defaults to []
TF_MUST_USE_RESULT Attrs FeatureListDenseTypes(const DataTypeSlice& x) {
Attrs ret = *this;
ret.feature_list_dense_types_ = x;
return ret;
}
/// A list of Ncontext_dense shapes; the shapes of data in
/// each context Feature given in context_dense_keys.
/// The number of elements in the Feature corresponding to context_dense_key[j]
/// must always equal context_dense_shapes[j].NumEntries().
/// The shape of context_dense_values[j] will match context_dense_shapes[j].
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs ContextDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
Attrs ret = *this;
ret.context_dense_shapes_ = x;
return ret;
}
/// A list of Nfeature_list_sparse types; the data types
/// of data in each FeatureList given in feature_list_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs FeatureListSparseTypes(const DataTypeSlice& x) {
Attrs ret = *this;
ret.feature_list_sparse_types_ = x;
return ret;
}
/// A list of Nfeature_list_dense shapes; the shapes of
/// data in each FeatureList given in feature_list_dense_keys.
/// The shape of each Feature in the FeatureList corresponding to
/// feature_list_dense_key[j] must always equal
/// feature_list_dense_shapes[j].NumEntries().
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs FeatureListDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
Attrs ret = *this;
ret.feature_list_dense_shapes_ = x;
return ret;
}
int64 Ncontext_sparse_ = 0;
int64 Ncontext_dense_ = 0;
int64 Nfeature_list_sparse_ = 0;
int64 Nfeature_list_dense_ = 0;
DataTypeSlice context_sparse_types_ = {};
DataTypeSlice feature_list_dense_types_ = {};
gtl::ArraySlice<PartialTensorShape> context_dense_shapes_ = {};
DataTypeSlice feature_list_sparse_types_ = {};
gtl::ArraySlice<PartialTensorShape> feature_list_dense_shapes_ = {};
};
ParseSequenceExample(const ::tensorflow::Scope& scope, ::tensorflow::Input
serialized, ::tensorflow::Input debug_name,
::tensorflow::InputList context_dense_defaults, const
gtl::ArraySlice<string>&
feature_list_dense_missing_assumed_empty, const
gtl::ArraySlice<string>& context_sparse_keys, const
gtl::ArraySlice<string>& context_dense_keys, const
gtl::ArraySlice<string>& feature_list_sparse_keys, const
gtl::ArraySlice<string>& feature_list_dense_keys);
ParseSequenceExample(const ::tensorflow::Scope& scope, ::tensorflow::Input
serialized, ::tensorflow::Input debug_name,
::tensorflow::InputList context_dense_defaults, const
gtl::ArraySlice<string>&
feature_list_dense_missing_assumed_empty, const
gtl::ArraySlice<string>& context_sparse_keys, const
gtl::ArraySlice<string>& context_dense_keys, const
gtl::ArraySlice<string>& feature_list_sparse_keys, const
gtl::ArraySlice<string>& feature_list_dense_keys, const
ParseSequenceExample::Attrs& attrs);
static Attrs NcontextSparse(int64 x) {
return Attrs().NcontextSparse(x);
}
static Attrs NcontextDense(int64 x) {
return Attrs().NcontextDense(x);
}
static Attrs NfeatureListSparse(int64 x) {
return Attrs().NfeatureListSparse(x);
}
static Attrs NfeatureListDense(int64 x) {
return Attrs().NfeatureListDense(x);
}
static Attrs ContextSparseTypes(const DataTypeSlice& x) {
return Attrs().ContextSparseTypes(x);
}
static Attrs FeatureListDenseTypes(const DataTypeSlice& x) {
return Attrs().FeatureListDenseTypes(x);
}
static Attrs ContextDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
return Attrs().ContextDenseShapes(x);
}
static Attrs FeatureListSparseTypes(const DataTypeSlice& x) {
return Attrs().FeatureListSparseTypes(x);
}
static Attrs FeatureListDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
return Attrs().FeatureListDenseShapes(x);
}
Operation operation;
::tensorflow::OutputList context_sparse_indices;
::tensorflow::OutputList context_sparse_values;
::tensorflow::OutputList context_sparse_shapes;
::tensorflow::OutputList context_dense_values;
::tensorflow::OutputList feature_list_sparse_indices;
::tensorflow::OutputList feature_list_sparse_values;
::tensorflow::OutputList feature_list_sparse_shapes;
::tensorflow::OutputList feature_list_dense_values;
::tensorflow::OutputList feature_list_dense_lengths;
};
/// Transforms a tf.Example proto (as a string) into typed tensors.
///
/// Arguments:
/// * scope: A Scope object
/// * serialized: A vector containing a batch of binary serialized Example protos.
/// * dense_defaults: A list of Tensors (some may be empty), whose length matches
/// the length of `dense_keys`. dense_defaults[j] provides default values
/// when the example's feature_map lacks dense_key[j]. If an empty Tensor is
/// provided for dense_defaults[j], then the Feature dense_keys[j] is required.
/// The input type is inferred from dense_defaults[j], even when it's empty.
/// If dense_defaults[j] is not empty, and dense_shapes[j] is fully defined,
/// then the shape of dense_defaults[j] must match that of dense_shapes[j].
/// If dense_shapes[j] has an undefined major dimension (variable strides dense
/// feature), dense_defaults[j] must contain a single element:
/// the padding element.
/// * num_sparse: The number of sparse features to be parsed from the example. This
/// must match the lengths of `sparse_keys` and `sparse_types`.
/// * sparse_keys: A list of `num_sparse` strings.
/// The keys expected in the Examples' features associated with sparse values.
/// * dense_keys: The keys expected in the Examples' features associated with dense
/// values.
/// * sparse_types: A list of `num_sparse` types; the data types of data in each
/// Feature given in sparse_keys.
/// Currently the ParseSingleExample op supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
/// * dense_shapes: The shapes of data in each Feature given in dense_keys.
/// The length of this list must match the length of `dense_keys`. The
/// number of elements in the Feature corresponding to dense_key[j] must
/// always equal dense_shapes[j].NumEntries(). If dense_shapes[j] ==
/// (D0, D1, ..., DN) then the shape of output Tensor dense_values[j]
/// will be (D0, D1, ..., DN): In the case dense_shapes[j] = (-1, D1,
/// ..., DN), the shape of the output Tensor dense_values[j] will be (M,
/// D1, .., DN), where M is the number of blocks of elements of length
/// D1 * .... * DN, in the input.
///
/// Returns:
/// * `OutputList` sparse_indices
/// * `OutputList` sparse_values
/// * `OutputList` sparse_shapes
/// * `OutputList` dense_values
class ParseSingleExample {
public:
ParseSingleExample(const ::tensorflow::Scope& scope, ::tensorflow::Input
serialized, ::tensorflow::InputList dense_defaults, int64
num_sparse, const gtl::ArraySlice<string>& sparse_keys,
const gtl::ArraySlice<string>& dense_keys, const
DataTypeSlice& sparse_types, const
gtl::ArraySlice<PartialTensorShape>& dense_shapes);
Operation operation;
::tensorflow::OutputList sparse_indices;
::tensorflow::OutputList sparse_values;
::tensorflow::OutputList sparse_shapes;
::tensorflow::OutputList dense_values;
};
/// Transforms a scalar brain.SequenceExample proto (as strings) into typed tensors.
///
/// Arguments:
/// * scope: A Scope object
/// * serialized: A scalar containing a binary serialized SequenceExample proto.
/// * feature_list_dense_missing_assumed_empty: A vector listing the
/// FeatureList keys which may be missing from the SequenceExample. If the
/// associated FeatureList is missing, it is treated as empty. By default,
/// any FeatureList not listed in this vector must exist in the SequenceExample.
/// * context_sparse_keys: A list of Ncontext_sparse string Tensors (scalars).
/// The keys expected in the Examples' features associated with context_sparse
/// values.
/// * context_dense_keys: A list of Ncontext_dense string Tensors (scalars).
/// The keys expected in the SequenceExamples' context features associated with
/// dense values.
/// * feature_list_sparse_keys: A list of Nfeature_list_sparse string Tensors
/// (scalars). The keys expected in the FeatureLists associated with sparse
/// values.
/// * feature_list_dense_keys: A list of Nfeature_list_dense string Tensors (scalars).
/// The keys expected in the SequenceExamples' feature_lists associated
/// with lists of dense values.
/// * context_dense_defaults: A list of Ncontext_dense Tensors (some may be empty).
/// context_dense_defaults[j] provides default values
/// when the SequenceExample's context map lacks context_dense_key[j].
/// If an empty Tensor is provided for context_dense_defaults[j],
/// then the Feature context_dense_keys[j] is required.
/// The input type is inferred from context_dense_defaults[j], even when it's
/// empty. If context_dense_defaults[j] is not empty, its shape must match
/// context_dense_shapes[j].
/// * debug_name: A scalar containing the name of the serialized proto.
/// May contain, for example, table key (descriptive) name for the
/// corresponding serialized proto. This is purely useful for debugging
/// purposes, and the presence of values here has no effect on the output.
/// May also be an empty scalar if no name is available.
///
/// Optional attributes (see `Attrs`):
/// * context_sparse_types: A list of Ncontext_sparse types; the data types of data in
/// each context Feature given in context_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
/// * context_dense_shapes: A list of Ncontext_dense shapes; the shapes of data in
/// each context Feature given in context_dense_keys.
/// The number of elements in the Feature corresponding to context_dense_key[j]
/// must always equal context_dense_shapes[j].NumEntries().
/// The shape of context_dense_values[j] will match context_dense_shapes[j].
/// * feature_list_sparse_types: A list of Nfeature_list_sparse types; the data types
/// of data in each FeatureList given in feature_list_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
/// * feature_list_dense_shapes: A list of Nfeature_list_dense shapes; the shapes of
/// data in each FeatureList given in feature_list_dense_keys.
/// The shape of each Feature in the FeatureList corresponding to
/// feature_list_dense_key[j] must always equal
/// feature_list_dense_shapes[j].NumEntries().
///
/// Returns:
/// * `OutputList` context_sparse_indices
/// * `OutputList` context_sparse_values
/// * `OutputList` context_sparse_shapes
/// * `OutputList` context_dense_values
/// * `OutputList` feature_list_sparse_indices
/// * `OutputList` feature_list_sparse_values
/// * `OutputList` feature_list_sparse_shapes
/// * `OutputList` feature_list_dense_values
class ParseSingleSequenceExample {
public:
/// Optional attribute setters for ParseSingleSequenceExample
struct Attrs {
/// A list of Ncontext_sparse types; the data types of data in
/// each context Feature given in context_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs ContextSparseTypes(const DataTypeSlice& x) {
Attrs ret = *this;
ret.context_sparse_types_ = x;
return ret;
}
/// Defaults to []
TF_MUST_USE_RESULT Attrs FeatureListDenseTypes(const DataTypeSlice& x) {
Attrs ret = *this;
ret.feature_list_dense_types_ = x;
return ret;
}
/// A list of Ncontext_dense shapes; the shapes of data in
/// each context Feature given in context_dense_keys.
/// The number of elements in the Feature corresponding to context_dense_key[j]
/// must always equal context_dense_shapes[j].NumEntries().
/// The shape of context_dense_values[j] will match context_dense_shapes[j].
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs ContextDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
Attrs ret = *this;
ret.context_dense_shapes_ = x;
return ret;
}
/// A list of Nfeature_list_sparse types; the data types
/// of data in each FeatureList given in feature_list_sparse_keys.
/// Currently the ParseSingleSequenceExample supports DT_FLOAT (FloatList),
/// DT_INT64 (Int64List), and DT_STRING (BytesList).
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs FeatureListSparseTypes(const DataTypeSlice& x) {
Attrs ret = *this;
ret.feature_list_sparse_types_ = x;
return ret;
}
/// A list of Nfeature_list_dense shapes; the shapes of
/// data in each FeatureList given in feature_list_dense_keys.
/// The shape of each Feature in the FeatureList corresponding to
/// feature_list_dense_key[j] must always equal
/// feature_list_dense_shapes[j].NumEntries().
///
/// Defaults to []
TF_MUST_USE_RESULT Attrs FeatureListDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
Attrs ret = *this;
ret.feature_list_dense_shapes_ = x;
return ret;
}
DataTypeSlice context_sparse_types_ = {};
DataTypeSlice feature_list_dense_types_ = {};
gtl::ArraySlice<PartialTensorShape> context_dense_shapes_ = {};
DataTypeSlice feature_list_sparse_types_ = {};
gtl::ArraySlice<PartialTensorShape> feature_list_dense_shapes_ = {};
};
ParseSingleSequenceExample(const ::tensorflow::Scope& scope,
::tensorflow::Input serialized, ::tensorflow::Input
feature_list_dense_missing_assumed_empty,
::tensorflow::InputList context_sparse_keys,
::tensorflow::InputList context_dense_keys,
::tensorflow::InputList feature_list_sparse_keys,
::tensorflow::InputList feature_list_dense_keys,
::tensorflow::InputList context_dense_defaults,
::tensorflow::Input debug_name);
ParseSingleSequenceExample(const ::tensorflow::Scope& scope,
::tensorflow::Input serialized, ::tensorflow::Input
feature_list_dense_missing_assumed_empty,
::tensorflow::InputList context_sparse_keys,
::tensorflow::InputList context_dense_keys,
::tensorflow::InputList feature_list_sparse_keys,
::tensorflow::InputList feature_list_dense_keys,
::tensorflow::InputList context_dense_defaults,
::tensorflow::Input debug_name, const
ParseSingleSequenceExample::Attrs& attrs);
static Attrs ContextSparseTypes(const DataTypeSlice& x) {
return Attrs().ContextSparseTypes(x);
}
static Attrs FeatureListDenseTypes(const DataTypeSlice& x) {
return Attrs().FeatureListDenseTypes(x);
}
static Attrs ContextDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
return Attrs().ContextDenseShapes(x);
}
static Attrs FeatureListSparseTypes(const DataTypeSlice& x) {
return Attrs().FeatureListSparseTypes(x);
}
static Attrs FeatureListDenseShapes(const gtl::ArraySlice<PartialTensorShape>& x) {
return Attrs().FeatureListDenseShapes(x);
}
Operation operation;
::tensorflow::OutputList context_sparse_indices;
::tensorflow::OutputList context_sparse_values;
::tensorflow::OutputList context_sparse_shapes;
::tensorflow::OutputList context_dense_values;
::tensorflow::OutputList feature_list_sparse_indices;
::tensorflow::OutputList feature_list_sparse_values;
::tensorflow::OutputList feature_list_sparse_shapes;
::tensorflow::OutputList feature_list_dense_values;
};
/// Transforms a serialized tensorflow.TensorProto proto into a Tensor.
///
/// Arguments:
/// * scope: A Scope object
/// * serialized: A scalar string containing a serialized TensorProto proto.
/// * out_type: The type of the serialized tensor. The provided type must match the
/// type of the serialized tensor and no implicit conversion will take place.
///
/// Returns:
/// * `Output`: A Tensor of type `out_type`.
class ParseTensor {
public:
ParseTensor(const ::tensorflow::Scope& scope, ::tensorflow::Input serialized,
DataType out_type);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Transforms a Tensor into a serialized TensorProto proto.
///
/// Arguments:
/// * scope: A Scope object
/// * tensor: A Tensor of type `T`.
///
/// Returns:
/// * `Output`: A serialized TensorProto proto of the input tensor.
class SerializeTensor {
public:
SerializeTensor(const ::tensorflow::Scope& scope, ::tensorflow::Input tensor);
operator ::tensorflow::Output() const { return serialized; }
operator ::tensorflow::Input() const { return serialized; }
::tensorflow::Node* node() const { return serialized.node(); }
Operation operation;
::tensorflow::Output serialized;
};
/// Converts each string in the input Tensor to the specified numeric type.
///
/// (Note that int32 overflow results in an error while float overflow
/// results in a rounded value.)
///
/// Arguments:
/// * scope: A Scope object
///
/// Optional attributes (see `Attrs`):
/// * out_type: The numeric type to interpret each string in `string_tensor` as.
///
/// Returns:
/// * `Output`: A Tensor of the same shape as the input `string_tensor`.
class StringToNumber {
public:
/// Optional attribute setters for StringToNumber
struct Attrs {
/// The numeric type to interpret each string in `string_tensor` as.
///
/// Defaults to DT_FLOAT
TF_MUST_USE_RESULT Attrs OutType(DataType x) {
Attrs ret = *this;
ret.out_type_ = x;
return ret;
}
DataType out_type_ = DT_FLOAT;
};
StringToNumber(const ::tensorflow::Scope& scope, ::tensorflow::Input
string_tensor);
StringToNumber(const ::tensorflow::Scope& scope, ::tensorflow::Input
string_tensor, const StringToNumber::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs OutType(DataType x) {
return Attrs().OutType(x);
}
Operation operation;
::tensorflow::Output output;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_PARSING_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_PARSING_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_PARSING_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup parsing_ops_internal Parsing Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_PARSING_OPS_INTERNAL_H_
@@ -0,0 +1,663 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_RANDOM_OPS_H_
#define TENSORFLOW_CC_OPS_RANDOM_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup random_ops Random Ops
/// @{
/// Draws samples from a multinomial distribution.
///
/// Arguments:
/// * scope: A Scope object
/// * logits: 2-D Tensor with shape `[batch_size, num_classes]`. Each slice `[i, :]`
/// represents the unnormalized log probabilities for all classes.
/// * num_samples: 0-D. Number of independent samples to draw for each row slice.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either seed or seed2 is set to be non-zero, the internal random number
/// generator is seeded by the given seed. Otherwise, a random seed is used.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: 2-D Tensor with shape `[batch_size, num_samples]`. Each slice `[i, :]`
/// contains the drawn class labels with range `[0, num_classes)`.
class Multinomial {
public:
/// Optional attribute setters for Multinomial
struct Attrs {
/// If either seed or seed2 is set to be non-zero, the internal random number
/// generator is seeded by the given seed. Otherwise, a random seed is used.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
/// Defaults to DT_INT64
TF_MUST_USE_RESULT Attrs OutputDtype(DataType x) {
Attrs ret = *this;
ret.output_dtype_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
DataType output_dtype_ = DT_INT64;
};
Multinomial(const ::tensorflow::Scope& scope, ::tensorflow::Input logits,
::tensorflow::Input num_samples);
Multinomial(const ::tensorflow::Scope& scope, ::tensorflow::Input logits,
::tensorflow::Input num_samples, const Multinomial::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
static Attrs OutputDtype(DataType x) {
return Attrs().OutputDtype(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random values from a normal distribution. The parameters may each be a
///
/// scalar which applies to the entire output, or a vector of length shape[0] which
/// stores the parameters for each batch.
///
/// Arguments:
/// * scope: A Scope object
/// * shape: The shape of the output tensor. Batches are indexed by the 0th dimension.
/// * means: The mean parameter of each batch.
/// * stdevs: The standard deviation parameter of each batch. Must be greater than 0.
/// * minvals: The minimum cutoff. May be -infinity.
/// * maxvals: The maximum cutoff. May be +infinity, and must be more than the minval
/// for each batch.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A matrix of shape num_batches x samples_per_batch, filled with random
/// truncated normal values using the parameters for each row.
class ParameterizedTruncatedNormal {
public:
/// Optional attribute setters for ParameterizedTruncatedNormal
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
ParameterizedTruncatedNormal(const ::tensorflow::Scope& scope,
::tensorflow::Input shape, ::tensorflow::Input
means, ::tensorflow::Input stdevs,
::tensorflow::Input minvals, ::tensorflow::Input
maxvals);
ParameterizedTruncatedNormal(const ::tensorflow::Scope& scope,
::tensorflow::Input shape, ::tensorflow::Input
means, ::tensorflow::Input stdevs,
::tensorflow::Input minvals, ::tensorflow::Input
maxvals, const
ParameterizedTruncatedNormal::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random values from the Gamma distribution(s) described by alpha.
///
/// This op uses the algorithm by Marsaglia et al. to acquire samples via
/// transformation-rejection from pairs of uniform and normal random variables.
/// See http://dl.acm.org/citation.cfm?id=358414
///
/// Arguments:
/// * scope: A Scope object
/// * shape: 1-D integer tensor. Shape of independent samples to draw from each
/// distribution described by the shape parameters given in alpha.
/// * alpha: A tensor in which each scalar is a "shape" parameter describing the
/// associated gamma distribution.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor with shape `shape + shape(alpha)`. Each slice
/// `[:, ..., :, i0, i1, ...iN]` contains the samples drawn for
/// `alpha[i0, i1, ...iN]`. The dtype of the output matches the dtype of alpha.
class RandomGamma {
public:
/// Optional attribute setters for RandomGamma
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
RandomGamma(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
::tensorflow::Input alpha);
RandomGamma(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
::tensorflow::Input alpha, const RandomGamma::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random values from the Poisson distribution(s) described by rate.
///
/// This op uses two algorithms, depending on rate. If rate >= 10, then
/// the algorithm by Hormann is used to acquire samples via
/// transformation-rejection.
/// See http://www.sciencedirect.com/science/article/pii/0167668793909974.
///
/// Otherwise, Knuth's algorithm is used to acquire samples via multiplying uniform
/// random variables.
/// See Donald E. Knuth (1969). Seminumerical Algorithms. The Art of Computer
/// Programming, Volume 2. Addison Wesley
///
/// Arguments:
/// * scope: A Scope object
/// * shape: 1-D integer tensor. Shape of independent samples to draw from each
/// distribution described by the shape parameters given in rate.
/// * rate: A tensor in which each scalar is a "rate" parameter describing the
/// associated poisson distribution.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor with shape `shape + shape(rate)`. Each slice
/// `[:, ..., :, i0, i1, ...iN]` contains the samples drawn for
/// `rate[i0, i1, ...iN]`.
class RandomPoissonV2 {
public:
/// Optional attribute setters for RandomPoissonV2
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
/// Defaults to DT_INT64
TF_MUST_USE_RESULT Attrs Dtype(DataType x) {
Attrs ret = *this;
ret.dtype_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
DataType dtype_ = DT_INT64;
};
RandomPoissonV2(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
::tensorflow::Input rate);
RandomPoissonV2(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
::tensorflow::Input rate, const RandomPoissonV2::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
static Attrs Dtype(DataType x) {
return Attrs().Dtype(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Randomly shuffles a tensor along its first dimension.
///
/// The tensor is shuffled along dimension 0, such that each `value[j]` is mapped
/// to one and only one `output[i]`. For example, a mapping that might occur for a
/// 3x2 tensor is:
///
/// ```
/// [[1, 2], [[5, 6],
/// [3, 4], ==> [1, 2],
/// [5, 6]] [3, 4]]
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * value: The tensor to be shuffled.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor of same shape and type as `value`, shuffled along its first
/// dimension.
class RandomShuffle {
public:
/// Optional attribute setters for RandomShuffle
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
RandomShuffle(const ::tensorflow::Scope& scope, ::tensorflow::Input value);
RandomShuffle(const ::tensorflow::Scope& scope, ::tensorflow::Input value,
const RandomShuffle::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random values from a normal distribution.
///
/// The generated values will have mean 0 and standard deviation 1.
///
/// Arguments:
/// * scope: A Scope object
/// * shape: The shape of the output tensor.
/// * dtype: The type of the output.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor of the specified shape filled with random normal values.
class RandomNormal {
public:
/// Optional attribute setters for RandomNormal
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
RandomNormal(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
DataType dtype);
RandomNormal(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
DataType dtype, const RandomNormal::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random values from a uniform distribution.
///
/// The generated values follow a uniform distribution in the range `[0, 1)`. The
/// lower bound 0 is included in the range, while the upper bound 1 is excluded.
///
/// Arguments:
/// * scope: A Scope object
/// * shape: The shape of the output tensor.
/// * dtype: The type of the output.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor of the specified shape filled with uniform random values.
class RandomUniform {
public:
/// Optional attribute setters for RandomUniform
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
RandomUniform(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
DataType dtype);
RandomUniform(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
DataType dtype, const RandomUniform::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random integers from a uniform distribution.
///
/// The generated values are uniform integers in the range `[minval, maxval)`.
/// The lower bound `minval` is included in the range, while the upper bound
/// `maxval` is excluded.
///
/// The random integers are slightly biased unless `maxval - minval` is an exact
/// power of two. The bias is small for values of `maxval - minval` significantly
/// smaller than the range of the output (either `2^32` or `2^64`).
///
/// Arguments:
/// * scope: A Scope object
/// * shape: The shape of the output tensor.
/// * minval: 0-D. Inclusive lower bound on the generated integers.
/// * maxval: 0-D. Exclusive upper bound on the generated integers.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor of the specified shape filled with uniform random integers.
class RandomUniformInt {
public:
/// Optional attribute setters for RandomUniformInt
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
RandomUniformInt(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
::tensorflow::Input minval, ::tensorflow::Input maxval);
RandomUniformInt(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
::tensorflow::Input minval, ::tensorflow::Input maxval, const
RandomUniformInt::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Outputs random values from a truncated normal distribution.
///
/// The generated values follow a normal distribution with mean 0 and standard
/// deviation 1, except that values whose magnitude is more than 2 standard
/// deviations from the mean are dropped and re-picked.
///
/// Arguments:
/// * scope: A Scope object
/// * shape: The shape of the output tensor.
/// * dtype: The type of the output.
///
/// Optional attributes (see `Attrs`):
/// * seed: If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
/// * seed2: A second seed to avoid seed collision.
///
/// Returns:
/// * `Output`: A tensor of the specified shape filled with random truncated normal
/// values.
class TruncatedNormal {
public:
/// Optional attribute setters for TruncatedNormal
struct Attrs {
/// If either `seed` or `seed2` are set to be non-zero, the random number
/// generator is seeded by the given seed. Otherwise, it is seeded by a
/// random seed.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed(int64 x) {
Attrs ret = *this;
ret.seed_ = x;
return ret;
}
/// A second seed to avoid seed collision.
///
/// Defaults to 0
TF_MUST_USE_RESULT Attrs Seed2(int64 x) {
Attrs ret = *this;
ret.seed2_ = x;
return ret;
}
int64 seed_ = 0;
int64 seed2_ = 0;
};
TruncatedNormal(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
DataType dtype);
TruncatedNormal(const ::tensorflow::Scope& scope, ::tensorflow::Input shape,
DataType dtype, const TruncatedNormal::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Seed(int64 x) {
return Attrs().Seed(x);
}
static Attrs Seed2(int64 x) {
return Attrs().Seed2(x);
}
Operation operation;
::tensorflow::Output output;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_RANDOM_OPS_H_
@@ -0,0 +1,47 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_RANDOM_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_RANDOM_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup random_ops_internal Random Ops Internal
/// @{
/// Computes the derivative of a Gamma random sample w.r.t. `alpha`.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The output tensor.
class RandomGammaGrad {
public:
RandomGammaGrad(const ::tensorflow::Scope& scope, ::tensorflow::Input alpha,
::tensorflow::Input sample);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_RANDOM_OPS_INTERNAL_H_
@@ -0,0 +1,46 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_REMOTE_FUSED_GRAPH_OPS_H_
#define TENSORFLOW_CC_OPS_REMOTE_FUSED_GRAPH_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup remote_fused_graph_ops Remote Fused Graph Ops
/// @{
/// TODO: add doc.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `OutputList`: The outputs tensor.
class RemoteFusedGraphExecute {
public:
RemoteFusedGraphExecute(const ::tensorflow::Scope& scope,
::tensorflow::InputList inputs, const DataTypeSlice&
Toutputs, StringPiece
serialized_remote_fused_graph_execute_info);
::tensorflow::Output operator[](size_t index) const { return outputs[index]; }
Operation operation;
::tensorflow::OutputList outputs;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_REMOTE_FUSED_GRAPH_OPS_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_SPARSE_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_SPARSE_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup sparse_ops_internal Sparse Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_SPARSE_OPS_INTERNAL_H_
@@ -0,0 +1,40 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_OPS_STANDARD_OPS_H_
#define TENSORFLOW_CC_OPS_STANDARD_OPS_H_
#include "tensorflow/cc/ops/array_ops.h"
#include "tensorflow/cc/ops/candidate_sampling_ops.h"
#include "tensorflow/cc/ops/const_op.h"
#include "tensorflow/cc/ops/control_flow_ops.h"
#include "tensorflow/cc/ops/data_flow_ops.h"
#include "tensorflow/cc/ops/image_ops.h"
#include "tensorflow/cc/ops/io_ops.h"
#include "tensorflow/cc/ops/linalg_ops.h"
#include "tensorflow/cc/ops/logging_ops.h"
#include "tensorflow/cc/ops/lookup_ops.h"
#include "tensorflow/cc/ops/math_ops.h"
#include "tensorflow/cc/ops/nn_ops.h"
#include "tensorflow/cc/ops/no_op.h"
#include "tensorflow/cc/ops/parsing_ops.h"
#include "tensorflow/cc/ops/random_ops.h"
#include "tensorflow/cc/ops/sparse_ops.h"
#include "tensorflow/cc/ops/state_ops.h"
#include "tensorflow/cc/ops/string_ops.h"
#include "tensorflow/cc/ops/training_ops.h"
#include "tensorflow/cc/ops/user_ops.h"
#endif // TENSORFLOW_CC_OPS_STANDARD_OPS_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_STATE_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_STATE_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup state_ops_internal State Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_STATE_OPS_INTERNAL_H_
@@ -0,0 +1,902 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_STRING_OPS_H_
#define TENSORFLOW_CC_OPS_STRING_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup string_ops String Ops
/// @{
/// Converts each entry in the given tensor to strings. Supports many numeric
///
/// types and boolean.
///
/// Arguments:
/// * scope: A Scope object
///
/// Optional attributes (see `Attrs`):
/// * precision: The post-decimal precision to use for floating point numbers.
/// Only used if precision > -1.
/// * scientific: Use scientific notation for floating point numbers.
/// * shortest: Use shortest representation (either scientific or standard) for
/// floating point numbers.
/// * width: Pad pre-decimal numbers to this width.
/// Applies to both floating point and integer numbers.
/// Only used if width > -1.
/// * fill: The value to pad if width > -1. If empty, pads with spaces.
/// Another typical value is '0'. String cannot be longer than 1 character.
///
/// Returns:
/// * `Output`: The output tensor.
class AsString {
public:
/// Optional attribute setters for AsString
struct Attrs {
/// The post-decimal precision to use for floating point numbers.
/// Only used if precision > -1.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs Precision(int64 x) {
Attrs ret = *this;
ret.precision_ = x;
return ret;
}
/// Use scientific notation for floating point numbers.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Scientific(bool x) {
Attrs ret = *this;
ret.scientific_ = x;
return ret;
}
/// Use shortest representation (either scientific or standard) for
/// floating point numbers.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Shortest(bool x) {
Attrs ret = *this;
ret.shortest_ = x;
return ret;
}
/// Pad pre-decimal numbers to this width.
/// Applies to both floating point and integer numbers.
/// Only used if width > -1.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs Width(int64 x) {
Attrs ret = *this;
ret.width_ = x;
return ret;
}
/// The value to pad if width > -1. If empty, pads with spaces.
/// Another typical value is '0'. String cannot be longer than 1 character.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Fill(StringPiece x) {
Attrs ret = *this;
ret.fill_ = x;
return ret;
}
int64 precision_ = -1;
bool scientific_ = false;
bool shortest_ = false;
int64 width_ = -1;
StringPiece fill_ = "";
};
AsString(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
AsString(const ::tensorflow::Scope& scope, ::tensorflow::Input input, const
AsString::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Precision(int64 x) {
return Attrs().Precision(x);
}
static Attrs Scientific(bool x) {
return Attrs().Scientific(x);
}
static Attrs Shortest(bool x) {
return Attrs().Shortest(x);
}
static Attrs Width(int64 x) {
return Attrs().Width(x);
}
static Attrs Fill(StringPiece x) {
return Attrs().Fill(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Decode web-safe base64-encoded strings.
///
/// Input may or may not have padding at the end. See EncodeBase64 for padding.
/// Web-safe means that input must use - and _ instead of + and /.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Base64 strings to decode.
///
/// Returns:
/// * `Output`: Decoded strings.
class DecodeBase64 {
public:
DecodeBase64(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Encode strings into web-safe base64 format.
///
/// Refer to the following article for more information on base64 format:
/// en.wikipedia.org/wiki/Base64. Base64 strings may have padding with '=' at the
/// end so that the encoded has length multiple of 4. See Padding section of the
/// link above.
///
/// Web-safe means that the encoder uses - and _ instead of + and /.
///
/// Arguments:
/// * scope: A Scope object
/// * input: Strings to be encoded.
///
/// Optional attributes (see `Attrs`):
/// * pad: Bool whether padding is applied at the ends.
///
/// Returns:
/// * `Output`: Input strings encoded in base64.
class EncodeBase64 {
public:
/// Optional attribute setters for EncodeBase64
struct Attrs {
/// Bool whether padding is applied at the ends.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs Pad(bool x) {
Attrs ret = *this;
ret.pad_ = x;
return ret;
}
bool pad_ = false;
};
EncodeBase64(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
EncodeBase64(const ::tensorflow::Scope& scope, ::tensorflow::Input input, const
EncodeBase64::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Pad(bool x) {
return Attrs().Pad(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Joins a string Tensor across the given dimensions.
///
/// Computes the string join across dimensions in the given string Tensor of shape
/// `[\\(d_0, d_1, ..., d_{n-1}\\)]`. Returns a new Tensor created by joining the input
/// strings with the given separator (default: empty string). Negative indices are
/// counted backwards from the end, with `-1` being equivalent to `n - 1`. If
/// indices are not specified, joins across all dimensions beginning from `n - 1`
/// through `0`.
///
/// For example:
///
/// ```python
/// # tensor `a` is [["a", "b"], ["c", "d"]]
/// tf.reduce_join(a, 0) ==> ["ac", "bd"]
/// tf.reduce_join(a, 1) ==> ["ab", "cd"]
/// tf.reduce_join(a, -2) = tf.reduce_join(a, 0) ==> ["ac", "bd"]
/// tf.reduce_join(a, -1) = tf.reduce_join(a, 1) ==> ["ab", "cd"]
/// tf.reduce_join(a, 0, keep_dims=True) ==> [["ac", "bd"]]
/// tf.reduce_join(a, 1, keep_dims=True) ==> [["ab"], ["cd"]]
/// tf.reduce_join(a, 0, separator=".") ==> ["a.c", "b.d"]
/// tf.reduce_join(a, [0, 1]) ==> "acbd"
/// tf.reduce_join(a, [1, 0]) ==> "abcd"
/// tf.reduce_join(a, []) ==> [["a", "b"], ["c", "d"]]
/// tf.reduce_join(a) = tf.reduce_join(a, [1, 0]) ==> "abcd"
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * inputs: The input to be joined. All reduced indices must have non-zero size.
/// * reduction_indices: The dimensions to reduce over. Dimensions are reduced in the
/// order specified. Omitting `reduction_indices` is equivalent to passing
/// `[n-1, n-2, ..., 0]`. Negative indices from `-n` to `-1` are supported.
///
/// Optional attributes (see `Attrs`):
/// * keep_dims: If `True`, retain reduced dimensions with length `1`.
/// * separator: The separator to use when joining.
///
/// Returns:
/// * `Output`: Has shape equal to that of the input with reduced dimensions removed or
/// set to `1` depending on `keep_dims`.
class ReduceJoin {
public:
/// Optional attribute setters for ReduceJoin
struct Attrs {
/// If `True`, retain reduced dimensions with length `1`.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs KeepDims(bool x) {
Attrs ret = *this;
ret.keep_dims_ = x;
return ret;
}
/// The separator to use when joining.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Separator(StringPiece x) {
Attrs ret = *this;
ret.separator_ = x;
return ret;
}
bool keep_dims_ = false;
StringPiece separator_ = "";
};
ReduceJoin(const ::tensorflow::Scope& scope, ::tensorflow::Input inputs,
::tensorflow::Input reduction_indices);
ReduceJoin(const ::tensorflow::Scope& scope, ::tensorflow::Input inputs,
::tensorflow::Input reduction_indices, const ReduceJoin::Attrs&
attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs KeepDims(bool x) {
return Attrs().KeepDims(x);
}
static Attrs Separator(StringPiece x) {
return Attrs().Separator(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Check if the input matches the regex pattern.
///
/// The input is a string tensor of any shape. The pattern is a scalar
/// string tensor which is applied to every element of the input tensor.
/// The boolean values (True or False) of the output tensor indicate
/// if the input matches the regex pattern provided.
///
/// The pattern follows the re2 syntax (https://github.com/google/re2/wiki/Syntax)
///
/// Arguments:
/// * scope: A Scope object
/// * input: A string tensor of the text to be processed.
/// * pattern: A scalar string tensor containing the regular expression to match the input.
///
/// Returns:
/// * `Output`: A bool tensor with the same shape as `input`.
class RegexFullMatch {
public:
RegexFullMatch(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input pattern);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Replaces the match of pattern in input with rewrite.
///
/// It follows the re2 syntax (https://github.com/google/re2/wiki/Syntax)
///
/// Arguments:
/// * scope: A Scope object
/// * input: The text to be processed.
/// * pattern: The regular expression to match the input.
/// * rewrite: The rewrite to be applied to the matched expresion.
///
/// Optional attributes (see `Attrs`):
/// * replace_global: If True, the replacement is global, otherwise the replacement
/// is done only on the first match.
///
/// Returns:
/// * `Output`: The text after applying pattern and rewrite.
class RegexReplace {
public:
/// Optional attribute setters for RegexReplace
struct Attrs {
/// If True, the replacement is global, otherwise the replacement
/// is done only on the first match.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs ReplaceGlobal(bool x) {
Attrs ret = *this;
ret.replace_global_ = x;
return ret;
}
bool replace_global_ = true;
};
RegexReplace(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input pattern, ::tensorflow::Input rewrite);
RegexReplace(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input pattern, ::tensorflow::Input rewrite, const
RegexReplace::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs ReplaceGlobal(bool x) {
return Attrs().ReplaceGlobal(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Formats a string template using a list of tensors.
///
/// Formats a string template using a list of tensors, pretty-printing tensor summaries.
///
/// Arguments:
/// * scope: A Scope object
/// * inputs: The list of tensors to format into the placeholder string.
///
/// Optional attributes (see `Attrs`):
/// * template_: A string, the template to format tensor summaries into.
/// * placeholder: A string, at each placeholder in the template a subsequent tensor summary will be inserted.
/// * summarize: When formatting the tensor summaries print the first and last summarize entries of each tensor dimension.
///
/// Returns:
/// * `Output`: = The resulting string scalar.
class StringFormat {
public:
/// Optional attribute setters for StringFormat
struct Attrs {
/// A string, the template to format tensor summaries into.
///
/// Defaults to "%s"
TF_MUST_USE_RESULT Attrs Template(StringPiece x) {
Attrs ret = *this;
ret.template_ = x;
return ret;
}
/// A string, at each placeholder in the template a subsequent tensor summary will be inserted.
///
/// Defaults to "%s"
TF_MUST_USE_RESULT Attrs Placeholder(StringPiece x) {
Attrs ret = *this;
ret.placeholder_ = x;
return ret;
}
/// When formatting the tensor summaries print the first and last summarize entries of each tensor dimension.
///
/// Defaults to 3
TF_MUST_USE_RESULT Attrs Summarize(int64 x) {
Attrs ret = *this;
ret.summarize_ = x;
return ret;
}
StringPiece template_ = "%s";
StringPiece placeholder_ = "%s";
int64 summarize_ = 3;
};
StringFormat(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs);
StringFormat(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs,
const StringFormat::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Template(StringPiece x) {
return Attrs().Template(x);
}
static Attrs Placeholder(StringPiece x) {
return Attrs().Placeholder(x);
}
static Attrs Summarize(int64 x) {
return Attrs().Summarize(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Joins the strings in the given list of string tensors into one tensor;
///
/// with the given separator (default is an empty separator).
///
/// Arguments:
/// * scope: A Scope object
/// * inputs: A list of string tensors. The tensors must all have the same shape,
/// or be scalars. Scalars may be mixed in; these will be broadcast to the shape
/// of non-scalar inputs.
///
/// Optional attributes (see `Attrs`):
/// * separator: string, an optional join separator.
///
/// Returns:
/// * `Output`: The output tensor.
class StringJoin {
public:
/// Optional attribute setters for StringJoin
struct Attrs {
/// string, an optional join separator.
///
/// Defaults to ""
TF_MUST_USE_RESULT Attrs Separator(StringPiece x) {
Attrs ret = *this;
ret.separator_ = x;
return ret;
}
StringPiece separator_ = "";
};
StringJoin(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs);
StringJoin(const ::tensorflow::Scope& scope, ::tensorflow::InputList inputs,
const StringJoin::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Separator(StringPiece x) {
return Attrs().Separator(x);
}
Operation operation;
::tensorflow::Output output;
};
/// String lengths of `input`.
///
/// Computes the length of each string given in the input tensor.
///
/// Arguments:
/// * scope: A Scope object
/// * input: The string for which to compute the length.
///
/// Optional attributes (see `Attrs`):
/// * unit: The unit that is counted to compute string length. One of: `"BYTE"` (for
/// the number of bytes in each string) or `"UTF8_CHAR"` (for the number of UTF-8
/// encoded Unicode code points in each string). Results are undefined
/// if `unit=UTF8_CHAR` and the `input` strings do not contain structurally
/// valid UTF-8.
///
/// Returns:
/// * `Output`: Integer tensor that has the same shape as `input`. The output contains the
/// element-wise string lengths of `input`.
class StringLength {
public:
/// Optional attribute setters for StringLength
struct Attrs {
/// The unit that is counted to compute string length. One of: `"BYTE"` (for
/// the number of bytes in each string) or `"UTF8_CHAR"` (for the number of UTF-8
/// encoded Unicode code points in each string). Results are undefined
/// if `unit=UTF8_CHAR` and the `input` strings do not contain structurally
/// valid UTF-8.
///
/// Defaults to "BYTE"
TF_MUST_USE_RESULT Attrs Unit(StringPiece x) {
Attrs ret = *this;
ret.unit_ = x;
return ret;
}
StringPiece unit_ = "BYTE";
};
StringLength(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
StringLength(const ::tensorflow::Scope& scope, ::tensorflow::Input input, const
StringLength::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs Unit(StringPiece x) {
return Attrs().Unit(x);
}
Operation operation;
::tensorflow::Output output;
};
/// Split elements of `input` based on `delimiter` into a `SparseTensor`.
///
/// Let N be the size of source (typically N will be the batch size). Split each
/// element of `input` based on `delimiter` and return a `SparseTensor`
/// containing the splitted tokens. Empty tokens are ignored.
///
/// `delimiter` can be empty, or a string of split characters. If `delimiter` is an
/// empty string, each element of `input` is split into individual single-byte
/// character strings, including splitting of UTF-8 multibyte sequences. Otherwise
/// every character of `delimiter` is a potential split point.
///
/// For example:
/// N = 2, input[0] is 'hello world' and input[1] is 'a b c', then the output
/// will be
///
/// indices = [0, 0;
/// 0, 1;
/// 1, 0;
/// 1, 1;
/// 1, 2]
/// shape = [2, 3]
/// values = ['hello', 'world', 'a', 'b', 'c']
///
/// Arguments:
/// * scope: A Scope object
/// * input: 1-D. Strings to split.
/// * delimiter: 0-D. Delimiter characters (bytes), or empty string.
///
/// Optional attributes (see `Attrs`):
/// * skip_empty: A `bool`. If `True`, skip the empty strings from the result.
///
/// Returns:
/// * `Output` indices: A dense matrix of int64 representing the indices of the sparse tensor.
/// * `Output` values: A vector of strings corresponding to the splited values.
/// * `Output` shape: a length-2 vector of int64 representing the shape of the sparse
/// tensor, where the first value is N and the second value is the maximum number
/// of tokens in a single input entry.
class StringSplit {
public:
/// Optional attribute setters for StringSplit
struct Attrs {
/// A `bool`. If `True`, skip the empty strings from the result.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs SkipEmpty(bool x) {
Attrs ret = *this;
ret.skip_empty_ = x;
return ret;
}
bool skip_empty_ = true;
};
StringSplit(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input delimiter);
StringSplit(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input delimiter, const StringSplit::Attrs& attrs);
static Attrs SkipEmpty(bool x) {
return Attrs().SkipEmpty(x);
}
Operation operation;
::tensorflow::Output indices;
::tensorflow::Output values;
::tensorflow::Output shape;
};
/// Split elements of `source` based on `sep` into a `SparseTensor`.
///
/// Let N be the size of source (typically N will be the batch size). Split each
/// element of `source` based on `sep` and return a `SparseTensor`
/// containing the split tokens. Empty tokens are ignored.
///
/// For example, N = 2, source[0] is 'hello world' and source[1] is 'a b c',
/// then the output will be
/// ```
/// st.indices = [0, 0;
/// 0, 1;
/// 1, 0;
/// 1, 1;
/// 1, 2]
/// st.shape = [2, 3]
/// st.values = ['hello', 'world', 'a', 'b', 'c']
/// ```
///
/// If `sep` is given, consecutive delimiters are not grouped together and are
/// deemed to delimit empty strings. For example, source of `"1<>2<><>3"` and
/// sep of `"<>"` returns `["1", "2", "", "3"]`. If `sep` is None or an empty
/// string, consecutive whitespace are regarded as a single separator, and the
/// result will contain no empty strings at the startor end if the string has
/// leading or trailing whitespace.
///
/// Note that the above mentioned behavior matches python's str.split.
///
/// Arguments:
/// * scope: A Scope object
/// * input: `1-D` string `Tensor`, the strings to split.
/// * sep: `0-D` string `Tensor`, the delimiter character.
///
/// Optional attributes (see `Attrs`):
/// * maxsplit: An `int`. If `maxsplit > 0`, limit of the split of the result.
///
/// Returns:
/// * `Output` indices
/// * `Output` values
/// * `Output` shape
class StringSplitV2 {
public:
/// Optional attribute setters for StringSplitV2
struct Attrs {
/// An `int`. If `maxsplit > 0`, limit of the split of the result.
///
/// Defaults to -1
TF_MUST_USE_RESULT Attrs Maxsplit(int64 x) {
Attrs ret = *this;
ret.maxsplit_ = x;
return ret;
}
int64 maxsplit_ = -1;
};
StringSplitV2(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input sep);
StringSplitV2(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input sep, const StringSplitV2::Attrs& attrs);
static Attrs Maxsplit(int64 x) {
return Attrs().Maxsplit(x);
}
Operation operation;
::tensorflow::Output indices;
::tensorflow::Output values;
::tensorflow::Output shape;
};
/// Strip leading and trailing whitespaces from the Tensor.
///
/// Arguments:
/// * scope: A Scope object
/// * input: A string `Tensor` of any shape.
///
/// Returns:
/// * `Output`: A string `Tensor` of the same shape as the input.
class StringStrip {
public:
StringStrip(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Converts each string in the input Tensor to its hash mod by a number of buckets.
///
/// The hash function is deterministic on the content of the string within the
/// process.
///
/// Note that the hash function may change from time to time.
/// This functionality will be deprecated and it's recommended to use
/// `tf.string_to_hash_bucket_fast()` or `tf.string_to_hash_bucket_strong()`.
///
/// Arguments:
/// * scope: A Scope object
/// * num_buckets: The number of buckets.
///
/// Returns:
/// * `Output`: A Tensor of the same shape as the input `string_tensor`.
class StringToHashBucket {
public:
StringToHashBucket(const ::tensorflow::Scope& scope, ::tensorflow::Input
string_tensor, int64 num_buckets);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Converts each string in the input Tensor to its hash mod by a number of buckets.
///
/// The hash function is deterministic on the content of the string within the
/// process and will never change. However, it is not suitable for cryptography.
/// This function may be used when CPU time is scarce and inputs are trusted or
/// unimportant. There is a risk of adversaries constructing inputs that all hash
/// to the same bucket. To prevent this problem, use a strong hash function with
/// `tf.string_to_hash_bucket_strong`.
///
/// Arguments:
/// * scope: A Scope object
/// * input: The strings to assign a hash bucket.
/// * num_buckets: The number of buckets.
///
/// Returns:
/// * `Output`: A Tensor of the same shape as the input `string_tensor`.
class StringToHashBucketFast {
public:
StringToHashBucketFast(const ::tensorflow::Scope& scope, ::tensorflow::Input
input, int64 num_buckets);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Converts each string in the input Tensor to its hash mod by a number of buckets.
///
/// The hash function is deterministic on the content of the string within the
/// process. The hash function is a keyed hash function, where attribute `key`
/// defines the key of the hash function. `key` is an array of 2 elements.
///
/// A strong hash is important when inputs may be malicious, e.g. URLs with
/// additional components. Adversaries could try to make their inputs hash to the
/// same bucket for a denial-of-service attack or to skew the results. A strong
/// hash prevents this by making it difficult, if not infeasible, to compute inputs
/// that hash to the same bucket. This comes at a cost of roughly 4x higher compute
/// time than `tf.string_to_hash_bucket_fast`.
///
/// Arguments:
/// * scope: A Scope object
/// * input: The strings to assign a hash bucket.
/// * num_buckets: The number of buckets.
/// * key: The key for the keyed hash function passed as a list of two uint64
/// elements.
///
/// Returns:
/// * `Output`: A Tensor of the same shape as the input `string_tensor`.
class StringToHashBucketStrong {
public:
StringToHashBucketStrong(const ::tensorflow::Scope& scope, ::tensorflow::Input
input, int64 num_buckets, const gtl::ArraySlice<int>&
key);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Return substrings from `Tensor` of strings.
///
/// For each string in the input `Tensor`, creates a substring starting at index
/// `pos` with a total length of `len`.
///
/// If `len` defines a substring that would extend beyond the length of the input
/// string, then as many characters as possible are used.
///
/// A negative `pos` indicates distance within the string backwards from the end.
///
/// If `pos` specifies an index which is out of range for any of the input strings,
/// then an `InvalidArgumentError` is thrown.
///
/// `pos` and `len` must have the same shape, otherwise a `ValueError` is thrown on
/// Op creation.
///
/// *NOTE*: `Substr` supports broadcasting up to two dimensions. More about
/// broadcasting
/// [here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
///
/// ---
///
/// Examples
///
/// Using scalar `pos` and `len`:
///
/// ```python
/// input = [b'Hello', b'World']
/// position = 1
/// length = 3
///
/// output = [b'ell', b'orl']
/// ```
///
/// Using `pos` and `len` with same shape as `input`:
///
/// ```python
/// input = [[b'ten', b'eleven', b'twelve'],
/// [b'thirteen', b'fourteen', b'fifteen'],
/// [b'sixteen', b'seventeen', b'eighteen']]
/// position = [[1, 2, 3],
/// [1, 2, 3],
/// [1, 2, 3]]
/// length = [[2, 3, 4],
/// [4, 3, 2],
/// [5, 5, 5]]
///
/// output = [[b'en', b'eve', b'lve'],
/// [b'hirt', b'urt', b'te'],
/// [b'ixtee', b'vente', b'hteen']]
/// ```
///
/// Broadcasting `pos` and `len` onto `input`:
///
/// ```
/// input = [[b'ten', b'eleven', b'twelve'],
/// [b'thirteen', b'fourteen', b'fifteen'],
/// [b'sixteen', b'seventeen', b'eighteen'],
/// [b'nineteen', b'twenty', b'twentyone']]
/// position = [1, 2, 3]
/// length = [1, 2, 3]
///
/// output = [[b'e', b'ev', b'lve'],
/// [b'h', b'ur', b'tee'],
/// [b'i', b've', b'hte'],
/// [b'i', b'en', b'nty']]
/// ```
///
/// Broadcasting `input` onto `pos` and `len`:
///
/// ```
/// input = b'thirteen'
/// position = [1, 5, 7]
/// length = [3, 2, 1]
///
/// output = [b'hir', b'ee', b'n']
/// ```
///
/// Arguments:
/// * scope: A Scope object
/// * input: Tensor of strings
/// * pos: Scalar defining the position of first character in each substring
/// * len: Scalar defining the number of characters to include in each substring
///
/// Returns:
/// * `Output`: Tensor of substrings
class Substr {
public:
Substr(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
::tensorflow::Input pos, ::tensorflow::Input len);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Determine the script codes of a given tensor of Unicode integer code points.
///
/// This operation converts Unicode code points to script codes corresponding to
/// each code point. Script codes correspond to International Components for
/// Unicode (ICU) UScriptCode values. See http://icu-project.org/apiref/icu4c/uscript_8h.html.
/// Returns -1 (USCRIPT_INVALID_CODE) for invalid codepoints. Output shape will
/// match input shape.
///
/// Arguments:
/// * scope: A Scope object
/// * input: A Tensor of int32 Unicode code points.
///
/// Returns:
/// * `Output`: A Tensor of int32 script codes corresponding to each input code point.
class UnicodeScript {
public:
UnicodeScript(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_STRING_OPS_H_
@@ -0,0 +1,105 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_STRING_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_STRING_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup string_ops_internal String Ops Internal
/// @{
/// Check if the input matches the regex pattern.
///
/// The input is a string tensor of any shape. The pattern is the
/// regular expression to be matched with every element of the input tensor.
/// The boolean values (True or False) of the output tensor indicate
/// if the input matches the regex pattern provided.
///
/// The pattern follows the re2 syntax (https://github.com/google/re2/wiki/Syntax)
///
/// Arguments:
/// * scope: A Scope object
/// * input: A string tensor of the text to be processed.
/// * pattern: The regular expression to match the input.
///
/// Returns:
/// * `Output`: A bool tensor with the same shape as `input`.
class StaticRegexFullMatch {
public:
StaticRegexFullMatch(const ::tensorflow::Scope& scope, ::tensorflow::Input
input, StringPiece pattern);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
Operation operation;
::tensorflow::Output output;
};
/// Replaces the match of pattern in input with rewrite.
///
/// It follows the re2 syntax (https://github.com/google/re2/wiki/Syntax)
///
/// Arguments:
/// * scope: A Scope object
/// * input: The text to be processed.
/// * pattern: The regular expression to match the input.
/// * rewrite: The rewrite to be applied to the matched expresion.
///
/// Optional attributes (see `Attrs`):
/// * replace_global: If True, the replacement is global, otherwise the replacement
/// is done only on the first match.
///
/// Returns:
/// * `Output`: The text after applying pattern and rewrite.
class StaticRegexReplace {
public:
/// Optional attribute setters for StaticRegexReplace
struct Attrs {
/// If True, the replacement is global, otherwise the replacement
/// is done only on the first match.
///
/// Defaults to true
TF_MUST_USE_RESULT Attrs ReplaceGlobal(bool x) {
Attrs ret = *this;
ret.replace_global_ = x;
return ret;
}
bool replace_global_ = true;
};
StaticRegexReplace(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
StringPiece pattern, StringPiece rewrite);
StaticRegexReplace(const ::tensorflow::Scope& scope, ::tensorflow::Input input,
StringPiece pattern, StringPiece rewrite, const
StaticRegexReplace::Attrs& attrs);
operator ::tensorflow::Output() const { return output; }
operator ::tensorflow::Input() const { return output; }
::tensorflow::Node* node() const { return output.node(); }
static Attrs ReplaceGlobal(bool x) {
return Attrs().ReplaceGlobal(x);
}
Operation operation;
::tensorflow::Output output;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_STRING_OPS_INTERNAL_H_
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,154 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_TRAINING_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_TRAINING_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup training_ops_internal Training Ops Internal
/// @{
/// Update '*var' according to the AdaMax algorithm.
///
/// m_t <- beta1 * m_{t-1} + (1 - beta1) * g
/// v_t <- max(beta2 * v_{t-1}, abs(g))
/// variable <- variable - learning_rate / (1 - beta1^t) * m_t / (v_t + epsilon)
///
/// Arguments:
/// * scope: A Scope object
/// * var: Should be from a Variable().
/// * m: Should be from a Variable().
/// * v: Should be from a Variable().
/// * beta1_power: Must be a scalar.
/// * lr: Scaling factor. Must be a scalar.
/// * beta1: Momentum factor. Must be a scalar.
/// * beta2: Momentum factor. Must be a scalar.
/// * epsilon: Ridge term. Must be a scalar.
/// * grad: The gradient.
///
/// Optional attributes (see `Attrs`):
/// * use_locking: If `True`, updating of the var, m, and v tensors will be protected
/// by a lock; otherwise the behavior is undefined, but may exhibit less
/// contention.
///
/// Returns:
/// * `Output`: Same as "var".
class ApplyAdaMax {
public:
/// Optional attribute setters for ApplyAdaMax
struct Attrs {
/// If `True`, updating of the var, m, and v tensors will be protected
/// by a lock; otherwise the behavior is undefined, but may exhibit less
/// contention.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs UseLocking(bool x) {
Attrs ret = *this;
ret.use_locking_ = x;
return ret;
}
bool use_locking_ = false;
};
ApplyAdaMax(const ::tensorflow::Scope& scope, ::tensorflow::Input var,
::tensorflow::Input m, ::tensorflow::Input v, ::tensorflow::Input
beta1_power, ::tensorflow::Input lr, ::tensorflow::Input beta1,
::tensorflow::Input beta2, ::tensorflow::Input epsilon,
::tensorflow::Input grad);
ApplyAdaMax(const ::tensorflow::Scope& scope, ::tensorflow::Input var,
::tensorflow::Input m, ::tensorflow::Input v, ::tensorflow::Input
beta1_power, ::tensorflow::Input lr, ::tensorflow::Input beta1,
::tensorflow::Input beta2, ::tensorflow::Input epsilon,
::tensorflow::Input grad, const ApplyAdaMax::Attrs& attrs);
operator ::tensorflow::Output() const { return out; }
operator ::tensorflow::Input() const { return out; }
::tensorflow::Node* node() const { return out.node(); }
static Attrs UseLocking(bool x) {
return Attrs().UseLocking(x);
}
Operation operation;
::tensorflow::Output out;
};
/// Update '*var' according to the AdaMax algorithm.
///
/// m_t <- beta1 * m_{t-1} + (1 - beta1) * g
/// v_t <- max(beta2 * v_{t-1}, abs(g))
/// variable <- variable - learning_rate / (1 - beta1^t) * m_t / (v_t + epsilon)
///
/// Arguments:
/// * scope: A Scope object
/// * var: Should be from a Variable().
/// * m: Should be from a Variable().
/// * v: Should be from a Variable().
/// * beta1_power: Must be a scalar.
/// * lr: Scaling factor. Must be a scalar.
/// * beta1: Momentum factor. Must be a scalar.
/// * beta2: Momentum factor. Must be a scalar.
/// * epsilon: Ridge term. Must be a scalar.
/// * grad: The gradient.
///
/// Optional attributes (see `Attrs`):
/// * use_locking: If `True`, updating of the var, m, and v tensors will be protected
/// by a lock; otherwise the behavior is undefined, but may exhibit less
/// contention.
///
/// Returns:
/// * the created `Operation`
class ResourceApplyAdaMax {
public:
/// Optional attribute setters for ResourceApplyAdaMax
struct Attrs {
/// If `True`, updating of the var, m, and v tensors will be protected
/// by a lock; otherwise the behavior is undefined, but may exhibit less
/// contention.
///
/// Defaults to false
TF_MUST_USE_RESULT Attrs UseLocking(bool x) {
Attrs ret = *this;
ret.use_locking_ = x;
return ret;
}
bool use_locking_ = false;
};
ResourceApplyAdaMax(const ::tensorflow::Scope& scope, ::tensorflow::Input var,
::tensorflow::Input m, ::tensorflow::Input v,
::tensorflow::Input beta1_power, ::tensorflow::Input lr,
::tensorflow::Input beta1, ::tensorflow::Input beta2,
::tensorflow::Input epsilon, ::tensorflow::Input grad);
ResourceApplyAdaMax(const ::tensorflow::Scope& scope, ::tensorflow::Input var,
::tensorflow::Input m, ::tensorflow::Input v,
::tensorflow::Input beta1_power, ::tensorflow::Input lr,
::tensorflow::Input beta1, ::tensorflow::Input beta2,
::tensorflow::Input epsilon, ::tensorflow::Input grad,
const ResourceApplyAdaMax::Attrs& attrs);
operator ::tensorflow::Operation() const { return operation; }
static Attrs UseLocking(bool x) {
return Attrs().UseLocking(x);
}
Operation operation;
};
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_TRAINING_OPS_INTERNAL_H_
@@ -0,0 +1,44 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_USER_OPS_H_
#define TENSORFLOW_CC_OPS_USER_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup user_ops User Ops
/// @{
/// Output a fact about factorials.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The fact tensor.
class Fact {
public:
Fact(const ::tensorflow::Scope& scope);
operator ::tensorflow::Output() const { return fact; }
operator ::tensorflow::Input() const { return fact; }
::tensorflow::Node* node() const { return fact.node(); }
Operation operation;
::tensorflow::Output fact;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_USER_OPS_H_
@@ -0,0 +1,28 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_CC_OPS_USER_OPS_INTERNAL_H_
#define TENSORFLOW_CC_OPS_USER_OPS_INTERNAL_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
namespace internal {
// NOTE: This namespace has internal TensorFlow details that
// are not part of TensorFlow's public API.
/// @defgroup user_ops_internal User Ops Internal
/// @{
} // namespace internal
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_USER_OPS_INTERNAL_H_
@@ -0,0 +1,74 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_OPS_WHILE_LOOP_H_
#define TENSORFLOW_CC_OPS_WHILE_LOOP_H_
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
namespace tensorflow {
namespace ops {
// Function that takes cond graph inputs and returns cond graph boolean output.
// 'output' need not be set if an error is returned.
typedef std::function<Status(const Scope&, const std::vector<Output>& inputs,
Output* output)>
CondGraphBuilderFn;
// Function that takes body graph inputs and returns body graph outputs.
// 'outputs' need not be populated if an error is returned.
typedef std::function<Status(const Scope&, const std::vector<Output>& inputs,
std::vector<Output>* outputs)>
BodyGraphBuilderFn;
// Constructs a while loop.
//
// Arguments:
// * scope: used to construct the while loop.
// * inputs: the initial values of the loop variables. Must be non-empty.
// * cond: a function that builds the condition graph of the loop. Takes the
// current loop variables as inputs and returns a scalar boolean Output
// indicating whether the loop should continue.
// * body: a function that builds the body graph of the loop. Takes the current
// loop variables as inputs and returns the updated loop variables.
// * frame_name: the frame name to use for this while loop. This should be a
// unique name. This will be used as a prefix for created operations.
// * outputs: output param that returns final loop variable outputs in non-error
// case. Must be non-null and empty.
// * create_while_ctx: if true, a WhileContext is created and populated for this
// loop. See core/graph/while_context.h for more details on
// WhileContexts. This is set to false for loops used as part of gradient
// computations, since they're part of the gradient for a loop in the
// forward-pass.
// TODO(skyewm): revisit this. Should we create WhileContexts for all loops,
// even if we don't need them?
// * cond_output: if non-null, the output of the predicate is returned. This
// will always be a LoopCond node.
//
// Returns an error if the while loop could not be fully constructed.
//
// TODO(skyewm): clean up partially-constructed loop in error case
// TODO(skyewm): create public interface to this method
Status BuildWhileLoop(const Scope& scope, const std::vector<Output>& inputs,
const CondGraphBuilderFn& cond,
const BodyGraphBuilderFn& body, const string& frame_name,
OutputList* outputs, bool create_while_ctx = true,
Output* cond_output = nullptr);
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_CC_OPS_WHILE_LOOP_H_
@@ -0,0 +1,97 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_PROFILER_PROFILER_H_
#define TENSORFLOW_CC_PROFILER_PROFILER_H_
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/profiler/internal/tfprof_stats.h"
#include "tensorflow/core/profiler/tfprof_options.h"
#include "tensorflow/core/profiler/tfprof_output.pb.h"
namespace tensorflow {
namespace tfprof {
/// @addtogroup core
/// @{
/// A `Profiler` object lets the caller profile the execution of a graph.
///
/// Example:
/// // First build a graph and run tracing.
/// Scope root = Scope::NewRootScope();
/// auto a = Placeholder(root, DT_INT32);
/// auto c = Add(root, a, {41});
///
/// ClientSession session(root);
/// std::vector<Tensor> outputs;
/// RunOptions run_options;
/// run_options.set_trace_level(RunOptions::FULL_TRACE);
/// RunMetadata run_meta;
/// Status s = session.Run(run_options, { {a, {1}} }, {c}, &outputs,
/// &run_meta);
/// if (!s.ok()) { ... }
///
/// // Then create profiler to do profiling.
/// GraphDef graph;
/// root.ToGraphDef(&graph);
/// Profiler profiler(graph);
/// profiler.AddStep(0, run_meta);
/// Options opts = ... // TODO(xpan): Support option building API.
/// MultiGraphNodeProto r = profiler.ProfileOperations(opts);
///
class Profiler {
public:
/// `graph` is the model's GraphDef.
Profiler(const GraphDef& graph);
/// Adds tracing information `run_meta` to profiler. A `run_meta` is
/// generated by a TensorFlow session run call. `step` is the key
/// to the `run_meta`. When calling ProfileXXX methods, caller can specify
/// `step` in `options` to selectively profile the corresponding `run_meta`.
/// Multiple different `run_meta` can be keyed by the same `step` in order
/// to group them together.
void AddStep(int64 step, const RunMetadata& run_meta);
/// Profiles the model by organizing nodes in graph structure.
/// Each node is an op and the nodes are connected by the op inputs/outputs.
GraphNodeProto ProfileGraph(const Options& options);
/// Profiles the model by organizing nodes in name scope structure.
/// Each node is an op, and nodes are organized by the ops' name
/// scope, similar to a file system tree.
/// E.g. /foo is the root of operation /foo/matmul_1 and foo/conv_2.
GraphNodeProto ProfileNameScope(const Options& options);
/// Profiles the model by organizing nodes by operation types.
/// Each node is an operation type (e.g. Conv2D or MatMul), containing all
/// ops belonging to that type in the model.
MultiGraphNodeProto ProfileOperations(const Options& options);
/// Serialize the profile content (ProfileProto) into a binary string,
/// User can write the string to file for offline analysis by
/// tfprof command-line tools or graphical user interface.
Status SerializeToString(string* content);
private:
std::unique_ptr<TFStats> stats_;
};
/// @}
} // namespace tfprof
} // namespace tensorflow
#endif // TENSORFLOW_CC_PROFILER_PROFILER_H_
@@ -0,0 +1,50 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_SAVED_MODEL_CONSTANTS_H_
#define TENSORFLOW_CC_SAVED_MODEL_CONSTANTS_H_
namespace tensorflow {
/// SavedModel assets directory.
constexpr char kSavedModelAssetsDirectory[] = "assets";
/// SavedModel assets.extra directory.
constexpr char kSavedModelAssetsExtraDirectory[] = "assets.extra";
/// SavedModel assets key for graph collection-def.
constexpr char kSavedModelAssetsKey[] = "saved_model_assets";
/// SavedModel proto filename.
constexpr char kSavedModelFilenamePb[] = "saved_model.pb";
/// SavedModel text format proto filename.
constexpr char kSavedModelFilenamePbTxt[] = "saved_model.pbtxt";
/// SavedModel legacy init op key.
constexpr char kSavedModelLegacyInitOpKey[] = "legacy_init_op";
/// SavedModel main op key.
constexpr char kSavedModelMainOpKey[] = "saved_model_main_op";
/// Directory in which to save the SavedModel variables.
constexpr char kSavedModelVariablesDirectory[] = "variables";
/// SavedModel variables filename.
constexpr char kSavedModelVariablesFilename[] = "variables";
} // namespace tensorflow
#endif // TENSORFLOW_CC_SAVED_MODEL_CONSTANTS_H_
@@ -0,0 +1,64 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
/// SavedModel loading functions and SavedModelBundle struct.
#ifndef TENSORFLOW_CC_SAVED_MODEL_LOADER_H_
#define TENSORFLOW_CC_SAVED_MODEL_LOADER_H_
#include <string>
#include <unordered_set>
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow/core/public/session.h"
namespace tensorflow {
/// SavedModel representation once the SavedModel is loaded from storage.
struct SavedModelBundle {
std::unique_ptr<Session> session;
MetaGraphDef meta_graph_def;
/// A TensorFlow Session does not Close itself on destruction. To avoid
/// resource leaks, we explicitly call Close on Sessions that we create.
~SavedModelBundle() {
if (session) {
session->Close().IgnoreError();
}
}
SavedModelBundle() = default;
};
/// Loads a SavedModel from the specified export directory. The meta graph def
/// to be loaded is identified by the supplied tags, corresponding exactly to
/// the set of tags used at SavedModel build time. Returns a SavedModel bundle
/// with a session and the requested meta graph def, if found.
Status LoadSavedModel(const SessionOptions& session_options,
const RunOptions& run_options, const string& export_dir,
const std::unordered_set<string>& tags,
SavedModelBundle* const bundle);
/// Checks whether the provided directory could contain a SavedModel. Note that
/// the method does not load any data by itself. If the method returns `false`,
/// the export directory definitely does not contain a SavedModel. If the method
/// returns `true`, the export directory may contain a SavedModel but provides
/// no guarantee that it can be loaded.
bool MaybeSavedModelDirectory(const string& export_dir);
} // namespace tensorflow
#endif // TENSORFLOW_CC_SAVED_MODEL_LOADER_H_
@@ -0,0 +1,39 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
/// Functions to read the SavedModel proto, or parts of it.
#ifndef TENSORFLOW_CC_SAVED_MODEL_READER_H_
#define TENSORFLOW_CC_SAVED_MODEL_READER_H_
#include <string>
#include <unordered_set>
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
namespace tensorflow {
// Reads the SavedModel proto from saved_model.pb(txt) in the given directory,
// finds the MetaGraphDef that matches the given set of tags and writes it to
// the `meta_graph_def` parameter. Returns a failure status when the SavedModel
// file does not exist or no MetaGraphDef matches the tags.
Status ReadMetaGraphDefFromSavedModel(const string& export_dir,
const std::unordered_set<string>& tags,
MetaGraphDef* const meta_graph_def);
} // namespace tensorflow
#endif // TENSORFLOW_CC_SAVED_MODEL_READER_H_
@@ -0,0 +1,69 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_SAVED_MODEL_SIGNATURE_CONSTANTS_H_
#define TENSORFLOW_CC_SAVED_MODEL_SIGNATURE_CONSTANTS_H_
namespace tensorflow {
/// Key in the signature def map for `default` serving signatures. The default
/// signature is used in inference requests where a specific signature was not
/// specified.
static constexpr char kDefaultServingSignatureDefKey[] = "serving_default";
////////////////////////////////////////////////////////////////////////////////
/// Classification API constants.
/// Classification inputs.
static constexpr char kClassifyInputs[] = "inputs";
/// Classification method name used in a SignatureDef.
static constexpr char kClassifyMethodName[] = "tensorflow/serving/classify";
/// Classification classes output.
static constexpr char kClassifyOutputClasses[] = "classes";
/// Classification scores output.
static constexpr char kClassifyOutputScores[] = "scores";
////////////////////////////////////////////////////////////////////////////////
/// Predict API constants.
/// Predict inputs.
static constexpr char kPredictInputs[] = "inputs";
/// Predict method name used in a SignatureDef.
static constexpr char kPredictMethodName[] = "tensorflow/serving/predict";
/// Predict outputs.
static constexpr char kPredictOutputs[] = "outputs";
////////////////////////////////////////////////////////////////////////////////
/// Regression API constants.
/// Regression inputs.
static constexpr char kRegressInputs[] = "inputs";
/// Regression method name used in a SignatureDef.
static constexpr char kRegressMethodName[] = "tensorflow/serving/regress";
/// Regression outputs.
static constexpr char kRegressOutputs[] = "outputs";
////////////////////////////////////////////////////////////////////////////////
} // namespace tensorflow
#endif // TENSORFLOW_CC_SAVED_MODEL_SIGNATURE_CONSTANTS_H_
@@ -0,0 +1,35 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_SAVED_MODEL_TAG_CONSTANTS_H_
#define TENSORFLOW_CC_SAVED_MODEL_TAG_CONSTANTS_H_
namespace tensorflow {
/// Tag for the `gpu` graph.
constexpr char kSavedModelTagGpu[] = "gpu";
/// Tag for the `tpu` graph.
constexpr char kSavedModelTagTpu[] = "tpu";
/// Tag for the `serving` graph.
constexpr char kSavedModelTagServe[] = "serve";
/// Tag for the `training` graph.
constexpr char kSavedModelTagTrain[] = "train";
} // namespace tensorflow
#endif // TENSORFLOW_CC_SAVED_MODEL_TAG_CONSTANTS_H_
@@ -0,0 +1,43 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_TOOLS_FREEZE_SAVED_MODEL_H_
#define TENSORFLOW_CC_TOOLS_FREEZE_SAVED_MODEL_H_
#include <unordered_set>
#include "tensorflow/cc/saved_model/loader.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// Returns a frozen GraphDef, input tensors, and output tensors from the loaded
// SavedModelBundle.
// `inputs` and `outputs` consist of the union of all inputs and outputs in the
// SignatureDefs in the SavedModelBundle.
// FreezeSavedModel sets `frozen_graph_def` to a GraphDef of all nodes needed by
// `outputs`. All variables in the supplied SavedModelBundle are converted to
// constants, set to the value of the variables, by running the restored Session
// in the SavedModelBundle.
// WARNING: Only the variable checkpoints will be reflected in the frozen
// graph_def. All saved_model assets will be ignored.
Status FreezeSavedModel(const SavedModelBundle& saved_model_bundle,
GraphDef* frozen_graph_def,
std::unordered_set<string>* inputs,
std::unordered_set<string>* outputs);
} // namespace tensorflow
#endif // TENSORFLOW_CC_TOOLS_FREEZE_SAVED_MODEL_H_
@@ -0,0 +1,131 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_TRAINING_COORDINATOR_H_
#define TENSORFLOW_CC_TRAINING_COORDINATOR_H_
#include <atomic>
#include <memory>
#include <unordered_set>
#include <vector>
#include "tensorflow/core/framework/cost_graph.pb.h"
#include "tensorflow/core/lib/core/error_codes.pb.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/macros.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/protobuf/config.pb.h"
namespace tensorflow {
/// The abstract interface for runners which must implement the Join and the
/// IsRunning function.
class RunnerInterface {
public:
virtual ~RunnerInterface() {}
virtual Status Join() = 0;
virtual Status ExportCostGraph(CostGraphDef* cost_graph) const {
return Status(error::INVALID_ARGUMENT, "No cost model to export.");
}
/// Returns true iff the runner is running, i.e. if it is trying to populate
/// its queue.
virtual bool IsRunning() const = 0;
};
/// Coordinator class manages the termination of a collection of QueueRunners.
/// Without a coordinator, QueueRunners have to be joined in a specific order;
/// otherwise the QueueRunner::Join() could sometimes hang. The
/// Coordinator::RequestStop() plays the key role which notifies all running
/// threads under a coordinator to stop. This function could be called by any
/// thread or any client.
/// Usage, in the client:
/// Coordinator coord;
/// std::unique_ptr<QueueRunner> qr(&coord, ...);
/// qr.Start(session);
/// coord.RegisterRunner(std::move(qr));
/// /// do some work
/// TF_CHECK_OK(coord.Join());
/// In each thread of QueueRunner, the coordinator needs to be used as:
/// void Run() {
/// while (!coord->ShouldStop()) {
/// /// do some work
/// if (error) {
/// coord->RequestStop();
/// coord->ReportStatus(error_status);
/// }
/// }
/// }
class Coordinator {
public:
Coordinator();
/// Constructor with a list of error codes which would not be taken as errors
/// in status reporting.
Coordinator(const std::vector<error::Code>& clean_stop_errors);
/// In the destructor, RequestStop() and Join() would be called.
~Coordinator();
/// Registers a runner, i.e. a unit of running threads which is usually a
/// QueueRunner. It takes the ownership of runner to avoid lifecycle-related
/// problems. Note, the coordinator would not start these threads; they are
/// supposed to be in running state when they are registered here.
Status RegisterRunner(std::unique_ptr<RunnerInterface> runner);
/// Returns true iff all the registered runners have been stopped.
bool AllRunnersStopped();
/// Requests all running threads to stop.
Status RequestStop();
/// Returns true if its RequestStop() has been called.
bool ShouldStop();
/// Joins all threads, returns OK or the first reported and unexpected status.
Status Join();
/// Reports status to the coordinator. This is usually called by threads.
void ReportStatus(const Status& status);
/// Returns the latest status.
Status GetStatus();
/// Returns immediately if the coordinator is stopped or blocks until
/// RequestStop() is called.
void WaitForStop();
// Returns the cost graph from stored run metadata in registered runners.
Status ExportCostGraph(CostGraphDef* cost_graph) const;
private:
std::unordered_set<int> clean_stop_errors_;
condition_variable wait_for_stop_;
mutex mu_;
bool should_stop_ GUARDED_BY(mu_);
mutex status_lock_;
Status status_ GUARDED_BY(status_lock_);
mutable mutex runners_lock_;
std::vector<std::unique_ptr<RunnerInterface>> runners_
GUARDED_BY(runners_lock_);
TF_DISALLOW_COPY_AND_ASSIGN(Coordinator);
};
} // namespace tensorflow
#endif // TENSORFLOW_CC_TRAINING_COORDINATOR_H_
@@ -0,0 +1,140 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_CC_TRAINING_QUEUE_RUNNER_H_
#define TENSORFLOW_CC_TRAINING_QUEUE_RUNNER_H_
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>
#include "tensorflow/cc/training/coordinator.h"
#include "tensorflow/core/lib/core/blocking_counter.h"
#include "tensorflow/core/lib/core/error_codes.pb.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/protobuf/config.pb.h"
#include "tensorflow/core/protobuf/queue_runner.pb.h"
#include "tensorflow/core/public/session.h"
namespace tensorflow {
/// QueueRunner class imitates the behavior of the python version of QueueRunner
/// which creates a thread for each enqueue op, runs close op on completion.
class QueueRunner : public RunnerInterface {
public:
/// Creates a new QueueRunner from proto.
// TODO(yuefengz): we may want to initialize from queues and ops in the
// future.
static Status New(const QueueRunnerDef& queue_runner_def,
std::unique_ptr<QueueRunner>* result);
/// Creates a new QueueRunner with a coordinator, see coordinator.h for usage.
static Status New(const QueueRunnerDef& queue_runner_def, Coordinator* coord,
std::unique_ptr<QueueRunner>* result);
/// Adds a callback that the queue runner will call when it detects an error.
void AddErrorCallback(const std::function<void(Status)>& cb);
/// Delete the previously registered callbacks.
void ClearErrorCallbacks();
/// The destructor would join all the threads.
~QueueRunner();
/// Starts the queue runner with the given session.
Status Start(Session* sess);
/// Starts the queue runner with the given session and sets the run arguments
/// for sess->Run. It also collects and stores the cost model.
Status StartAndCollectCostGraph(Session* sess,
const RunOptions& run_options = RunOptions());
/// Starts the queue runner with the given session, and wait for up to the
/// specified time (in milliseconds) for the queues to start to fill up.
Status Start(Session* sess, int wait_for_ms);
Status StartAndCollectCostGraph(Session* session, int wait_for_ms,
const RunOptions& run_options = RunOptions());
/// Requests to stop and runs the cancel op. It would be called in a separate
/// thread when coordinator is set. If there is no coordinator it should be
/// called before calling Join.
void Stop(Session* sess);
/// Joins all the threads. Returns okay if all threads run successfully;
/// otherwise returns the first captured failure status.
Status Join() final;
/// Returns the latest status.
Status GetStatus();
// Returns the stored cost model.
Status ExportCostGraph(CostGraphDef* cost_graph) const override;
private:
QueueRunner() : coord_(nullptr), stopped_(false), cg_mu_(nullptr) {}
// Initializes the instance with the QueueRunnerDef proto.
Status Init(const QueueRunnerDef& queue_runner_def);
// The Run function for each thread.
void Run(Session* sess, const string& enqueue_op);
// Updates the internal status; it only keeps OK or the first unexpected error
// status.
void UpdateStatus(const Status& status);
bool IsQueueClosed(Status status) const {
return queue_closed_exception_types_.count(
static_cast<int>(status.code())) > 0;
}
bool IsRunning() const override { return !stopped_; }
void SetRunArgumentsAndCostGraph(const RunOptions& run_options);
Status RealRun(Session* sess, const string& op, bool update_costs);
string queue_name_;
std::vector<string> enqueue_op_names_;
string close_op_name_;
string cancel_op_name_;
// code::Code casted to int to avoid a hash function.
std::unordered_set<int> queue_closed_exception_types_;
std::unique_ptr<thread::ThreadPool> thread_pool_;
mutex mu_;
int runs_ = 0;
Status status_ GUARDED_BY(mu_);
Status enqueue_status_ GUARDED_BY(mu_);
std::unique_ptr<BlockingCounter> counter_;
Coordinator* coord_;
std::atomic<bool> stopped_;
mutex cb_mu_;
std::vector<std::function<void(Status)>> callbacks_;
mutable std::unique_ptr<mutex> cg_mu_;
std::unique_ptr<CostGraphDef> cost_graph_ GUARDED_BY(cg_mu_);
RunOptions run_options_;
};
} // namespace tensorflow
#endif // TENSORFLOW_CC_TRAINING_QUEUE_RUNNER_H_
@@ -0,0 +1,33 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_BUILD_XLA_OPS_PASS_H_
#define TENSORFLOW_COMPILER_JIT_BUILD_XLA_OPS_PASS_H_
#include "tensorflow/core/common_runtime/optimization_registry.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// Adds _XlaCompile and _XlaRun operations to the TF graph that compiles and
// executes (using XLA) TF function calls marked with "_XlaCompiledKernel".
class BuildXlaOpsPass : public GraphOptimizationPass {
public:
Status Run(const GraphOptimizationPassOptions& options) override;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_BUILD_XLA_OPS_PASS_H_
@@ -0,0 +1,68 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_H_
#define TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_H_
#include "tensorflow/core/graph/graph.h"
namespace tensorflow {
// This analyzes a TensorFlow graph to identify nodes which may have partially
// dead inputs (i.e. these nodes may have some dead inputs and some alive
// inputs).
//
// For example, the ADD node in the following graph
//
// V0 PRED0 V1 PRED1
// | | | |
// v v v v
// SWITCH SWITCH
// | |
// +---+ + ---+
// | |
// v v
// ADD
//
// can have its inputs independently dead or alive based on the runtime values
// of PRED0 and PRED1.
//
// It is tempting to call this a liveness analysis but I avoided that because
// "liveness" already has other connotations.
class DeadnessAnalysis {
public:
// Returns true if `node` may have some live inputs and some dead inputs.
//
// This is a conservatively correct routine -- if it returns false then `node`
// is guaranteed to not have inputs with mismatching liveness, but not the
// converse.
//
// REQUIRES: node is not a Merge operation.
virtual bool HasInputsWithMismatchingDeadness(const Node& node) = 0;
// Prints out the internal state of this instance. For debugging purposes
// only.
virtual void Print() const = 0;
virtual ~DeadnessAnalysis();
// Run the deadness analysis over `graph` and returns an error or a populated
// instance of DeadnessAnalysis in `result`.
static Status Run(const Graph& graph,
std::unique_ptr<DeadnessAnalysis>* result);
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_H_
@@ -0,0 +1,40 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_INTERNAL_H_
#define TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_INTERNAL_H_
#include "absl/container/flat_hash_map.h"
#include "tensorflow/core/graph/tensor_id.h"
namespace tensorflow {
namespace deadness_analysis_internal {
// Returns a map describing the predicate each Tensor was mapped to. For
// testing purposes only.
using PredicateMapTy = absl::flat_hash_map<TensorId, string, TensorId::Hasher>;
Status ComputePredicates(const Graph& graph, PredicateMapTy* out_predicate_map);
// Returns a map describing the predicate each Tensor was mapped to. For
// testing purposes only. Makes deadness analysis visit the graph in the order
// specified in `reverse_post_order` which must be a valid RPO for the graph
// minus NextIteration->Merge edges.
Status ComputePredicates(const Graph& graph,
absl::Span<Node* const> reverse_post_order,
PredicateMapTy* out_predicate_map);
} // namespace deadness_analysis_internal
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_INTERNAL_H_
@@ -0,0 +1,30 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Provides definitions needed for use of the TensorFlow XLA
// device.
#ifndef TENSORFLOW_COMPILER_JIT_DEFS_H_
#define TENSORFLOW_COMPILER_JIT_DEFS_H_
namespace tensorflow {
// Name of attribute used to tag operators for compilation with XLA
extern const char* const kXlaCompileAttr; // "_XlaCompile"
extern const char* const kXlaScopeAttr; // "_XlaScope"
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_DEFS_H_
@@ -0,0 +1,118 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// An optimization pass that groups nodes marked with a common
// kXlaClusterAttr into functions, and replaces the original nodes by
// calls. The calls are annotated with kXlaCompiledKernelAttr.
#ifndef TENSORFLOW_COMPILER_JIT_ENCAPSULATE_SUBGRAPHS_PASS_H_
#define TENSORFLOW_COMPILER_JIT_ENCAPSULATE_SUBGRAPHS_PASS_H_
#include "tensorflow/core/common_runtime/optimization_registry.h"
#include "tensorflow/core/framework/function.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// A rewriting function to apply to each subgraph during encapsulation.
// 'arg_source_tensors' are the tensors corresponding to the arguments in the
// original source graph (*not* 'graph').
//
// 'graph' is the subgraph. The rewriting may renumber the inputs and outputs;
// 'input_permutation' is a mapping from old argument numbers to new argument
// numbers, whereas 'output_permutation' is the same for outputs. Both
// 'input_permutation' and 'output_permutation' are initialized to the identity
// permutation. 'nodedef' is the NodeDef for the call to the function under
// construction, provided to allow additional attributes to be set.
// The rewrite may also change the NodeDef's operator name, and that
// name will be used as the name of the generated function.
typedef std::function<Status(
const std::vector<OutputTensor>& arg_source_tensors,
std::unique_ptr<Graph>* graph, std::vector<int>* input_permutation,
std::vector<int>* output_permutation, NodeDef* node_def)>
RewriteSubgraphFn;
// Transformation that finds subgraphs whose nodes are marked with
// 'group_attribute', splits those subgraphs into functions, and replaces
// the originals with function calls.
//
// 'group_attribute' must be a string valued-attribute that names the new
// functions to introduce.
//
// 'outside_compilation_attribute' must be a string-valued attribute that is
// used to tag nodes within a subgraph to be part of an 'outside_compilation'
// cluster within the subgraph. A cluster is formed from the set of nodes with
// the same value of outside_compilation_subgraph and group_attribute. The nodes
// in an outside_compilation cluster are left in the original graph. Edges
// crossing from the subgraph to an outside_compilation cluster nested in the
// subgraph are lifted into a SendToHost/RecvAtHost pair of nodes, and edges
// crossing from an outside_compilation cluster into its enclosing subgraph are
// lifted into a SendFromHost/RecvFromHost pair of nodes.
//
// If 'rewrite_subgraph_fn' is set, it is applied to each subgraph before
// function conversion.
//
// If 'reuse_existing_functions' is set, use an existing function with the
// same name, if any.
//
// TODO(phawkins): currently, some information in control edges
// is not preserved. Suppose you have A and B in the main
// graph, C and D in a subgraph. B and C have control deps from A, D has control
// dep from B. Originally D must run after C, post-transformation this
// dependency is lost.
Status EncapsulateSubgraphsInFunctions(
string group_attribute, string outside_compilation_attribute,
const Graph& graph_in, const RewriteSubgraphFn& rewrite_subgraph_fn,
bool reuse_existing_functions, std::unique_ptr<Graph>* graph_out,
FunctionLibraryDefinition* library);
// The attribute that marks function calls produced by the encapsulate
// subgraphs pass and that should in turn be compiled via XlaLaunch operators.
extern const char* const kXlaCompiledKernelAttr;
// Does `node` have the kXlaCompiledKernelAttr attribute?
bool IsXlaCompiledKernel(const Node& node);
// Functions produced by the EncapsulateSubgraphs pass have their arguments in
// the order:
// 1) compile-time constant arguments, in host memory,
// 2) other arguments, in device memory.
// 3) resource variable arguments, in host memory. Note that only the resource
// Tensor itself is in host memory; the underlying value may be in device
// memory.
// The functions are annotated with the following attributes that describe how
// many constant and resource arguments there are:
// Name of the attribute containing the number of constant arguments.
extern const char* const kXlaNumConstantArgsAttr;
// Name of the attribute containing the number of resource variable arguments.
extern const char* const kXlaNumResourceArgsAttr;
// Sorts each node's control inputs by their names. This guarantees that for two
// structually equivalent GraphDefs, we get the same traversal ordering on
// node's control input fields.
// TODO(hpucha): Move the utilities to a more appropriate place.
void SortControlInputs(GraphDef* gdef);
class EncapsulateSubgraphsPass : public GraphOptimizationPass {
public:
Status Run(const GraphOptimizationPassOptions& options) override;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_ENCAPSULATE_SUBGRAPHS_PASS_H_
@@ -0,0 +1,60 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Rewrites computations generated by the xla.compile() Python code into
// XlaLaunch nodes.
//
// xla.compile() does two main things:
// a) marks operators that make up an XLA computation with the attribute
// _xla_compile_id=XYZ, where XYZ is a unique key.
// b) adds XlaClusterOutput nodes to represent outputs of the computation.
// These nodes are not marked with the _xla_compile_id attribute.
#ifndef TENSORFLOW_COMPILER_JIT_ENCAPSULATE_XLA_COMPUTATIONS_PASS_H_
#define TENSORFLOW_COMPILER_JIT_ENCAPSULATE_XLA_COMPUTATIONS_PASS_H_
#include "tensorflow/core/common_runtime/optimization_registry.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/platform/env.h"
namespace tensorflow {
// Encapsulates nodes marked with the _xla_compile_id attribute into
// XlaLaunch operators.
class EncapsulateXlaComputationsPass : public GraphOptimizationPass {
public:
static const char* const kXlaClusterAttr; // _xla_compile_id
Status Run(const GraphOptimizationPassOptions& options) override;
// The following methods are public only for unit tests.
// This pass has two stages:
// a) first, we call EncapsulateSubgraphsPass to encapsulate all nodes
// marked with the same _xla_compile_id attribute into functions. These
// functions contain the computations to be passed to XlaLaunch. During
// encapsulation, we sort the arguments into the order expected by
// XlaLaunch.
static Status Encapsulate(std::unique_ptr<Graph>* graph,
FunctionLibraryDefinition* flib_def);
// b) we rewrite the function calls generated in phase (a) into XlaLaunch
// operators. We also convert the XlaClusterOutput output nodes of the
// function call into the outputs of the XlaLaunch operator.
static Status BuildXlaLaunchOps(Graph* graph);
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_ENCAPSULATE_XLA_COMPUTATIONS_PASS_H_
@@ -0,0 +1,132 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_GRAPHCYCLES_GRAPHCYCLES_H_
#define TENSORFLOW_COMPILER_JIT_GRAPHCYCLES_GRAPHCYCLES_H_
// GraphCycles detects the introduction of a cycle into a directed
// graph that is being built up incrementally.
//
// Nodes are identified by small integers. It is not possible to
// record multiple edges with the same (source, destination) pair;
// requests to add an edge where one already exists are silently
// ignored.
//
// It is also not possible to introduce a cycle; an attempt to insert
// an edge that would introduce a cycle fails and returns false.
//
// GraphCycles uses no internal locking; calls into it should be
// serialized externally.
// Performance considerations:
// Works well on sparse graphs, poorly on dense graphs.
// Extra information is maintained incrementally to detect cycles quickly.
// InsertEdge() is very fast when the edge already exists, and reasonably fast
// otherwise.
// FindPath() is linear in the size of the graph.
// The current implementation uses O(|V|+|E|) space.
#include <unordered_set>
#include "tensorflow/core/platform/macros.h"
#include "tensorflow/core/platform/types.h"
namespace tensorflow {
// NOTE!!!
// For now a copy of this is forked to net/plaque. If you
// find a bug or add a feature, please inform the owners of the
// net/plaque copy in case it should be integrated.
// NOTE!!!
class GraphCycles {
public:
GraphCycles();
~GraphCycles();
// Allocate an unused node id and return it.
// The new node has a null pointer for its node data.
// All node identifiers passed to other routines in this interface
// must have been allocated by NewNode() and not yet deallocated
// by RemoveNode().
int32 NewNode();
// Remove "node" from the graph, deleting all edges to and from it.
// After this call the identifier "node" it may no longer be used
// as an argument to any routine until it has been reallocated with
// NewNode().
void RemoveNode(int32 node);
// Attempt to insert an edge from source_node to dest_node. If the
// edge would introduce a cycle, return false without making any
// changes. Otherwise add the edge and return true.
bool InsertEdge(int32 source_node, int32 dest_node);
// Remove any edge that exists from source_node to dest_node.
void RemoveEdge(int32 source_node, int32 dest_node);
// Return whether there is an edge directly from source_node to dest_node.
bool HasEdge(int32 source_node, int32 dest_node) const;
// Contracts the edge from 'a' to node 'b', merging nodes 'a' and 'b'. 'b' is
// removed from the graph, and edges to/from 'b' are replaced with edges
// to/from 'a'. If contracting the edge would create a cycle, does nothing
// and returns false.
bool ContractEdge(int32 a, int32 b);
// Return true if can contract edge, otherwise return false.
bool CanContractEdge(int32 a, int32 b);
// Return whether dest_node is reachable from source_node
// by following edges.
bool IsReachable(int32 source_node, int32 dest_node) const;
// A faster non-thread-safe version of IsReachable.
bool IsReachableNonConst(int32 source_node, int32 dest_node);
// Return or set the node data for a node. This data is unused
// by the implementation.
void *GetNodeData(int32 node) const;
void SetNodeData(int32 node, void *data);
// Find a path from "source" to "dest". If such a path exists, place the
// node IDs of the nodes on the path in the array path[], and return the
// number of nodes on the path. If the path is longer than max_path_len
// nodes, only the first max_path_len nodes are placed in path[]. The client
// should compare the return value with max_path_len" to see when this
// occurs. If no path exists, return 0. Any valid path stored in path[]
// will start with "source" and end with "dest". There is no guarantee that
// the path is the shortest, but no node will appear twice in the path,
// except the source and destination node if they are identical; therefore,
// the return value is at most one greater than the number of nodes in the
// graph.
int FindPath(int32 source, int32 dest, int max_path_len, int32 path[]) const;
// Check internal invariants. Crashes on failure, returns true on success.
// Expensive: should only be called from graphcycles_test.cc.
bool CheckInvariants() const;
std::unordered_set<int32> Successors(int32 node);
std::unordered_set<int32> Predecessors(int32 node);
// ----------------------------------------------------
struct Rep;
private:
Rep *rep_; // opaque representation
TF_DISALLOW_COPY_AND_ASSIGN(GraphCycles);
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_GRAPHCYCLES_GRAPHCYCLES_H_
@@ -0,0 +1,168 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_KERNELS_XLA_OPS_H_
#define TENSORFLOW_COMPILER_JIT_KERNELS_XLA_OPS_H_
#include "tensorflow/compiler/jit/xla_compilation_cache.h"
#include "tensorflow/compiler/jit/xla_device.h"
#include "tensorflow/compiler/jit/xla_launch_util.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/platform/macros.h"
#include "tensorflow/core/util/stream_executor_util.h"
namespace tensorflow {
// Holds some information about the platform on which an
// XlaLaunch/_XlaCompile/_XlaRun op must run on.
class XlaPlatformInfo {
public:
XlaPlatformInfo() : device_type_("") {}
explicit XlaPlatformInfo(const DeviceType device_type,
se::Platform::Id platform_id,
const XlaDevice::Metadata* xla_device_metadata,
std::unique_ptr<XlaAllocator> xla_allocator,
xla::DeviceMemoryAllocator* device_allocator)
: device_type_(device_type),
platform_id_(platform_id),
xla_device_metadata_(xla_device_metadata),
xla_allocator_(std::move(xla_allocator)),
device_allocator_(device_allocator) {
CHECK((device_allocator_ != nullptr) ^ (xla_allocator_.get() != nullptr));
}
XlaPlatformInfo& operator=(XlaPlatformInfo&& other) = default;
bool UseMultipleStreams() const {
return xla_device_metadata_ && xla_device_metadata_->UseMultipleStreams();
}
xla::DeviceMemoryAllocator* allocator() const {
return device_allocator_ ? device_allocator_ : xla_allocator_.get();
}
DeviceType device_type() const { return device_type_; }
// This is equal to xla_device_metadata()->platform()->id() if
// xla_device_metadata() is not nullptr.
se::Platform::Id platform_id() const { return platform_id_; }
// This may be null if the op this XlaPlatformInfo is for was not placed on an
// XLA device.
const XlaDevice::Metadata* xla_device_metadata() const {
return xla_device_metadata_;
}
bool is_on_xla_device() const { return xla_device_metadata() != nullptr; }
private:
DeviceType device_type_;
se::Platform::Id platform_id_;
// xla_device_metadata_ lives in the tensorflow::DeviceBase in which the
// XlaLaunch/_XlaCompile/_XlaRun op is placed and thus does not die before the
// XlaLaunch/_XlaCompile/_XlaRun OpKernel.
const XlaDevice::Metadata* xla_device_metadata_;
// If the op associated with this XlaPlatformInfo is placed on an XLA device
// then device_allocator_ is the xla::Backend's memory allocator and
// xla_allocator_ is null. If the op is placed on a regular CPU or GPU device
// then device_allocator_ is null and xla_allocator_ points to an appropriate
// XlaAllocator instance.
std::unique_ptr<XlaAllocator> xla_allocator_;
xla::DeviceMemoryAllocator* device_allocator_;
TF_DISALLOW_COPY_AND_ASSIGN(XlaPlatformInfo);
};
// XlaLocalLaunchBase is almost the same as XlaLocalLaunchOp.
// The only difference is that it does not require arguments to follow
// the "constants, then regular args, then resources" order.
// It takes vectors of constant and resource arguments explicitly.
// It does not have corresponding OpDef because it is never present
// in the GraphDef.
// Currently, it is used by eager runtime. FunctionLibraryRuntime creates
// this kernel when asked to create a kernel for an XLA-compiled function.
class XlaLocalLaunchBase : public OpKernel {
public:
XlaLocalLaunchBase(OpKernelConstruction* ctx,
const std::vector<int>& constants,
const std::vector<int>& resources,
const NameAttrList& function);
XlaLocalLaunchBase(const XlaLocalLaunchBase&) = delete;
XlaLocalLaunchBase& operator=(const XlaLocalLaunchBase&) = delete;
~XlaLocalLaunchBase() override = default;
void Compute(OpKernelContext* ctx) override;
protected:
// Indexes of compile-time constant inputs
std::vector<int> constants_;
// Indexes of resource inputs
std::vector<int> resources_;
NameAttrList function_;
XlaPlatformInfo platform_info_;
};
// XlaLocalLaunchOp is used to replace a region of the TensorFlow graph
// which will be compiled and executed using XLA. The XlaLocalLaunchOp is
// responsible for handling interactions with the TensorFlow executor.
// Once all inputs are present, and their shapes are known, the op can
// use a 'XlaCompilationCache' to compile and execute code which is specific
// to the shapes of input Tensors.
// XlaLocalLaunchOp uses xla::LocalClient::Compile() and
// xla::LocalExecutable::Run(), and passes arguments into/out of XLA in device
// memory.
class XlaLocalLaunchOp : public XlaLocalLaunchBase {
public:
explicit XlaLocalLaunchOp(OpKernelConstruction* ctx);
~XlaLocalLaunchOp() override;
private:
TF_DISALLOW_COPY_AND_ASSIGN(XlaLocalLaunchOp);
};
class XlaCompileOp : public OpKernel {
public:
explicit XlaCompileOp(OpKernelConstruction* ctx);
void Compute(OpKernelContext* ctx) override;
private:
// Indexes of compile-time constant inputs
std::vector<int> constants_;
// Indexes of resource inputs
std::vector<int> resources_;
NameAttrList function_;
XlaPlatformInfo platform_info_;
};
class XlaRunOp : public OpKernel {
public:
explicit XlaRunOp(OpKernelConstruction* ctx);
void Compute(OpKernelContext* ctx) override;
private:
XlaPlatformInfo platform_info_;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_KERNELS_XLA_LAUNCH_OP_H_
@@ -0,0 +1,68 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_LEGACY_FLAGS_MARK_FOR_COMPILATION_PASS_FLAGS_H_
#define TENSORFLOW_COMPILER_JIT_LEGACY_FLAGS_MARK_FOR_COMPILATION_PASS_FLAGS_H_
// Legacy flags for the XLA bridge's mark_for_compilation_pass module.
#include <vector>
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/command_line_flags.h"
namespace tensorflow {
namespace legacy_flags {
// Append to *flag_list flag definitions associated with the XLA bridge's
// mark_for_compilation_pass module.
void AppendMarkForCompilationPassFlags(
std::vector<tensorflow::Flag>* flag_list);
// The values of flags associated with the XLA bridge's
// mark_for_compilation_pass module.
typedef struct {
int32 tf_xla_auto_jit; // Control compilation of operators into XLA
// computations on CPU and GPU devices. 0 = use
// ConfigProto setting; -1 = off; 1 = on for things
// very likely to be improved; 2 = on for everything.
// Experimental.
int32 tf_xla_min_cluster_size; // Minimum number of operators in an XLA
// compilation. Ignored for operators placed
// on an XLA device or operators explicitly
// marked for compilation.
int32 tf_xla_max_cluster_size; // Maximum number of operators in an XLA
// compilation.
bool tf_xla_clustering_debug; // Dump graphs during XLA compilation.
bool tf_xla_cpu_global_jit; // Enables global JIT compilation for CPU
// via SessionOptions.
int64 tf_xla_clustering_fuel; // "Compiler fuel" for clustering. Only this
// many ops will be marked as eligible for
// clustering.
bool tf_xla_fusion_only; // This flag is effective only when global_jit_level
// is set to ON* and overrides its behavior. If
// true, enable fusion of element-wise operations
// only using XLA.
} MarkForCompilationPassFlags;
// Return a pointer to the MarkForCompilationPassFlags struct;
// repeated calls return the same pointer.
// This should be called only after Flags::Parse() has returned.
MarkForCompilationPassFlags* GetMarkForCompilationPassFlags();
} // namespace legacy_flags
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_LEGACY_FLAGS_MARK_FOR_COMPILATION_PASS_FLAGS_H_
@@ -0,0 +1,47 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_LEGACY_FLAGS_XLA_DEVICE_FLAGS_H_
#define TENSORFLOW_COMPILER_JIT_LEGACY_FLAGS_XLA_DEVICE_FLAGS_H_
// Legacy flags for the XLA bridge's xla_device module.
#include <vector>
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/command_line_flags.h"
namespace tensorflow {
namespace legacy_flags {
// The values of flags associated with the XLA bridge's
// xla_device module.
typedef struct {
// Switch the CPU device into "on-demand" mode, where instead of
// autoclustering ops are compiled one by one just-in-time.
// Enabling this mode by a legacy flag is a temporary mechanism. When this
// feature is battle-tested, we will switch this to be a session option.
bool tf_xla_compile_on_demand;
} XlaDeviceFlags;
// Return a pointer to the XlaDeviceFlags struct;
// repeated calls return the same pointer.
// This should be called only after Flags::Parse() has returned.
XlaDeviceFlags* GetXlaDeviceFlags();
} // namespace legacy_flags
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_LEGACY_FLAGS_XLA_DEVICE_FLAGS_H_
@@ -0,0 +1,57 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// An optimization passes that marks nodes that are to be compiled with
// attribute kXlaClusterAttr. Nodes with the same cluster ID will be compiled
// together.
#ifndef TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_
#define TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_
#include "tensorflow/core/common_runtime/optimization_registry.h"
namespace tensorflow {
// The attribute that marks nodes to be grouped into functions by the
// encapsulate subgraphs pass.
extern const char* const kXlaClusterAttr;
// The attribute that marks nodes in a cluster to be placed outside the xla
// compilation by the encapsulate subgraphs pass.
extern const char* const kXlaOutsideCompilationAttr;
// Pass that marks a subset of operators in the graph with attribute
// _XlaCluster so they are compiled by the EncapsulateSubgraphsPass.
class MarkForCompilationPass : public GraphOptimizationPass {
public:
MarkForCompilationPass() = default;
Status Run(const GraphOptimizationPassOptions& options) override;
private:
Status RunImpl(const GraphOptimizationPassOptions& options,
const std::function<bool(const Node*, const DeviceType&)>&
is_compilable_fn = {});
friend class MarkForCompilationPassTestHelper;
};
// Returns true iff 'ndef' is a call to a function that is compilable. A
// function is compilable iff every operator in the function body is
// compilable.
bool IsCompilable(FunctionLibraryRuntime* flr, const NodeDef& ndef);
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_
@@ -0,0 +1,40 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_TEST_HELPER_H_
#define TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_TEST_HELPER_H_
#include "tensorflow/compiler/jit/mark_for_compilation_pass.h"
namespace tensorflow {
class MarkForCompilationPassTestHelper {
public:
// Runs the MarkForCompilation pass on `graph` after assigning all nodes in
// `graph` to the CPU device. To make testing easier, ignores device
// registration, _XlaCompile attributes, input deadness and global jit level.
static Status MarkForCompilation(std::unique_ptr<Graph>* graph,
FunctionLibraryDefinition* flib_def,
SessionOptions* session_options);
// Like `MarkForCompilation` but creates a default SessionOptions.
static Status MarkForCompilation(std::unique_ptr<Graph>* graph,
FunctionLibraryDefinition* flib_def);
// Like `MarkForCompilation` but creates `flib_def` from the op registry.
static Status MarkForCompilation(std::unique_ptr<Graph>* graph);
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_TEST_HELPER_H_
@@ -0,0 +1,35 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_PARTIALLY_DECLUSTER_PASS_H_
#define TENSORFLOW_COMPILER_JIT_PARTIALLY_DECLUSTER_PASS_H_
#include "tensorflow/core/common_runtime/optimization_registry.h"
namespace tensorflow {
// Clones or moves nodes from within a cluster to outside the cluster if
// profitable. There are two reasons why we do this:
//
// - Reducing device-to-host copies.
// - Reducing the number of XLA recompilations.
class PartiallyDeclusterPass : public GraphOptimizationPass {
public:
Status Run(const GraphOptimizationPassOptions& options) override;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_PARTIALLY_DECLUSTER_PASS_H_
@@ -0,0 +1,73 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_RESOURCE_OPERATION_SAFETY_ANALYSIS_H_
#define TENSORFLOW_COMPILER_JIT_RESOURCE_OPERATION_SAFETY_ANALYSIS_H_
#include "tensorflow/compiler/jit/graphcycles/graphcycles.h"
#include "tensorflow/core/framework/function.h"
#include "tensorflow/core/graph/graph.h"
namespace tensorflow {
// An XLA cluster hoists all resource reads to be beginning of the cluster
// execution and all the resource writes to the end. This means it cannot
// enforce arbitrary ordering dependencies (via control or data edges) between
// resource operations. Since all resource reads happen before all resource
// writes, edges constraining resource reads to happen before resource writes
// are fine, but all other kinds of edges are problematic. This analysis
// returns the set of pairs of resource operations that cannot be put in the
// same cluster because XLA cannot respect the dependencies between them in the
// TensorFlow program.
//
// The restrictions are not transitive: it is fine to put A and C in the same
// cluster even if the returned set contains (A,B) and (B,C).
//
// In other words, if these pairs are seen as edges in an undirected graph of
// the nodes in `g` then auto-clustering is at least as constrained as the graph
// coloring problem on this graph.
//
//
// For instance if we auto-cluster all operations in this TensorFlow graph:
//
// ReadVariablepOp0 -> ReadVariableOp1
// |
// v
// AssignVariableOp0 -> AssignVariableOp1
//
// we will lose the ReadVariablepOp0 -> ReadVariableOp1 and the
// AssignVariableOp0 -> AssignVariableOp1 dependencies. I.e. it is possible for
// XlaLaunchOp to issue ReadVariableOp1 before ReadVariablepOp0 since it reads
// all the resource variables when the cluster starts executing without any
// particular ordering between them; same holds for the AssignVariableOp0 ->
// AssignVariableOp1 edge. The ReadVariableOp1 -> AssignVariableOp0 edge will
// be respected by XlaLaunchOp though because all reads happen before all
// writes.
//
//
// NB! The result computed by this analysis assumes that we don't auto-cluster
// back-edges (i.e. the edges from NextIteration to Merge).
//
// NB! The result computed by this analysis assumes that we don't auto-cluster
// functional control flow nodes containing resource operations.
//
// If `resource_ops_to_ignore` is set then nodes for which it returns true are
// ignored (we pretend these nodes are not resource operations).
Status ComputeIncompatibleResourceOperationPairs(
const Graph& g, const FunctionLibraryDefinition* flib_def,
const std::function<Status(const Node&, bool*)>& resource_ops_to_ignore,
std::vector<std::pair<int, int>>* result);
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_RESOURCE_OPERATION_SAFETY_ANALYSIS_H_
@@ -0,0 +1,65 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_SHAPE_INFERENCE_HELPERS_H_
#define TENSORFLOW_COMPILER_JIT_SHAPE_INFERENCE_HELPERS_H_
#include <vector>
#include "tensorflow/core/graph/graph.h"
namespace tensorflow {
// Helper class to temporarily remove, then replace, the back edges in a
// graph. Simple algorithms for shape inference don't work with cycles, and this
// class can be used to remove cycles before running inference and replace them
// after. Correct usage requires exactly one call to Remove(), followed by any
// number of calls to RemovedEdges() and at most one call to Replace(). The call
// to Replace() is optional if the graph will be discarded without being
// executed, e.g., if it is being used purely for a shape inference pass.
class BackEdgeHelper {
public:
struct BackEdge {
const Edge* edge;
Node* src;
int src_output;
Node* dst;
int dst_input;
};
BackEdgeHelper() = default;
// Disallows copy and assign.
BackEdgeHelper(const BackEdgeHelper& other) = delete;
BackEdgeHelper& operator=(const BackEdgeHelper& other) = delete;
// Temporarily removes all the back edges in graph.
Status Remove(Graph* graph);
// Gets the list of removed edges.
const std::vector<BackEdge>& RemovedEdges() const;
// Replaces the back edges removed by a prior call to Remove.
Status Replace();
private:
Graph* graph_ = nullptr; // not owned
std::vector<BackEdge> back_edges_;
// Set once Replace has been called.
bool replaced_ = false;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_SHAPE_INFERENCE_HELPERS_H_
@@ -0,0 +1,81 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_UNION_FIND_H_
#define TENSORFLOW_COMPILER_JIT_UNION_FIND_H_
namespace tensorflow {
// Union-Find data structure.
// Each cluster has an associated value; when merging clusters we can control
// which value becomes the representative of the merged clusters. Values must be
// copyable.
template <typename T>
class UnionFind {
public:
UnionFind() : rank_(0), size_(1), parent_(nullptr) {}
// Returns the number of elements in a cluster.
int Size() { return FindRoot()->size_; }
// Merges this cluster with 'other'. This cluster's value becomes
// the value of the merged cluster; the value of 'other' is ignored.
void Merge(UnionFind* other);
// Each cluster has an associated value. Retrieves the value associated
// with this cluster.
T& Get() { return FindRoot()->value_; }
private:
// Finds the root element of the cluster. Performs path compression.
UnionFind* FindRoot();
int rank_;
int size_; // Size of the cluster.
UnionFind* parent_;
T value_;
};
template <typename T>
void UnionFind<T>::Merge(UnionFind* other) {
UnionFind<T>* a = FindRoot();
UnionFind<T>* b = other->FindRoot();
if (a == b) return;
if (a->rank_ > b->rank_) {
b->parent_ = a;
a->size_ += b->size_;
return;
}
a->parent_ = b;
if (a->rank_ == b->rank_) {
b->rank_++;
}
b->value_ = a->value_;
b->size_ += a->size_;
}
template <typename T>
UnionFind<T>* UnionFind<T>::FindRoot() {
if (!parent_) return this;
// Path compression: update intermediate nodes to point to the root of the
// equivalence class.
parent_ = parent_->FindRoot();
return parent_;
}
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_UNION_FIND_H_
@@ -0,0 +1,70 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Contains utilities for clustering compilable graph nodes via XLA.
#ifndef TENSORFLOW_COMPILER_JIT_XLA_CLUSTER_UTIL_H_
#define TENSORFLOW_COMPILER_JIT_XLA_CLUSTER_UTIL_H_
#include "absl/types/optional.h"
#include "tensorflow/compiler/jit/graphcycles/graphcycles.h"
#include "tensorflow/core/graph/algorithm.h"
namespace tensorflow {
// The attribute that marks nodes to be grouped into functions by the
// encapsulate subgraphs pass.
extern const char* const kXlaClusterAttr;
// The attribute that marks nodes in a cluster to be placed outside the xla
// compilation by the encapsulate subgraphs pass.
extern const char* const kXlaOutsideCompilationAttr;
using OrderedNodeSet = std::set<Node*, NodeComparatorID>;
// Returns the DeviceType corresponding to 'device'.
Status DeviceToDeviceType(const string& device, DeviceType* device_type);
// Returns true if `node` has a ref tensor input that it forwards to its output.
bool HasForwardedRefInput(const Node& node);
// Creates a graph representation to enable cycle detection when clustering.
// This representation handles loops in graph by disconnecting each loop from
// the enclosing graph.
Status CreateCycleDetectionGraph(const Graph* graph, GraphCycles* cycles);
// Returns the XLA cluster in which `node` is placed if it is in an XLA cluster,
// otherwise returns nullopt.
absl::optional<absl::string_view> GetXlaClusterForNode(const Node& node);
// Removes `node_def` its XLA cluster (by clearing its _XlaCluster attribute).
void RemoveFromXlaCluster(NodeDef* node_def);
// Removes `node` its XLA cluster (by clearing its _XlaCluster attribute).
void RemoveFromXlaCluster(Node* node);
// Returns true if `node` has a DT_RESOURCE typed input or output.
bool HasResourceInputOrOutput(const Node& node);
// Adds edges to `cycles` to prevent clustering resource operations that cannot
// be legally clustered.
Status AdjustCycleDetectionGraphForResourceOps(
const Graph* graph, const FunctionLibraryDefinition* flib_def,
const std::function<Status(const Node&, bool*)>& resource_ops_to_ignore,
GraphCycles* cycles);
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_CLUSTER_UTIL_H_
@@ -0,0 +1,176 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_XLA_COMPILATION_CACHE_H_
#define TENSORFLOW_COMPILER_JIT_XLA_COMPILATION_CACHE_H_
#include "absl/container/flat_hash_map.h"
#include "tensorflow/compiler/tf2xla/xla_compiler.h"
#include "tensorflow/compiler/tf2xla/xla_context.h"
#include "tensorflow/compiler/xla/client/local_client.h"
#include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_mgr.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/platform/thread_annotations.h"
namespace tensorflow {
// Struct that represents a possibly-absent Tensor.
struct OptionalTensor {
string name; // A descriptive name
bool present = false; // Is the tensor present?
Tensor value; // If present, what is the Tensor's value?
};
// The XlaCompilationCache class caches the results of the XlaCompiler class,
// which converts a Tensorflow graph into a compiled XLA compilation.
//
// Since XLA computations must have static shapes, the cache generates a new
// XLA computation for each new set of input shapes.
//
// Currently no cache eviction policy is implemented and the cache grows without
// bound.
class XlaCompilationCache : public ResourceBase {
public:
XlaCompilationCache(xla::LocalClient* client, DeviceType device_type);
~XlaCompilationCache() override;
// Compiles a function into a XlaCompiler::CompilationResult that can be used
// to execute an XLA Computation. Compilation results are cached.
// `function` is the name of a Tensorflow function to compile.
// `constant_args` is a map of tensorflow argument number to its constant
// value.
// `variable_args` is a snapshot of the current values of the
// resource variable arguments to `function`; uninitialized variables are
// represented by an absent OptionalTensor.
// The result of compilation is written to `*compilation_result`, which must
// be non-null. If `executable` is non-null, also builds an
// xla::LocalExecutable and sets `executable` to point to it. The resulting
// executable pointer may be null if the computation has no non-constant
// outputs.
Status Compile(const XlaCompiler::Options& options,
const NameAttrList& function,
const std::map<int, Tensor>& constant_args,
const std::map<int, OptionalTensor>& variable_args,
OpKernelContext* ctx,
const XlaCompiler::CompilationResult** compilation_result,
xla::LocalExecutable** executable,
const XlaCompiler::CompileOptions& compile_options);
// As above, but calls XlaCompiler::CompileSingleOp instead of
// XlaCompiler::CompileFunction.
Status CompileSingleOp(
const XlaCompiler::Options& options,
const std::map<int, Tensor>& constant_args,
const std::map<int, OptionalTensor>& variable_args, OpKernelContext* ctx,
const XlaCompiler::CompilationResult** compilation_result,
xla::LocalExecutable** executable,
const XlaCompiler::CompileOptions& compile_options);
xla::LocalClient* client() const { return client_; }
const DeviceType& device_type() const { return device_type_; }
string DebugString() override;
private:
// Common implementation of Compile and CompileSingleOp.
Status CompileImpl(const XlaCompiler::Options& options,
const NameAttrList& function,
const std::map<int, Tensor>& constant_args,
const std::map<int, OptionalTensor>& variable_args,
OpKernelContext* ctx,
const XlaCompiler::CompilationResult** compilation_result,
xla::LocalExecutable** executable,
const XlaCompiler::CompileOptions& compile_options,
bool compile_single_op);
// Takes `result` which has been compiled from a Tensorflow subgraph to a
// XLA computation already, and generates an XLA LocalExecutable `executable`.
Status BuildExecutable(const XlaCompiler::Options& options,
const XlaCompiler::CompilationResult& result,
std::unique_ptr<xla::LocalExecutable>* executable);
xla::LocalClient* const client_;
const DeviceType device_type_;
// Describes the types, shapes and any compile-time constant arguments
// to a kernel. Key that uniquely identifies a compilation output.
struct Signature {
string name;
std::vector<std::pair<DataType, TensorShape>> arg_types;
// List of Tensor values for compile-time constant arguments to the
// compilation, ordered by argument number. Tensors must be in host memory.
std::vector<Tensor> arg_values;
bool operator==(const Signature& other) const;
struct Hash {
uint64 operator()(const Signature& signature) const;
};
};
static string SignatureDebugString(const Signature& sig);
// Builds the signature for a compilation.
Status BuildSignature(const NameAttrList& function,
const std::map<int, Tensor>& constant_args,
const std::map<int, OptionalTensor>& variable_args,
OpKernelContext* ctx, Signature* signature);
// The value associated with a cache entry.
struct Entry {
mutex mu;
// Have we tried compiling this entry?
bool compiled = false;
// Did compilation succeed?
Status compilation_status GUARDED_BY(mu);
// Output of the XlaCompiler.
XlaCompiler::CompilationResult compilation_result GUARDED_BY(mu);
// The XLA executable compiled from <computation>. May be null if no
// executable has been built.
std::unique_ptr<xla::LocalExecutable> executable GUARDED_BY(mu);
};
mutex compile_cache_mu_;
absl::flat_hash_map<Signature, std::unique_ptr<Entry>, Signature::Hash> cache_
GUARDED_BY(compile_cache_mu_);
struct CompileStats {
// Number of times the cluster has been (re-)compiled.
int64 compile_count = 0;
// Cumulative time spent compiling the cluster.
int64 cumulative_compile_time_us = 0;
};
mutex compile_stats_mu_;
// Maps cluster names to compilation statistics for said cluster.
absl::flat_hash_map<string, CompileStats> compile_stats_
GUARDED_BY(compile_stats_mu_);
TF_DISALLOW_COPY_AND_ASSIGN(XlaCompilationCache);
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_COMPILATION_CACHE_H_
@@ -0,0 +1,53 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// The XlaCompileOnDemandOp is an OpKernel that, when its Compute method is
// called, will generate an xla::Computation and run it asynchronously.
#ifndef TENSORFLOW_COMPILER_JIT_XLA_COMPILE_ON_DEMAND_OP_H_
#define TENSORFLOW_COMPILER_JIT_XLA_COMPILE_ON_DEMAND_OP_H_
#include "tensorflow/compiler/jit/xla_device.h"
#include "tensorflow/compiler/tf2xla/xla_compiler.h"
#include "tensorflow/compiler/xla/client/local_client.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// An OpKernel that compiles an op to an XLA computation and runs it. Unlike
// XlaLaunch this doesn't rely on any rewrites of the graphdef - it will run a
// vanilla TensorFlow op as long as the bridge supports it.
class XlaCompileOnDemandOp : public OpKernel {
public:
explicit XlaCompileOnDemandOp(OpKernelConstruction* ctx) : OpKernel(ctx) {}
void Compute(OpKernelContext* ctx) override;
private:
XlaCompiler::Argument CreateCompilerArgument(OpKernelContext* ctx, int64 i);
bool ShouldArgumentBeConstant(const OpKernel* op_kernel, int64 argument_idx);
bool MustArgumentBeConstant(const OpKernel* op_kernel, int64 argument_idx);
Status Compile(OpKernelContext* ctx, const XlaDevice::Metadata& metadata,
const XlaCompiler::CompilationResult** result,
xla::LocalExecutable** executable);
Status Run(OpKernelContext* ctx, const XlaDevice::Metadata& metadata,
const XlaCompiler::CompilationResult* result,
xla::LocalExecutable* executable);
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_COMPILE_ON_DEMAND_OP_H_
@@ -0,0 +1,234 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// The XlaDevice executes a TensorFlow graph using the XLA linear algebra
// runtime.
//
// Operators assigned to an XlaDevice are compiled into XLA computations.
// Tensors on an XlaDevice are thin wrappers around XLA ScopedShapedBuffers.
//
// XlaDevice is instantiated separately for each XLA backend (e.g., CPU or GPU),
// under different names (e.g., XLA_CPU or XLA_GPU).
#ifndef TENSORFLOW_COMPILER_JIT_XLA_DEVICE_H_
#define TENSORFLOW_COMPILER_JIT_XLA_DEVICE_H_
#include "tensorflow/compiler/jit/xla_device_context.h"
#include "tensorflow/compiler/jit/xla_tensor.h"
#include "tensorflow/compiler/tf2xla/xla_compiler.h"
#include "tensorflow/compiler/tf2xla/xla_op_registry.h"
#include "tensorflow/compiler/xla/client/local_client.h"
#include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/local_device.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/device_base.h"
#include "tensorflow/core/framework/node_def_builder.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/resource_mgr.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/platform/stream_executor_no_cuda.h"
namespace tensorflow {
class XlaDevice : public LocalDevice {
public:
// Given a tensor, sets `xla::Shape*` the shape of tensor's representation
// on device, fully padded. On error, the contents of `xla::Shape*`
// are undefined.
typedef std::function<Status(const Tensor&, xla::Shape*)> PaddedShapeFn;
// Wrapper class to store metadata about the XlaDevice, where it can be
// retrieved e.g., when lazily creating the XlaCompilationCache device.
class Metadata {
public:
Metadata(int device_ordinal, se::Platform* platform,
const DeviceType& device_type,
XlaCompiler::ShapeRepresentationFn shape_representation_fn,
PaddedShapeFn padded_shape_fn, bool use_multiple_streams);
// The index of the device on this host.
int device_ordinal() const;
se::Platform* platform() const;
xla::LocalClient* client() const;
const DeviceType& jit_device_type() const;
const XlaCompiler::ShapeRepresentationFn& shape_representation_fn() const {
return shape_representation_fn_;
}
const PaddedShapeFn& padded_shape_fn() const { return padded_shape_fn_; }
bool UseMultipleStreams() const { return use_multiple_streams_; }
private:
const int device_ordinal_;
const DeviceType device_type_;
se::Platform* platform_; // Not owned.
XlaCompiler::ShapeRepresentationFn shape_representation_fn_;
PaddedShapeFn padded_shape_fn_;
const bool use_multiple_streams_;
TF_DISALLOW_COPY_AND_ASSIGN(Metadata);
};
// Sets `*metadata` to the XlaDevice Metadata in the XLA device used by `ctx`.
static Status GetMetadata(OpKernelContext* ctx, const Metadata** metadata);
// Sets `*metadata` to the XlaDevice Metadata in the XLA device used by `ctx`.
static Status GetMetadata(OpKernelConstruction* ctx,
const Metadata** metadata);
// Factory function. 'platform_name' is the name of the XLA platform.
// 'device_name' is the name of the Tensorflow device to create.
// 'jit_device_name' is the name of the corresponding JIT device.
// 'transfer_as_literal' is true if device<->host transfers must be done using
// XLA's TransferLiteral{To,From}Device interface. If false, we can use
// ThenMemcpy instead.
// If 'use_multiple_streams' is true, we create separate streams for
// host-to-device and device-to-host communication.
// If padded_shape_fn is empty, a default implementation that returns
// the on-host shape is used.
static Status Create(
const string& platform_name, const string& device_name,
int device_ordinal, const string& jit_device_name,
const SessionOptions& options, const string& name_prefix,
const XlaOpRegistry::DeviceRegistration& registration,
bool transfer_as_literal, bool use_multiple_streams,
const XlaCompiler::ShapeRepresentationFn& shape_representation_fn,
const PaddedShapeFn& padded_shape_fn, std::unique_ptr<XlaDevice>* device);
// Creates a new XLA Device.
// If padded_shape_fn is empty, a default implementation that returns
// the logical on-device shape without padding is used.
XlaDevice(const SessionOptions& options, const DeviceAttributes& attrs,
int device_ordinal, const DeviceType& jit_device_name,
se::Platform* platform, bool transfer_as_literal,
bool use_multiple_streams,
const XlaCompiler::ShapeRepresentationFn& shape_representation_fn,
const PaddedShapeFn& padded_shape_fn);
~XlaDevice() override;
Allocator* GetAllocator(AllocatorAttributes attr) override
LOCKS_EXCLUDED(mu_);
void Compute(OpKernel* op_kernel, OpKernelContext* context) override;
void ComputeAsync(AsyncOpKernel* op_kernel, OpKernelContext* context,
AsyncOpKernel::DoneCallback done) override;
Status Sync() override;
Status FillContextMap(const Graph* graph,
DeviceContextMap* device_context_map) override
LOCKS_EXCLUDED(mu_);
Status MakeTensorFromProto(const TensorProto& tensor_proto,
const AllocatorAttributes alloc_attrs,
Tensor* tensor) override LOCKS_EXCLUDED(mu_);
const Metadata& metadata() { return xla_metadata_; }
// Ensures the DeviceContext associated with this XlaDevice is created and
// valid (i.e. all streams are ok). If any state is not valid, a new
// DeviceContext will be created.
//
// TODO(b/111859745): The Eager context needs to call this method to recover
// from failures.
Status EnsureDeviceContextOk() LOCKS_EXCLUDED(mu_);
// Instructs this XlaDevice to set a GpuDeviceInfo, which holds extra
// information for GPU and TPU devices.
Status UseGpuDeviceInfo() LOCKS_EXCLUDED(mu_);
// Instructs this XlaDevice to return 'sync_on_completion' for
// RequiresSyncOnCompletion().
void SetRequiresSyncOnCompletion(bool sync_on_completion) LOCKS_EXCLUDED(mu_);
bool RequiresSyncOnCompletion() const override LOCKS_EXCLUDED(mu_);
private:
xla::LocalClient* client() const;
Allocator* GetAllocatorLocked(AllocatorAttributes attr)
EXCLUSIVE_LOCKS_REQUIRED(mu_);
Status EnsureStreamOkLocked(xla::Backend* backend, const string& name,
std::shared_ptr<se::Stream>* stream,
bool* stream_was_changed)
EXCLUSIVE_LOCKS_REQUIRED(mu_);
xla::StatusOr<XlaDeviceContext*> GetDeviceContextLocked()
EXCLUSIVE_LOCKS_REQUIRED(mu_);
static Status GetMetadataFromDevice(DeviceBase* device,
const XlaDevice::Metadata** metadata);
mutable mutex mu_;
// The metadata of this XlaDevice.
const Metadata xla_metadata_;
// Which hardware device in the client's platform this XlaDevice controls.
const int device_ordinal_;
// The name of the device that is used to compile Ops for this XlaDevice.
const DeviceType jit_device_name_;
// The platform for this device.
se::Platform* const platform_; // Not owned.
// Memory allocator associated with this device.
Allocator* xla_allocator_ GUARDED_BY(mu_) = nullptr; // Not owned.
// Stream associated with this device. Operations enqueued on this
// stream are executed on the device. Operations include data
// copying back and forth between CPU and the device, and
// computations enqueued by XLA.
std::shared_ptr<se::Stream> stream_ GUARDED_BY(mu_);
// If false, only stream_ is valid and all computation and transfers use
// stream_. If true, computation is performed by stream_ and transfers are
// performed by host_to_device/device_to_host_stream.
const bool use_multiple_streams_;
// If use_multiple_streams_, host to device transfers are performed using this
// stream.
std::shared_ptr<se::Stream> host_to_device_stream_ GUARDED_BY(mu_);
// If use_multiple_streams_, device to host transfers are performed using this
// stream.
std::shared_ptr<se::Stream> device_to_host_stream_ GUARDED_BY(mu_);
// Must we use XLA's transfer manager for correct host<->device transfers? if
// false, we can use ThenMemcpy() instead.
const bool transfer_as_literal_;
const XlaCompiler::ShapeRepresentationFn shape_representation_fn_;
// The device context accessed by all users of the XlaDevice, set by calls to
// EnsureDeviceContextOk. If gpu_device_info_ is non-null, this pointer is
// also filled in to that struct. XlaDeviceContext is a ref-counted object.
XlaDeviceContext* device_context_ GUARDED_BY(mu_) = nullptr;
// Holds extra information for GPU and TPU devices, e.g. the device context.
bool use_gpu_device_info_ GUARDED_BY(mu_) = false;
std::unique_ptr<GpuDeviceInfo> gpu_device_info_ GUARDED_BY(mu_);
// Thread pool used for running closures
std::unique_ptr<thread::ThreadPool> thread_pool_;
// True if the device requires XlaDevice::Sync to be called on completion
// regardless of status.
bool sync_on_completion_ GUARDED_BY(mu_) = false;
};
// Builds OpKernel registrations on 'device' for the JIT operators
// registered on 'jit_device'. Returns ownership of a XlaDeviceOpRegistrations
// object that encapsulates the kernel registrations.
struct XlaDeviceOpRegistrations {
std::vector<std::unique_ptr<kernel_factory::OpKernelRegistrar>>
op_kernel_registrars;
};
XlaDeviceOpRegistrations* RegisterXlaDeviceKernels(const char* device,
const char* jit_device);
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_DEVICE_H_
@@ -0,0 +1,127 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_XLA_DEVICE_CONTEXT_H_
#define TENSORFLOW_COMPILER_JIT_XLA_DEVICE_CONTEXT_H_
#include <memory>
#include "tensorflow/compiler/jit/xla_tensor.h"
#include "tensorflow/compiler/tf2xla/xla_compiler.h"
#include "tensorflow/compiler/xla/client/global_data.h"
#include "tensorflow/compiler/xla/client/local_client.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/device_base.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// The allocator used for Tensors assigned to the XLA device. The allocator
// ignores the alignment and size of the request and always returns a new,
// empty, XlaTensor.
class XlaDeviceAllocator : public Allocator {
public:
XlaDeviceAllocator();
~XlaDeviceAllocator() override;
string Name() override;
void* AllocateRaw(size_t alignment, size_t num_bytes) override;
void DeallocateRaw(void* ptr) override;
void GetStats(AllocatorStats* stats) override;
};
// Helper class for managing data transfers between host and XLA devices.
class XlaTransferManager {
public:
explicit XlaTransferManager(
std::shared_ptr<se::Stream> compute_stream,
std::shared_ptr<se::Stream> host_to_device_stream,
std::shared_ptr<se::Stream> device_to_host_stream,
xla::LocalClient* client, bool transfer_as_literal,
XlaCompiler::ShapeRepresentationFn shape_representation_fn,
thread::ThreadPool* thread_pool);
void CopyCPUTensorToDevice(const Tensor* cpu_tensor, Device* device,
Tensor* device_tensor, StatusCallback done) const;
void CopyDeviceTensorToCPU(const Tensor* device_tensor,
absl::string_view tensor_name, Device* device,
Tensor* cpu_tensor, StatusCallback done);
void CopyDeviceTensorToDevice(const Tensor& src_tensor, Tensor* dst_tensor,
const StatusCallback& done);
se::Stream* stream() const { return stream_.get(); }
private:
Status TransferLiteralToDevice(const Tensor& host_tensor,
Tensor* device_tensor) const;
void TransferLiteralFromDevice(Tensor* host_tensor,
const Tensor& device_tensor,
const StatusCallback& done) const;
bool UseMultipleStreams() const { return stream_ != host_to_device_stream_; }
// The main compute stream of the device, used to synchronize the transfer
// streams if they are set.
std::shared_ptr<se::Stream> stream_;
// The stream to use for transferring data from host to device. Can be
// idential to stream_, but must not be nullptr.
std::shared_ptr<se::Stream> host_to_device_stream_;
// The stream to use for transferring data from device to host. Can be
// idential to stream_, but must not be nullptr.
std::shared_ptr<se::Stream> device_to_host_stream_;
// For the underlying memory allocator and XLA's TransferManager.
xla::LocalClient* client_;
// Transfer manager, for marshalling data to and from the device.
xla::TransferManager* transfer_manager_;
// True if we must use XLA's TransferManager for correct device transfers.
const bool transfer_as_literal_;
XlaCompiler::ShapeRepresentationFn shape_representation_fn_;
// Thread pool used for running closures
thread::ThreadPool* thread_pool_;
};
// DeviceContext for operators assigned to XlaDevice devices. The
// implementation must inherit from DeviceContext but otherwise just
// wraps the methods in XlaTransferManager.
class XlaDeviceContext : public DeviceContext {
public:
explicit XlaDeviceContext(
std::shared_ptr<se::Stream> compute_stream,
std::shared_ptr<se::Stream> host_to_device_stream,
std::shared_ptr<se::Stream> device_to_host_stream,
xla::LocalClient* client, bool transfer_as_literal,
XlaCompiler::ShapeRepresentationFn shape_representation_fn,
thread::ThreadPool* thread_pool);
void CopyCPUTensorToDevice(const Tensor* cpu_tensor, Device* device,
Tensor* device_tensor,
StatusCallback done) const override;
void CopyDeviceTensorToCPU(const Tensor* device_tensor,
absl::string_view tensor_name, Device* device,
Tensor* cpu_tensor, StatusCallback done) override;
void CopyDeviceTensorToDevice(const Tensor& src_tensor, Tensor* dst_tensor,
const StatusCallback& done);
se::Stream* stream() const override { return manager_.stream(); }
private:
XlaTransferManager manager_;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_DEVICE_CONTEXT_H_
@@ -0,0 +1,264 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Common kernel registrations for XLA devices.
#ifndef TENSORFLOW_COMPILER_JIT_XLA_DEVICE_OPS_H_
#define TENSORFLOW_COMPILER_JIT_XLA_DEVICE_OPS_H_
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/resource_mgr.h"
#include "tensorflow/core/kernels/cast_op.h"
#include "tensorflow/core/kernels/constant_op.h"
#include "tensorflow/core/kernels/control_flow_ops.h"
#include "tensorflow/core/kernels/data/generator_dataset_op.h"
#include "tensorflow/core/kernels/data/iterator_ops.h"
#include "tensorflow/core/kernels/data/prefetch_dataset_op.h"
#include "tensorflow/core/kernels/fifo_queue.h"
#include "tensorflow/core/kernels/function_ops.h"
#include "tensorflow/core/kernels/identity_n_op.h"
#include "tensorflow/core/kernels/identity_op.h"
#include "tensorflow/core/kernels/no_op.h"
#include "tensorflow/core/kernels/queue_op.h"
#include "tensorflow/core/kernels/resource_variable_ops.h"
#include "tensorflow/core/kernels/sendrecv_ops.h"
#include "tensorflow/core/kernels/shape_ops.h"
#include "tensorflow/core/kernels/variable_ops.h"
namespace tensorflow {
// Dummy OpKernel, used for kernels assigned to an XLA device that should be
// compiled. Should never be called at runtime since such ops should be
// rewritten to a XlaLaunch op. If it is called, it means the placer placed an
// operator on an XLA device but the compiler did not compile it.
class XlaDeviceDummyOp : public OpKernel {
public:
explicit XlaDeviceDummyOp(OpKernelConstruction* ctx);
void Compute(OpKernelContext* ctx) override;
};
class XlaAssignVariableOp : public AsyncOpKernel {
public:
explicit XlaAssignVariableOp(OpKernelConstruction* c);
void ComputeAsync(OpKernelContext* context, DoneCallback done) override;
private:
DataType dtype_;
};
#define REGISTER_XLA_LAUNCH_KERNEL(DEVICE, KERNEL, TYPES) \
REGISTER_KERNEL_BUILDER(Name("XlaLaunch") \
.Device(DEVICE) \
.HostMemory("constants") \
.HostMemory("resources"), \
KERNEL);
#define REGISTER_XLA_COMPILE_KERNEL(DEVICE, KERNEL, TYPES) \
REGISTER_KERNEL_BUILDER(Name("_XlaCompile") \
.Device(DEVICE) \
.HostMemory("constants") \
.HostMemory("resources"), \
KERNEL);
#define REGISTER_XLA_RUN_KERNEL(DEVICE, KERNEL, TYPES) \
REGISTER_KERNEL_BUILDER(Name("_XlaRun").Device(DEVICE), KERNEL);
#define REGISTER_XLA_DEVICE_KERNELS(DEVICE, TYPES) \
REGISTER_KERNEL_BUILDER(Name("_Send").Device(DEVICE), SendOp); \
REGISTER_KERNEL_BUILDER(Name("_Recv").Device(DEVICE), RecvOp); \
REGISTER_KERNEL_BUILDER( \
Name("_HostSend").Device(DEVICE).HostMemory("tensor"), SendOp); \
REGISTER_KERNEL_BUILDER( \
Name("_HostRecv").Device(DEVICE).HostMemory("tensor"), RecvOp); \
REGISTER_KERNEL_BUILDER( \
Name("_HostCast").Device(DEVICE).HostMemory("x").HostMemory("y"), \
CpuCastOp); \
REGISTER_KERNEL_BUILDER(Name("NoOp").Device(DEVICE), NoOp); \
REGISTER_KERNEL_BUILDER( \
Name("Const").Device(DEVICE).TypeConstraint("dtype", TYPES), \
ConstantOp); \
REGISTER_KERNEL_BUILDER( \
Name("Identity").Device(DEVICE).TypeConstraint("T", TYPES), IdentityOp); \
REGISTER_KERNEL_BUILDER(Name("IdentityN").Device(DEVICE), IdentityNOp); \
REGISTER_KERNEL_BUILDER(Name("Placeholder").Device(DEVICE), PlaceholderOp); \
REGISTER_KERNEL_BUILDER(Name("PlaceholderV2").Device(DEVICE), \
PlaceholderOp); \
\
REGISTER_KERNEL_BUILDER( \
Name("VarHandleOp").Device(DEVICE).HostMemory("resource"), \
ResourceHandleOp<Var>); \
REGISTER_KERNEL_BUILDER( \
Name("_VarHandlesOp").Device(DEVICE).HostMemory("resources"), \
ResourceHandlesOp<Var>); \
REGISTER_KERNEL_BUILDER( \
Name("ReadVariableOp").Device(DEVICE).HostMemory("resource"), \
ReadVariableOp); \
REGISTER_KERNEL_BUILDER( \
Name("_ReadVariablesOp").Device(DEVICE).HostMemory("resources"), \
ReadVariablesOp); \
REGISTER_KERNEL_BUILDER( \
Name("DestroyResourceOp").Device(DEVICE).HostMemory("resource"), \
DestroyResourceOp); \
REGISTER_KERNEL_BUILDER(Name("Shape") \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<int32>("out_type") \
.TypeConstraint("T", TYPES), \
ShapeOp<int32>); \
REGISTER_KERNEL_BUILDER(Name("Shape") \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<int64>("out_type") \
.TypeConstraint("T", TYPES), \
ShapeOp<int64>); \
REGISTER_KERNEL_BUILDER(Name("ShapeN") \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<int32>("out_type") \
.TypeConstraint("T", TYPES), \
ShapeNOp<int32>); \
REGISTER_KERNEL_BUILDER(Name("ShapeN") \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<int64>("out_type") \
.TypeConstraint("T", TYPES), \
ShapeNOp<int64>); \
REGISTER_KERNEL_BUILDER(Name("Size") \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<int32>("out_type") \
.TypeConstraint("T", TYPES), \
SizeOp<int32>); \
REGISTER_KERNEL_BUILDER(Name("Size") \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<int64>("out_type") \
.TypeConstraint("T", TYPES), \
SizeOp<int64>); \
REGISTER_KERNEL_BUILDER( \
Name("Rank").Device(DEVICE).HostMemory("output").TypeConstraint("T", \
TYPES), \
RankOp); \
REGISTER_KERNEL_BUILDER( \
Name("AssignVariableOp").Device(DEVICE).HostMemory("resource"), \
XlaAssignVariableOp); \
REGISTER_KERNEL_BUILDER(Name("ControlTrigger").Device(DEVICE), \
ControlTriggerOp); \
REGISTER_KERNEL_BUILDER(Name("Switch").Device(DEVICE).HostMemory("pred"), \
SwitchOp); \
REGISTER_KERNEL_BUILDER( \
Name("Merge").Device(DEVICE).HostMemory("value_index"), MergeOp); \
REGISTER_KERNEL_BUILDER(Name("Enter").Device(DEVICE), EnterOp); \
REGISTER_KERNEL_BUILDER(Name("Exit").Device(DEVICE), ExitOp); \
REGISTER_KERNEL_BUILDER(Name("NextIteration").Device(DEVICE), \
NextIterationOp); \
REGISTER_KERNEL_BUILDER(Name("LoopCond") \
.Device(DEVICE) \
.HostMemory("input") \
.HostMemory("output"), \
LoopCondOp); \
\
REGISTER_KERNEL_BUILDER( \
Name("QueueEnqueueV2").Device(DEVICE).HostMemory("handle"), EnqueueOp); \
REGISTER_KERNEL_BUILDER( \
Name("QueueDequeueV2").Device(DEVICE).HostMemory("handle"), DequeueOp); \
REGISTER_KERNEL_BUILDER( \
Name("QueueCloseV2").Device(DEVICE).HostMemory("handle"), QueueCloseOp); \
REGISTER_KERNEL_BUILDER(Name("QueueSizeV2") \
.Device(DEVICE) \
.HostMemory("size") \
.HostMemory("handle"), \
QueueSizeOp); \
REGISTER_KERNEL_BUILDER( \
Name("QueueIsClosedV2").Device(DEVICE).HostMemory("handle"), \
QueueIsClosedOp); \
\
REGISTER_KERNEL_BUILDER( \
Name("FIFOQueueV2").Device(DEVICE).HostMemory("handle"), FIFOQueueOp); \
\
REGISTER_KERNEL_BUILDER( \
Name(kArgOp).Device(DEVICE).HostMemory("output").TypeConstraint("T", \
TYPES), \
ArgOp); \
REGISTER_KERNEL_BUILDER(Name(kArgOp) \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<ResourceHandle>("T"), \
ArgOp); \
\
REGISTER_KERNEL_BUILDER(Name(kRetOp) \
.Device(DEVICE) \
.TypeConstraint("T", TYPES) \
.HostMemory("input"), \
RetvalOp); \
REGISTER_KERNEL_BUILDER(Name(kRetOp) \
.Device(DEVICE) \
.TypeConstraint<ResourceHandle>("T") \
.HostMemory("input"), \
RetvalOp); \
\
REGISTER_KERNEL_BUILDER( \
Name("RemoteCall").Device(DEVICE).HostMemory("target"), RemoteCallOp); \
\
REGISTER_KERNEL_BUILDER( \
Name("GeneratorDataset").Device(DEVICE).HostMemory("handle"), \
data::GeneratorDatasetOp); \
REGISTER_KERNEL_BUILDER(Name("PrefetchDataset") \
.Device(DEVICE) \
.HostMemory("buffer_size") \
.HostMemory("input_dataset") \
.HostMemory("handle"), \
data::PrefetchDatasetOp); \
\
REGISTER_KERNEL_BUILDER(Name("IteratorV2").Device(DEVICE), \
data::IteratorHandleOp); \
REGISTER_KERNEL_BUILDER( \
Name("MakeIterator").Device(DEVICE).HostMemory("dataset"), \
data::MakeIteratorOp); \
REGISTER_KERNEL_BUILDER(Name("AnonymousIterator").Device(DEVICE), \
data::AnonymousIteratorHandleOp); \
REGISTER_KERNEL_BUILDER(Name("IteratorGetNext").Device(DEVICE), \
data::IteratorGetNextOp); \
REGISTER_KERNEL_BUILDER(Name("IteratorGetNextSync").Device(DEVICE), \
data::IteratorGetNextSyncOp); \
REGISTER_KERNEL_BUILDER(Name("IteratorToStringHandle") \
.Device(DEVICE) \
.HostMemory("string_handle"), \
data::IteratorToStringHandleOp); \
REGISTER_KERNEL_BUILDER(Name("IteratorFromStringHandleV2") \
.Device(DEVICE) \
.HostMemory("string_handle"), \
data::IteratorFromStringHandleOp); \
REGISTER_KERNEL_BUILDER(Name(FunctionLibraryDefinition::kArgOp) \
.Device(DEVICE) \
.HostMemory("output") \
.TypeConstraint<string>("T"), \
ArgOp); \
REGISTER_KERNEL_BUILDER(Name(FunctionLibraryDefinition::kRetOp) \
.Device(DEVICE) \
.TypeConstraint<string>("T") \
.HostMemory("input"), \
RetvalOp);
// TODO(phawkins): currently we do not register the QueueEnqueueMany,
// QueueDequeueMany, or QueueDequeueUpTo kernels because they attempt to read
// and write the tensors they access in order to concatenate them into a batch.
// We would need either to call out to an XLA computation to perform the
// concatenation, or we would need to refactor those kernels so the splitting
// or merging is done in a separate operator that can be compiled.
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_DEVICE_OPS_H_
@@ -0,0 +1,181 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Contains utilities for launching compiled XLA kernels for a KernelContext.
#ifndef TENSORFLOW_COMPILER_JIT_XLA_LAUNCH_UTIL_H_
#define TENSORFLOW_COMPILER_JIT_XLA_LAUNCH_UTIL_H_
#include "tensorflow/compiler/jit/xla_compilation_cache.h"
#include "tensorflow/compiler/jit/xla_tensor.h"
#include "tensorflow/compiler/tf2xla/xla_compiler.h"
#include "tensorflow/compiler/xla/client/local_client.h"
#include "tensorflow/compiler/xla/service/device_memory_allocator.h"
#include "tensorflow/compiler/xla/service/owning_device_memory.h"
#include "tensorflow/core/framework/allocation_description.pb.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/kernels/variable_ops.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
class XlaAllocator;
// Takes a snapshot of the values of resource variable arguments, whose
// indices are specified in `variables` argument. We snapshot tensors that back
// resource variables since concurrent updates may modify the shape, and it is
// important that the shapes used for compilation match the true shapes of the
// buffers.
//
// Returns a map of TensorFlow argument index to resource variable. If a
// resource variable is not initialized, the corresponding OptionalTensor
// will have its `present` field set to false.
std::map<int, OptionalTensor> SnapshotResourceVariables(
OpKernelContext* ctx, absl::Span<const int> variables);
// Adapter class that wraps a Tensorflow allocator as an XLA allocator.
// Assumes that the Tensorflow allocator permits asynchronous deallocation:
// see comment on `AllowsAsynchronousDeallocation()`.
class XlaAllocator : public xla::DeviceMemoryAllocator {
public:
XlaAllocator(const se::Platform* platform, Allocator* wrapped);
~XlaAllocator() override;
xla::StatusOr<xla::OwningDeviceMemory> Allocate(
int device_ordinal, uint64 size, bool retry_on_failure) override;
Status Deallocate(int device_ordinal, se::DeviceMemoryBase mem) override;
// The Tensorflow BFC allocator used on GPU allows host-side deallocation
// before GPU execution takes place. Tensorflow uses the ordering of the main
// compute stream to enforce a happens-before relationship between a memory
// allocation and code that reuses the same memory. If Tensorflow adds
// support for multiple GPU streams or allocators with different ordering
// requirements, this code may need to change.
// (This attribute has no effect on CPU.)
bool AllowsAsynchronousDeallocation() const override { return true; }
private:
Allocator* wrapped_;
};
// Helper class to perform the marshalling of TensorFlow inputs and outputs to
// ShapedBuffers suitable for passing to an XLA computation.
class XlaComputationLaunchContext {
public:
// Create a new launch context. 'allocate_xla_tensors' is true if allocated
// output tensors and variables are always XlaTensors. If false they are
// assumed to be "normal" device pointers.
// If 'use_multiple_streams' is true, tensors may be defined and used on
// multiple streams and so se::Events must be defined and waited for. If
// 'use_multiple_streams' is true, 'allocate_xla_tensors' must also be true
// because we track inter-stream dependencies through events inside XlaTensor
// objects.
XlaComputationLaunchContext(xla::LocalClient* client,
xla::DeviceMemoryAllocator* xla_allocator,
bool allocate_xla_tensors,
bool use_multiple_streams);
// Add all inputs within `ctx` as XLA arguments (returned by arguments()).
// `variables` is a map from TensorFlow argument number to resource variable.
//
// Assumes that the first `missing_ctx_input_prefix` inputs to the kernel are
// missing and adjusts input indices accordingly. All elements in kernel's
// input_mapping must be greater than or equal to `missing_ctx_input_prefix`
// (in other words, no inputs actually required by the kernel can be missing).
void PopulateInputs(OpKernelContext* ctx,
const XlaCompiler::CompilationResult* kernel,
const std::map<int, OptionalTensor>& variables,
int missing_ctx_input_prefix);
// Given the XLA output in `output`, populate all outputs of `ctx`.
//
// Assumes that the first `missing_ctx_input_prefix` inputs to the kernel are
// missing and adjusts input indices accordingly.
Status PopulateOutputs(OpKernelContext* ctx,
const XlaCompiler::CompilationResult* kernel,
xla::ScopedShapedBuffer output,
int missing_ctx_input_prefix);
// Return the argument list. Only valid after PopulateInputs() has been
// called.
const std::vector<xla::ShapedBuffer*>& arguments() const { return arg_ptrs_; }
private:
xla::LocalClient* client_;
xla::DeviceMemoryAllocator* xla_allocator_;
bool allocate_xla_tensors_;
bool use_multiple_streams_;
std::vector<std::unique_ptr<xla::ShapedBuffer>> arg_buffers_;
std::vector<xla::ShapedBuffer*> arg_ptrs_;
};
// A simple TensorBuffer implementation that allows us to create Tensors that
// take ownership of pre-allocated memory.
class XlaTensorBuffer : public TensorBuffer {
public:
XlaTensorBuffer(const void* ptr, size_t expected_size, size_t actual_size,
Allocator* allocator)
: expected_size_(expected_size),
actual_size_(actual_size),
allocator_(allocator) {
data_ = const_cast<void*>(ptr);
}
~XlaTensorBuffer() override {
if (data_) {
allocator_->DeallocateRaw(data_);
}
}
void* data() const override { return data_; }
size_t size() const override { return expected_size_; }
TensorBuffer* root_buffer() override { return this; }
void FillAllocationDescription(AllocationDescription* proto) const override {
proto->set_allocated_bytes(actual_size_);
}
static Tensor MakeTensor(DataType dtype, const TensorShape& shape,
se::DeviceMemoryBase buffer, Allocator* allocator) {
size_t expected_size = shape.num_elements() * DataTypeSize(dtype);
auto* tensor_buffer = new XlaTensorBuffer(buffer.opaque(), expected_size,
buffer.size(), allocator);
Tensor t(dtype, shape, tensor_buffer);
tensor_buffer->Unref();
return t;
}
private:
void* data_;
size_t expected_size_;
size_t actual_size_;
Allocator* allocator_;
};
// Exposed in this header file for microbenchmarking purposes, but this is an
// internal implementation detail.
namespace internal {
// Return the 'index''th subtree of the given ShapedBuffer as a
// ScopedShapedBuffer. The returned ScopedShapedBuffer takes ownership of the
// subtree, and sets the input's buffer pointers to nullptr for the subtree.
xla::ScopedShapedBuffer ExtractSubShapedBuffer(
xla::ShapedBuffer* shaped_buffer, int index,
xla::DeviceMemoryAllocator* allocator);
} // namespace internal
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_LAUNCH_UTIL_H_
@@ -0,0 +1,131 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_JIT_XLA_TENSOR_H_
#define TENSORFLOW_COMPILER_JIT_XLA_TENSOR_H_
#include <memory>
#include "absl/memory/memory.h"
#include "tensorflow/compiler/xla/client/local_client.h"
#include "tensorflow/compiler/xla/service/shaped_buffer.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/device_base.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/mutex.h"
namespace tensorflow {
// The implementation of a Tensor for an XlaDevice. All device tensors are
// actually one of these.
//
// To distinguish between "normal" device tensors and XlaTensors, the raw
// pointer data stored in the TensorBuffer is a tagged pointer.
class XlaTensor {
public:
// Downcast from a Tensor to an XlaTensor. Return nullptr if the downcast
// fails.
static XlaTensor* FromTensor(const Tensor* tensor);
static bool RefCountIsOne(const Tensor& tensor);
// Create a DeviceMemoryBase from a Tensor. The Tensor can be an XlaTensor, in
// which case the returned value is shaped_buffer()->root_buffer(), or a
// normal Tensor in which case the returned value is
// {tensor.tensor_data().data(), tensor.tensor_data().size}.
static se::DeviceMemoryBase DeviceMemoryFromTensor(const Tensor& tensor);
// Assign the internal ShapedBuffer to new memory for the given dtype and
// shape. If a ShapedBuffer exists already (has_shaped_buffer() == true), it
// is replaced and the managed memory deallocated.
Status AllocateShapedBuffer(DataType dtype, const TensorShape& shape,
xla::LocalClient* client, int device_ordinal);
// Some Tensors can have complex on-device shapes, including tuple shapes. To
// manage the memory for these tensors a ShapedBuffer may be required.
// Return true if this XlaTensor contains a ShapedBuffer.
bool has_shaped_buffer() const { return shaped_buffer_ != nullptr; }
// Return the contained ShapedBuffer.
// REQUIRES: has_shaped_buffer()
const xla::ShapedBuffer& shaped_buffer() const {
CHECK(has_shaped_buffer());
return *shaped_buffer_;
}
xla::ShapedBuffer& shaped_buffer() {
CHECK(has_shaped_buffer());
return *shaped_buffer_;
}
// Mutates the XlaTensor to set the ShapedBuffer.
void set_shaped_buffer(xla::ScopedShapedBuffer shaped_buffer) {
shaped_buffer_ =
absl::make_unique<xla::ScopedShapedBuffer>(std::move(shaped_buffer));
}
// Some tensors on the device may have known values on the host. We use these
// in on-demand mode to avoid re-copying values from the device if we know the
// host value already.
// Return true if this XlaTensor contains a host tensor.
bool has_host_tensor() const { return host_tensor_ != nullptr; }
// Return the contained host tensor.
// REQUIRES: has_host_tensor()
const Tensor& host_tensor() const { return *host_tensor_; }
// Sets the contained host tensor.
void set_host_tensor(const Tensor& tensor) {
host_tensor_.reset(new Tensor(tensor));
}
// If the tensor's content is not yet defined on 'stream', and there exists an
// se::Event declaring when the tensor's content is defined, return it.
// Otherwise, return nullptr. If this function returns nullptr then the
// tensor's content can be read on 'stream' without additional
// synchronization.
se::Event* GetDefinitionEvent(se::Stream* stream);
// Assert that the tensor's content is defined on 'stream' by the time 'event'
// triggers.
void SetDefinedOn(se::Stream* stream, std::shared_ptr<se::Event> event);
// Assert that the tensor's content is defined on 'stream'. This version does
// not provide an event, and must be called *after* SetDefinedOn(Stream,
// Event). This call can be read as an assertion that the definition event has
// been waited on by 'stream', so further calls to GetDefinitionEvent(stream)
// do not need to also wait on the event.
void SetDefinedOn(se::Stream* stream);
// Convert from a raw pointer to an XlaTensor, removing the pointer tag.
static XlaTensor* FromOpaquePointer(void* ptr);
// Convert to a raw pointer from an XlaTensor, adding the pointer tag.
static void* ToOpaquePointer(XlaTensor* tensor);
private:
// The optional contained ShapedBuffer.
std::unique_ptr<xla::ScopedShapedBuffer> shaped_buffer_;
// An optional host tensor value.
std::unique_ptr<Tensor> host_tensor_;
// An optional event that is triggered when the tensor's content has been
// defined. If this event is nullptr, it is assumed that the tensor's content
// is always defined.
std::shared_ptr<se::Event> definition_event_;
// A list of all streams for which the tensor's content is defined for any
// newly enqueued command.
absl::InlinedVector<se::Stream*, 2> streams_defined_on_ GUARDED_BY(mu_);
mutex mu_;
};
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_JIT_XLA_TENSOR_H_
@@ -0,0 +1,108 @@
// This file is MACHINE GENERATED! Do not edit.
#ifndef TENSORFLOW_COMPILER_TF_XLA_CC_OPS_XLA_JIT_OPS_H_
#define TENSORFLOW_COMPILER_TF_XLA_CC_OPS_XLA_JIT_OPS_H_
// This file is MACHINE GENERATED! Do not edit.
#include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow {
namespace ops {
/// @defgroup xla_jit_ops Xla Jit Ops
/// @{
/// Operator that connects the output of an XLA computation to other consumer graph nodes.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output`: The outputs tensor.
class XlaClusterOutput {
public:
XlaClusterOutput(const ::tensorflow::Scope& scope, ::tensorflow::Input input);
operator ::tensorflow::Output() const { return outputs; }
operator ::tensorflow::Input() const { return outputs; }
::tensorflow::Node* node() const { return outputs.node(); }
Operation operation;
::tensorflow::Output outputs;
};
/// XLA Launch Op. For use by the XLA JIT only.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `OutputList`: The results tensor.
class XlaLaunch {
public:
XlaLaunch(const ::tensorflow::Scope& scope, ::tensorflow::InputList constants,
::tensorflow::InputList args, ::tensorflow::InputList resources,
const DataTypeSlice& Tresults, const NameAttrList& function);
::tensorflow::Output operator[](size_t index) const { return results[index]; }
Operation operation;
::tensorflow::OutputList results;
};
/// XLA Compile Op. For use by the XLA JIT only.
///
/// Compiles a TensorFlow function into an XLA LocalExecutable and returns a key
/// that _XlaRun can use to look up the LocalExecutable and execute it.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `Output` key: A key that can be used to look up the local executable compiled by the
/// node and associated metadata.
/// * `Output` compilation_successful: True iff the compilation was successful. Always true
/// for now.
class _XlaCompile {
public:
_XlaCompile(const ::tensorflow::Scope& scope, ::tensorflow::InputList
constants, ::tensorflow::InputList args, ::tensorflow::InputList
resources, const NameAttrList& function);
Operation operation;
::tensorflow::Output key;
::tensorflow::Output compilation_successful;
};
/// XLA Run Op. For use by the XLA JIT only.
///
/// Executes a TensorFlow function previously compiled into a LocalExecutable by an
/// _XlaCompile op.
///
/// Arguments:
/// * scope: A Scope object
///
/// Returns:
/// * `OutputList`: The results tensor.
class _XlaRun {
public:
_XlaRun(const ::tensorflow::Scope& scope, ::tensorflow::InputList args,
::tensorflow::Input key, const DataTypeSlice& Tresults);
::tensorflow::Output operator[](size_t index) const { return results[index]; }
Operation operation;
::tensorflow::OutputList results;
};
/// @}
} // namespace ops
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_TF_XLA_CC_OPS_XLA_JIT_OPS_H_
@@ -0,0 +1,45 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_TF2XLA_CONST_ANALYSIS_H_
#define TENSORFLOW_COMPILER_TF2XLA_CONST_ANALYSIS_H_
#include <vector>
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/lib/core/status.h"
namespace tensorflow {
// Backwards dataflow analysis that finds nodes in a graph that must be
// compile-time constants for us to be able to lower the graph to XLA.
//
// The indices of the arguments to `graph` that must be constant are returned in
// `compile_time_const_arg_indices`, if `compile_time_const_arg_indices` is not
// null.
//
// The ids of the nodes in `graph` that must be constant are returned in
// `compile_time_const_nodes`, if `compile_time_const_nodes` is not null.
//
// Only propagate const-ness along edges for which `edge_filter` returns true.
Status BackwardsConstAnalysis(const Graph& g,
std::vector<bool>* compile_time_const_arg_indices,
std::vector<bool>* compile_time_const_nodes,
std::function<bool(const Edge&)> edge_filter =
[](const Edge& e) { return true; });
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_TF2XLA_CONST_ANALYSIS_H_
@@ -0,0 +1,165 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_TF2XLA_CPU_FUNCTION_RUNTIME_H_
#define TENSORFLOW_COMPILER_TF2XLA_CPU_FUNCTION_RUNTIME_H_
#include "tensorflow/core/platform/types.h"
#include <cassert>
namespace tensorflow {
namespace cpu_function_runtime {
// Stores information about one buffer used by an XLA:CPU compiled function.
// These buffers are used for holding inputs to the computation, outputs from
// the computation and as temporary scratch space.
class BufferInfo {
public:
// Creates a BufferInfo from a serialized encoding generated by `Encode`.
explicit BufferInfo(std::pair<uint64, uint64> encoding)
: entry_param_number_(encoding.second) {
Kind kind;
uint64 size;
Unpack(encoding.first, &kind, &size);
kind_ = kind;
size_ = size;
}
// Returns true if this buffer stores a constant. These never need to be
// allocated by the runtime.
bool is_constant() const { return kind() == Kind::kConstant; }
// Returns true if this buffer stores an entry parameter. These may or may
// not need to be allocated by the runtime, depending on
// XlaCompiledCpuFunction::AllocMode.
bool is_entry_parameter() const { return kind() == Kind::kEntryParameter; }
// Returns the entry parameter number of this buffer.
uint64 entry_parameter_number() const {
assert(is_entry_parameter());
return entry_param_number_;
}
// Returns true if this buffer is temporary scratch space required by the XLA
// computations. These are always allocated by the runtime.
bool is_temp_buffer() const { return kind() == Kind::kTempBuffer; }
// Returns true if this buffer is allocated on the C stack or into registers.
// These buffers are never allocated by the runtime.
bool is_on_stack_buffer() const { return kind() == Kind::kOnStackBuffer; }
// Returns the size for this buffer.
uint64 size() const { return size_; }
// Encodes this BufferInfo into two 64 bit integers that can be used to
// reconstruct the BufferInfo later using the constructor. We need this
// because we use BufferInfo in places where using protocol buffers would
// negatively impact binary size.
std::pair<uint64, uint64> Encode() const {
static_assert(sizeof(*this) == 16, "");
uint64 upper = Pack(kind(), size_);
uint64 lower = entry_param_number_;
return {upper, lower};
}
bool operator==(const BufferInfo& buffer_info) const {
if (kind() != buffer_info.kind() || size() != buffer_info.size()) {
return false;
}
return !is_entry_parameter() ||
entry_parameter_number() == buffer_info.entry_parameter_number();
}
// Factory methods:
static BufferInfo MakeTempBuffer(uint64 size) {
return BufferInfo(Kind::kTempBuffer, /*size=*/size,
/*entry_param_number=*/-1);
}
static BufferInfo MakeConstant(uint64 size) {
return BufferInfo(Kind::kConstant, /*size=*/size,
/*entry_param_number=*/-1);
}
static BufferInfo MakeEntryParameter(uint64 size, uint64 param_number) {
return BufferInfo(Kind::kEntryParameter, /*size=*/size,
/*entry_param_number=*/param_number);
}
static BufferInfo MakeOnStackBuffer(uint64 size) {
return BufferInfo(Kind::kOnStackBuffer, /*size=*/size,
/*entry_param_number=*/-1);
}
private:
BufferInfo() = default;
enum class Kind : unsigned {
kConstant,
kTempBuffer,
kEntryParameter,
kOnStackBuffer
};
Kind kind() const { return static_cast<Kind>(kind_); }
explicit BufferInfo(Kind kind, uint64 size, uint64 entry_param_number)
: kind_(kind), size_(size), entry_param_number_(entry_param_number) {}
static uint64 Pack(Kind kind, uint64 size) {
return (static_cast<uint64>(size) << 2) | static_cast<uint64>(kind);
}
static void Unpack(uint64 packed, Kind* kind, uint64* size) {
*size = packed >> 2;
*kind = static_cast<Kind>((packed << 62) >> 62);
}
Kind kind_ : 2;
uint64 size_ : 62;
int64 entry_param_number_;
};
// Align to 64-bytes, to mimic tensorflow::Allocator::kAllocatorAlignment.
constexpr size_t kAlign = 64;
// AlignedBufferBytes returns the sum of the size of each buffer in
// `buffer_infos`, skipping constants, on-stack buffers and, if
// allocate_entry_params is false, entry parameters. There are `n` entries in
// `buffer_infos`. Each buffer is aligned to kAlign byte boundaries.
size_t AlignedBufferBytes(const BufferInfo* buffer_infos, size_t n,
bool allocate_entry_params);
// MallocContiguousBuffers allocates buffers for use by the entry point
// generated by tfcompile. There are `n` entries in `buffer_infos`. If
// `annotate_initialized` is set, the allocated memory will be annotated as
// having been initialized - this is useful when allocating temporary buffers.
// If allocate_entry_params is true then allocates temp buffers and entry
// parameters, otherwise allocated only temp buffers. Slots in `bufs`
// corresponding to unallocated buffers are set to nullptr.
//
// A single contiguous block of memory is allocated, and portions of it are
// parceled out into `bufs`, which must have space for `n` entries. Returns
// the head of the allocated contiguous block, which should be passed to
// FreeContiguous when the buffers are no longer in use.
void* MallocContiguousBuffers(const BufferInfo* buffer_infos, size_t n,
bool allocate_entry_params, void** bufs,
bool annotate_initialized);
// FreeContiguous frees the contiguous block of memory allocated by
// MallocContiguousBuffers.
void FreeContiguous(void* contiguous);
} // namespace cpu_function_runtime
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_TF2XLA_CPU_FUNCTION_RUNTIME_H_
@@ -0,0 +1,50 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Helper functions for dumping Graphs, GraphDefs, and FunctionDefs to files for
// debugging.
#ifndef TENSORFLOW_COMPILER_TF2XLA_DUMP_GRAPH_H_
#define TENSORFLOW_COMPILER_TF2XLA_DUMP_GRAPH_H_
#include "tensorflow/core/framework/function.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/graph/graph.h"
namespace tensorflow {
namespace dump_graph {
// Dumps 'graph_def' to a file, as a GraphDef text proto. Returns the file name
// chosen.
//
// Automatically picks a file name. Prefixes 'name' with the value of the
// --tf_dump_graph_prefix flag and suffixes it with ".pbtxt" to form a name.
// If a graph has already been dumped by this process with the same name,
// suffixes with "_n.pbtxt", where 'n' is a sequence number.
string DumpGraphDefToFile(const string& name, GraphDef const& graph_def);
// Similar to DumpGraphDefToFile, but builds the GraphDef to dump from a 'graph'
// and an optional function library 'flib_def'. Returns the file name chosen.
string DumpGraphToFile(const string& name, Graph const& graph,
const FunctionLibraryDefinition* flib_def = nullptr);
// Similar to DumpGraphDefToFile, but dumps a function as a FunctionDef text
// proto. Returns the file name chosen.
string DumpFunctionDefToFile(const string& name, FunctionDef const& fdef);
} // namespace dump_graph
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_TF2XLA_DUMP_GRAPH_H_
@@ -0,0 +1,48 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_TF2XLA_DUMP_GRAPH_FLAGS_H_
#define TENSORFLOW_COMPILER_TF2XLA_DUMP_GRAPH_FLAGS_H_
// Legacy flags for the XLA bridge's dump_graph module.
#include <vector>
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/command_line_flags.h"
namespace tensorflow {
namespace legacy_flags {
// Append to *flag_list flag definitions associated with the XLA bridge's
// dump_graph module.
void AppendDumpGraphFlags(std::vector<tensorflow::Flag>* flag_list);
// The values of flags associated with the XLA bridge's
// dump_graph module.
typedef struct {
string tf_dump_graph_prefix; // Path prefix to which graphs dumped during
// debugging should be written.
} DumpGraphFlags;
// Return a pointer to the DumpGraphFlags struct;
// repeated calls return the same pointer.
// This should be called only after Flags::Parse() has returned.
DumpGraphFlags* GetDumpGraphFlags();
} // namespace legacy_flags
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_TF2XLA_DUMP_GRAPH_FLAGS_H_
@@ -0,0 +1,243 @@
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_TF2XLA_FUNCTIONALIZE_COND_H_
#define TENSORFLOW_COMPILER_TF2XLA_FUNCTIONALIZE_COND_H_
#include <deque>
#include "tensorflow/compiler/xla/status_macros.h"
#include "tensorflow/core/framework/function.h"
#include "tensorflow/core/graph/graph.h"
namespace tensorflow {
// Functionalize all the switch-merge nodes of a loop-free graph into If
// nodes. That is, attempt to transform every remaining switch and merge nodes
// in the graph into If nodes.
// Precondition: All while loops have been removed from graph.
Status FunctionalizeCond(Graph* graph, FunctionLibraryDefinition* library);
// Internal functions/classes exposed for testing purposes.
namespace functionalize_cond {
// All nodes are assumed to be either in no branch, then branch, else branch,
// or both branches (such as merge nodes).
// The code below relies on Else and Then being 0 and 1 (corresponding to the
// switch outputs). Both and Neither are arbitrary.
enum class BranchType {
kElseBranch = 0,
kThenBranch = 1,
kBoth = 2,
kNeither = 3,
};
// StateMap is responsible for mapping from each graph Node to
// * a CondState, where each CondState is a map from predicate to branch (i,e.,
// what predicates have to hold or not hold).
// * a AncestorState, where each AncestorState is a set of switch/merge nodes
// that are an ancestor of the node in the graph;
// For efficiency, this class interns the CondState (AncestorState), so that
// CondState (AncestorState) equality comparisons are simply pointer
// comparisons.
class StateMap {
public:
explicit StateMap(Graph* graph);
// Compare two OutputTensors by (node id, index).
struct OutputTensorLess {
bool operator()(const OutputTensor& lhs, const OutputTensor& rhs) const;
};
// A node in the graph is executed when multiple conditions hold. Keep track
// of the predicates that must hold for a node to execute.
using CondState = std::map<OutputTensor, BranchType, OutputTensorLess>;
// Every unique ID is mapped to a CondState.
using CondId = const CondState*;
// Keep track of which switch/merge node's feed into a node's values.
using AncestorState = std::set<Node*>;
// Every unique ID is mapped to a AncestorState.
using AncestorId = const AncestorState*;
// Returns the CondId for a given node.
CondId LookupCondId(const Node* node) const;
// Returns the unique CondId for CondState.
CondId GetCondId(const CondState& state);
// Resets the CondId for a given node.
void ResetCondId(const Node* node, CondId id);
// Returns the AncestorId for a given node.
AncestorId LookupAncestorId(const Node* node) const;
// Returns the unique AncestorId for CondState.
AncestorId GetAncestorId(const AncestorState& state);
// Resets the AncestorId for a given node.
void ResetAncestorId(const Node* node, AncestorId id);
// Marks `node` as dead.
void MarkDead(const Node* node);
// Determine branch execution of CondState.
BranchType FindBranchOf(CondId id, OutputTensor predicate) const;
// Returns textual representation of node's CondState.
string CondStateToString(const Node* node) const;
string CondStateToString(CondId id) const;
// Returns textual representation of node's AncestorState.
string AncestorStateToString(const Node* node) const;
// Returns whether the cond state is the dead state.
bool IsDead(CondId id) const;
// Returns whether the cond state is the empty state.
bool IsEmpty(CondId id) const;
private:
// Hash for CondState and AncestorState.
struct Hash {
size_t operator()(const CondState& map) const;
size_t operator()(const AncestorState& map) const;
};
// Set to keep track of unique CondStates.
// Pointers to the entries in the unordered set are used as identifiers:
// unordered_set guarantees that the pointers remain the same.
std::unordered_set<CondState, Hash> condstate_set_;
// Mapping from Node id to CondId.
std::vector<CondId> node_to_condid_map_;
// Track the CondId for newly inserted nodes. We use a vector to quickly map
// from Node id in the original graph to the CondId, but there will be nodes
// added to the original graph (such as If nodes) whose CondState needs to be
// tracked too.
std::unordered_map<int, CondId> added_node_condid_mapping_;
// AncestorId variants of the CondId members.
std::unordered_set<AncestorState, Hash> ancestorstate_set_;
std::vector<AncestorId> node_to_ancestorid_map_;
std::unordered_map<int, AncestorId> added_node_ancestorid_mapping_;
// Identifier of the dead flow state. The empty flow state is represented with
// a nullptr.
CondId dead_id_;
};
// FunctionalizeCond groups all the state used by functionalizing conditionals
// of the given graph together.
class FunctionalizeCond {
public:
// Functionalize all the switch-merge nodes of a loop-free graph into If
// nodes. That is, attempt to transform every remaining switch and merge nodes
// in the graph into If nodes.
// Precondition: All while loops have been removed from graph.
static Status Functionalize(Graph* graph, FunctionLibraryDefinition* library);
// Build identity node with the same name as the merge that will be replaced
// in case the output is fetched/colocated.
Status AddIdentityNode(const Node* replacee, Node* if_node, int port);
// Add a If node to the graph defined by def that will, amongst other, replace
// replacee in the graph.
xla::StatusOr<Node*> AddIfNode(const NodeDef& def, const Node* replacee,
const OutputTensor& predicate);
// Propagates the state of a newly inserted node.
Status PropagateUpdatedState(const Node* replacee);
// Dump graph with the CondState annotated.
void DumpGraphWithCondState(const string& name);
private:
FunctionalizeCond(Graph* graph, FunctionLibraryDefinition* library);
// Performs the actual cond functionalization. Iterate over groups of merge
// nodes (linked by common predicates & ancestor IDs), from innermost to
// outermost, and extract into If nodes.
Status FunctionalizeInternal();
// Returns the forward flow state propagated along edge `e`.
// This may modify state_map_.
StateMap::CondId StateAlongEdge(const Edge* e);
// Determines the CondState and AncestorState of all the nodes in the given
// vector where the input is expected in reverse topological order.
// This populates the state_map_.
Status DetermineStates(std::vector<Node*> rev_topo_order);
// Determine the CondState for a given node using the incomming edges
// to the node. Note: it is expected that this node's CondState is only
// determined once its input's CondState is.
Status DetermineCondState(Node* dst) {
if (IsMerge(dst)) return DetermineCondStateMerge(dst);
return DetermineCondStateNonMerge(dst);
}
// Helper functions for DetermineCondState.
Status DetermineCondStateNonMerge(Node* dst);
Status DetermineCondStateMerge(Node* dst);
// Determines the dst node's CondState by joining the src and dst's CondState
// where either the dst node is a merge or not.
// These may modify state_map_.
xla::StatusOr<StateMap::CondId> JoinCondStatesMerge(Node* merge,
StateMap::CondId src,
StateMap::CondId dst);
xla::StatusOr<StateMap::CondId> JoinCondStatesNonMerge(StateMap::CondId src,
StateMap::CondId dst);
// Determines which switch/merge nodes are ancestors of this node.
Status DetermineAncestorState(Node* dst);
// Checks if a merge node is redundant and if so removes it from the graph.
Status RemoveRedundantMerge(Node* node);
// Checks if a switch node is redundant and if so removes it from the graph.
Status RemoveRedundantSwitch(Node* node);
// Sorts merge nodes (in reverse topological order) in order of increasing
// nesting depth.
void SortMergeNodes(std::vector<Node*>* merge_order);
// Deletes all nodes in/consumers reachable from switch/merge nodes that were
// extracted.
void DeleteReachableAndDeadNodes(const std::vector<int>& switch_ids,
const std::vector<Node*>& merge_order);
// Member used to unique the CondState to a unique CondId (AncestorState to a
// unique AncestorId) and keep track of CondState/CondId
// (AncestorState/AncestorId) per Node.
StateMap state_map_;
// Mapping from merge nodes to predicate.
std::unordered_map<Node*, OutputTensor> merge_to_predicate_;
FunctionLibraryDefinition* library_;
Graph* graph_;
friend class FunctionalizeCondTest;
};
} // namespace functionalize_cond
} // namespace tensorflow
#endif // TENSORFLOW_COMPILER_TF2XLA_FUNCTIONALIZE_COND_H_
Loaded 100 of 1283 files, more files were not shown because too many files have changed in this diff. Show more