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

Add support for executable duplication in encoding specialization pass. #19527

Closed
wants to merge 3 commits into from
Closed
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
25 changes: 25 additions & 0 deletions compiler/src/iree/compiler/Dialect/HAL/IR/HALAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "iree/compiler/Dialect/HAL/IR/HALDialect.h"
#include "iree/compiler/Dialect/HAL/IR/HALOps.h"
#include "iree/compiler/Dialect/HAL/IR/HALTypes.h"
#include "iree/compiler/Dialect/Util/IR/UtilOps.h"
#include "iree/compiler/Utils/StringUtils.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -893,6 +894,30 @@ bool DeviceAffinityAttr::isExecutableWith(
return false;
}

bool DeviceAffinityAttr::isTranslatableWith(
ModuleOp moduleOp, IREE::Stream::AffinityAttr other) const {
if (!other)
return true;

auto otherAffinityAttr = llvm::dyn_cast_if_present<DeviceAffinityAttr>(other);
if (!otherAffinityAttr)
return false;

SymbolTable symbolTable(moduleOp);
auto getExecutableTargets = [&](SymbolRefAttr symbol) {
auto globalOp = llvm::cast<IREE::Util::GlobalOp>(
symbolTable.lookupSymbolIn(moduleOp, symbol));
return globalOp.getInitialValueAttr();
};
auto device = llvm::dyn_cast<IREE::HAL::DeviceTargetAttr>(
getExecutableTargets(getDevice()));
auto otherDevice = llvm::dyn_cast<IREE::HAL::DeviceTargetAttr>(
getExecutableTargets(otherAffinityAttr.getDevice()));
if (!device || !otherDevice)
return false;
return device.getExecutableTargets() == otherDevice.getExecutableTargets();
}

IREE::Stream::AffinityAttr
DeviceAffinityAttr::joinOR(IREE::Stream::AffinityAttr other) const {
if (!other)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/iree/compiler/Dialect/HAL/IR/HALAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ def HAL_DeviceSelectAttr : AttrDef<HAL_Dialect, "DeviceSelect", [
def HAL_DeviceAffinityAttr : AttrDef<HAL_Dialect, "DeviceAffinity", [
DeclareAttrInterfaceMethods<Stream_AffinityAttr, [
"isExecutableWith",
"isTranslatableWith",
"joinOR",
"joinAND",
]>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def Stream_AffinityAttr : AttrInterface<"AffinityAttr"> {
return IREE::Stream::AffinityAttr::areCompatible($_attr, other);
}]
>,
InterfaceMethod<
/*desc=*/[{
Returns true if it can share the same execution configuration (e.g.,
translation artifacts) with the `other` and vice versa.
}],
/*retTy=*/"bool",
/*methodName=*/"isTranslatableWith",
/*args=*/(ins "ModuleOp":$moduleOp,
"IREE::Stream::AffinityAttr":$other),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return IREE::Stream::AffinityAttr::areTranslationCompatible(moduleOp, $_attr, other);
}]
>,
InterfaceMethod<
/*desc=*/[{
Returns an affinity describing the union with |other| constraints.
Expand Down Expand Up @@ -118,6 +132,11 @@ def Stream_AffinityAttr : AttrInterface<"AffinityAttr"> {
// Returns true if |lhs| and |rhs| indicate that their operations can
// execute together on the same execution queue.
static bool canExecuteTogether(AffinityAttr lhs, AffinityAttr rhs);

// Returns true if |lhs| and |rhs| are translation compatible. E.g., they
// are compatible if they have the same executable targets.
static bool areTranslationCompatible(ModuleOp moduleOp, AffinityAttr lhs,
AffinityAttr rhs);
}];
}

Expand Down
10 changes: 10 additions & 0 deletions compiler/src/iree/compiler/Dialect/Stream/IR/StreamTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ bool AffinityAttr::canExecuteTogether(AffinityAttr lhs, AffinityAttr rhs) {
return lhs.isExecutableWith(rhs);
}

// static
bool AffinityAttr::areTranslationCompatible(ModuleOp moduleOp, AffinityAttr lhs,
AffinityAttr rhs) {
if (lhs == rhs)
return true;
if ((lhs && !rhs) || (rhs && !lhs))
return true;
return lhs.isTranslatableWith(moduleOp, rhs);
}

//===----------------------------------------------------------------------===//
// #stream.partitioning_config
//===----------------------------------------------------------------------===//
Expand Down
Loading