1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_KERNELS_ARGMAX_OP_H_
17#define TENSORFLOW_CORE_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
24namespace tensorflow {
25
26namespace functor {
27
28template <typename Device, typename T, typename Tout>
29struct 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 DECLARE_COMPUTE_SPEC(6);
43 DECLARE_COMPUTE_SPEC(7);
44
45#undef DECLARE_COMPUTE_SPEC
46};
47
48template <typename Device, typename T, typename Tout>
49struct ArgMin {
50#define DECLARE_COMPUTE_SPEC(Dims) \
51 EIGEN_ALWAYS_INLINE static void Reduce##Dims( \
52 const Device& d, typename TTypes<T, Dims>::ConstTensor input, \
53 const int32 dimension, typename TTypes<Tout, Dims - 1>::Tensor output) { \
54 output.device(d) = input.argmin(dimension).template cast<Tout>(); \
55 }
56
57 DECLARE_COMPUTE_SPEC(1);
58 DECLARE_COMPUTE_SPEC(2);
59 DECLARE_COMPUTE_SPEC(3);
60 DECLARE_COMPUTE_SPEC(4);
61 DECLARE_COMPUTE_SPEC(5);
62 DECLARE_COMPUTE_SPEC(6);
63 DECLARE_COMPUTE_SPEC(7);
64
65#undef DECLARE_COMPUTE_SPEC
66};
67
68} // namespace functor
69
70} // namespace tensorflow
71
72#endif // TENSORFLOW_CORE_KERNELS_ARGMAX_OP_H_
73