• Aucun résultat trouvé

Journéescompil’,04/2011 MatthieuMoy PinaVMandTweto:CompilationandOptimizationTechniquesforSystemC

N/A
N/A
Protected

Academic year: 2022

Partager "Journéescompil’,04/2011 MatthieuMoy PinaVMandTweto:CompilationandOptimizationTechniquesforSystemC"

Copied!
90
0
0

Texte intégral

(1)SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM and Tweto: Compilation and Optimization Techniques for SystemC Matthieu Moy Verimag (Grenoble INP) Grenoble France. Journées compil’, 04/2011. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 1 / 53 >.

(2) SystemC. Overview. PinaVM. Tweto. Conclusion. Summary. 1. SystemC and Transaction Level Modeling. 2. Overview of PinaVM and Tweto. 3. PinaVM: a SystemC Front-End. 4. Tweto: TLM With Elaboration-Time Optimizations. 5. Conclusion. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 2 / 53 >.

(3) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 1. SystemC and Transaction Level Modeling. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 3 / 53 >.

(4) SystemC. Overview. PinaVM. Tweto. Conclusion. Modern Systems-on-a-Chip. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 4 / 53 >.

(5) SystemC. Overview. PinaVM. Tweto. Conclusion. Modern Systems-on-a-Chip Software. Hardware. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 4 / 53 >.

(6) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC and Transaction-Level Modeling (Fast) simulation essential in the design-flow I I I. To write/debug software To validate architectural choices As reference for hardware verification. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 5 / 53 >.

(7) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC and Transaction-Level Modeling (Fast) simulation essential in the design-flow I I I. To write/debug software To validate architectural choices As reference for hardware verification. Transaction-Level Modeling (TLM): I I. high level of abstraction, suitable for. SystemC: I. I. Industry-standard for high-level modeling (TLM, . . . ) of Systems-on-a-Chip, Library for C++ (compile with g++ -lsystemc. . . ). Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 5 / 53 >.

