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#include "tensorflow/core/kernels/reduction_ops_common.h"
17
18namespace tensorflow {
19
20#define REGISTER_CPU_KERNELS(type) \
21 REGISTER_KERNEL_BUILDER( \
22 Name("Max") \
23 .Device(DEVICE_CPU) \
24 .TypeConstraint<type>("T") \
25 .TypeConstraint<int32>("Tidx"), \
26 ReductionOp<CPUDevice, type, int32, \
27 Eigen::internal::MaxReducer<type, Eigen::PropagateNaN>>); \
28 REGISTER_KERNEL_BUILDER( \
29 Name("Max") \
30 .Device(DEVICE_CPU) \
31 .TypeConstraint<type>("T") \
32 .TypeConstraint<int64_t>("Tidx"), \
33 ReductionOp<CPUDevice, type, int64, \
34 Eigen::internal::MaxReducer<type, Eigen::PropagateNaN>>);
35TF_CALL_REAL_NUMBER_TYPES(REGISTER_CPU_KERNELS);
36#undef REGISTER_CPU_KERNELS
37
38#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
39
40#define REGISTER_GPU_KERNELS(type) \
41 REGISTER_KERNEL_BUILDER( \
42 Name("Max") \
43 .Device(DEVICE_GPU) \
44 .TypeConstraint<type>("T") \
45 .TypeConstraint<int32>("Tidx") \
46 .HostMemory("reduction_indices"), \
47 ReductionOp<GPUDevice, type, int32, \
48 Eigen::internal::MaxReducer<type, Eigen::PropagateNaN>>); \
49 REGISTER_KERNEL_BUILDER( \
50 Name("Max") \
51 .Device(DEVICE_GPU) \
52 .TypeConstraint<type>("T") \
53 .TypeConstraint<int64_t>("Tidx") \
54 .HostMemory("reduction_indices"), \
55 ReductionOp<GPUDevice, type, int64, \
56 Eigen::internal::MaxReducer<type, Eigen::PropagateNaN>>);
57
58REGISTER_GPU_KERNELS(Eigen::half);
59REGISTER_GPU_KERNELS(float);
60REGISTER_GPU_KERNELS(double);
61REGISTER_GPU_KERNELS(int64_t);
62
63#undef REGISTER_GPU_KERNELS
64#endif
65
66// A special DEVICE_DEFAULT kernel for int32.
67// TODO(b/25387198): Also enable int32 in device memory. This kernel
68// registration requires all int32 inputs and outputs to be in host memory.
69REGISTER_KERNEL_BUILDER(
70 Name("Max")
71 .Device(DEVICE_DEFAULT)
72 .HostMemory("reduction_indices")
73 .HostMemory("input")
74 .HostMemory("output")
75 .TypeConstraint<int32>("T")
76 .TypeConstraint<int32>("Tidx"),
77 ReductionOp<CPUDevice, int32, int32, Eigen::internal::MaxReducer<int32>>);
78REGISTER_KERNEL_BUILDER(
79 Name("Max")
80 .Device(DEVICE_DEFAULT)
81 .HostMemory("reduction_indices")
82 .HostMemory("input")
83 .HostMemory("output")
84 .TypeConstraint<int32>("T")
85 .TypeConstraint<int64_t>("Tidx"),
86 ReductionOp<CPUDevice, int32, int64, Eigen::internal::MaxReducer<int32>>);
87
88} // namespace tensorflow
89