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

[PIR] OneDNN Pir onednn instruction #60257

Merged
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9efacb5
onednn dialect gen
wanghuancoder Dec 15, 2023
0db3ed6
merge
wanghuancoder Dec 15, 2023
7555dc2
refine
wanghuancoder Dec 15, 2023
7c8c581
refine
wanghuancoder Dec 18, 2023
307d5fc
refine
wanghuancoder Dec 18, 2023
6e4f8f8
refine
wanghuancoder Dec 18, 2023
1907da1
refine
wanghuancoder Dec 18, 2023
2f3f243
refine
wanghuancoder Dec 18, 2023
c83a066
refine
wanghuancoder Dec 18, 2023
5f17461
refine
wanghuancoder Dec 18, 2023
94a7cd7
refine
wanghuancoder Dec 18, 2023
ff94b90
refine
wanghuancoder Dec 18, 2023
fd4f845
refine
wanghuancoder Dec 18, 2023
9987288
refine
wanghuancoder Dec 19, 2023
d189be9
refine
wanghuancoder Dec 19, 2023
46aafd2
refine
wanghuancoder Dec 19, 2023
d9fa4de
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 19, 2023
1145d13
refine
wanghuancoder Dec 19, 2023
d7d9438
instruction
wanghuancoder Dec 19, 2023
43a3f59
refine
wanghuancoder Dec 19, 2023
53d0f0d
refine
wanghuancoder Dec 19, 2023
fe4ee21
refine
wanghuancoder Dec 19, 2023
50d2638
refine
wanghuancoder Dec 19, 2023
7711601
refine
wanghuancoder Dec 19, 2023
7383d3a
refine
wanghuancoder Dec 20, 2023
e497a50
refine
wanghuancoder Dec 20, 2023
78e3e95
merge
wanghuancoder Dec 20, 2023
9804390
refine
wanghuancoder Dec 20, 2023
e708252
refine
wanghuancoder Dec 20, 2023
387b5c0
refine
wanghuancoder Dec 21, 2023
2560f7f
refine
wanghuancoder Dec 21, 2023
dc2fecd
refine
wanghuancoder Dec 21, 2023
24b55d1
refine
wanghuancoder Dec 21, 2023
b2466eb
refine
wanghuancoder Dec 21, 2023
3284848
refine
wanghuancoder Dec 21, 2023
716894e
refine
wanghuancoder Dec 21, 2023
f3a8bd8
refine
wanghuancoder Dec 22, 2023
dcd2ade
refine
wanghuancoder Dec 22, 2023
bfb3b42
refine
wanghuancoder Dec 22, 2023
22573ea
Merge branch 'pir_onednn' of https://github.com/wanghuancoder/Paddle …
wanghuancoder Dec 22, 2023
556c194
refine
wanghuancoder Dec 22, 2023
9dee464
refine
wanghuancoder Dec 22, 2023
8f9fc8a
Merge branch 'pir_onednn' of https://github.com/wanghuancoder/Paddle …
wanghuancoder Dec 22, 2023
afdc617
refine
wanghuancoder Dec 22, 2023
bea4572
refine
wanghuancoder Dec 22, 2023
9c97de7
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 22, 2023
8608d49
refine
wanghuancoder Dec 22, 2023
8b7751b
merge
wanghuancoder Dec 25, 2023
7a3412a
refine
wanghuancoder Dec 25, 2023
b5493dc
refine
wanghuancoder Dec 25, 2023
43a6921
refine
wanghuancoder Dec 25, 2023
6ff60e1
refine
wanghuancoder Dec 25, 2023
29accca
refine
wanghuancoder Dec 26, 2023
19423a8
refine
wanghuancoder Dec 26, 2023
d8e315f
refine
wanghuancoder Dec 26, 2023
935ad92
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 26, 2023
8ca1f82
refine
wanghuancoder Dec 26, 2023
972a8a0
refine
wanghuancoder Dec 27, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ paddle/fluid/pir/dialect/operator/ir/pd_api.*
paddle/fluid/pir/dialect/operator/ir/op_decomp.cc
paddle/fluid/pir/dialect/operator/ir/pd_op_vjp.cc
paddle/fluid/pir/dialect/operator/ir/pd_op.*
paddle/fluid/pir/dialect/operator/ir/pd_onednn_op.*
paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.*
paddle/fluid/pir/dialect/operator/ir/pd_op_bwd.*
paddle/fluid/pir/dialect/operator/ir/pd_op_fused.*
paddle/fluid/pir/dialect/operator/ir/pd_op_fused_bwd.*
Expand Down
18 changes: 18 additions & 0 deletions paddle/fluid/framework/new_executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ if(NOT (WITH_CINN AND NOT CINN_ONLY))
${CMAKE_CURRENT_SOURCE_DIR}/instruction/cinn_jit_instruction.cc)
endif()

if(NOT WITH_MKLDNN)
list(
REMOVE_ITEM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOVE_ITEM支持移除多个,可以合并:https://cmake.org/cmake/help/v3.0/command/list.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx!

standalone_executor_srcs
${CMAKE_CURRENT_SOURCE_DIR}/instruction/onednn/onednn_phi_kernel_instruction.cc
)
list(
REMOVE_ITEM
standalone_executor_srcs
${CMAKE_CURRENT_SOURCE_DIR}/instruction/onednn/onednn_mixed_phi_kernel_instruction.cc
)
list(
REMOVE_ITEM
standalone_executor_srcs
${CMAKE_CURRENT_SOURCE_DIR}/instruction/onednn/onednn_legacy_kernel_instruction.cc
)
endif()

