• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "tensorflow/core/kernels/reduction_ops_common.h"
17 
18 namespace 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, Eigen::internal::MaxReducer<type>>); \
27   REGISTER_KERNEL_BUILDER(                                                     \
28       Name("Max")                                                              \
29           .Device(DEVICE_CPU)                                                  \
30           .TypeConstraint<type>("T")                                           \
31           .TypeConstraint<int64>("Tidx"),                                      \
32       ReductionOp<CPUDevice, type, int64, Eigen::internal::MaxReducer<type>>);
33 TF_CALL_REAL_NUMBER_TYPES(REGISTER_CPU_KERNELS);
34 #undef REGISTER_CPU_KERNELS
35 
36 #if GOOGLE_CUDA
37 
38 #define REGISTER_GPU_KERNELS(type)                                             \
39   REGISTER_KERNEL_BUILDER(                                                     \
40       Name("Max")                                                              \
41           .Device(DEVICE_GPU)                                                  \
42           .TypeConstraint<type>("T")                                           \
43           .TypeConstraint<int32>("Tidx")                                       \
44           .HostMemory("reduction_indices"),                                    \
45       ReductionOp<GPUDevice, type, int32, Eigen::internal::MaxReducer<type>>); \
46   REGISTER_KERNEL_BUILDER(                                                     \
47       Name("Max")                                                              \
48           .Device(DEVICE_GPU)                                                  \
49           .TypeConstraint<type>("T")                                           \
50           .TypeConstraint<int64>("Tidx")                                       \
51           .HostMemory("reduction_indices"),                                    \
52       ReductionOp<GPUDevice, type, int64, Eigen::internal::MaxReducer<type>>);
53 
54 REGISTER_GPU_KERNELS(Eigen::half);
55 REGISTER_GPU_KERNELS(float);
56 REGISTER_GPU_KERNELS(double);
57 REGISTER_GPU_KERNELS(int64);
58 
59 // A special GPU kernel for int32.
60 // TODO(b/25387198): Also enable int32 in device memory. This kernel
61 // registration requires all int32 inputs and outputs to be in host memory.
62 REGISTER_KERNEL_BUILDER(
63     Name("Max")
64         .Device(DEVICE_GPU)
65         .HostMemory("reduction_indices")
66         .HostMemory("input")
67         .HostMemory("output")
68         .TypeConstraint<int32>("T")
69         .TypeConstraint<int32>("Tidx"),
70     ReductionOp<CPUDevice, int32, int32, Eigen::internal::MaxReducer<int32>>);
71 REGISTER_KERNEL_BUILDER(
72     Name("Max")
73         .Device(DEVICE_GPU)
74         .HostMemory("reduction_indices")
75         .HostMemory("input")
76         .HostMemory("output")
77         .TypeConstraint<int32>("T")
78         .TypeConstraint<int64>("Tidx"),
79     ReductionOp<CPUDevice, int32, int64, Eigen::internal::MaxReducer<int32>>);
80 
81 #undef REGISTER_GPU_KERNELS
82 
83 #endif
84 
85 #ifdef TENSORFLOW_USE_SYCL
86 #define REGISTER_SYCL_KERNELS(type)                                        \
87   REGISTER_KERNEL_BUILDER(Name("Max")                                      \
88                               .Device(DEVICE_SYCL)                         \
89                               .TypeConstraint<type>("T")                   \
90                               .TypeConstraint<int32>("Tidx")               \
91                               .HostMemory("reduction_indices"),            \
92                           ReductionOp<SYCLDevice, type, int32,             \
93                                       Eigen::internal::MaxReducer<type>>); \
94   REGISTER_KERNEL_BUILDER(Name("Max")                                      \
95                               .Device(DEVICE_SYCL)                         \
96                               .TypeConstraint<type>("T")                   \
97                               .TypeConstraint<int64>("Tidx")               \
98                               .HostMemory("reduction_indices"),            \
99                           ReductionOp<SYCLDevice, type, int64,             \
100                                       Eigen::internal::MaxReducer<type>>);
101 REGISTER_SYCL_KERNELS(float);
102 REGISTER_SYCL_KERNELS(double);
103 
104 REGISTER_KERNEL_BUILDER(
105     Name("Max")
106         .Device(DEVICE_SYCL)
107         .HostMemory("reduction_indices")
108         .HostMemory("input")
109         .HostMemory("output")
110         .TypeConstraint<int32>("T")
111         .TypeConstraint<int32>("Tidx"),
112     ReductionOp<CPUDevice, int32, int32, Eigen::internal::MaxReducer<int32>>);
113 REGISTER_KERNEL_BUILDER(
114     Name("Max")
115         .Device(DEVICE_SYCL)
116         .HostMemory("reduction_indices")
117         .HostMemory("input")
118         .HostMemory("output")
119         .TypeConstraint<int32>("T")
120         .TypeConstraint<int64>("Tidx"),
121     ReductionOp<CPUDevice, int32, int64, Eigen::internal::MaxReducer<int32>>);
122 #undef REGISTER_SYCL_KERNELS
123 #endif  // TENSORFLOW_USE_SYCL
124 
125 }  // namespace tensorflow
126