-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[NewIR]new ir support yaml backend config #56570
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd3bc13
update
phlrain db878e9
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
phlrain 2f3e46a
fix comile error
phlrain 5fa4fbb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
phlrain a46b108
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
phlrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,6 +209,150 @@ ir::OpResult AddPlaceTransferOp(ir::OpResult in, | |
} | ||
} | ||
|
||
phi::DataType GetKernelDataTypeByYamlInfo( | ||
const ir::Operation* op, | ||
const std::unordered_map<ir::Value, ir::OpResult>& map_value_pair, | ||
const dialect::OpYamlInfoParser* op_info_parser) { | ||
auto& attr_map = op->attributes(); | ||
auto& data_type_info = op_info_parser->OpRuntimeInfo().kernel_key_dtype; | ||
phi::DataType kernel_data_type = phi::DataType::UNDEFINED; | ||
|
||
for (size_t i = 0; i < data_type_info.size(); ++i) { | ||
auto slot_name = data_type_info[i]; | ||
auto& input_map = op_info_parser->InputName2Id(); | ||
|
||
auto find_it = Str2PhiDataType.find(slot_name); | ||
if (find_it != Str2PhiDataType.end()) { | ||
kernel_data_type = find_it->second; | ||
} else if (input_map.count(slot_name)) { | ||
// parse from input | ||
int in_index = input_map.at(slot_name); | ||
auto type = map_value_pair.at(op->operand_source(in_index)).type(); | ||
|
||
if (type.isa<paddle::dialect::AllocatedDenseTensorType>()) { | ||
kernel_data_type = TransToPhiDataType( | ||
type.dyn_cast<paddle::dialect::AllocatedDenseTensorType>().dtype()); | ||
} else if (type.isa<ir::VectorType>()) { | ||
auto vec_data = type.dyn_cast<ir::VectorType>().data(); | ||
if (vec_data.empty()) { | ||
kernel_data_type = phi::DataType::UNDEFINED; | ||
} else { | ||
if (vec_data[0].isa<paddle::dialect::AllocatedDenseTensorType>()) { | ||
kernel_data_type = TransToPhiDataType( | ||
vec_data[0] | ||
.dyn_cast<paddle::dialect::AllocatedDenseTensorType>() | ||
.dtype()); | ||
} else { | ||
PADDLE_THROW(phi::errors::Unimplemented( | ||
"Only support DenseTensorType in vector")); | ||
} | ||
} | ||
} else if (type.isa<paddle::dialect::AllocatedSelectedRowsType>()) { | ||
kernel_data_type = TransToPhiDataType( | ||
type.dyn_cast<paddle::dialect::AllocatedSelectedRowsType>() | ||
.dtype()); | ||
} else { | ||
PADDLE_THROW(phi::errors::Unimplemented( | ||
"Only support DenseTensorType, SelectedRows, VectorType")); | ||
} | ||
|
||
} else { | ||
PADDLE_ENFORCE_EQ(attr_map.count(slot_name), | ||
true, | ||
phi::errors::PreconditionNotMet( | ||
"[%s] MUST in attribute map", slot_name)); | ||
|
||
auto attr_type = op_info_parser->AttrTypeName(slot_name); | ||
PADDLE_ENFORCE_EQ(attr_type, | ||
"paddle::dialect::DataTypeAttribute", | ||
phi::errors::PreconditionNotMet( | ||
"Type of [%s] should be DataType", slot_name)); | ||
kernel_data_type = attr_map.at(slot_name) | ||
.dyn_cast<paddle::dialect::DataTypeAttribute>() | ||
.data(); | ||
} | ||
|
||
if (kernel_data_type != phi::DataType::UNDEFINED) { | ||
// In yaml definition, data type have an order | ||
// like: data_type : dtype > x | ||
// Should break when found a defined data type | ||
break; | ||
} | ||
} | ||
|
||
return kernel_data_type; | ||
} | ||
|
||
phi::Backend GetKernelBackendByYamlInfo( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GetKernelBackendByYamlInfo 和 GetKernelDataTypeByYamlInfo 的内容几乎是一样的,后续可以合并成一个 |
||
const ir::Operation* op, | ||
const std::unordered_map<ir::Value, ir::OpResult>& map_value_pair, | ||
const dialect::OpYamlInfoParser* op_info_parser) { | ||
auto& attr_map = op->attributes(); | ||
auto& backend_info = op_info_parser->OpRuntimeInfo().kernel_key_backend; | ||
phi::Backend kernel_backend = phi::Backend::UNDEFINED; | ||
for (size_t i = 0; i < backend_info.size(); ++i) { | ||
auto slot_name = backend_info[i]; | ||
auto& input_map = op_info_parser->InputName2Id(); | ||
|
||
if (input_map.count(slot_name)) { | ||
// parse from input | ||
int in_index = input_map.at(slot_name); | ||
auto type = map_value_pair.at(op->operand_source(in_index)).type(); | ||
|
||
if (type.isa<paddle::dialect::AllocatedDenseTensorType>()) { | ||
kernel_backend = paddle::experimental::ParseBackend( | ||
type.dyn_cast<paddle::dialect::AllocatedDenseTensorType>().place()); | ||
} else if (type.isa<ir::VectorType>()) { | ||
auto vec_data = type.dyn_cast<ir::VectorType>().data(); | ||
if (vec_data.empty()) { | ||
kernel_backend = phi::Backend::UNDEFINED; | ||
} else { | ||
if (vec_data[0].isa<paddle::dialect::AllocatedDenseTensorType>()) { | ||
kernel_backend = paddle::experimental::ParseBackend( | ||
vec_data[0] | ||
.dyn_cast<paddle::dialect::AllocatedDenseTensorType>() | ||
.place()); | ||
} else { | ||
PADDLE_THROW(phi::errors::Unimplemented( | ||
"Only support DenseTensorType in vector")); | ||
} | ||
} | ||
} else if (type.isa<paddle::dialect::AllocatedSelectedRowsType>()) { | ||
kernel_backend = paddle::experimental::ParseBackend( | ||
type.dyn_cast<paddle::dialect::AllocatedSelectedRowsType>() | ||
.place()); | ||
} else { | ||
PADDLE_THROW(phi::errors::Unimplemented( | ||
"Only support DenseTensorType, SelectedRows, VectorType")); | ||
} | ||
|
||
} else { | ||
PADDLE_ENFORCE_EQ(attr_map.count(slot_name), | ||
true, | ||
phi::errors::PreconditionNotMet( | ||
"[%s] MUST in attribute map", slot_name)); | ||
|
||
auto attr_type = op_info_parser->AttrTypeName(slot_name); | ||
PADDLE_ENFORCE_EQ(attr_type, | ||
"paddle::dialect::PlaceAttribute", | ||
phi::errors::PreconditionNotMet( | ||
"Type of [%s] should be DataType", slot_name)); | ||
kernel_backend = paddle::experimental::ParseBackend( | ||
attr_map.at(slot_name) | ||
.dyn_cast<paddle::dialect::PlaceAttribute>() | ||
.data()); | ||
} | ||
if (kernel_backend != phi::Backend::UNDEFINED) { | ||
// In yaml definition, backend have an order | ||
// like: backend : place > x | ||
// Should break when found a defined data type | ||
break; | ||
} | ||
} | ||
|
||
return kernel_backend; | ||
} | ||
|
||
phi::KernelKey GetKernelKey( | ||
ir::Operation* op, | ||
const phi::Place& place, | ||
|
@@ -245,66 +389,11 @@ phi::KernelKey GetKernelKey( | |
// only suppurt non vector input for now | ||
int tensor_input_number = op_info_parser->InputTensorNumber(); | ||
|
||
auto attr_map = op->attributes(); | ||
auto& data_type_info = op_info_parser->OpRuntimeInfo().kernel_key_dtype; | ||
|
||
if (!data_type_info.empty()) { | ||
// only support single input and attribute | ||
auto slot_name = data_type_info[0]; | ||
auto& input_map = op_info_parser->InputName2Id(); | ||
|
||
auto find_it = Str2PhiDataType.find(slot_name); | ||
if (find_it != Str2PhiDataType.end()) { | ||
kernel_data_type = find_it->second; | ||
} else if (input_map.count(slot_name)) { | ||
// parse from input | ||
int in_index = input_map.at(slot_name); | ||
auto type = map_value_pair.at(op->operand_source(in_index)).type(); | ||
|
||
if (type.isa<paddle::dialect::AllocatedDenseTensorType>()) { | ||
kernel_data_type = TransToPhiDataType( | ||
type.dyn_cast<paddle::dialect::AllocatedDenseTensorType>() | ||
.dtype()); | ||
} else if (type.isa<ir::VectorType>()) { | ||
auto vec_data = type.dyn_cast<ir::VectorType>().data(); | ||
if (vec_data.empty()) { | ||
kernel_data_type = phi::DataType::UNDEFINED; | ||
} else { | ||
if (vec_data[0].isa<paddle::dialect::AllocatedDenseTensorType>()) { | ||
kernel_data_type = TransToPhiDataType( | ||
vec_data[0] | ||
.dyn_cast<paddle::dialect::AllocatedDenseTensorType>() | ||
.dtype()); | ||
} else { | ||
PADDLE_THROW(phi::errors::Unimplemented( | ||
"Only support DenseTensorType in vector")); | ||
} | ||
} | ||
} else if (type.isa<paddle::dialect::AllocatedSelectedRowsType>()) { | ||
kernel_data_type = TransToPhiDataType( | ||
type.dyn_cast<paddle::dialect::AllocatedSelectedRowsType>() | ||
.dtype()); | ||
} else { | ||
PADDLE_THROW(phi::errors::Unimplemented( | ||
"Only support DenseTensorType, SelectedRows, VectorType")); | ||
} | ||
|
||
} else { | ||
PADDLE_ENFORCE_EQ(attr_map.count(slot_name), | ||
true, | ||
phi::errors::PreconditionNotMet( | ||
"[%s] MUST in attribute map", slot_name)); | ||
|
||
auto attr_type = op_info_parser->AttrTypeName(slot_name); | ||
PADDLE_ENFORCE_EQ(attr_type, | ||
"paddle::dialect::DataTypeAttribute", | ||
phi::errors::PreconditionNotMet( | ||
"Type of [%s] should be DataType", slot_name)); | ||
kernel_data_type = attr_map.at(slot_name) | ||
.dyn_cast<paddle::dialect::DataTypeAttribute>() | ||
.data(); | ||
} | ||
} | ||
// get datatype info | ||
kernel_data_type = | ||
GetKernelDataTypeByYamlInfo(op, map_value_pair, op_info_parser); | ||
kernel_backend = | ||
GetKernelBackendByYamlInfo(op, map_value_pair, op_info_parser); | ||
|
||
// parse all the input tensor | ||
if (tensor_input_number == 0 || op->name() == "pd.full_") { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么一定要用 opresult 获取 type?