1 /* Copyright 2015 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_CORE_KERNELS_SLICE_OP_H_ 17 #define TENSORFLOW_CORE_KERNELS_SLICE_OP_H_ 18 19 // Functor definition for SliceOp, must be compilable by nvcc. 20 21 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" 22 #include "tensorflow/core/framework/tensor_types.h" 23 24 namespace tensorflow { 25 namespace functor { 26 27 template <typename Device, typename T, int NDIMS> 28 struct Slice { operatorSlice29 void operator()(const Device& d, typename TTypes<T, NDIMS>::Tensor output, 30 typename TTypes<T, NDIMS>::ConstTensor input, 31 const Eigen::DSizes<Eigen::DenseIndex, NDIMS>& slice_indices, 32 const Eigen::DSizes<Eigen::DenseIndex, NDIMS>& slice_sizes) { 33 bool use_64bit = (input.size() > Eigen::NumTraits<int>::highest()); 34 if (!use_64bit && 35 Eigen::internal::is_same<Device, Eigen::GpuDevice>::value) { 36 Eigen::DSizes<int, NDIMS> indices; 37 for (int i = 0; i < NDIMS; ++i) { 38 indices[i] = slice_indices[i]; 39 } 40 Eigen::DSizes<int, NDIMS> sizes; 41 for (int i = 0; i < NDIMS; ++i) { 42 sizes[i] = slice_sizes[i]; 43 } 44 To32Bit(output).device(d) = To32Bit(input).slice(indices, sizes); 45 } else { 46 output.device(d) = input.slice(slice_indices, slice_sizes); 47 } 48 } 49 }; 50 51 } // namespace functor 52 } // namespace tensorflow 53 54 #endif // TENSORFLOW_CORE_KERNELS_SLICE_OP_H_ 55