concat_and_split.cu 2.1 KB
Newer Older
C
chengduoZH 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2018 paddlepaddle Authors. All Rights Reserved.

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

    http://www.apache.org/licenses/LICENSE-2.0

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. */

C
chengduo 已提交
15
#include "paddle/fluid/operators/math/concat_and_split.h"
C
chengduoZH 已提交
16

L
Leo Chen 已提交
17
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
C
chengduoZH 已提交
18 19 20 21 22
namespace paddle {
namespace operators {
namespace math {

/*
C
chengduoZH 已提交
23
 * All tensors' dimension should be the same and the values of
24
 * each dimension must be the same, except the axis dimension.
C
chengduoZH 已提交
25 26 27 28 29
 */
template <typename T>
class ConcatFunctor<platform::CUDADeviceContext, T> {
 public:
  void operator()(const platform::CUDADeviceContext& context,
C
chengduoZH 已提交
30
                  const std::vector<framework::Tensor>& input, int axis,
C
chengduoZH 已提交
31
                  framework::Tensor* output) {
L
Leo Chen 已提交
32 33
    phi::funcs::ConcatFunctor<phi::GPUContext, T> functor;
    functor(context, input, axis, output);
C
chengduoZH 已提交
34 35 36
  }
};

C
chengduoZH 已提交
37 38
/*
 * All tensors' dimension should be the same and the values of
39
 * each dimension must be the same, except the axis dimension.
C
chengduoZH 已提交
40
 */
C
chengduoZH 已提交
41
template <typename T>
C
chengduo 已提交
42
class SplitFunctor<platform::CUDADeviceContext, T> {
C
chengduoZH 已提交
43 44
 public:
  void operator()(const platform::CUDADeviceContext& context,
Q
qiaolongfei 已提交
45
                  const framework::Tensor& input,
C
chengduoZH 已提交
46 47
                  const std::vector<const framework::Tensor*>& ref_inputs,
                  int axis, std::vector<framework::Tensor*>* outputs) {
L
Leo Chen 已提交
48 49
    phi::funcs::SplitFunctor<phi::GPUContext, T> functor;
    functor(context, input, ref_inputs, axis, outputs);
C
chengduoZH 已提交
50 51 52
  }
};

C
chengduoZH 已提交
53 54
#define DEFINE_FUNCTOR(type)                                       \
  template class ConcatFunctor<platform::CUDADeviceContext, type>; \
C
chengduo 已提交
55
  template class SplitFunctor<platform::CUDADeviceContext, type>
C
chengduoZH 已提交
56

C
chengduoZH 已提交
57
FOR_ALL_TYPES(DEFINE_FUNCTOR);
C
chengduoZH 已提交
58

C
chengduoZH 已提交
59 60 61
}  // namespace math
}  // namespace operators
}  // namespace paddle