Skip to content

FIX-#111: oneDnn JsonParser: Convert auto_broadcast attribute to boolean #112

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

Merged
merged 1 commit into from
May 31, 2024
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
19 changes: 18 additions & 1 deletion src/dnnl/JsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,24 @@ void JsonParser::readOp() {
_reader.begin_object();
while (_reader.next_object_item(&_str)) {
auto name = mlir::StringAttr::get(_builder.getContext(), _str);
_attributes.emplace_back(name, readAttr());
auto value = readAttr();

if (name == "auto_broadcast") { // Convert to boolean
if (value.getTypeID() != mlir::StringAttr::getTypeID()) {
_str = "auto_broadcast";
throwErr<std::invalid_argument>("Invalid attribute type: ");
}
if (_str == "numpy") {
value = _builder.getBoolAttr(true);
} else if (_str == "none") {
value = _builder.getBoolAttr(false);
} else {
throwErr<std::invalid_argument>(
"Invalid auto_broadcast attribute value: ");
}
}

_attributes.emplace_back(name, value);
}
} else if (_str == "inputs") {
_reader.begin_array();
Expand Down
4 changes: 2 additions & 2 deletions test/dnnl/TestJsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ TEST(TestJsonParser, AddRelu) {
ASSERT_EQ(attrs.size(), 1);
ASSERT_EQ(attrs.begin()->getName(),
mlir::StringAttr::get(addOp->getContext(), "auto_broadcast"));
ASSERT_EQ(mlir::cast<mlir::StringAttr>(attrs.begin()->getValue()).getValue(),
"numpy");
ASSERT_FALSE(
mlir::cast<mlir::BoolAttr>(attrs.begin()->getValue()).getValue());
checkTensorType(addOp->getOperandTypes()[0]);
checkTensorType(addOp->getOperandTypes()[1]);
checkTensorType(addOp->getResultTypes()[0]);
Expand Down
2 changes: 1 addition & 1 deletion test/dnnl/resources/add_relu.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"attrs": {
"auto_broadcast": {
"type": "string",
"value": "numpy"
"value": "none"
}
},
"inputs": [
Expand Down