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