| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 28807c5 commit 54c2584
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + op { | ||
| 2 | + graph_op_name: "Snapshot" | ||
| 3 | + summary: "Returns a copy of the input tensor." | ||
| 4 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + op { | ||
| 2 | + graph_op_name: "Snapshot" | ||
| 3 | + visibility: HIDDEN | ||
| 4 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -605,6 +605,7 @@ cc_library( | |||
| 605 | 605 | ":reverse_sequence_op", | |
| 606 | 606 | ":shape_ops", | |
| 607 | 607 | ":slice_op", | |
| 608 | + ":snapshot_op", | ||
| 608 | 609 | ":split_op", | |
| 609 | 610 | ":split_v_op", | |
| 610 | 611 | ":strided_slice_op", | |
@@ -801,6 +802,12 @@ tf_kernel_library( | |||
| 801 | 802 | deps = ARRAY_DEPS + [":strided_slice_op"], | |
| 802 | 803 | ) | |
| 803 | 804 | ||
| 805 | + tf_kernel_library( | ||
| 806 | + name = "snapshot_op", | ||
| 807 | + prefix = "snapshot_op", | ||
| 808 | + deps = ARRAY_DEPS, | ||
| 809 | + ) | ||
| 810 | + | ||
| 804 | 811 | tf_kernel_library( | |
| 805 | 812 | name = "split_op", | |
| 806 | 813 | gpu_srcs = ["cuda_device_array.h"], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. | ||
| 2 | + | ||
| 3 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + you may not use this file except in compliance with the License. | ||
| 5 | + You may obtain a copy of the License at | ||
| 6 | + | ||
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + | ||
| 9 | + Unless required by applicable law or agreed to in writing, software | ||
| 10 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + See the License for the specific language governing permissions and | ||
| 13 | + limitations under the License. | ||
| 14 | + ==============================================================================*/ | ||
| 15 | + | ||
| 16 | + // See docs in ../ops/array_ops.cc. | ||
| 17 | + #include "tensorflow/core/kernels/snapshot_op.h" | ||
| 18 | + | ||
| 19 | + #include "tensorflow/core/framework/op_kernel.h" | ||
| 20 | + #include "tensorflow/core/framework/register_types.h" | ||
| 21 | + #include "tensorflow/core/framework/types.h" | ||
| 22 | + | ||
| 23 | + namespace tensorflow { | ||
| 24 | + typedef Eigen::ThreadPoolDevice CPUDevice; | ||
| 25 | + | ||
| 26 | + #define REGISTER_KERNEL(TYPE) \ | ||
| 27 | + REGISTER_KERNEL_BUILDER( \ | ||
| 28 | + Name("Snapshot").Device(DEVICE_CPU).TypeConstraint<TYPE>("T"), \ | ||
| 29 | + SnapshotOp<CPUDevice, TYPE>); | ||
| 30 | + | ||
| 31 | + TF_CALL_POD_TYPES(REGISTER_KERNEL); | ||
| 32 | + #undef REGISTER_KERNEL | ||
| 33 | + | ||
| 34 | + #if TENSORFLOW_USE_SYCL | ||
| 35 | + typedef Eigen::SyclDevice SyclDevice; | ||
| 36 | + #define REGISTER_SYCL_KERNEL(TYPE) \ | ||
| 37 | + REGISTER_KERNEL_BUILDER( \ | ||
| 38 | + Name("Snapshot").Device(DEVICE_SYCL).TypeConstraint<TYPE>("T"), \ | ||
| 39 | + SnapshotOp<SyclDevice, TYPE>); | ||
| 40 | + | ||
| 41 | + TF_CALL_POD_TYPES(REGISTER_SYCL_KERNEL); | ||
| 42 | + | ||
| 43 | + #undef REGISTER_SYCL_KERNEL | ||
| 44 | + #endif // TENSORFLOW_USE_SYCL | ||
| 45 | + | ||
| 46 | + } // namespace tensorflow | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,49 @@ | |||
| 1 | + /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. | ||
| 2 | + | ||
| 3 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + you may not use this file except in compliance with the License. | ||
| 5 | + You may obtain a copy of the License at | ||
| 6 | + | ||
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + | ||
| 9 | + Unless required by applicable law or agreed to in writing, software | ||
| 10 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + See the License for the specific language governing permissions and | ||
| 13 | + limitations under the License. | ||
| 14 | + ==============================================================================*/ | ||
| 15 | + | ||
| 16 | + #ifndef TENSORFLOW_KERNELS_SNAPSHOT_OP_H_ | ||
| 17 | + #define TENSORFLOW_KERNELS_SNAPSHOT_OP_H_ | ||
| 18 | + | ||
| 19 | + #if GOOGLE_CUDA | ||
| 20 | + #define EIGEN_USE_GPU | ||
| 21 | + #endif | ||
| 22 | + | ||
| 23 | + #define EIGEN_USE_THREADS | ||
| 24 | + | ||
| 25 | + #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" | ||
| 26 | + #include "tensorflow/core/framework/op_kernel.h" | ||
| 27 | + | ||
| 28 | + namespace tensorflow { | ||
| 29 | + | ||
| 30 | + template <typename Device, typename Scalar> | ||
| 31 | + class SnapshotOp : public OpKernel { | ||
| 32 | + public: | ||
| 33 | + explicit SnapshotOp(OpKernelConstruction* context) : OpKernel(context) {} | ||
| 34 | + | ||
| 35 | + void Compute(OpKernelContext* context) override { | ||
| 36 | + const Tensor& input = context->input(0); | ||
| 37 | + Tensor* output = nullptr; | ||
| 38 | + OP_REQUIRES_OK(context, | ||
| 39 | + context->allocate_output(0, input.shape(), &output)); | ||
| 40 | + const Device& device = context->eigen_device<Device>(); | ||
| 41 | + device.memcpy(output->template flat<Scalar>().data(), | ||
| 42 | + input.template flat<Scalar>().data(), | ||
| 43 | + input.NumElements() * sizeof(Scalar)); | ||
| 44 | + } | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + } // namespace tensorflow | ||
| 48 | + | ||
| 49 | + #endif // TENSORFLOW_KERNELS_SNAPSHOT_OP_H_ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. | ||
| 2 | + | ||
| 3 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + you may not use this file except in compliance with the License. | ||
| 5 | + You may obtain a copy of the License at | ||
| 6 | + | ||
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + | ||
| 9 | + Unless required by applicable law or agreed to in writing, software | ||
| 10 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + See the License for the specific language governing permissions and | ||
| 13 | + limitations under the License. | ||
| 14 | + ==============================================================================*/ | ||
| 15 | + #if GOOGLE_CUDA | ||
| 16 | + | ||
| 17 | + // See docs in ../ops/array_ops.cc. | ||
| 18 | + #include "tensorflow/core/kernels/snapshot_op.h" | ||
| 19 | + | ||
| 20 | + #include "tensorflow/core/framework/op_kernel.h" | ||
| 21 | + #include "tensorflow/core/framework/register_types.h" | ||
| 22 | + #include "tensorflow/core/framework/types.h" | ||
| 23 | + | ||
| 24 | + namespace tensorflow { | ||
| 25 | + typedef Eigen::GpuDevice GPUDevice; | ||
| 26 | + | ||
| 27 | + #define REGISTER_KERNEL(TYPE) \ | ||
| 28 | + REGISTER_KERNEL_BUILDER( \ | ||
| 29 | + Name("Snapshot").Device(DEVICE_GPU).TypeConstraint<TYPE>("T"), \ | ||
| 30 | + SnapshotOp<GPUDevice, TYPE>); | ||
| 31 | + | ||
| 32 | + TF_CALL_POD_TYPES(REGISTER_KERNEL); | ||
| 33 | + #undef REGISTER_KERNEL | ||
| 34 | + | ||
| 35 | + } // namespace tensorflow | ||
| 36 | + | ||
| 37 | + #endif // GOOGLE_CUDA | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1722,6 +1722,20 @@ REGISTER_OP("Identity") | |||
| 1722 | 1722 | Return a tensor with the same shape and contents as the input tensor or value. | |
| 1723 | 1723 | )Doc"); | |
| 1724 | 1724 | ||
| 1725 | + REGISTER_OP("Snapshot") | ||
| 1726 | + .Input("input: T") | ||
| 1727 | + .Output("output: T") | ||
| 1728 | + .Attr("T: type") | ||
| 1729 | + .SetShapeFn([](shape_inference::InferenceContext* c) { | ||
| 1730 | + c->set_output(0, c->input(0)); | ||
| 1731 | + auto* handle_data = c->input_handle_shapes_and_types(0); | ||
| 1732 | + if (handle_data != nullptr) { | ||
| 1733 | + c->set_output_handle_shapes_and_types(0, *handle_data); | ||
| 1734 | + } | ||
| 1735 | + return Status::OK(); | ||
| 1736 | + }) | ||
| 1737 | + .Doc(R"Doc(Returns a copy of the input tensor.)Doc"); | ||
| 1738 | + | ||
| 1725 | 1739 | #ifdef INTEL_MKL | |
| 1726 | 1740 | REGISTER_OP("_MklIdentity") | |
| 1727 | 1741 | .Input("input: T") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ | |||
| 33 | 33 | from tensorflow.python.framework import test_ops | |
| 34 | 34 | from tensorflow.python.framework import test_util | |
| 35 | 35 | from tensorflow.python.ops import array_ops | |
| 36 | + from tensorflow.python.ops import gen_array_ops | ||
| 36 | 37 | from tensorflow.python.ops import gradients_impl | |
| 37 | 38 | from tensorflow.python.ops import init_ops | |
| 38 | 39 | from tensorflow.python.ops import math_ops | |
@@ -1124,5 +1125,15 @@ def testResourceRejection(self): | |||
| 1124 | 1125 | guarantee_a.eval() | |
| 1125 | 1126 | ||
| 1126 | 1127 | ||
| 1128 | + class SnapshotOpTest(test_util.TensorFlowTestCase): | ||
| 1129 | + | ||
| 1130 | + def testInvertPermutation(self): | ||
| 1131 | + for dtype in [dtypes.int32, dtypes.int64, dtypes.float32, dtypes.float64]: | ||
| 1132 | + with self.test_session(use_gpu=True): | ||
| 1133 | + x = constant_op.constant([0, 1, 2, 3], dtype=dtype) | ||
| 1134 | + y = gen_array_ops._snapshot(x) | ||
| 1135 | + self.assertAllEqual(y.eval(), [0, 1, 2, 3]) | ||
| 1136 | + | ||
| 1137 | + | ||
| 1127 | 1138 | if __name__ == "__main__": | |
| 1128 | 1139 | test_lib.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ ParallelConcat | |||
| 21 | 21 | Placeholder | |
| 22 | 22 | RefIdentity | |
| 23 | 23 | Reverse | |
| 24 | + Snapshot | ||
| 24 | 25 | SpaceToBatch | |
| 25 | 26 | Split | |
| 26 | 27 | SplitV | |
| Back | FazBrowse Home | New Git URL |
0 commit comments