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