Home | History | Annotate | Download | only in kernels
      1 /* Copyright 2016 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 #define EIGEN_USE_THREADS
     17 
     18 #include "tensorflow/core/framework/attr_value.pb.h"
     19 #include "tensorflow/core/framework/register_types.h"
     20 #include "tensorflow/core/kernels/ops_util.h"
     21 #include "tensorflow/core/kernels/tile_functor.h"
     22 
     23 namespace tensorflow {
     24 
     25 namespace internal {
     26 
     27 template <typename Device, typename T>
     28 void TileSimple(const Device& d, Tensor* out, const Tensor& in) {
     29   const int ndims = in.dims();
     30   const int64 nelem = out->NumElements();
     31   gtl::InlinedVector<int64, 8> in_strides = ComputeStride<int64>(in.shape());
     32   gtl::InlinedVector<int64, 8> out_strides = ComputeStride<int64>(out->shape());
     33   const T* p = in.flat<T>().data();
     34   T* q = out->flat<T>().data();
     35 
     36   for (int64 o_idx = 0; o_idx < nelem; ++o_idx) {
     37     int64 i_idx = 0;
     38     int64 t = o_idx;
     39     for (int i = 0; i < ndims; ++i) {
     40       i_idx += t / out_strides[i] % in.dim_size(i) * in_strides[i];
     41       t %= out_strides[i];
     42     }
     43     q[o_idx] = p[i_idx];
     44   }
     45 }
     46 
     47 }  // end namespace internal
     48 
     49 namespace functor {
     50 
     51 typedef Eigen::ThreadPoolDevice CPUDevice;
     52 
     53 // Register functors used for Tile functor.
     54 #define DEFINE_TYPE(T)                       \
     55   template struct Tile<CPUDevice, T, int32>; \
     56   template struct Tile<CPUDevice, T, int64>;
     57 
     58 TF_CALL_bool(DEFINE_TYPE);
     59 TF_CALL_float(DEFINE_TYPE);
     60 TF_CALL_double(DEFINE_TYPE);
     61 TF_CALL_uint8(DEFINE_TYPE);
     62 TF_CALL_int32(DEFINE_TYPE);
     63 TF_CALL_int16(DEFINE_TYPE);
     64 TF_CALL_int64(DEFINE_TYPE);
     65 TF_CALL_half(DEFINE_TYPE);
     66 TF_CALL_complex64(DEFINE_TYPE);
     67 TF_CALL_complex128(DEFINE_TYPE);
     68 TF_CALL_string(DEFINE_TYPE);
     69 
     70 #undef DEFINE_TYPE
     71 
     72 #ifdef TENSORFLOW_USE_SYCL
     73 typedef Eigen::SyclDevice SYCLDevice;
     74 
     75 #define DEFINE_TYPE(T)                        \
     76   template struct Tile<SYCLDevice, T, int32>; \
     77   template struct Tile<SYCLDevice, T, int64>;
     78 
     79 TF_CALL_bool(DEFINE_TYPE);
     80 TF_CALL_float(DEFINE_TYPE);
     81 TF_CALL_double(DEFINE_TYPE);
     82 TF_CALL_uint8(DEFINE_TYPE);
     83 TF_CALL_int32(DEFINE_TYPE);
     84 TF_CALL_int16(DEFINE_TYPE);
     85 TF_CALL_int64(DEFINE_TYPE);
     86 
     87 #undef DEFINE_TYPE
     88 #endif  // TENSORFLOW_USE_SYCL
     89 
     90 }  // end namespace functor
     91 }  // end namespace tensorflow
     92