transpose_op.h 2.0 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
X
xzl 已提交
2

L
Luo Tao 已提交
3 4 5
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
X
xzl 已提交
6

L
Luo Tao 已提交
7
    http://www.apache.org/licenses/LICENSE-2.0
X
xzl 已提交
8

L
Luo Tao 已提交
9 10 11 12 13
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
X
xzl 已提交
14 15 16

#pragma once

17
#include <vector>
18

Y
Yi Wang 已提交
19
#include "paddle/fluid/framework/op_registry.h"
20
#include "paddle/phi/kernels/funcs/math_function.h"
X
xzl 已提交
21 22 23 24

namespace paddle {
namespace operators {

25 26
enum { kTransposeMKLDNNFP32 = 1, kTransposeMKLDNNINT8 = 2 };

Q
QI JUN 已提交
27 28
template <typename DeviceContext, typename T>
inline void TransCompute(const int dim, const DeviceContext& dev_ctx,
29 30 31 32
                         const framework::Tensor& in, framework::Tensor* out,
                         const std::vector<int>& axis) {
  switch (dim) {
    case 1:
33
      phi::funcs::Transpose<DeviceContext, T, 1> trans1;
34 35 36
      trans1(dev_ctx, in, out, axis);
      break;
    case 2:
37
      phi::funcs::Transpose<DeviceContext, T, 2> trans2;
38 39 40
      trans2(dev_ctx, in, out, axis);
      break;
    case 3:
41
      phi::funcs::Transpose<DeviceContext, T, 3> trans3;
42 43 44
      trans3(dev_ctx, in, out, axis);
      break;
    case 4:
45
      phi::funcs::Transpose<DeviceContext, T, 4> trans4;
46 47 48
      trans4(dev_ctx, in, out, axis);
      break;
    case 5:
49
      phi::funcs::Transpose<DeviceContext, T, 5> trans5;
50 51 52
      trans5(dev_ctx, in, out, axis);
      break;
    case 6:
53
      phi::funcs::Transpose<DeviceContext, T, 6> trans6;
54 55 56
      trans6(dev_ctx, in, out, axis);
      break;
    default:
57
      // for dim >= 7 situation
58
      phi::funcs::TransposeNormal<DeviceContext, T> trans_normal;
59
      trans_normal(dev_ctx, in, out, axis);
X
xzl 已提交
60 61 62 63 64
  }
}

}  // namespace operators
}  // namespace paddle