The Polyhedral Model Beyond Loops Recursion Optimization and Parallelization Through Polyhedral Modeling Salwa Kobeissi & Philippe Clauss CAMUS team - Inria, University of Strasbourg, ICPS team - ICube Laboratory IMPACT - HIPEAC 2019, January 23, 2019 Salwa Kobeissi & Philippe Clauss 1 / 24
Outline 1 Introduction 2 Proposed Solution: From Recursive Functions to Optimized Loops 3 Case Studies 4 Conclusion and Perspectives Salwa Kobeissi & Philippe Clauss 2 / 24
Introduction 1 Introduction 2 Proposed Solution: From Recursive Functions to Optimized Loops 3 Case Studies 4 Conclusion and Perspectives Salwa Kobeissi & Philippe Clauss 3 / 24
Introduction Motivation There may be a huge gap between: • the statements in a program source code • the instructions actually performed by a given processor architecture Salwa Kobeissi & Philippe Clauss 4 / 24
Introduction Motivation There may be a huge gap between: • the statements in a program source code • the instructions actually performed by a given processor architecture Efficient optimizations may be applied as soon as the actual runtime behavior has been discovered • dedicated to specific control structures & memory access patterns Salwa Kobeissi & Philippe Clauss 4 / 24
Introduction Inspiration Apollo Memory Accesses Behavior at Runtime • Captures a polyhedral from statically non-polyhedral loops! behavior of loops at runtime • Applies the polyhedral model Salwa Kobeissi & Philippe Clauss 5 / 24
Introduction Inspiration Apollo Memory Accesses Behavior at Runtime • Captures a polyhedral from statically non-polyhedral loops! behavior of loops at runtime • Applies the polyhedral model We apply the Apollo Approach for codes that are originally not loops! => recursions Salwa Kobeissi & Philippe Clauss 5 / 24
Introduction Objectives We are interested in recursive functions: 1 whose runtime behavior can be modeled as polyhedral loops 2 where the structure of their modeling loops is constant regarding the input Salwa Kobeissi & Philippe Clauss 6 / 24
Introduction Objectives We are interested in recursive functions: 1 whose runtime behavior can be modeled as polyhedral loops 2 where the structure of their modeling loops is constant regarding the input Objectives 1 optimizing recursive functions through transformation into affine loops 2 extending the scope of polyhedral optimizations to cover recursive functions Salwa Kobeissi & Philippe Clauss 6 / 24
Proposed Solution: From Recursive Functions to Optimized Loops 1 Introduction 2 Proposed Solution: From Recursive Functions to Optimized Loops 3 Case Studies 4 Conclusion and Perspectives Salwa Kobeissi & Philippe Clauss 7 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Implementation Recursive Code Clang/LLVM Compiler The implementation Optimized LLVM IR & Call Graph consists of 3 main Recursion Analysis steps: Direct & Indirect Recursions Reachability Analysis & Impacting Instructions Recursive Control 1 Instrumented Recursive Code and Memory Behavior Analysis Execution New Input Trace of Basic Block IDs & Memory Adresses Nested Loop Recognition (NLR) Affine Loop Model Code Generation Iterative Code with Affine Loops Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 8 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Implementation Recursive Code Clang/LLVM Compiler The implementation Optimized LLVM IR & Call Graph consists of 3 main Recursion Analysis steps: Direct & Indirect Recursions Reachability Analysis & Impacting Instructions Recursive Control 1 Instrumented Recursive Code and Memory Behavior Analysis Execution 2 Recursion to Affine New Input Trace of Basic Block IDs & Memory Adresses Loop Nest Nested Loop Recognition (NLR) Transformation Affine Loop Model Code Generation Iterative Code with Affine Loops Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 8 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Implementation Recursive Code Clang/LLVM Compiler The implementation Optimized LLVM IR & Call Graph consists of 3 main Recursion Analysis steps: Direct & Indirect Recursions Reachability Analysis & Impacting Instructions Recursive Control 1 Instrumented Recursive Code and Memory Behavior Analysis Execution 2 Recursion to Affine New Input Trace of Basic Block IDs & Memory Adresses Loop Nest Nested Loop Recognition (NLR) Transformation Affine Loop Model Polyhedral 3 Code Generation Optimizations Iterative Code with Affine Loops Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 8 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Recursive Control and Memory Behavior Analysis Recursive Code Clang/LLVM Compiler Optimized LLVM IR & Call Graph Input: recursive code Recursion Analysis Direct & Indirect Recursions Apply classical LLVM optimization Reachability Analysis & Impacting Inst. passes Instrumented Recursive Code • promote memory to register Execution • simplify CFG New Input Trace of BB IDs & Memory Adresses • dead code elimination Nested Loop Recognition Affine Loop Model Output: optimized LLVM IR & call Code Generation graph Iterative Code with Affine Loops Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 9 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Recursive Control and Memory Behavior Analysis Recursive Code Input: optimized IR & call graph Clang/LLVM Compiler Optimized LLVM IR & Call Graph Recursion Analysis Direct & Indirect Recursions main Reachability Analysis & Impacting Inst. Instrumented Recursive Code h f Execution New Input Trace of BB IDs & Memory Adresses g Nested Loop Recognition j k i Affine Loop Model Code Generation Iterative Code with Affine Loops Output: direct & indirect Compiler & Polyhedral Optimization recursions Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 9 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Recursive Control and Memory Behavior Analysis Recursive Code Input: direct & indirect recursions Clang/LLVM Compiler Optimized LLVM IR & Call Graph Recursion Analysis Direct & Indirect Recursions main Reachability Analysis & Impacting Inst. Instrumented Recursive Code h f Execution New Input Trace of BB IDs & Memory Adresses g Nested Loop Recognition j k i Affine Loop Model Code Generation Iterative Code with Affine Loops Output: instrumented recursive Compiler & Polyhedral Optimization code Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 9 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Recursive Control and Memory Behavior Analysis Recursive Code Clang/LLVM Compiler Input: Trace of the program execution : Optimized LLVM IR & Call Graph Basic Block IDs & Memory Addresses Recursion Analysis Nested Loop Reconginition (NLR) Direct & Indirect Recursions algorithm applications: Reachability Analysis & Impacting Inst. 1 program behavior modeling Instrumented Recursive Code for any measured quantity Execution New Input Trace of BB IDs & Memory Adresses such as memory accesses Nested Loop Recognition (NLR) 2 execution trace compressing Affine Loop Model 3 value prediction Code Generation (ketterlin & Clauss, GGO 2008) Iterative Code with Affine Loops Output: Affine Loop Model Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 9 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Recursion to Affine Loop Nest Transformation Recursive Code Clang/LLVM Compiler Optimized LLVM IR & Call Graph Input: Affine loop model Recursion Analysis Direct & Indirect Recursions Direct & Indirect Recursions 1 Extract NLR resulting loop Reachability Analysis & Impacting Inst. nests structures Instrumented Recursive Code 2 Construct loops in the LLVM IR Execution using: New Input Trace of BB IDs & Memory Adresses • Instrumented basic blocks • Interpolated memory Nested Loop Recognition Affine Loop Model addresses Code Generation Output: Iterative code with affine loops Iterative Code with Affine Loops Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 10 / 24
Proposed Solution: From Recursive Functions to Optimized Loops Polyhedral Optimizations Recursive Code Clang/LLVM Compiler Optimized LLVM IR & Call Graph Recursion Analysis Input: Iterative code with affine loops Direct & Indirect Recursions Direct & Indirect Recursions Reachability Analysis & Impacting Inst. • Apply LLVM optimization Instrumented Recursive Code passes Execution • Use polly LLVM polyhedral New Input Trace of BB IDs & Memory Adresses optimizer (Grosser et al., PPL 2012) Nested Loop Recognition Affine Loop Model Output: Optimized recursive code Code Generation Iterative Code with Affine Loops Compiler & Polyhedral Optimization Optimized Recursive Code Salwa Kobeissi & Philippe Clauss 11 / 24
Case Studies 1 Introduction 2 Proposed Solution: From Recursive Functions to Optimized Loops 3 Case Studies 4 Conclusion and Perspectives Salwa Kobeissi & Philippe Clauss 12 / 24
Recommend
More recommend