Skip to content

Commit

Permalink
Add convenience method to CustomCallOp for checking empty backend con…
Browse files Browse the repository at this point in the history
…fig (#2432)

This logic is used many times in openxla/xla, so decided to turn it into
a method
  • Loading branch information
GleasonK authored Jul 11, 2024
1 parent 8817ff1 commit 289eadf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stablehlo/dialect/StablehloOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,16 @@ mlir::Attribute CustomCallOp::getBackendConfigOrDefault() {
return StringAttr::get(getContext(), "");
}

// Returns if the backend config is unset, or if empty dict / string attribute.
bool CustomCallOp::hasEmptyBackendConfig() {
if (!getBackendConfig().has_value()) return true;
Attribute backendConfig = getBackendConfigOrDefault();
if (auto strAttr = dyn_cast<StringAttr>(backendConfig)) {
return strAttr.empty();
}
return cast<DictionaryAttr>(backendConfig).empty();
}

//===----------------------------------------------------------------------===//
// CholeskyOp
//===----------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions stablehlo/dialect/StablehloOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,7 @@ def StableHLO_CustomCallOp: StableHLO_Op<"custom_call",

let extraClassDeclaration = commonClassDeclaration # [{
mlir::Attribute getBackendConfigOrDefault();
bool hasEmptyBackendConfig();
}];
}

Expand Down

0 comments on commit 289eadf

Please sign in to comment.