(8) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC: Simple Example N1 SC_MODULE(not_gate) { sc_in<bool> in; sc_out<bool> out; void compute (void) { // Behavior bool val = in.read(); out.write(!val); } SC_CTOR(not_gate) { SC_METHOD(compute); sensitive << in; }. N2 int sc_main(int argc, char **argv) { // Elaboration phase (Architecture) // Instantiate modules ... not_gate n1("N1"); not_gate n2("N2"); sc_signal<bool> s1, s2; // ... and bind them together n1.out.bind(s1); n2.out.bind(s2); n1.in.bind(s2); n2.in.bind(s1); // Start simulation sc_start(100, SC_NS); return 0;. }; } Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 6 / 53 >.

(9) SystemC. Overview. PinaVM. Tweto. Conclusion. Summary. 1. SystemC and Transaction Level Modeling. 2. Overview of PinaVM and Tweto. 3. PinaVM: a SystemC Front-End. 4. Tweto: TLM With Elaboration-Time Optimizations. 5. Conclusion. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 7 / 53 >.

(10) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 2. Overview of PinaVM and Tweto. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 8 / 53 >.

(11) SystemC. Overview. PinaVM. Tweto. Conclusion. This talk: PinaVM and Tweto. C++. Front end. IR. Code Generation. Link. Executable. Execution. Optimizer. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 9 / 53 >.

(12) SystemC. Overview. PinaVM. Tweto. Conclusion. This talk: PinaVM and Tweto. SystemC. C++. Front end. IR. Code Generation. Link. Executable. Execution. Optimizer. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 9 / 53 >.

(13) SystemC. Overview. PinaVM. Tweto. Conclusion. This talk: PinaVM and Tweto. JIT. SystemC. C++. Front end. IR. Code Generation. Link. Executable. Execution. Optimizer. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 9 / 53 >.

(14) SystemC. Overview. PinaVM. Tweto. Conclusion. This talk: PinaVM and Tweto. JIT. SystemC. C++. Front end. IR. Code Generation. Link. Executable. Execution. Optimizer. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 9 / 53 >.

(15) SystemC. Overview. PinaVM. Tweto. Conclusion. This talk: PinaVM and Tweto PinaVM: just like a compiler front-end, but for the SystemC library JIT. SystemC. C++. Front end. IR. Code Generation. Link. Executable. Execution. Optimizer. Tweto: use the information provided by PinaVM to optimize the program better than C++ compilers Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 9 / 53 >.

(16) SystemC. Overview. PinaVM. Tweto. Conclusion. This talk: PinaVM and Tweto Matthieu Moy. PinaVM: just like a compiler front-end, but for the SystemC library. Claire Maïza. Kevin Marquet JIT. SystemC. C++. Front end. IR. Code Generation. Link. Executable. Execution. Optimizer Si-Mohamed Lamraoui. Claude Helmstetter. Tweto: use the information provided by PinaVM to optimize the program better than C++ compilers Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 9 / 53 >.

(17) SystemC. Overview. PinaVM. Tweto. Conclusion. Summary. 1. SystemC and Transaction Level Modeling. 2. Overview of PinaVM and Tweto. 3. PinaVM: a SystemC Front-End. 4. Tweto: TLM With Elaboration-Time Optimizations. 5. Conclusion. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 10 / 53 >.

(18) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 3. PinaVM: a SystemC Front-End SystemC Front-Ends The Beginning ... PinaVM Is Not A Virtual Machine PinaVM: Summary. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 11 / 53 >.

(19) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 3. PinaVM: a SystemC Front-End SystemC Front-Ends The Beginning ... PinaVM Is Not A Virtual Machine PinaVM: Summary. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 12 / 53 >.

(20) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC Front-End In this talk: Front-end = “Compiler front-end” (AKA “Parser”). SystemC. Front end. Intermediate Representation. Back end. Intermediate Representation = Architecture + Behavior. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 13 / 53 >.

(21) SystemC. Overview. PinaVM. Tweto. Conclusion. When you don’t need a front-end. Main application of SystemC: simulation I. Just need a C++ compiler + the library. Testing, run-time verification, monitoring. . . I. (Small) modifications of the SystemC library. IDE integration, Debugging . . . I. Plain C++ front-ends can do most of the job.. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 14 / 53 >.

(22) SystemC. Overview. PinaVM. Tweto. Conclusion. When you don’t need a front-end. Main application of SystemC: simulation I. Just need a C++ compiler + the library. Testing, run-time verification, monitoring. . . I. (Small) modifications of the SystemC library. IDE integration, Debugging . . . I. Plain C++ front-ends can do most of the job.. No reference front-end available on http://www.systemc.org/. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 14 / 53 >.

(23) SystemC. Overview. PinaVM. Tweto. Conclusion. When you really need a front-end Symbolic formal verification, high-level synthesis Visualization Introspection. Advanced debugging features (architecture → source code, . . . ) SystemC-specific compiler optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 15 / 53 >.

(24) SystemC. Overview. PinaVM. Tweto. Conclusion. When you really need a front-end Symbolic formal verification, high-level synthesis I. Need to extract almost everything about the platform. Visualization Introspection. Advanced debugging features (architecture → source code, . . . ) SystemC-specific compiler optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 15 / 53 >.

(25) SystemC. Overview. PinaVM. Tweto. Conclusion. When you really need a front-end Symbolic formal verification, high-level synthesis I. Need to extract almost everything about the platform. Visualization I. Need to extract the architecture. Behavior is less important. Introspection. Advanced debugging features (architecture → source code, . . . ) SystemC-specific compiler optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 15 / 53 >.

(26) SystemC. Overview. PinaVM. Tweto. Conclusion. When you really need a front-end Symbolic formal verification, high-level synthesis I. Need to extract almost everything about the platform. Visualization I. Need to extract the architecture. Behavior is less important. Introspection I. Information about the module (architecture) + possibly local variables (behavior). Advanced debugging features (architecture → source code, . . . ) SystemC-specific compiler optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 15 / 53 >.

(27) SystemC. Overview. PinaVM. Tweto. Conclusion. When you really need a front-end Symbolic formal verification, high-level synthesis I. Need to extract almost everything about the platform. Visualization I. Need to extract the architecture. Behavior is less important. Introspection I. Information about the module (architecture) + possibly local variables (behavior). Advanced debugging features (architecture → source code, . . . ) I. Need architecture and behavior. SystemC-specific compiler optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 15 / 53 >.

(28) SystemC. Overview. PinaVM. Tweto. Conclusion. When you really need a front-end Symbolic formal verification, high-level synthesis I. Need to extract almost everything about the platform. Visualization I. Need to extract the architecture. Behavior is less important. Introspection I. Information about the module (architecture) + possibly local variables (behavior). Advanced debugging features (architecture → source code, . . . ) I. Need architecture and behavior. SystemC-specific compiler optimizations I. Can use architecture information to optimize behavior. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 15 / 53 >.

(29) SystemC. Overview. PinaVM. Tweto. Conclusion. Challenges and Solutions with SystemC Front-Ends 1. C++ is complex (e.g. clang ≈ 200,000 LOC). 2. Architecture built at runtime, with C++ code. SC_MODULE(not_gate) { sc_in<bool> in; sc_out<bool> out; void compute (void) { // Behavior bool val = in.read(); out.write(!val); } SC_CTOR(not_gate) { SC_METHOD(compute); sensitive << in; } };. int sc_main(int argc, char **argv) { // Elaboration phase (Architecture) not_gate n1("N1"); not_gate n2("N2"); sc_signal<bool> s1, s2; // Binding n1.out.bind(s1); n2.out.bind(s2); n1.in.bind(s2); n2.in.bind(s1); // Start simulation sc_start(100, SC_NS); return 0; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 16 / 53 >.

(30) SystemC. Overview. PinaVM. Tweto. Conclusion. Challenges and Solutions with SystemC Front-Ends 1. 2. C++ is complex (e.g. clang ≈ 200,000 LOC) Write a C++ front-end or reuse one (g++, clang, edg, . . . ) Architecture built at runtime, with C++ code Analyze elaboration phase or execute it. SC_MODULE(not_gate) { sc_in<bool> in; sc_out<bool> out; void compute (void) { // Behavior bool val = in.read(); out.write(!val); } SC_CTOR(not_gate) { SC_METHOD(compute); sensitive << in; } };. int sc_main(int argc, char **argv) { // Elaboration phase (Architecture) not_gate n1("N1"); not_gate n2("N2"); sc_signal<bool> s1, s2; // Binding n1.out.bind(s1); n2.out.bind(s2); n1.in.bind(s2); n2.in.bind(s1); // Start simulation sc_start(100, SC_NS); return 0; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 16 / 53 >.

(31) SystemC. Overview. PinaVM. Tweto. Conclusion. Challenges and Solutions with SystemC Front-Ends 1. 2. C++ is complex (e.g. clang ≈ 200,000 LOC) Write a C++ front-end or reuse one (g++, clang, edg, . . . ) Architecture built at runtime, with C++ code Analyze elaboration phase or execute it. SC_MODULE(not_gate) { sc_in<bool> in; sc_out<bool> out; void compute (void) { // Behavior bool val = in.read(); Static Approaches out.write(!val); } SC_CTOR(not_gate) { SC_METHOD(compute); sensitive << in; } };. int sc_main(int argc, char **argv) { // Elaboration phase (Architecture) not_gate n1("N1"); Dynamic Approaches not_gate n2("N2"); sc_signal<bool> s1, s2; // Binding n1.out.bind(s1); n2.out.bind(s2); n1.in.bind(s2); n2.in.bind(s1); // Start simulation sc_start(100, SC_NS); return 0; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 16 / 53 >.

(32) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with the architecture When it becomes tricky. . .. int sc_main(int argc, char **argv) { int n = atoi(argv[1]); int m = atoi(argv[2]); Node array[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i][j] = new Node(...); ... } } sc_start(100, SC_NS); return 0; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 17 / 53 >.

(33) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with the architecture When it becomes tricky. . .. Static approach: cannot deal with such code Dynamic approach: can extract the architecture for individual instances of the system. int sc_main(int argc, char **argv) { int n = atoi(argv[1]); int m = atoi(argv[2]); Node array[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i][j] = new Node(...); ... } } sc_start(100, SC_NS); return 0; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 17 / 53 >.

(34) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with the architecture When it becomes very tricky. . .. void compute(void) { for (int i = 0; i < n; i++) { ports[i].write(true); } ... }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 18 / 53 >.

(35) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with the architecture When it becomes very tricky. . .. One can unroll the loop to let i become constant, Undecidable in the general case.. Matthieu Moy (Verimag). void compute(void) { for (int i = 0; i < n; i++) { ports[i].write(true); } ... }. PinaVM and Tweto. Journées compil’, 04/2011. < 18 / 53 >.

(36) SystemC. Overview. PinaVM. Tweto. Conclusion. Existing SystemC front-ends An attempt at a classification. Static Home-made parser Existing parser. Dynamic. KaSCPar, sc2v, ParSyC, Scoot, SystemPerl. . . SystemCXML. DATE09, Pinapa, PinaVM. Hard to classify: Quiny (purely dynamic approach) Commercial tools (closed, not detailed here): Synopsys, Semantic Design, NC-SystemC (Cadence). Self-advertisement A Theoretical and Experimental Review of SystemC Front-ends, Marquet et al. FDL 2010 Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 19 / 53 >.

(37) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 3. PinaVM: a SystemC Front-End SystemC Front-Ends The Beginning ... PinaVM Is Not A Virtual Machine PinaVM: Summary. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 20 / 53 >.

(38) SystemC. Overview. PinaVM. Tweto. Conclusion. Before it started: Pinapa [Moy et al, EMSOFT 05] AKA “my Ph.D’s front-end”. Pinapa’s principle: I I. Use GCC’s C++ front-end Compile, dynamically load and execute the elaboration (sc_main). Pinapa’s drawbacks: I I I I. I. Uses GCC’s internals (hard to port to newer versions) Hard to install No separate compilation Based on complex Abstract Syntax Tree (AST) (e.g. one construct for for, one for while and one for do ... while) Ad-hoc match of SystemC constructs in AST. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 21 / 53 >.

(39) SystemC. Overview. PinaVM. Tweto. Conclusion. Static Single Assignment Non-SSA program. SSA program. x = 42; x = x + 1; y = x;. x1 = 42; x2 = x1 + 1; y = x2;. SSA form widely used by modern compilers. . . . . . and by some formal verification tools1 Candidates C++ front-end providing SSA form: I I. GCC ≥ 4.0 LLVM. 1. Automatic translation of C/C++ parallel code into synchronous formalism using an SSA intermediate form. Besnard et al. AVOCS 2009 Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 22 / 53 >.

(40) SystemC. Overview. PinaVM. Tweto. Conclusion. LLVM: Low Level Virtual Machine JIT compilation. C++ Front ends. C. Bitcode. ... Optimizer. Matthieu Moy (Verimag). PinaVM and Tweto. Back ends Code Generation. Journées compil’, 04/2011. < 23 / 53 >.

(41) SystemC. Overview. PinaVM. Tweto. Conclusion. LLVM: Low Level Virtual Machine JIT compilation. C++ Front ends. C. Bitcode. ... Optimizer. Back ends Code Generation. Clean API Clean SSA intermediate representation Many tools available Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 23 / 53 >.

(42) SystemC. Overview. PinaVM. Tweto. Conclusion. LLVM: Low Level Virtual Machine JIT compilation. C++ Front ends. C. Bitcode. ... Optimizer. Back ends Code Generation. Can we be here?. Clean API Clean SSA intermediate representation Many tools available Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 23 / 53 >.

(43) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 3. PinaVM: a SystemC Front-End SystemC Front-Ends The Beginning ... PinaVM Is Not A Virtual Machine PinaVM: Summary. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 24 / 53 >.

(44) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM: Architecture SystemC. Compilation (llvm-g++, llvm-link). LLVM bitcode. Execute elaboration. Identify SC constructs. Architecture. bitcode++. Intermediate Representation. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 25 / 53 >.

(45) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM: Architecture SystemC. Existing tools Compilation (llvm-g++, llvm-link). LLVM’s JIT (Just-In-Time) Engine. LLVM bitcode. Intermediate file. Execute elaboration. Identify SC constructs. Architecture. bitcode++. Pattern-match function names. SystemC’s data-structure after elaboration Intermediate Representation. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 25 / 53 >.

(46) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM: Architecture SystemC. Existing tools Compilation (llvm-g++, llvm-link). LLVM’s JIT (Just-In-Time) Engine. LLVM bitcode. Execute elaboration. Intermediate file. Identify SC constructs. Architecture. bitcode++. PinaVM front-end. Pattern-match function names. SystemC’s data-structure after elaboration Intermediate Representation. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 25 / 53 >.

(47) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC constructs in LLVM’s bitcode SystemC (C++) source code: void compute() { out.write(true); } Bitcode after compilation with llvm-g++: define linkonce_odr void @_ZN6Source7computeEv(%struct.Source* %this) { entry: %0 = alloca i8 %"alloca point" = bitcast i32 0 to i32 store i8 1, i8* %0, align 1 %1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1 %2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0 call void @_ZN7sc_core8sc_inoutIbE5writeERKb (%"struct.sc_core::sc_inout<bool>"* %2, i8* %0) br label %return return: ret void }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 26 / 53 >.

(48) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC constructs in LLVM’s bitcode SystemC (C++) source code: void compute() { out.write(true); } Bitcode after compilation with llvm-g++: define linkonce_odr void @_ZN6Source7computeEv(%struct.Source* %this) { entry: %0 = alloca i8 %"alloca point" = bitcast i32 0 to i32 store i8 1, i8* %0, align 1 %1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1 %2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0 call void @_ZN7sc_core8sc_inoutIbE5writeERKb (%"struct.sc_core::sc_inout<bool>"* %2, i8* %0) br label %return return: ret void }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 26 / 53 >.

(49) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC constructs in LLVM’s bitcode Simplified Bitcode: define void Source::compute(%this) { ; "out.write(true)" compiled into: ; piece of code computing %data = true = 1 ; piece of code computing %port as ; a function of %this call sc_core::sc_inout::write(%port, %data) ret void }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 27 / 53 >.

(50) SystemC. Overview. PinaVM. Tweto. Conclusion. SystemC constructs in LLVM’s bitcode Simplified Bitcode: define void Source::compute(%this) { ; "out.write(true)" compiled into: ; piece of code computing %data = true = 1 ; piece of code computing %port as ; a function of %this call sc_core::sc_inout::write(%port, %data) ret void }. Computation of %port and %data (argument of SystemC primitive) I I. Unknown statically (depend on this) Computable for each module once we know this!. What PinaVM does: I I. Extract (slice) pieces of code computing %data and %port JIT-compile and execute them after fixing %this. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 27 / 53 >.

(51) SystemC. Overview. PinaVM. Tweto. Conclusion. Back to the example Computation of “port” in port.write(true): define linkonce_odr void @_ZN6Source7computeEv(%struct.Source* %this) { entry: %0 = alloca i8 %"alloca point" = bitcast i32 0 to i32 store i8 1, i8* %0, align 1 %1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1 %2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0 call void @_ZN7sc_core8sc_inoutIbE5writeERKb (%"struct.sc_core::sc_inout<bool>"* %2, i8* %0) br label %return return: ret void } Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 28 / 53 >.

(52) SystemC. Overview. PinaVM. Tweto. Conclusion. Back to the example Computation of “port” in port.write(true): define linkonce_odr void @_ZN6Source7computeEv(%struct.Source* %this) { entry: %0 = alloca i8 %"alloca point" = bitcast i32 0 to i32 store i8 1, i8* %0, align 1 %1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1 %2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0 call void @_ZN7sc_core8sc_inoutIbE5writeERKb (%"struct.sc_core::sc_inout<bool>"* %2, i8* %0) br label %return return: ret void } Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 28 / 53 >.

(53) SystemC. Overview. PinaVM. Tweto. Conclusion. Back to the example Computation of “port” in port.write(true): define private %"struct.sc_core::sc_inout<bool>"* function_to_jit(%struct.Source* %this) {. %1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1 %2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0 ret %"struct.sc_core::sc_inout<bool>"* %2 }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 28 / 53 >.

(54) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM: Enriching the bitcode? SystemC. Compilation (llvm-g++, llvm-link). LLVM bitcode. Execute elaboration. Identify SC constructs. Architecture. bitcode++. Intermediate Representation. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 29 / 53 >.

(55) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM: Enriching the bitcode? SystemC. Compilation (llvm-g++, llvm-link). SystemC construct is still a normal function. LLVM bitcode. Execute elaboration. %this is fixed. ... %port = expr1 %data = expr2 call write %port, %data .... %this not known Cannot compute %port. Identify SC constructs. Architecture. bitcode++. Execute dependencies. Intermediate Representation. ... %port = expr1 %data = expr2 SCWrite - data = ?? - port = ?? .... ... %port = expr1 %data = expr2 SCWrite   Process 0 → data d0 - data = Process 1 → data d1  - port =. Process 0 → port p0 Process 1 → port p1. . .... Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 29 / 53 >.

(56) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 3. PinaVM: a SystemC Front-End SystemC Front-Ends The Beginning ... PinaVM Is Not A Virtual Machine PinaVM: Summary. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 30 / 53 >.

(57) SystemC. Overview. PinaVM. Tweto. Conclusion. Summary. PinaVM relies on executability (JIT Compiler) for: I I. Execution of elaboration phase (≈ like Pinapa) Execution of sliced pieces of code. Using a virtual machine to write a SystemC front-end is a really good idea! Could have benefited from some higher-level constructs in bytecode (builtin object and method calls?). Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 31 / 53 >.

(58) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM. Open Source: http://gitorious.org/pinavm/pages/Home Still a prototype, but very few fundamental limitations ≈ 3000 lines of C++ code on top of LLVM Experimental back-ends for I I. Model-checking (using SPIN) Execution (Tweto). PinaVM: a SystemC front-end based on an executable intermediate representation. Marquet et al. EMSOFT 2010.. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 32 / 53 >.

(59) SystemC. Overview. PinaVM. Tweto. Conclusion. Summary. 1. SystemC and Transaction Level Modeling. 2. Overview of PinaVM and Tweto. 3. PinaVM: a SystemC Front-End. 4. Tweto: TLM With Elaboration-Time Optimizations. 5. Conclusion. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 33 / 53 >.

(60) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 4. Tweto: TLM With Elaboration-Time Optimizations Limitations of Plain C++ Compilers and How to do Better Exploiting Constant Data Dealing with Addresses: Protocol-Aware Optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 34 / 53 >.

(61) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 4. Tweto: TLM With Elaboration-Time Optimizations Limitations of Plain C++ Compilers and How to do Better Exploiting Constant Data Dealing with Addresses: Protocol-Aware Optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 35 / 53 >.

(62) SystemC. Overview. PinaVM. Tweto. Conclusion. Typical Transaction Journey 0x6000 0x5000. CPU. 0x3000 0x2000 0x1000 0x0000. RAM. T2 T1. Bus. T1. T2 RAM. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 36 / 53 >.

(63) SystemC. Overview. PinaVM. Tweto. Conclusion. Typical Transaction Journey 0x6000 0x5000. CPU. RAM. .... socket.write(addr,data); .... 0x3000 0x2000 0x1000 0x0000. T2 T1. Bus. T1. T2 RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 36 / 53 >.

(64) SystemC. Overview. PinaVM. Tweto. Conclusion. Typical Transaction Journey 0x6000 0x5000. CPU. RAM. .... socket.write(addr,data); .... 0x3000 0x2000 0x1000 Forward method 0x0000 call to target socket. Call virtual method on socket. T2 Address Decoding T1. Bus. T1. Another virtual T2 method call. Forwarded to target socket. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 36 / 53 >.

(65) SystemC. Overview. PinaVM. Tweto. Conclusion. Typical Transaction Journey 0x6000 0x5000. CPU. RAM. .... socket.write(addr,data); .... 0x3000 0x2000 0x1000 Forward method 0x0000 call to target socket. Call virtual method on socket. Bus. T1 Ends-up calling target module’s method. T2 Address Decoding T1. Another virtual T2 method call. Forwarded to target socket. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 36 / 53 >.

(66) SystemC. Overview. PinaVM. Tweto. Conclusion. Typical Transaction Journey 0x6000 0x5000. CPU. RAM. .... socket.write(addr,data); .... 0x3000 0x2000 0x1000 Forward method 0x0000 call to target socket. Call virtual method on socket. Bus. T1 Ends-up calling target module’s method. T2 Address Decoding T1. Another virtual T2 method call. Forwarded to target socket. RAM status write(addr,data) { mem[addr] = data; }. Many costly operations for a simple functionality Work-around: backdoor access (DMI = Direct Memory Interface) I I. CPU get a pointer to RAM’s internal data Manual, dangerous optimization. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 36 / 53 >.

(67) SystemC. Overview. PinaVM. Tweto. Conclusion. Typical Transaction Journey 0x6000 0x5000. CPU. RAM. .... socket.write(addr,data); .... 0x3000 0x2000 0x1000 Forward method 0x0000 call to target socket. Call virtual method on socket. Bus. T1 Ends-up calling target module’s method. T2 Address Decoding T1. Another virtual T2 method call. Forwarded to target socket. RAM status write(addr,data) { mem[addr] = data; }. Many costly operations for a simple functionality Work-around: backdoor access (DMI = Direct Memory Interface) I I. CPU get a pointer to RAM’s internal data Manual, dangerous optimization. Can a compiler do as good as DMI, automatically? Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 36 / 53 >.

(68) SystemC. Overview. PinaVM. Tweto. Conclusion. Basic Ideas. Do statically what can be done statically ... ... considering “statically” = “after elaboration” Examples: I I I. Virtual function resolution Inlining through SystemC ports Static address resolution. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 37 / 53 >.

(69) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 4. Tweto: TLM With Elaboration-Time Optimizations Limitations of Plain C++ Compilers and How to do Better Exploiting Constant Data Dealing with Addresses: Protocol-Aware Optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 38 / 53 >.

(70) SystemC. Overview. PinaVM. Tweto. Conclusion. Constant data. Things that are not const for C++, but constant for SystemC: I. I. this pointer for each module ⇒ becomes constant if we specialize functions Architecture (set during elaboration, does not change after) ⇒ marked (by user or within SystemC) with tweto_mark_const(). Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 39 / 53 >.

(71) SystemC. Overview. PinaVM. Tweto. Conclusion. Exploiting constant data. Specialize process: for each instance, duplicate body, setting this pointer to its value Execute constant loads using data collected by tweto_mark_const() Resolve indirect calls once the called function is constant Specialize calls when their argument is constant. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 40 / 53 >.

(72) SystemC. Overview. PinaVM. Tweto. Conclusion. Specialize Process (simplified) Starting point: define @systemc_process(%struct.Module* %this) { entry: ... ... ; uses %this ... } Intermediate: define @systemc_process_specialized() { entry: %this = %struct.Module* <addr-of-this-module>; call @systemc_process (%this) ; use llvm::inlineFunction on this call } Result: function with this replaced by constant Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 41 / 53 >.

(73) SystemC. Overview. PinaVM. Tweto. Conclusion. Execute constant loads Replace inttoptr instructions by constant integer if possible inttoptr syntax: <result> = inttoptr <ty> <value> to <ty2> Example: ; X = (int *)42; %X = inttoptr i32 42 to i32* ; Y = *X %Y = load i32* %X ⇒ %Y = i32* <value at address 42>. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 42 / 53 >.

(74) SystemC. Overview. PinaVM. Tweto. Conclusion. Resolve indirect calls. Replace indirect call instructions by direct call. Example: %1 = load <pointer_to_fun> %2 = call %1(<function args>) ⇒ %2 = call fun(<function args>). Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 43 / 53 >.

(75) SystemC. Overview. PinaVM. Tweto. Conclusion. Specialize calls. Replace calls with constant args by specialized functions. Example: read(int a){a+1;} ⇒ read_42(){42+1;}. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 44 / 53 >.

(76) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 4. Tweto: TLM With Elaboration-Time Optimizations Limitations of Plain C++ Compilers and How to do Better Exploiting Constant Data Dealing with Addresses: Protocol-Aware Optimizations. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 45 / 53 >.

(77) SystemC. Overview. PinaVM. Tweto. Conclusion. What can we hope? (1) #define TIMER_ADDR 0x1000 #define START_REG_OFFSET 4 cpu::compute () { ... // start timer socket.write(TIMER_ADDR+START_REG_OFFSET, 0); ... } ⇒ address known statically, but address resolution still done dynamically. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 46 / 53 >.

(78) SystemC. Overview. PinaVM. Tweto. Conclusion. What can we hope? (2) cpu::compute () { ... // Clear portion of RAM for (addr = 0x1000; addr < 0x2000; addr++) { socket.write(addr, 0); } ... } ⇒ address not constant, but simple analysis could allow static address resolution. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 47 / 53 >.

(79) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); .... 0x3000 0x2000 0x1000 0x0000. T2 T1. Bus. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(80) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); .... Get actual port addr from PinaVM. 0x3000 0x2000 0x1000 0x0000. T2 T1. Bus. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(81) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); ... Follow path to bus Get actual port addr from PinaVM. 0x3000 0x2000 0x1000 0x0000. T2 T1. Bus. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(82) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); ... Follow path to bus Get actual port addr from PinaVM. 0x3000 T2 0x2000 0x1000 Address T1 0x0000 Decoding. Bus. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(83) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); ... Follow path to bus Get actual port addr from PinaVM. Bus. 0x3000 T2 0x2000 0x1000 Address T1 0x0000 Decoding Find target socket at this address. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(84) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); ... Follow path to bus Get actual port addr from PinaVM. Find function in target module. Bus. 0x3000 T2 0x2000 0x1000 Address T1 0x0000 Decoding Find target socket at this address. RAM status write(addr,data) { mem[addr] = data; }. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(85) SystemC. Overview. PinaVM. Tweto. Conclusion. Dealing with addresses Statically 0x6000 0x5000. CPU. RAM. .... socket.write(0x1000,data); ... Follow path to bus Get actual port addr from PinaVM. Find function in target module. 0x3000 T2 0x2000 0x1000 Address T1 0x0000 Decoding. Bus. Find target socket at this address. RAM status write(addr,data) { mem[addr] = data; }. Possible optimizations: I I. Replace call to socket.write() with RAM.write() Possibly inline it. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 48 / 53 >.

(86) SystemC. Overview. PinaVM. Tweto. Conclusion. Optimizing Register Banks // typical code executed when receiving transaction status target::write(addr, data) { switch(addr) { case REG_1: f(); break; case REG_2: g(); break; default: return TLM_ADDRESS_ERROR_RESPONSE; } return TLM_OK_RESPONSE; } ⇒ Accesses to constant addresses could execute f or g directly Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 49 / 53 >.

(87) SystemC. Overview. PinaVM. Tweto. Conclusion. Summary. 1. SystemC and Transaction Level Modeling. 2. Overview of PinaVM and Tweto. 3. PinaVM: a SystemC Front-End. 4. Tweto: TLM With Elaboration-Time Optimizations. 5. Conclusion. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 50 / 53 >.

(88) SystemC. Overview. PinaVM. Tweto. Conclusion. This section. 5. Conclusion. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 51 / 53 >.

(89) SystemC. Overview. PinaVM. Tweto. Conclusion. PinaVM and Tweto PinaVM (front-end): prototype implemented (Kevin Marquet, Post-Doc Verimag; myself when I have time) Tweto (optimizer): work in progress (Claude Helmstetter, Post-doc LIAMA; Si-Mohamed Lamraoui, TER M1 Verimag) Other back-ends for PinaVM: I. I. I. Promela: model-checking with SPIN (prototype; Kevin Marquet) Simple: abstract interpretation with ConcurInterproc (draft; Kevin Marquet) 42: Control Contracts (draft; Pierre-Yves Delahaye, TER Ensimag). Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 52 / 53 >.

(90) SystemC. Overview. PinaVM. Tweto. Conclusion. Thank you. Questions?. http://gitorious.org/pinavm/pages/Home. Matthieu Moy (Verimag). PinaVM and Tweto. Journées compil’, 04/2011. < 53 / 53 >.

(91)

Références

Documents relatifs

Note: Unlike the PRELOAD command, the old PRLDF command determined the value of outputs not registers. The example below shows a partial simulation segment for a PALCE16V8.

The contributions of this paper are the following: • A novel approach for the development of SystemC frontends, relying on a just-in-time compiler JIT compiler to execute fragments

The original triage nurse came in, took out Ben’s IV line, and gave us a dose of oral ondansetron in a syringe to take home,. “just in case.” “The best thing for rotavirus!”

In the in-between states, we are then proving two simulation diagrams at once: each of these states is related both to the Anchor (in dashed lines), and to a corresponding state

(Note, however, that the CPU may be interrupted with a Non-Maskable interrupt from a separate source. This simply inserts a pause into the process of reading data from the HPC.

The opening section of a .jacc file is a sequence of directives that can be used to customize certain aspects of the generated Java source file (Section 3.1.1), to specify the

Comme le suggère Laurent Siproudhis d ’ emblée dans le titre de son dernier éditorial pour la revue Colon &amp; Rectum (vous noterez en passant la grande souplesse d ’ esprit de

However, since Python also allows execution of code at load time (or rather, since there is no clear distinction between ‘run time’ and ‘load time’), we can apply the same library