Home | History | Annotate | Download | only in kernels
      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 #ifndef TENSORFLOW_KERNELS_FILL_FUNCTOR_H_
     17 #define TENSORFLOW_KERNELS_FILL_FUNCTOR_H_
     18 
     19 #define EIGEN_USE_THREADS
     20 
     21 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
     22 #include "tensorflow/core/framework/tensor_types.h"
     23 #include "tensorflow/core/framework/types.h"
     24 
     25 namespace tensorflow {
     26 namespace functor {
     27 
     28 template <typename Device, typename T>
     29 struct FillFunctor {
     30   // Computes on device "d": out = out.constant(in(0)),
     31   void operator()(const Device& d, typename TTypes<T>::Flat out,
     32                   typename TTypes<T>::ConstScalar in);
     33 };
     34 
     35 template <typename Device, typename T>
     36 struct SetZeroFunctor {
     37   // Computes on device "d": out = out.setZero(),
     38   void operator()(const Device& d, typename TTypes<T>::Flat out);
     39 };
     40 
     41 // Partial specialization of SetZeroFunctor<Device=Eigen::ThreadPoolDevice, T>.
     42 template <typename T>
     43 struct SetZeroFunctor<Eigen::ThreadPoolDevice, T> {
     44   void operator()(const Eigen::ThreadPoolDevice& d,
     45                   typename TTypes<T>::Flat out);
     46 };
     47 
     48 #ifdef TENSORFLOW_USE_SYCL
     49 // Partial specialization of SetZeroFunctor<Device=Eigen::SyclDevice, T>.
     50 template <typename T>
     51 struct SetZeroFunctor<Eigen::SyclDevice, T> {
     52   void operator()(const Eigen::SyclDevice& d, typename TTypes<T>::Flat out);
     53 };
     54 #endif  // TENSORFLOW_USE_SYCL
     55 
     56 template <>
     57 struct SetZeroFunctor<Eigen::ThreadPoolDevice, string> {
     58   void operator()(const Eigen::ThreadPoolDevice& d,
     59                   typename TTypes<string>::Flat out);
     60 };
     61 
     62 template <typename Device, typename T>
     63 struct SetOneFunctor {
     64   // Computes on device "d": out = out.setOne(),
     65   void operator()(const Device& d, typename TTypes<T>::Flat out);
     66 };
     67 
     68 // Partial specialization of SetOneFunctor<Device=Eigen::ThreadPoolDevice, T>.
     69 template <typename T>
     70 struct SetOneFunctor<Eigen::ThreadPoolDevice, T> {
     71   void operator()(const Eigen::ThreadPoolDevice& d,
     72                   typename TTypes<T>::Flat out);
     73 };
     74 
     75 #ifdef TENSORFLOW_USE_SYCL
     76 // Partial specialization of SetOneFunctor<Device=Eigen::SyclDevice, T>.
     77 template <typename T>
     78 struct SetOneFunctor<Eigen::SyclDevice, T> {
     79   void operator()(const Eigen::SyclDevice& d, typename TTypes<T>::Flat out);
     80 };
     81 #endif  // TENSORFLOW_USE_SYCL
     82 
     83 template <>
     84 struct SetOneFunctor<Eigen::ThreadPoolDevice, string> {
     85   void operator()(const Eigen::ThreadPoolDevice& d,
     86                   typename TTypes<string>::Flat out);
     87 };
     88 
     89 }  // namespace functor
     90 }  // namespace tensorflow
     91 
     92 #endif  // TENSORFLOW_KERNELS_FILL_FUNCTOR_H_
     93