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/fill_functor.h" |
17 | |
18 | #define EIGEN_USE_THREADS |
19 | |
20 | #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" |
21 | #include "tensorflow/core/framework/register_types.h" |
22 | #include "tensorflow/core/framework/tensor_types.h" |
23 | #include "tensorflow/core/framework/types.h" |
24 | #include "tensorflow/core/framework/variant_encode_decode.h" |
25 | |
26 | namespace tensorflow { |
27 | namespace functor { |
28 | |
29 | template <typename T> |
30 | void SetZeroFunctor<Eigen::ThreadPoolDevice, T>::operator()( |
31 | const Eigen::ThreadPoolDevice& d, typename TTypes<T>::Flat out) { |
32 | out.device(d) = out.constant(T(0)); |
33 | } |
34 | |
35 | void SetZeroFunctor<Eigen::ThreadPoolDevice, tstring>::operator()( |
36 | const Eigen::ThreadPoolDevice& d, typename TTypes<tstring>::Flat out) { |
37 | out.device(d) = out.constant(tstring()); |
38 | } |
39 | |
40 | // Explicit instantiations. |
41 | #define DEFINE_SETZERO_CPU(T) \ |
42 | template struct SetZeroFunctor<Eigen::ThreadPoolDevice, T>; |
43 | DEFINE_SETZERO_CPU(bool); |
44 | DEFINE_SETZERO_CPU(Eigen::half); |
45 | DEFINE_SETZERO_CPU(bfloat16); |
46 | DEFINE_SETZERO_CPU(float); |
47 | DEFINE_SETZERO_CPU(double); |
48 | DEFINE_SETZERO_CPU(uint32); |
49 | DEFINE_SETZERO_CPU(uint64); |
50 | DEFINE_SETZERO_CPU(uint8); |
51 | DEFINE_SETZERO_CPU(int8); |
52 | DEFINE_SETZERO_CPU(uint16); |
53 | DEFINE_SETZERO_CPU(int16); |
54 | DEFINE_SETZERO_CPU(int32); |
55 | DEFINE_SETZERO_CPU(int64_t); |
56 | DEFINE_SETZERO_CPU(quint8); |
57 | DEFINE_SETZERO_CPU(qint8); |
58 | DEFINE_SETZERO_CPU(quint16); |
59 | DEFINE_SETZERO_CPU(qint16); |
60 | DEFINE_SETZERO_CPU(qint32); |
61 | DEFINE_SETZERO_CPU(complex64); |
62 | DEFINE_SETZERO_CPU(complex128); |
63 | DEFINE_SETZERO_CPU(Variant); |
64 | #undef DEFINE_SETZERO_CPU |
65 | |
66 | |
67 | template <typename T> |
68 | void SetOneFunctor<Eigen::ThreadPoolDevice, T>::operator()( |
69 | const Eigen::ThreadPoolDevice& d, typename TTypes<T>::Flat out) { |
70 | out.device(d) = out.constant(T(1)); |
71 | } |
72 | |
73 | // Explicit instantiations. |
74 | #define DEFINE_SETONE_CPU(T) \ |
75 | template struct SetOneFunctor<Eigen::ThreadPoolDevice, T>; |
76 | DEFINE_SETONE_CPU(bool); |
77 | DEFINE_SETONE_CPU(Eigen::half); |
78 | DEFINE_SETONE_CPU(bfloat16); |
79 | DEFINE_SETONE_CPU(float); |
80 | DEFINE_SETONE_CPU(double); |
81 | DEFINE_SETONE_CPU(uint32); |
82 | DEFINE_SETONE_CPU(uint64); |
83 | DEFINE_SETONE_CPU(uint8); |
84 | DEFINE_SETONE_CPU(int8); |
85 | DEFINE_SETONE_CPU(uint16); |
86 | DEFINE_SETONE_CPU(int16); |
87 | DEFINE_SETONE_CPU(int32); |
88 | DEFINE_SETONE_CPU(int64_t); |
89 | DEFINE_SETONE_CPU(complex64); |
90 | DEFINE_SETONE_CPU(complex128); |
91 | #undef DEFINE_SETONE_CPU |
92 | |
93 | template <typename T> |
94 | void SetNanFunctor<Eigen::ThreadPoolDevice, T>::operator()( |
95 | const Eigen::ThreadPoolDevice& d, typename TTypes<T>::Flat out) { |
96 | out.device(d) = out.constant(Eigen::NumTraits<T>::quiet_NaN()); |
97 | } |
98 | |
99 | // Explicit instantiations. |
100 | #define DEFINE_SETNAN_CPU(T) \ |
101 | template struct SetNanFunctor<Eigen::ThreadPoolDevice, T>; |
102 | TF_CALL_NUMBER_TYPES(DEFINE_SETNAN_CPU); |
103 | TF_CALL_bool(DEFINE_SETNAN_CPU); |
104 | #undef DEFINE_SETNAN_CPU |
105 | |
106 | template <typename T> |
107 | struct FillFunctor<Eigen::ThreadPoolDevice, T> { |
108 | void operator()(const Eigen::ThreadPoolDevice& d, |
109 | typename TTypes<T>::Flat out, |
110 | typename TTypes<T>::ConstScalar in) { |
111 | out.device(d) = out.constant(in()); |
112 | } |
113 | }; |
114 | |
115 | // Explicit instantiations. |
116 | #define DEFINE_FILL_CPU(T) \ |
117 | template struct FillFunctor<Eigen::ThreadPoolDevice, T>; |
118 | |
119 | TF_CALL_ALL_TYPES(DEFINE_FILL_CPU); |
120 | DEFINE_FILL_CPU(quint8); |
121 | DEFINE_FILL_CPU(quint16); |
122 | DEFINE_FILL_CPU(qint8); |
123 | DEFINE_FILL_CPU(qint16); |
124 | DEFINE_FILL_CPU(qint32); |
125 | #undef DEFINE_FILL_CPU |
126 | |
127 | |
128 | } // namespace functor |
129 | } // namespace tensorflow |
130 | |