concat_and_split.cu 2.5 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

17
#include "paddle/phi/kernels/gpu/concat_and_split.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) {
32
    std::vector<phi::DenseTensor> pt_input{input.begin(), input.end()};
33

34 35
    phi::ConcatImpl<T, platform::CUDADeviceContext>(context, pt_input, axis,
                                                    output);
C
chengduoZH 已提交
36 37 38
  }
};

C
chengduoZH 已提交
39 40
/*
 * All tensors' dimension should be the same and the values of
41
 * each dimension must be the same, except the axis dimension.
C
chengduoZH 已提交
42
 */
C
chengduoZH 已提交
43
template <typename T>
C
chengduo 已提交
44
class SplitFunctor<platform::CUDADeviceContext, T> {
C
chengduoZH 已提交
45
 public:
46
  SplitFunctor();
C
chengduoZH 已提交
47
  void operator()(const platform::CUDADeviceContext& context,
Q
qiaolongfei 已提交
48
                  const framework::Tensor& input,
C
chengduoZH 已提交
49 50
                  const std::vector<const framework::Tensor*>& ref_inputs,
                  int axis, std::vector<framework::Tensor*>* outputs) {
51 52 53 54
    std::vector<const phi::DenseTensor*> pt_ref_inputs{ref_inputs.begin(),
                                                       ref_inputs.end()};
    std::vector<phi::DenseTensor*> pt_outputs{outputs->begin(), outputs->end()};
    phi::SplitImpl<T, platform::CUDADeviceContext>(
55
        context, input, pt_ref_inputs, axis, &pt_outputs);
C
chengduoZH 已提交
56 57 58
  }
};

C
chengduoZH 已提交
59 60
#define DEFINE_FUNCTOR(type)                                       \
  template class ConcatFunctor<platform::CUDADeviceContext, type>; \
C
chengduo 已提交
61
  template class SplitFunctor<platform::CUDADeviceContext, type>
C
chengduoZH 已提交
62

C
chengduoZH 已提交
63
FOR_ALL_TYPES(DEFINE_FUNCTOR);
C
chengduoZH 已提交
64

C
chengduoZH 已提交
65 66 67
}  // namespace math
}  // namespace operators
}  // namespace paddle