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_KERNELS_ARGMAX_OP_H_ 17 #define TENSORFLOW_KERNELS_ARGMAX_OP_H_ 18 // Generator definition for ArgMaxOp, must be compilable by nvcc. 19 20 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" 21 #include "tensorflow/core/framework/tensor_types.h" 22 #include "tensorflow/core/platform/types.h" 23 24 namespace tensorflow { 25 26 namespace functor { 27 28 template <typename Device, typename T, typename Tout> 29 struct ArgMax { 30 #define DECLARE_COMPUTE_SPEC(Dims) \ 31 EIGEN_ALWAYS_INLINE static void Reduce##Dims( \ 32 const Device& d, typename TTypes<T, Dims>::ConstTensor input, \ 33 const int32 dimension, typename TTypes<Tout, Dims - 1>::Tensor output) { \ 34 output.device(d) = input.argmax(dimension).template cast<Tout>(); \ 35 } 36 37 DECLARE_COMPUTE_SPEC(1); 38 DECLARE_COMPUTE_SPEC(2); 39 DECLARE_COMPUTE_SPEC(3); 40 DECLARE_COMPUTE_SPEC(4); 41 DECLARE_COMPUTE_SPEC(5); 42 43 #undef DECLARE_COMPUTE_SPEC 44 }; 45 46 template <typename Device, typename T, typename Tout> 47 struct ArgMin { 48 #define DECLARE_COMPUTE_SPEC(Dims) \ 49 EIGEN_ALWAYS_INLINE static void Reduce##Dims( \ 50 const Device& d, typename TTypes<T, Dims>::ConstTensor input, \ 51 const int32 dimension, typename TTypes<Tout, Dims - 1>::Tensor output) { \ 52 output.device(d) = input.argmin(dimension).template cast<Tout>(); \ 53 } 54 55 DECLARE_COMPUTE_SPEC(1); 56 DECLARE_COMPUTE_SPEC(2); 57 DECLARE_COMPUTE_SPEC(3); 58 DECLARE_COMPUTE_SPEC(4); 59 DECLARE_COMPUTE_SPEC(5); 60 61 #undef DECLARE_COMPUTE_SPEC 62 }; 63 64 } // namespace functor 65 66 } // namespace tensorflow 67 68 #endif // TENSORFLOW_KERNELS_ARGMAX_OP_H_ 69