• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TENSORFLOW_CORE_KERNELS_TILE_FUNCTOR_CPU_H_
16 #define TENSORFLOW_CORE_KERNELS_TILE_FUNCTOR_CPU_H_
17 
18 #define EIGEN_USE_THREADS
19 
20 #include "tensorflow/core/kernels/ops_util.h"
21 #include "tensorflow/core/kernels/tile_functor.h"
22 
23 namespace tensorflow {
24 namespace internal {
25 
26 template <typename Device, typename T>
TileSimpleImpl(const Device & d,Tensor * out,const Tensor & in)27 void TileSimpleImpl(const Device& d, Tensor* out, const Tensor& in) {
28   const int ndims = in.dims();
29   const int64_t nelem = out->NumElements();
30   gtl::InlinedVector<int64, 8> in_strides = ComputeStride<int64>(in.shape());
31   gtl::InlinedVector<int64, 8> out_strides = ComputeStride<int64>(out->shape());
32   const T* p = in.flat<T>().data();
33   T* q = out->flat<T>().data();
34 
35   for (int64_t o_idx = 0; o_idx < nelem; ++o_idx) {
36     int64_t i_idx = 0;
37     int64_t t = o_idx;
38     for (int i = 0; i < ndims; ++i) {
39       i_idx += t / out_strides[i] % in.dim_size(i) * in_strides[i];
40       t %= out_strides[i];
41     }
42     q[o_idx] = p[i_idx];
43   }
44 }
45 
46 template <typename T>
TileSimple(const Eigen::ThreadPoolDevice & d,Tensor * out,const Tensor & in)47 void TileSimple(const Eigen::ThreadPoolDevice& d, Tensor* out,
48                 const Tensor& in) {
49   return TileSimpleImpl<Eigen::ThreadPoolDevice, T>(d, out, in);
50 }
51 
52 }  // namespace internal
53 }  // end namespace tensorflow
54 
55 #endif  // TENSORFLOW_CORE_KERNELS_TILE_FUNCTOR_CPU_H_
56