Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Phi] Move mul op kernel into phi #40833

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "paddle/fluid/framework/parallel_executor.h"
#include "paddle/fluid/framework/program_desc.h"

USE_OP(mul);
USE_OP_ITSELF(mul);
USE_OP(cinn_launch);
USE_OP_ITSELF(elementwise_add);
namespace paddle::framework {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/paddle2cinn/build_cinn_pass_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ TEST(BuildCinnPassTest, NoNeedBufferInput) {
} // namespace paddle

USE_PASS(build_cinn_pass);
USE_OP(mul);
USE_OP_ITSELF(mul);
USE_OP_ITSELF(relu);
USE_OP_ITSELF(elementwise_add);
USE_OP_ITSELF(relu_grad);
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/paddle2cinn/cinn_compiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ TEST(CinnCompilerTest, Compile) {

USE_PASS(build_cinn_pass);
USE_PASS(graph_viz_pass);
USE_OP(mul);
USE_OP_ITSELF(mul);
USE_OP_ITSELF(relu);
USE_OP_ITSELF(elementwise_add);
2 changes: 1 addition & 1 deletion paddle/fluid/imperative/tests/test_eager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ TEST(test_var_helper, eager_var_helper) {
} // namespace imperative
} // namespace paddle

USE_OP(mul);
USE_OP_ITSELF(mul);
6 changes: 4 additions & 2 deletions paddle/fluid/imperative/tests/test_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

PD_DECLARE_KERNEL(add, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(add_grad, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(matmul_with_flatten, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(matmul_with_flatten_grad, CPU, ALL_LAYOUT);

namespace platform = paddle::platform;
namespace framework = paddle::framework;
Expand Down Expand Up @@ -267,7 +269,7 @@ TEST(TestHooks, TestGradVarLeafBackwardHookWithSortedGradAccmulated) {
} // namespace imperative
} // namespace paddle

USE_OP(mul);
USE_OP(mul_grad);
USE_OP_ITSELF(mul);
USE_OP_ITSELF(mul_grad);
USE_OP_ITSELF(elementwise_add);
USE_OP_ITSELF(elementwise_add_grad);
2 changes: 1 addition & 1 deletion paddle/fluid/imperative/tests/test_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,4 @@ TEST(test_layer, test_eager) {
} // namespace imperative
} // namespace paddle

USE_OP(mul);
USE_OP_ITSELF(mul);
8 changes: 6 additions & 2 deletions paddle/fluid/imperative/tests/test_tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ PD_DECLARE_KERNEL(add, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(add_grad, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sum, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sum_grad, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(matmul_with_flatten, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(matmul_with_flatten_grad, CPU, ALL_LAYOUT);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_DECLARE_KERNEL(add_grad, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sum_grad, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(matmul_with_flatten, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(matmul_with_flatten_grad, GPU, ALL_LAYOUT);
#endif

namespace imperative = paddle::imperative;
Expand Down Expand Up @@ -598,8 +602,8 @@ TEST(test_tracer, eager_tracer) {
} // namespace imperative
} // namespace paddle

USE_OP(mul);
USE_OP(mul_grad);
USE_OP_ITSELF(mul);
USE_OP_ITSELF(mul_grad);
USE_OP_ITSELF(reduce_sum);
USE_OP_ITSELF(reduce_sum_grad);
USE_OP_ITSELF(elementwise_add);
2 changes: 1 addition & 1 deletion paddle/fluid/inference/tensorrt/convert/test_fc_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ TEST(fc_op, test) {
} // namespace tensorrt
} // namespace inference
} // namespace paddle
USE_OP(mul);
USE_OP_ITSELF(mul);
2 changes: 1 addition & 1 deletion paddle/fluid/inference/tensorrt/convert/test_mul_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ TEST(MulOpConverter, main) {
} // namespace inference
} // namespace paddle

USE_OP(mul);
USE_OP_ITSELF(mul);
5 changes: 4 additions & 1 deletion paddle/fluid/operators/mkldnn/mul_mkldnn_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License. */

#include <string>

#include "paddle/fluid/operators/mul_op.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/platform/mkldnn_reuse.h"

namespace phi {
Expand Down Expand Up @@ -46,6 +46,9 @@ using dnnl::memory;
using dnnl::prop_kind;
using dnnl::stream;

constexpr int kMULMKLDNNINT8 = 1;
constexpr int kMULMKLDNNFP32 = 2;

template <typename XT, typename YT, typename OT>
class MulPrimitiveFactory {
public:
Expand Down
18 changes: 4 additions & 14 deletions paddle/fluid/operators/mul_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ 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 "paddle/fluid/operators/mul_op.h"
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "paddle/fluid/framework/op_registry.h"
#ifdef PADDLE_WITH_MKLDNN
#include "paddle/fluid/platform/mkldnn_helper.h"
#endif
Expand All @@ -27,6 +27,9 @@ namespace operators {
using framework::OpKernelType;
using framework::Tensor;

constexpr int kMULMKLDNNINT8 = 1;
constexpr int kMULMKLDNNFP32 = 2;

class MulOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;
Expand Down Expand Up @@ -354,16 +357,3 @@ REGISTER_OPERATOR(mul_grad, ops::MulGradOp,
ops::MulDoubleGradMaker<paddle::imperative::OpBase>);

REGISTER_OPERATOR(mul_grad_grad, ops::MulDoubleGradOp);

REGISTER_OP_CPU_KERNEL(
mul, ops::MulKernel<paddle::platform::CPUDeviceContext, float>,
ops::MulKernel<paddle::platform::CPUDeviceContext, double>);

REGISTER_OP_CPU_KERNEL(
mul_grad, ops::MulGradKernel<paddle::platform::CPUDeviceContext, float>,
ops::MulGradKernel<paddle::platform::CPUDeviceContext, double>);

REGISTER_OP_CPU_KERNEL(
mul_grad_grad,
ops::MulDoubleGradKernel<paddle::platform::CPUDeviceContext, float>,
ops::MulDoubleGradKernel<paddle::platform::CPUDeviceContext, double>);
30 changes: 0 additions & 30 deletions paddle/fluid/operators/mul_op.cu.cc

This file was deleted.

207 changes: 0 additions & 207 deletions paddle/fluid/operators/mul_op.h

This file was deleted.

Loading