- 
                Notifications
    You must be signed in to change notification settings 
- Fork 780
[DT] Collapse MaterializeEncodingIntoPaddingPass into the generic pass. #22472
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
          
     Open
      
      
            hanhanW
  wants to merge
  5
  commits into
  iree-org:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
hanhanW:drop-pad-specific-pass
  
      
      
   
  
    
  
  
  
 
  
      
    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.
          
          
      
        
          +139
        
        
          −228
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      bde9dfc
              
                [DT] Collapse MaterializeEncodingIntoPaddingPass into the generic pass.
              
              
                hanhanW 8c765b2
              
                move test (clean todo)
              
              
                hanhanW aa91572
              
                update comments and improve variable name
              
              
                hanhanW bba7f05
              
                improve comments
              
              
                hanhanW 3a77c48
              
                Fix cuda
              
              
                hanhanW 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
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | 
|---|---|---|
|  | @@ -10,7 +10,9 @@ | |
| #include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenDialect.h" | ||
| #include "iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUAttrs.h" | ||
| #include "iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUDialect.h" | ||
| #include "iree/compiler/Codegen/Dialect/GPU/TargetUtils/KnownTargets.h" | ||
| #include "iree/compiler/Codegen/Utils/GPUUtils.h" | ||
| #include "iree/compiler/Dialect/Encoding/IR/EncodingDialect.h" | ||
| #include "iree/compiler/Dialect/Encoding/IR/EncodingTypes.h" | ||
| #include "iree/compiler/Dialect/HAL/Analysis/DeviceAnalysis.h" | ||
| #include "iree/compiler/Dialect/HAL/IR/HALTypes.h" | ||
|  | @@ -59,42 +61,43 @@ updateFuncSignature(FunctionOpInterface funcOp, | |
| } | ||
| } | ||
|  | ||
| static LogicalResult | ||
| materializeFuncOpEncodings(FunctionOpInterface funcOp, | ||
| IREE::HAL::ExecutableTargetAttr targetAttr, | ||
| bool testCLGPUTarget = false) { | ||
| static LogicalResult materializeFuncOpEncodings( | ||
| FunctionOpInterface funcOp, IREE::HAL::ExecutableTargetAttr targetAttr, | ||
| ::mlir::iree_compiler::detail::TestingResolverKind resolverSource = | ||
| ::mlir::iree_compiler::detail::TestingResolverKind::kNone) { | ||
| MLIRContext *ctx = funcOp.getContext(); | ||
| { | ||
| RewritePatternSet patterns(ctx); | ||
| DictionaryAttr targetConfig = | ||
| targetAttr ? targetAttr.getConfiguration() : nullptr; | ||
| // Check if the encoding resolver is a GPUPaddingResolverAttr. For padding | ||
| // encoding materialization, we use a separate pass, so skip materialization | ||
| // here. | ||
| // TODO(#20160): Support GPUPaddingResolverAttr materialization through this | ||
| // pass, and remove the ad-hoc materialization pass for padding. | ||
| if (targetConfig && targetConfig.getAs<IREE::GPU::GPUPaddingResolverAttr>( | ||
| IREE::Encoding::kEncodingResolverAttrName)) { | ||
| LDBG() | ||
| << "Found GPUPaddingResolverAttr encoding resolver. Materialization " | ||
| "will be handled later."; | ||
| return success(); | ||
| } | ||
|  | ||
| auto getTestTargetOrNopLayout = | ||
| auto getTestTargetResolverOrIdentityResolver = | ||
| [&]() -> IREE::Encoding::LayoutMaterializerAttr { | ||
| if (testCLGPUTarget) { | ||
| LDBG() << "Select GPUEncodingResolverAttr attribute as the layout " | ||
| "attribute. (testCLGPUTarget)"; | ||
| SmallVector<NamedAttribute> configItems; | ||
| // Setting a nullptr to `target` below returns the target from command | ||
| // line. | ||
| IREE::GPU::TargetAttr targetAttr = | ||
| getGPUTargetAttr(ctx, /*target=*/nullptr); | ||
| SmallVector<NamedAttribute> configItems; | ||
| IREE::GPU::TargetAttr targetAttr = | ||
| getGPUTargetAttr(ctx, /*target=*/nullptr); | ||
| if (targetAttr) { | ||
| addConfigGPUTarget(ctx, targetAttr, configItems); | ||
| return cast<IREE::Encoding::LayoutMaterializerAttr>( | ||
| IREE::GPU::GPUEncodingResolverAttr::get( | ||
| ctx, DictionaryAttr::get(ctx, configItems))); | ||
| switch (resolverSource) { | ||
| case ::mlir::iree_compiler::detail::TestingResolverKind:: | ||
| 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. also here and below | ||
| kGPUDataTiling: { | ||
| LDBG() << "Select GPUEncodingResolverAttr attribute as the layout " | ||
| "attribute. (kGPUDataTiling)"; | ||
| return cast<IREE::Encoding::LayoutMaterializerAttr>( | ||
| IREE::GPU::GPUEncodingResolverAttr::get( | ||
| ctx, DictionaryAttr::get(ctx, configItems))); | ||
| } | ||
| case ::mlir::iree_compiler::detail::TestingResolverKind::kGPUPadding: { | ||
| LDBG() << "Select GPUPaddingResolverAttr attribute as the layout " | ||
| "attribute. (kGPUPadding)"; | ||
| std::optional<IREE::GPU::L1CacheInfo> cache = | ||
| IREE::GPU::getL1CacheInfo(targetAttr); | ||
| return cast<IREE::Encoding::LayoutMaterializerAttr>( | ||
| IREE::GPU::GPUPaddingResolverAttr::get(ctx, cache->cacheLineBytes, | ||
| cache->cacheSets)); | ||
| } | ||
| case ::mlir::iree_compiler::detail::TestingResolverKind::kNone: | ||
| break; | ||
| } | ||
| } | ||
| LDBG() << "Select IdentityResolverAttr attribute as the layout " | ||
| "attribute (Encoding resolver unknown or unsupported)."; | ||
|  | @@ -107,8 +110,9 @@ materializeFuncOpEncodings(FunctionOpInterface funcOp, | |
| // so it can access the target info during materialization. | ||
| // | ||
| // If the layoutAttr was not found, or if it does not implement the layout | ||
| // resolver interface, fall back to the resolver for getCLGPUTarget. If | ||
| // there is also no test target set, fall back to the nop layout. | ||
| // resolver interface, fall back to the resolver for TestingResolverKind | ||
| // resolver. If there is also no test target set or it is kNone, fall back | ||
| // to the identity resolver. | ||
| IREE::Encoding::LayoutMaterializerAttr layoutAttr = | ||
| targetConfig | ||
| ? targetConfig.getAs<IREE::Encoding::LayoutMaterializerAttr>( | ||
|  | @@ -121,7 +125,7 @@ materializeFuncOpEncodings(FunctionOpInterface funcOp, | |
| layoutAttr && resolverAttr | ||
| ? cast<IREE::Encoding::LayoutMaterializerAttr>( | ||
| resolverAttr.cloneWithSimplifiedConfig(targetConfig)) | ||
| : getTestTargetOrNopLayout(); | ||
| : getTestTargetResolverOrIdentityResolver(); | ||
|  | ||
| LDBG() << "Selected Encoding::LayoutMaterializerAttr with target " | ||
| "configuration: " | ||
|  | @@ -132,10 +136,10 @@ materializeFuncOpEncodings(FunctionOpInterface funcOp, | |
| populateMaterializeEncodingPatterns(patterns, target, typeConverter); | ||
|  | ||
| // Replace any unrealized conversions to tensor.cast ops if they come from | ||
| // block arguments. The function signature is updated to match the converted | ||
| // types after the partial conversion. This is used in testing, where | ||
| // function arguments have encodings to reduce the amount of IR, but we do | ||
| // not expect function arguments to have encodings in practice. | ||
| // block arguments. The function signature is updated to match the | ||
| // converted types after the partial conversion. This is used in testing, | ||
| // where function arguments have encodings to reduce the amount of IR, but | ||
| // we do not expect function arguments to have encodings in practice. | ||
| auto castFnArguments = [](OpBuilder &builder, Type resultTy, | ||
| ValueRange inputs, Location loc) -> Value { | ||
| if (inputs.size() != 1) { | ||
|  | @@ -177,11 +181,11 @@ materializeFuncOpEncodings(FunctionOpInterface funcOp, | |
| patterns, [](OpOperand *opOperand) { | ||
| Operation *producer = opOperand->get().getDefiningOp(); | ||
| Operation *consumer = opOperand->getOwner(); | ||
| // If we have a pack/unpack consumer and a producer that has multiple | ||
| // uses, this _probably_ means the producer won't get dce'd. If that | ||
| // is the case, by folding the consumer pack/unpack, we break the | ||
| // producer consumer chain between them and inhibit fusion later in | ||
| // the pipeline. | ||
| // If we have a pack/unpack consumer and a producer that has | ||
| // multiple uses, this _probably_ means the producer won't get | ||
| // dce'd. If that is the case, by folding the consumer pack/unpack, | ||
| // we break the producer consumer chain between them and inhibit | ||
| // fusion later in the pipeline. | ||
| if (isa<linalg::PackOp, linalg::UnPackOp>(consumer) && | ||
| isa_and_nonnull<TilingInterface>(producer) && | ||
| !producer->hasOneUse()) | ||
|  | @@ -296,15 +300,16 @@ struct MaterializeDeviceEncodingPass final | |
|  | ||
| void getDependentDialects(DialectRegistry ®istry) const override { | ||
| registry.insert<arith::ArithDialect, tensor::TensorDialect, | ||
| vector::VectorDialect, IREE::Codegen::IREECodegenDialect, | ||
| vector::VectorDialect, IREE::Encoding::IREEEncodingDialect, | ||
| IREE::Codegen::IREECodegenDialect, | ||
| IREE::CPU::IREECPUDialect, IREE::GPU::IREEGPUDialect>(); | ||
| } | ||
|  | ||
| void runOnOperation() override { | ||
| FunctionOpInterface funcOp = getOperation(); | ||
| auto executableTargetAttr = IREE::HAL::ExecutableTargetAttr::lookup(funcOp); | ||
| if (failed(materializeFuncOpEncodings(funcOp, executableTargetAttr, | ||
| testCLGPUTarget))) { | ||
| testGPUEncodingResolver))) { | ||
| return signalPassFailure(); | ||
| } | ||
| } | ||
|  | ||
        
          
  
    
      
          
            121 changes: 0 additions & 121 deletions
          
          121 
        
  compiler/src/iree/compiler/Codegen/Common/MaterializeEncodingIntoPadding.cpp
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or 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 hidden or 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
    
  
  
    
              
              
      
      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.
do we need these
::mlir::prefixes?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.
There are other
detailnamespaces in eithermliroriree_compilerwhich makes it confusing.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.
I'd think that
iree_compiler::detailwould suffice, no?