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> |
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_t, 8> in_strides = |
31 | ComputeStride<int64_t>(in.shape()); |
32 | gtl::InlinedVector<int64_t, 8> out_strides = |
33 | ComputeStride<int64_t>(out->shape()); |
34 | const T* p = in.flat<T>().data(); |
35 | T* q = out->flat<T>().data(); |
36 | |
37 | for (int64_t o_idx = 0; o_idx < nelem; ++o_idx) { |
38 | int64_t i_idx = 0; |
39 | int64_t t = o_idx; |
40 | for (int i = 0; i < ndims; ++i) { |
41 | i_idx += t / out_strides[i] % in.dim_size(i) * in_strides[i]; |
42 | t %= out_strides[i]; |
43 | } |
44 | q[o_idx] = p[i_idx]; |
45 | } |
46 | } |
47 | |
48 | template <typename T> |
49 | void TileSimple(const Eigen::ThreadPoolDevice& d, Tensor* out, |
50 | const Tensor& in) { |
51 | return TileSimpleImpl<Eigen::ThreadPoolDevice, T>(d, out, in); |
52 | } |
53 | |
54 | } // namespace internal |
55 | } // end namespace tensorflow |
56 | |
57 | #endif // TENSORFLOW_CORE_KERNELS_TILE_FUNCTOR_CPU_H_ |
58 | |