“048b00132e9e6b86d21e520319cbe13de0dc2098”上不存在“python/paddle/incubate/nn/layer/fused_ec_moe.py”
dispatch_test_op.cc 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// Copyright (c) 2021 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.

#include <iostream>
#include <vector>

#include "paddle/extension.h"

template <typename data_t>
void assign_cpu_kernel(const data_t* x_data,
                       data_t* out_data,
                       int64_t x_numel) {
  for (int i = 0; i < x_numel; ++i) {
    out_data[i] = x_data[i];
  }
}

std::vector<paddle::Tensor> DispatchTestInterger(const paddle::Tensor& x) {
  auto out = paddle::Tensor(paddle::PlaceType::kCPU);
  out.reshape(x.shape());

  PD_DISPATCH_INTEGRAL_TYPES(
      x.type(), "assign_cpu_kernel", ([&] {
        assign_cpu_kernel<data_t>(
            x.data<data_t>(), out.mutable_data<data_t>(), x.size());
      }));

  return {out};
}

42
PD_BUILD_OP(dispatch_test_integer)
43 44
    .Inputs({"X"})
    .Outputs({"Out"})
45
    .SetKernelFn(PD_KERNEL(DispatchTestInterger));
46 47 48 49 50 51 52 53 54 55 56 57 58 59

std::vector<paddle::Tensor> DispatchTestComplex(const paddle::Tensor& x) {
  auto out = paddle::Tensor(paddle::PlaceType::kCPU);
  out.reshape(x.shape());

  PD_DISPATCH_COMPLEX_TYPES(
      x.type(), "assign_cpu_kernel", ([&] {
        assign_cpu_kernel<data_t>(
            x.data<data_t>(), out.mutable_data<data_t>(), x.size());
      }));

  return {out};
}

60
PD_BUILD_OP(dispatch_test_complex)
61 62
    .Inputs({"X"})
    .Outputs({"Out"})
63
    .SetKernelFn(PD_KERNEL(DispatchTestComplex));
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

std::vector<paddle::Tensor> DispatchTestFloatAndInteger(
    const paddle::Tensor& x) {
  auto out = paddle::Tensor(paddle::PlaceType::kCPU);
  out.reshape(x.shape());

  PD_DISPATCH_FLOATING_AND_INTEGRAL_TYPES(
      x.type(), "assign_cpu_kernel", ([&] {
        assign_cpu_kernel<data_t>(
            x.data<data_t>(), out.mutable_data<data_t>(), x.size());
      }));

  return {out};
}

79
PD_BUILD_OP(dispatch_test_float_and_integer)
80 81
    .Inputs({"X"})
    .Outputs({"Out"})
82
    .SetKernelFn(PD_KERNEL(DispatchTestFloatAndInteger));
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

std::vector<paddle::Tensor> DispatchTestFloatAndComplex(
    const paddle::Tensor& x) {
  auto out = paddle::Tensor(paddle::PlaceType::kCPU);
  out.reshape(x.shape());

  PD_DISPATCH_FLOATING_AND_COMPLEX_TYPES(
      x.type(), "assign_cpu_kernel", ([&] {
        assign_cpu_kernel<data_t>(
            x.data<data_t>(), out.mutable_data<data_t>(), x.size());
      }));

  return {out};
}

98
PD_BUILD_OP(dispatch_test_float_and_complex)
99 100
    .Inputs({"X"})
    .Outputs({"Out"})
101
    .SetKernelFn(PD_KERNEL(DispatchTestFloatAndComplex));
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

std::vector<paddle::Tensor> DispatchTestFloatAndIntegerAndComplex(
    const paddle::Tensor& x) {
  auto out = paddle::Tensor(paddle::PlaceType::kCPU);
  out.reshape(x.shape());

  PD_DISPATCH_FLOATING_AND_INTEGRAL_AND_COMPLEX_TYPES(
      x.type(), "assign_cpu_kernel", ([&] {
        assign_cpu_kernel<data_t>(
            x.data<data_t>(), out.mutable_data<data_t>(), x.size());
      }));

  return {out};
}

117
PD_BUILD_OP(dispatch_test_float_and_integer_and_complex)
118 119
    .Inputs({"X"})
    .Outputs({"Out"})
120
    .SetKernelFn(PD_KERNEL(DispatchTestFloatAndIntegerAndComplex));