150 likes | 272 Views
Code specialization is a technique that tailors general algorithms to domain-specific implementations by optimizing for performance and resource efficiency. It can lead to significant performance boosts (up to 60%) by eliminating unnecessary computations and utilizing JIT (Just-In-Time) compilation. Applications span across embedded systems, cryptography, and software optimizations, enhancing performance while addressing specific constraints. This overview explores the principles, methods such as partial evaluation and memoization, and the importance of invariants in coding practices.
E N D
Code Specialization Michael E. LocastoSeptember 19, 2002
What is Code Specialization? • General algorithm --> domain-specific implementation • eliminate (hold invariant) some inputs • a compiler optimization
Compiler Optimizations Invariants partial evaluation promotion and accumulation memoization JIT code obfuscation transformational programming finite differencing loop unrolling Related Terms & Concepts
Why Is It Useful? • Performance boost ~13-25%, and sometimes more (60%) • Don’t need to “save the world” (just your continent) • Respond to change in environment (JIT) • useful in embedded env (highly specialized hardware)
Why Is It Useful ? (con) • MAC operation in DSP Harvard 56000 • “three approaches to providing performance guarantees in algorithm design: randomize, amortize, or optimize.” • manual optimizations (better programmers) • automatic optimizations (save your fingers)
Some Manual Optimizations • Algebraic and logical expression manipulation • eliminate recursive method calls (& method call overhead in general) • reduce excessive object creation • write in ASM
int foo( int a, int b){ if( a>b ){ //many instructions }else if( a==b ){ //many instructions }else{ return a; }} int foo( int a, int b ){ return a;}//or even:int foo( int a ){ return a;}//or evena The Idea of Invariants
Partial Evaluation • Non-deterministic, may fail to terminate • lazy evaluation • Program p + Data d = new source (p_d) • Basic idea: your data has mostly been evaluated so the program does not waste time getting, scanning, and verifying large set of input
Another Example • See sheet • (http://www.cs.columbia.edu/~locasto/projects/codespec/codespecialization.summary.html )
Database querying hardware simulation spreadsheet computations Configuration files (seldom-changing parameters) Support both modularity and performance crypto (many repeated operations with predictable data) R: replacing complex function with multiplication by 2,3 Specific Applications
Security and Code Specialization • Partial Evaluation is used to create the intermediate permissions for java.security.Policy • in some way make code simpler (proof of security may be easier) • 2.29 Gb/s Rijndael processor (for AES) - designers used code specialization to turn the C ref imp to hardware
Rijndael Code Specialization • Look up table (Galois field) • large mem required, embedded device limits • analysis revealed simple 2 or 3 mul
Embedded Devices • Much work being done here (as well as for the JVM/JIT) • save power, space, heat, cpu cycles • these devices have highly specialized architecture, making it natural to want to automatically specialize an algorithm. Also, their data is of a predictable and uniform type.
Resources • http://www.diku.dk/research-groups/topps/activities/PartialEvaluation.html • http://www.cs.columbia.edu/~locasto/projects/codespec/codespecialization.survey.html • http://www.dina.dk/~sestoft/pebook/pebook.html
Questions && /*Comments*/ • Specific problems? • Applications • how to apply to crypto • optimizations