1/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_KERNELS_TRANSPOSE_OP_H_
17#define TENSORFLOW_CORE_KERNELS_TRANSPOSE_OP_H_
18
19#include "tensorflow/core/framework/op_kernel.h"
20#include "tensorflow/core/framework/tensor.h"
21
22namespace tensorflow {
23
24class TransposeOp : public OpKernel {
25 public:
26 explicit TransposeOp(OpKernelConstruction* ctx) : OpKernel(ctx) {}
27
28 void Compute(OpKernelContext* ctx) override;
29
30 protected:
31 virtual Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
32 gtl::ArraySlice<int32> perm, Tensor* out) = 0;
33 virtual bool IsConjugate() const { return false; }
34};
35
36class TransposeCpuOp : public TransposeOp {
37 public:
38 explicit TransposeCpuOp(OpKernelConstruction* ctx) : TransposeOp(ctx) {}
39
40 protected:
41 Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
42 gtl::ArraySlice<int32> perm, Tensor* out) override;
43};
44
45#if defined(INTEL_MKL)
46class MklTransposeCpuOp : public TransposeOp {
47 public:
48 explicit MklTransposeCpuOp(OpKernelConstruction* ctx) : TransposeOp(ctx) {}
49
50 protected:
51 Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
52 gtl::ArraySlice<int32> perm, Tensor* out) override;
53};
54#endif // INTEL_MKL
55
56class TransposeGpuOp : public TransposeOp {
57 public:
58 explicit TransposeGpuOp(OpKernelConstruction* ctx) : TransposeOp(ctx) {}
59
60 protected:
61 Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
62 gtl::ArraySlice<int32> perm, Tensor* out) override;
63};
64
65
66// Conjugating transpose ops.
67class ConjugateTransposeCpuOp : public TransposeOp {
68 public:
69 explicit ConjugateTransposeCpuOp(OpKernelConstruction* ctx)
70 : TransposeOp(ctx) {}
71
72 protected:
73 Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
74 gtl::ArraySlice<int32> perm, Tensor* out) override;
75 bool IsConjugate() const override { return true; }
76};
77
78#if defined(INTEL_MKL)
79class MklConjugateTransposeCpuOp : public TransposeOp {
80 public:
81 explicit MklConjugateTransposeCpuOp(OpKernelConstruction* ctx)
82 : TransposeOp(ctx) {}
83
84 protected:
85 Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
86 gtl::ArraySlice<int32> perm, Tensor* out) override;
87 bool IsConjugate() const override { return true; }
88};
89#endif // INTEL_MKL
90
91class ConjugateTransposeGpuOp : public TransposeOp {
92 public:
93 explicit ConjugateTransposeGpuOp(OpKernelConstruction* ctx)
94 : TransposeOp(ctx) {}
95
96 protected:
97 Status DoTranspose(OpKernelContext* ctx, const Tensor& in,
98 gtl::ArraySlice<int32> perm, Tensor* out) override;
99 bool IsConjugate() const override { return true; }
100};
101
102
103} // namespace tensorflow
104
105#endif // TENSORFLOW_CORE_KERNELS_TRANSPOSE_OP_H_
106