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