- 
                Notifications
    You must be signed in to change notification settings 
- Fork 112
shorten mlir dump filename #4197
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
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      04762ad
              
                shorten mlir dump filename
              
              
                shivadbhavsar e78cea4
              
                update to avoid conflicting names and simply softmax in known cases
              
              
                shivadbhavsar f3a0029
              
                Merge branch 'develop' into mlir_dump_fix
              
              
                shivadbhavsar b59fa13
              
                tidy
              
              
                shivadbhavsar c431830
              
                wrap atomic int in function
              
              
                shivadbhavsar 5a02ea9
              
                Merge branch 'develop' into mlir_dump_fix
              
              
                shivadbhavsar 4b4e538
              
                simplify truncation logic
              
              
                shivadbhavsar b16cbee
              
                add comment
              
              
                shivadbhavsar a486ac6
              
                cppcheck and review fixes
              
              
                shivadbhavsar 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -22,6 +22,7 @@ | |
| * THE SOFTWARE. | ||
| */ | ||
| #include <algorithm> | ||
| #include <atomic> | ||
| #include <cstdint> | ||
| #include <migraphx/shape.hpp> | ||
| #include <migraphx/algorithm.hpp> | ||
|  | @@ -163,6 +164,13 @@ using mlir_tuning_space = MIGRAPHX_MANAGE_MLIR_HANDLE(MlirRockTuningSpace, | |
| using mlir_tuning_param = MIGRAPHX_MANAGE_MLIR_HANDLE(MlirRockTuningParam, | ||
| mlirRockTuningParamDestroy); | ||
|  | ||
| static std::atomic<int>& dump_counter() | ||
| { | ||
| // NOLINTNEXTLINE | ||
| static std::atomic<int> c = 0; | ||
| return c; | ||
| } | ||
|  | ||
| static std::string_view to_string_view(MlirStringRef s) { return {s.data, s.length}; } | ||
|  | ||
| static MlirStringRef make_mlir_string_ref(const std::string_view& s) | ||
|  | @@ -1094,6 +1102,20 @@ std::string dump_mlir(module m, const std::vector<shape>& inputs) | |
| return mlir_print(&mlirOperationPrint, mod_op); | ||
| } | ||
|  | ||
| static void abbreviate_symbol_names(std::string& n) | ||
| { | ||
| static const std::map<std::string, std::string> abbrs = { | ||
| {"reduce_max_reshape_sub_exp_reshape_reduce_sum_reshape_div", "softmax"}, | ||
| {"reshape", "rsp"}, | ||
| {"transpose", "trp"}, | ||
| {"slice", "slc"}}; | ||
|  | ||
| for(auto const& [key, val] : abbrs) | ||
| { | ||
| replace_string_inplace(n, key, val); | ||
| } | ||
| } | ||
|  | ||
| static std::string compute_dump_name(const module& m, const std::string& ext) | ||
| { | ||
| std::vector<instruction_ref> sizes; | ||
|  | @@ -1102,11 +1124,25 @@ static std::string compute_dump_name(const module& m, const std::string& ext) | |
| if(contains({"quant_convolution", "quant_dot", "convolution", "dot"}, ins->name())) | ||
| sizes.insert(sizes.end(), ins->inputs().begin(), ins->inputs().end()); | ||
| } | ||
| auto name = | ||
| mlir_program::get_symbol_name(m) + "_" + shape::to_sizes_string(to_shapes(sizes)) + ext; | ||
| replace_string_inplace(name, ", ", "_"); | ||
| replace_string_inplace(name, ":", "s"); | ||
| return name; | ||
| auto shape_str = "_" + shape::to_sizes_string(to_shapes(sizes)); | ||
| auto sym_names = mlir_program::get_symbol_name(m); | ||
| abbreviate_symbol_names(sym_names); | ||
|  | ||
| // On most commonly used file systems, the max file name size is 255 characters | ||
| const int max_file_length = 255; | ||
|         
                  shivadbhavsar marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| auto cnt = "_" + std::to_string(dump_counter()++); | ||
| 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. This nitpicking likely shows my poor programming aesthetics :-) | ||
| std::string fname = sym_names + shape_str; | ||
| replace_string_inplace(fname, ", ", "_"); | ||
| replace_string_inplace(fname, ":", "s"); | ||
|  | ||
| if(fname.length() + cnt.length() + ext.length() > max_file_length) | ||
| { | ||
| auto cutoff = max_file_length - ext.length() - cnt.length(); | ||
| fname.resize(cutoff); | ||
| } | ||
| fname += cnt + ext; | ||
|  | ||
| return fname; | ||
| } | ||
|  | ||
| void dump_mlir_to_file(module m, const std::vector<shape>& inputs, const fs::path& location) | ||
|  | ||
  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.
There is a bug lurking here, should the loop iterate over the string
reshapebefore the longer string (for softmax) which also has the same substring inside it. It is just that the std::map would be in an order which works here. But change it to a another data structure, e.g. a hash, and the renaming scheme could be a surprise for us :-)