junrushao1994 edited a comment on pull request #8767:
URL: https://github.com/apache/tvm/pull/8767#issuecomment-903229077


   Thanks for the discussion. I would love to specifically put up a proposal on 
re-organizing the spaghetti code for better readability, and prove it actually 
practical in our particular case.
   
   The code can be reorganized into 4 methods:
   - Method 1. Collect the loops provided by users into an unordered set, and 
its signature is:
   
   ```C++
   (
     self: ScheduleState,
     ordered_loop_srefs: Array<StmtSRef>
   ) -> std::unordered_set<const StmtSRefNode*>;
   ```
   
   - Method 2: Find `top` and `bottom` of the chain, and its signature is:
   
   ```C++
   (
       self: ScheduleState,
       loop_srefs: std::unordered_set<const StmtSRefNode*>
   ) -> (const StmtSRefNode*, const StmtSRefNode*)
   ```
   
   Note that we don't need `ordered_loop_srefs` in this method because the 
order of the loops doesn't actually affect the algorithm.
   
   - Method 3: Construct the loop chain:
   
   ```C++
   (
     self: ScheduleState,
     top: const StmtSRefNode*,
     bottom: const StmtSRefNode*
   ) -> std::vector<const StmtSRefNode*>
   ```
   
   - Method 4: Construct the new loop chain:
   
   ```C++
   (
     self: ScheduleState,
     chain: std::vector<const StmtSRefNode*>,
     ordered_loop_srefs: Array<StmtSRef>,
     loop_srefs: std::unordered_set<const StmtSRefNode*>,
   ) -> For
   ```
   
   By this decomposition, we eliminate a handful of temporary variables and 
data structures, and made the hundred-line logic much clearer with small 
methods of within 30 lines. There is not much "data sharing" between methods 
either. Therefore, in terms of code quality, I do believe we have concrete 
motivation to improve the code quality.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to