- 
                Notifications
    You must be signed in to change notification settings 
- Fork 780
[DT] Implement MaterializeInterfaceBindingEncoding with interface methods. #22467
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
      
      
    
      
        
          +117
        
        
          −190
        
        
          
        
      
    
  
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            4 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 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
    
  
  
    
              
  
    
      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 | ||||
|---|---|---|---|---|---|---|
|  | @@ -580,10 +580,81 @@ struct GPULayoutResolverAttr final | |||||
| } | ||||||
| }; | ||||||
|  | ||||||
| // Returns the pad encoding layout, or nullptr if this is not the only layout or | ||||||
| // if there's no encoding at all. | ||||||
| static IREE::Encoding::PaddingAttr | ||||||
| getPadLayout(IREE::Encoding::LayoutResolverAttr layoutAttr, | ||||||
| RankedTensorType type) { | ||||||
| if (!type.getEncoding()) { | ||||||
| return nullptr; | ||||||
| } | ||||||
| auto encoding = | ||||||
| dyn_cast_or_null<IREE::Encoding::LayoutAttr>(type.getEncoding()); | ||||||
| if (encoding) { | ||||||
| ArrayAttr layouts = encoding.getLayouts(); | ||||||
| if (layouts.size() != 1) { | ||||||
| return nullptr; | ||||||
| } | ||||||
| return dyn_cast<IREE::Encoding::PaddingAttr>(*layouts.begin()); | ||||||
| } | ||||||
| Attribute resolvedEncoding = layoutAttr.getLayout(type); | ||||||
| LDBG() << "Unresolved type: " << type; | ||||||
| LDBG() << "layoutAttr: " << layoutAttr; | ||||||
| LDBG() << "Resolved into: " << resolvedEncoding; | ||||||
| return dyn_cast<IREE::Encoding::PaddingAttr>(resolvedEncoding); | ||||||
| } | ||||||
|  | ||||||
| // Returns a padded tensor type (without encoding) for tensor types with the pad | ||||||
| // encoding layout, or the same type for all other tensors. | ||||||
| static RankedTensorType | ||||||
| getPaddedType(IREE::Encoding::LayoutResolverAttr layoutAttr, | ||||||
| RankedTensorType type) { | ||||||
| IREE::Encoding::PaddingAttr layout = getPadLayout(layoutAttr, type); | ||||||
| if (layout.isIdentityLayout()) { | ||||||
|         
                  hanhanW marked this conversation as resolved.
              Show resolved
            Hide resolved | ||||||
| return type.dropEncoding(); | ||||||
| } | ||||||
|  | ||||||
| ArrayRef<int64_t> padding = layout.getPadding().asArrayRef(); | ||||||
| auto newShape = llvm::to_vector_of<int64_t>(type.getShape()); | ||||||
| for (auto [newDim, padValue] : llvm::zip_equal(newShape, padding)) { | ||||||
| assert((padValue == 0 || ShapedType::isStatic(newDim)) && | ||||||
| "Padding dynamic dims not supported"); | ||||||
| newDim += padValue; | ||||||
| } | ||||||
|  | ||||||
| return RankedTensorType::get(newShape, type.getElementType()); | ||||||
| } | ||||||
|  | ||||||
| struct GPUPadEncodingLayoutMaterializerAttr final | ||||||
| : IREE::Encoding::LayoutMaterializerAttr::ExternalModel< | ||||||
| GPUPadEncodingLayoutMaterializerAttr, GPUPaddingResolverAttr> { | ||||||
|  | ||||||
| Type convertType(Attribute attr, Type type) const { | ||||||
| auto layoutAttr = cast<IREE::Encoding::LayoutResolverAttr>(attr); | ||||||
| return TypeSwitch<Type, Type>(type) | ||||||
| .Case<RankedTensorType>([&](auto type) { | ||||||
|         
                  hanhanW marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||
| // By the definition, the final converted type is the same tensor type | ||||||
| // without encodings. | ||||||
| return type.dropEncoding(); | ||||||
| }) | ||||||
| .Case<IREE::TensorExt::DispatchTensorType>( | ||||||
| [&](auto dispatchTensorType) { | ||||||
|         
                  hanhanW marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||
| auto type = | ||||||
| dyn_cast<RankedTensorType>(dispatchTensorType.getBoundType()); | ||||||
| if (!type || !type.getEncoding()) { | ||||||
| return dispatchTensorType; | ||||||
| } | ||||||
| // The incoming bindings have the padded type, if `padding` is | ||||||
| // present. | ||||||
| if (getPadLayout(layoutAttr, type)) { | ||||||
| type = getPaddedType(layoutAttr, type); | ||||||
| } | ||||||
| return IREE::TensorExt::DispatchTensorType::get( | ||||||
| dispatchTensorType.getAccess(), type); | ||||||
| }) | ||||||
| .Default([&](Type type) { return type; }); | ||||||
|          | ||||||
| .Default([&](Type type) { return type; }); | |
| .Default([](Type type) { return type; }); | 
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.
oh thanks, somehow I missed it.
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.