set(standalone_executor_deps
pir
program_translator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2023 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 "paddle/fluid/framework/new_executor/instruction/onednn/onednn_legacy_kernel_instruction.h"

#include "paddle/fluid/framework/new_executor/instruction/instruction_util.h"
#include "paddle/fluid/framework/new_executor/interpreter/interpreter_util.h"
#include "paddle/fluid/framework/new_executor/interpreter/stream_analyzer.h"
#include "paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/pir/dialect/operator/interface/infermeta.h"
#include "paddle/fluid/pir/dialect/operator/interface/op_yaml_info.h"
#include "paddle/fluid/pir/dialect/operator/ir/op_dialect.h"
#include "paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h"

#include "paddle/fluid/platform/device_context.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/core/meta_tensor.h"
#include "paddle/phi/core/type_defs.h"

namespace paddle {
namespace framework {

OneDNNLegacyKernelInstruction::OneDNNLegacyKernelInstruction(
size_t id,
const platform::Place& place,
pir::Operation* op,
const ValueExecutionInfo* value_exec_info)
: InstructionBase(id, place), value_exec_info_(value_exec_info) {
PADDLE_THROW(platform::errors::Unimplemented(
"OneDNNLegacyKernelInstruction not defined now."));
}

OneDNNLegacyKernelInstruction::~OneDNNLegacyKernelInstruction() {}

void OneDNNLegacyKernelInstruction::Run() {
PADDLE_THROW(platform::errors::Unimplemented(
"OneDNNLegacyKernelInstruction not defined now."));
}
} // namespace framework
} // namespace paddle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2023 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.

#pragma once

#include "paddle/fluid/framework/new_executor/instruction/instruction_base.h"

namespace pir {
class Operation;
} // namespace pir

namespace paddle {
namespace framework {
class Scope;
class ValueExecutionInfo;

class OneDNNLegacyKernelInstruction : public InstructionBase {
public:
OneDNNLegacyKernelInstruction(size_t id,
const platform::Place& place,
::pir::Operation* op,
const ValueExecutionInfo* value_exec_info);

~OneDNNLegacyKernelInstruction();
phi::Kernel* PhiKernel() const { return phi_kernel_; }

const phi::InferMetaContext& InferMetaContext() const {
return infer_meta_context_;
}

paddle::dialect::InferMetaInterface::Concept* InferMetaInterface() const {
return infer_meta_interface_;
}

void Run() override;

const std::string& Name() const override { return legacy_op_name_; }

::pir::Operation* Operation() const override { return op_; }

private:
std::string legacy_op_name_;

paddle::dialect::InferMetaInterface::Concept* infer_meta_interface_{
nullptr}; // not owned

phi::InferMetaContext infer_meta_context_;

paddle::framework::ExecutionContext* kernel_context_{nullptr};
std::shared_ptr<framework::RuntimeContext> runtime_context_;
std::shared_ptr<paddle::framework::OperatorBase> operator_base_;

phi::Kernel* phi_kernel_{nullptr}; // not owned

::pir::Operation* op_{nullptr}; // not owned

const ValueExecutionInfo* value_exec_info_; // not owned
};

} // namespace framework
} // namespace paddle
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2023 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 "paddle/fluid/framework/new_executor/instruction/onednn/onednn_mixed_phi_kernel_instruction.h"

#include "paddle/fluid/framework/new_executor/interpreter/interpreter_util.h"
#include "paddle/fluid/framework/new_executor/interpreter/stream_analyzer.h"
#include "paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/pir/dialect/operator/interface/infermeta.h"
#include "paddle/fluid/pir/dialect/operator/interface/op_yaml_info.h"
#include "paddle/fluid/pir/dialect/operator/ir/op_dialect.h"
#include "paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h"
#include "paddle/fluid/platform/collective_helper.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/core/meta_tensor.h"
#include "paddle/phi/core/type_defs.h"

#include "paddle/pir/core/builtin_attribute.h"
#include "paddle/pir/core/operation.h"
#include "paddle/pir/core/value.h"

#include "dnnl.hpp" // NOLINT
#include "paddle/fluid/framework/new_executor/instruction/instruction_util.h"
#include "paddle/fluid/framework/type_defs.h"
#include "paddle/fluid/ir_adaptor/translator/op_compat_info.h"
#include "paddle/phi/backends/onednn/onednn_context.h"
#include "paddle/phi/backends/onednn/onednn_helper.h"
#include "paddle/phi/kernels/funcs/data_layout_transform.h"

namespace paddle {
namespace framework {

OneDNNMixedPhiKernelInstruction::OneDNNMixedPhiKernelInstruction(
size_t id,
const platform::Place& place,
pir::Operation* op,
const ValueExecutionInfo* value_exec_info)
: OneDNNPhiKernelInstruction(id, place, op, value_exec_info) {}

void OneDNNMixedPhiKernelInstruction::Run() {
// Step1. Mixed Dynamic Choose Kernel
// todo if (input_tensor.layout() != phi::DataLayout::ONEDNN)

OneDNNPhiKernelInstruction::Run();
}

} // namespace framework
} // namespace paddle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2023 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.

#pragma once

#include "paddle/fluid/framework/new_executor/instruction/onednn/onednn_phi_kernel_instruction.h"

namespace pir {
class Operation;
} // namespace pir

namespace paddle {
namespace framework {
class Scope;
class ValueExecutionInfo;

using RuntimeAttribute = phi::Attribute;
using PIRAttribute = pir::Attribute;

class OneDNNMixedPhiKernelInstruction : public OneDNNPhiKernelInstruction {
public:
OneDNNMixedPhiKernelInstruction(size_t id,
const platform::Place& place,
::pir::Operation* op,
const ValueExecutionInfo* value_exec_info);

void Run() override;
};

} // namespace framework
} // namespace paddle
Loading