elementwise_mul_op.h 1.9 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
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
6

L
Luo Tao 已提交
7
    http://www.apache.org/licenses/LICENSE-2.0
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. */
14 15

#pragma once
16

17
#include <string>
18

W
Wu Yi 已提交
19
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
20
#include "paddle/fluid/platform/cpu_info.h"
Y
YuanRisheng 已提交
21
#include "paddle/phi/kernels/elementwise_kernel.h"
22

23 24 25
namespace paddle {
namespace operators {

26 27
class ElementwiseMulOp : public ElementwiseOp {
 public:
28
  using Tensor = phi::DenseTensor;
29 30 31 32
  using ElementwiseOp::ElementwiseOp;

  framework::OpKernelType GetExpectedKernelType(
      const framework::ExecutionContext& ctx) const override {
33 34
    auto input_data_type =
        OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "X", "Y");
35 36
    return framework::OpKernelType(input_data_type, ctx.GetPlace());
  }
37 38

  framework::OpKernelType GetKernelTypeForVar(
39
      const std::string& var_name,
40
      const phi::DenseTensor& tensor,
41
      const framework::OpKernelType& expected_kernel_type) const override {
42 43
    if (framework::IsComplexType(expected_kernel_type.data_type_)) {
      // only promote inputs’s types when contains complex input
44
      return framework::OpKernelType(
45 46
          framework::TransToProtoVarType(tensor.dtype()),
          tensor.place(),
47
          tensor.layout());
48
    } else {
49 50
      return framework::OpKernelType(
          expected_kernel_type.data_type_, tensor.place(), tensor.layout());
51 52
    }
  }
53 54
};

55 56
}  // namespace operators
}  // namespace paddle