-
Notifications
You must be signed in to change notification settings - Fork 14
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
Enable end to end non-DPS testing #289
Open
jhalakpatel
wants to merge
2
commits into
main
Choose a base branch
from
jhalakp-python-exec-non-dps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -65,17 +65,26 @@ struct RemoveWithValuesRewriter : public OpRewritePattern<plan::WithValuesOp> { | |
} // namespace | ||
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. Changes here were merged with some additional tests |
||
|
||
/// Get a map from `tensorrt.func` functions to associated `tensorrt.call` | ||
/// operations. | ||
static llvm::DenseMap<func::FuncOp, SmallVector<tensorrt::CallOp>> | ||
/// and `tensorrt.call_alloc` operations. | ||
static llvm::DenseMap<func::FuncOp, SmallVector<Operation *>> | ||
getTensorRTFunctionCallMap(ModuleOp op, SymbolTableCollection &collection) { | ||
llvm::DenseMap<func::FuncOp, SmallVector<tensorrt::CallOp>> map; | ||
op->walk([&](tensorrt::CallOp callOp) { | ||
func::FuncOp func = callOp.getFuncCallee(collection); | ||
if (map.contains(func)) { | ||
map[func].push_back(callOp); | ||
llvm::DenseMap<func::FuncOp, SmallVector<Operation *>> map; | ||
op->walk([&](Operation *callOp) { | ||
if (!isa<tensorrt::CallOp, tensorrt::CallAllocOp>(callOp)) | ||
return; | ||
|
||
func::FuncOp func; | ||
if (auto call = dyn_cast<tensorrt::CallOp>(callOp)) { | ||
func = call.getFuncCallee(collection); | ||
} else { | ||
auto callAlloc = dyn_cast<tensorrt::CallAllocOp>(callOp); | ||
func = callAlloc.getFuncCallee(collection); | ||
} | ||
map.insert(std::make_pair(func, SmallVector<tensorrt::CallOp>{callOp})); | ||
|
||
if (map.count(func)) | ||
map[func].push_back(callOp); | ||
else | ||
map.insert({func, SmallVector<Operation *>{callOp}}); | ||
}); | ||
return map; | ||
} | ||
|
@@ -84,7 +93,7 @@ getTensorRTFunctionCallMap(ModuleOp op, SymbolTableCollection &collection) { | |
/// `tensorrt.call` operations. | ||
static LogicalResult removeUnusedArgs(SymbolTableCollection &collection, | ||
ModuleOp op, func::FuncOp funcOp, | ||
ArrayRef<tensorrt::CallOp> callOps) { | ||
ArrayRef<Operation *> callOps) { | ||
llvm::SmallBitVector unusedArgs(funcOp.getNumArguments(), 0); | ||
for (BlockArgument arg : funcOp.getArguments()) { | ||
if (arg.use_empty()) | ||
|
@@ -99,10 +108,16 @@ static LogicalResult removeUnusedArgs(SymbolTableCollection &collection, | |
funcOp.eraseArgument(i); | ||
|
||
// Update the call ops. | ||
for (tensorrt::CallOp callOp : callOps) | ||
callOp.getInputsMutable().erase(i); | ||
for (Operation *callOp : callOps) { | ||
if (auto call = dyn_cast<tensorrt::CallOp>(callOp)) | ||
call.getInputsMutable().erase(i); | ||
else if (auto callAlloc = dyn_cast<tensorrt::CallAllocOp>(callOp)) | ||
callAlloc.getInputsMutable().erase(i); | ||
else | ||
return emitError(funcOp->getLoc()) | ||
<< "Unexpected operation type in callOps"; | ||
} | ||
} | ||
|
||
return success(); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -156,28 +156,32 @@ getTensorRTShapeProfile(plan::BoundsAttr attr, Value v) { | |
return getProfileAttr(attr.getMinShape(), attr.getMaxShape()); | ||
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. Changes in this pass were merged with some additional tests |
||
} | ||
|
||
static LogicalResult outlineTensorRTRegion(RewriterBase &rewriter, | ||
plan::InlineClosedGroupOp op) { | ||
tensorrt::TensorRTModuleOp trtModuleOp = getOrCreateTensorRTModuleOp(op); | ||
auto funcArgTypes = llvm::to_vector(TypeRange(op.getInputs())); | ||
FailureOr<FunctionOpInterface> func = createOutlinedFunc( | ||
rewriter, op.getLoc(), op, trtModuleOp, "tensorrt_cluster", | ||
"cluster.tensorrt", TypeRange(op.getInputs()), | ||
op.getYield()->getOperandTypes()); | ||
if (failed(func)) | ||
return failure(); | ||
assert(func->getFunctionBody().getBlocks().size() == 1 && | ||
"expected body with one block"); | ||
func->setPublic(); | ||
|
||
rewriter.setInsertionPoint(op); | ||
auto callOp = rewriter.create<tensorrt::CallOp>( | ||
op.getLoc(), op.getResultTypes(), op.getInputs(), op.getOuts(), | ||
SymbolRefAttr::get(trtModuleOp.getNameAttr(), | ||
{FlatSymbolRefAttr::get(*func)})); | ||
template <typename OpType> | ||
static auto createCallOp(RewriterBase &rewriter, OpType op, | ||
tensorrt::TensorRTModuleOp trtModuleOp, | ||
FunctionOpInterface func) { | ||
static_assert( | ||
std::is_same_v<OpType, plan::InlineClosedGroupOp> || | ||
std::is_same_v<OpType, plan::InlineClosedAllocGroupOp>, | ||
"OpType must be either InlineClosedGroupOp or InlineClosedAllocGroupOp"); | ||
if constexpr (std::is_same_v<OpType, plan::InlineClosedGroupOp>) | ||
return rewriter.create<tensorrt::CallOp>( | ||
op.getLoc(), op.getResultTypes(), op.getInputs(), op.getOuts(), | ||
SymbolRefAttr::get(trtModuleOp.getNameAttr(), | ||
{FlatSymbolRefAttr::get(func)})); | ||
else if constexpr (std::is_same_v<OpType, plan::InlineClosedAllocGroupOp>) | ||
return rewriter.create<tensorrt::CallAllocOp>( | ||
op.getLoc(), op.getResultTypes(), op.getInputs(), | ||
SymbolRefAttr::get(trtModuleOp.getNameAttr(), | ||
{FlatSymbolRefAttr::get(func)})); | ||
} | ||
|
||
template <typename OpType> | ||
static LogicalResult populateFunctionAttributes(RewriterBase &rewriter, | ||
OpType op, | ||
FunctionOpInterface *func) { | ||
// Populate the function arguments attributes. | ||
for (unsigned i = 0; i < (*func).getNumArguments(); i++) { | ||
for (unsigned i = 0; i < func->getNumArguments(); i++) { | ||
BoundsAttr srcAttr = cast<BoundsAttr>(op.getInputAttrs()[i]); | ||
// We may have scalar (index|signless int)-typed values since we haven't | ||
// eliminated `plan.(with_shape|with_values)` ops yet. | ||
|
@@ -202,30 +206,57 @@ static LogicalResult outlineTensorRTRegion(RewriterBase &rewriter, | |
func->setArgAttr(i, mlir::getHostTensorArgAttrName(), | ||
rewriter.getUnitAttr()); | ||
} | ||
// Populate the function result attributes. | ||
for (unsigned i = 0; i < (*func).getNumResults(); i++) { | ||
BoundsAttr srcAttr = cast<BoundsAttr>(op.getResAttrs()[i]); | ||
if (srcAttr.isNone()) | ||
continue; | ||
FailureOr<tensorrt::ShapeProfileAttr> boundsAttr = | ||
getTensorRTShapeProfile(srcAttr, op.getResults()[i]); | ||
if (failed(boundsAttr)) | ||
return op->emitOpError("failed to create TensorRT shape profile " | ||
"attribute from Plan BoundsAttr for result #") | ||
<< i << " (" << srcAttr << ")"; | ||
if (srcAttr.isShapeBound()) { | ||
// Populate the function result attributes for DPS call op. | ||
if constexpr (std::is_same_v<OpType, plan::InlineClosedGroupOp>) { | ||
for (unsigned i = 0; i < func->getNumResults(); i++) { | ||
BoundsAttr srcAttr = cast<BoundsAttr>(op.getResAttrs()[i]); | ||
if (srcAttr.isNone()) | ||
continue; | ||
FailureOr<tensorrt::ShapeProfileAttr> boundsAttr = | ||
getTensorRTShapeProfile(srcAttr, op.getResults()[i]); | ||
if (failed(boundsAttr)) | ||
return op->emitOpError("failed to create TensorRT shape profile " | ||
"attribute from Plan BoundsAttr for result #") | ||
<< i << " (" << srcAttr << ")"; | ||
if (srcAttr.isShapeBound()) { | ||
func->setResultAttr( | ||
i, tensorrt::TensorRTDialect::getShapeProfileArgAttrName(), | ||
*boundsAttr); | ||
continue; | ||
} | ||
assert(srcAttr.isValueBound() && "expected value bound or shape bound"); | ||
func->setResultAttr( | ||
i, tensorrt::TensorRTDialect::getShapeProfileArgAttrName(), | ||
i, tensorrt::TensorRTDialect::getShapeTensorValueBoundsArgAttrName(), | ||
*boundsAttr); | ||
continue; | ||
func->setResultAttr(i, mlir::getHostTensorArgAttrName(), | ||
rewriter.getUnitAttr()); | ||
} | ||
assert(srcAttr.isValueBound() && "expected value bound or shape bound"); | ||
func->setResultAttr( | ||
i, tensorrt::TensorRTDialect::getShapeTensorValueBoundsArgAttrName(), | ||
*boundsAttr); | ||
func->setResultAttr(i, mlir::getHostTensorArgAttrName(), | ||
rewriter.getUnitAttr()); | ||
} | ||
return success(); | ||
} | ||
|
||
template <typename OpType> | ||
static LogicalResult outlineTensorRTRegion(RewriterBase &rewriter, OpType op) { | ||
tensorrt::TensorRTModuleOp trtModuleOp = getOrCreateTensorRTModuleOp(op); | ||
auto funcArgTypes = llvm::to_vector(TypeRange(op.getInputs())); | ||
|
||
FailureOr<FunctionOpInterface> func = createOutlinedFunc( | ||
rewriter, op.getLoc(), op, trtModuleOp, "tensorrt_cluster", | ||
"cluster.tensorrt", TypeRange(op.getInputs()), | ||
op.getYield()->getOperandTypes()); | ||
|
||
if (failed(func)) | ||
return failure(); | ||
|
||
assert(func->getFunctionBody().getBlocks().size() == 1 && | ||
"expected body with one block"); | ||
func->setPublic(); | ||
|
||
rewriter.setInsertionPoint(op); | ||
auto callOp = createCallOp<OpType>(rewriter, op, trtModuleOp, *func); | ||
|
||
if (failed(populateFunctionAttributes(rewriter, op, &(*func)))) | ||
return failure(); | ||
|
||
// Populate the function entry block. | ||
rewriter.eraseBlock(&func->getFunctionBody().front()); | ||
|
@@ -234,14 +265,14 @@ static LogicalResult outlineTensorRTRegion(RewriterBase &rewriter, | |
// ops to the `tensorrt.module` op. This is needed since `tensorrt.module` op | ||
// has its own symbol table. | ||
SymbolTableCollection symbolTable; | ||
for (auto compositeOp : op.getBody().getOps<stablehlo::CompositeOp>()) { | ||
for (auto compositeOp : | ||
op.getBody().template getOps<stablehlo::CompositeOp>()) { | ||
auto decompositionFunc = dyn_cast_if_present<func::FuncOp>( | ||
symbolTable.lookupSymbolIn(op->getParentOfType<ModuleOp>(), | ||
symbolTable.lookupSymbolIn(op->template getParentOfType<ModuleOp>(), | ||
compositeOp.getDecompositionAttr())); | ||
if (!decompositionFunc) | ||
return emitError(compositeOp.getLoc()) | ||
<< "failed to lookup stablehlo.composite decomposition " | ||
"function: " | ||
<< "failed to lookup stablehlo.composite decomposition function: " | ||
<< compositeOp.getDecompositionAttr(); | ||
rewriter.moveOpAfter(decompositionFunc, func->getOperation()); | ||
} | ||
|
@@ -254,24 +285,20 @@ static LogicalResult outlineTensorRTRegion(RewriterBase &rewriter, | |
rewriter.replaceOpWithNewOp<func::ReturnOp>(regionYieldOp, | ||
regionYieldOp->getOperands()); | ||
|
||
// Erase the DPS arugments, which now should be unused. | ||
if (llvm::any_of(func->getArguments().take_back(op.getOuts().size()), | ||
[](BlockArgument arg) { return !arg.use_empty(); })) | ||
return failure(); | ||
func->getFunctionBody().front().eraseArguments(op.getInputs().size(), | ||
op.getOuts().size()); | ||
if constexpr (std::is_same_v<OpType, plan::InlineClosedGroupOp>) { | ||
// Erase the DPS arugments, which now should be unused. | ||
if (llvm::any_of(func->getArguments().take_back(op.getOuts().size()), | ||
[](BlockArgument arg) { return !arg.use_empty(); })) | ||
return failure(); | ||
func->getFunctionBody().front().eraseArguments(op.getInputs().size(), | ||
op.getOuts().size()); | ||
} | ||
|
||
// replace the original region results. | ||
rewriter.replaceOp(op, callOp); | ||
return success(); | ||
} | ||
|
||
static LogicalResult outlineTensorRTRegion(RewriterBase &rewriter, | ||
plan::InlineClosedAllocGroupOp op) { | ||
return op.emitError("outlinining inline closed alloc group ops to tensorrt " | ||
"dialect is not yet implemented"); | ||
} | ||
|
||
/// Create outlined functions for each `scf.execute_region` operation within | ||
/// `region`. | ||
static FailureOr<SmallVector<FunctionOpInterface>> | ||
|
@@ -302,12 +329,14 @@ createFunctionsFromRegions(RewriterBase &rewriter, Region ®ion, | |
} | ||
|
||
if (auto group = dyn_cast<plan::InlineClosedGroupOp>(op)) { | ||
if (failed(outlineTensorRTRegion(rewriter, group))) | ||
if (failed(outlineTensorRTRegion<plan::InlineClosedGroupOp>(rewriter, | ||
group))) | ||
return WalkResult::interrupt(); | ||
return WalkResult::advance(); | ||
} | ||
if (auto allocGroup = dyn_cast<plan::InlineClosedAllocGroupOp>(op)) { | ||
if (failed(outlineTensorRTRegion(rewriter, allocGroup))) | ||
if (failed(outlineTensorRTRegion<plan::InlineClosedAllocGroupOp>( | ||
rewriter, allocGroup))) | ||
return WalkResult::interrupt(); | ||
return WalkResult::advance(); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
these changes are merged