Post on 24-Jun-2020
transcript
CornellUniversityComputerSystemsLaboratory
Pydgin for RISC-V:A Fast and Productive Instruction-Set Simulator
Berkin Ilbeyi
In collaboration with Derek Lockhart (Google), and Christopher Batten
3rd RISC-V Workshop, Jan 2016
Cornell UniversityComputer Systems Laboratory
Motivation
Instruction-SetSimulator
Software
Hardware
1-10 MIPS (1-10 days)100s MIPS (1-3 hours)1000 MIPS (0.5 hours)
PerformanceProductivity- Develop- Extend- Instrument
Interpretive:Typical DBT:QEMU DBT:
RISC-VFoundation
RISC-V
SpecializedRISC-V
SpecializedRISC-V
1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
PerformanceProductivity
InstructionSetInterpreterinC
withDBT
DynamicLanguageInterpreterinCwithJITCompiler
[SimIt-ARM2006][Wagstaff2013]
ArchitecturalDescriptionLanguage
KeyInsight:
Similarproductivity-performancechallengesforbuildinghigh-performanceinterpretersof
dynamiclanguages.(e.g.JavaScript,Python)
2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
PerformanceProductivity
RPythonTranslationToolchain
[SimIt-ARM2006][Wagstaff2013]
InstructionSetInterpreterinC
withDBT
Dynamic-LanguageInterpreterinRPython
DynamicLanguageInterpreterinCwithJITCompiler
ArchitecturalDescriptionLanguage
Meta-TracingJIT:makesJITgenerationgenericacrosslanguages
2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
PerformanceProductivity
RPythonTranslationToolchain
InstructionSetInterpreterinC
withDBT
ArchitecturalDescriptionLanguage
Pydgin
2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
JIT≈DBT
Pydgin Architecture Description Language
3/16
Architectural StateInstruction EncodingInstruction Semantics
State
Encoding Semantics
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Architecture Description Language
class State( object ):
def __init__( self, memory, reset_addr=0x400 ):
self.pc = reset_addrself.rf = RiscVRegisterFile()self.mem = memory
# optional state if floating point is enabledif ENABLE_FP:
self.fp = RiscVFPRegisterFile() self.fcsr = 0
4/16
Architectural StateState
Encoding Semantics
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Architecture Description Language
encodings = [# ...
['xori', 'xxxxxxxxxxxxxxxxx100xxxxx0010011'], ['ori', 'xxxxxxxxxxxxxxxxx110xxxxx0010011'], ['andi', 'xxxxxxxxxxxxxxxxx111xxxxx0010011'], ['slli', '000000xxxxxxxxxxx001xxxxx0010011'], ['srli', '000000xxxxxxxxxxx101xxxxx0010011'], ['srai', '010000xxxxxxxxxxx101xxxxx0010011'], ['add', '0000000xxxxxxxxxx000xxxxx0110011'], ['sub', '0100000xxxxxxxxxx000xxxxx0110011'], ['sll', '0000000xxxxxxxxxx001xxxxx0110011'],
# ...]
5/16
Instruction EncodingState
Encoding Semantics
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Architecture Description Language
def execute_addi( s, inst ):s.rf[inst.rd] = s.rf[inst.rs1] + inst.i_imms.pc += 4
def execute_sw( s, inst ):addr = trim_xlen( s.rf[inst.rs1] + inst.s_imm )s.mem.write( addr, 4, trim_32( s.rf[inst.rs2] ) )s.pc += 4
def execute_beq( s, inst ):if s.rf[inst.rs1] == s.rf[inst.rs2]: s.pc = trim_xlen( s.pc + inst.sb_imm )
else:s.pc += 4
6/16
Instruction SemanticsState
Encoding Semantics
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Framework
7/16
def instruction_set_interpreter( memory ):state = State( memory )
while True:
pc = state.fetch_pc()
inst = memory[ pc ] # fetchexecute = decode( inst ) # decodeexecute( state, inst ) # execute
State
PydginFramework
Encoding Semantics
Interpreter Loop
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Framework
7 /16
State
PydginFramework
DebugonPython
Interpreter
Encoding Semantics def instruction_set_interpreter( memory ):state = State( memory )
while True:
pc = state.fetch_pc()
inst = memory[ pc ] # fetchexecute = decode( inst ) # decodeexecute( state, inst ) # execute
Interpreter Loop
100KIPS
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
The RPython Translation Toolchain
8/16
RPython�Source
Type�Inference
Op�miza�on
Code�Genera�on
Compila�on
Compiled�Interpreter
State
PydginFramework
RPythonTranslationToolchain
DebugonPython
Interpreter
Encoding Semantics
100KIPS
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
The RPython Translation Toolchain
8/16
RPython�Source
Type�Inference
Op�miza�on
Code�Genera�on
Compila�on
Compiled�Interpreter
State
PydginFramework
RPythonTranslationToolchain
DebugonPython
Interpreter
PydginInterpretiveSimulator
Encoding Semantics
100KIPS
10MIPS
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
The RPython Translation Toolchain
8/16
RPython�Source
Type�Inference
Op�miza�on
Code�Genera�on
Compila�on
JIT�Generator
Compiled�Interpreter�with�JIT
State
PydginFramework
RPythonTranslationToolchain
DebugonPython
Interpreter
PydginInterpretiveSimulator
Encoding Semantics
100KIPS
10MIPS
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
The RPython Translation Toolchain
8/16
RPython�Source
Type�Inference
Op�miza�on
Code�Genera�on
Compila�on
JIT�Generator
Compiled�Interpreter�with�JIT
State
PydginFramework
RPythonTranslationToolchain
DebugonPython
Interpreter
PydginInterpretiveSimulator
PydginDBT
Simulator
Encoding Semantics
100KIPS
10MIPS <10MIPS
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
JIT Annotations and Optimizations
9/16
State
PydginFramework+JITAnnot.
RPythonTranslationToolchain
DebugonPython
Interpreter
PydginInterpretiveSimulator
PydginDBT
Simulator
Encoding Semantics
100KIPS
10MIPS 100+MIPS
Additional RPython JIT hints:
+ Elidable Instruction Fetch+ Elidable Decode+ Constant Promotion of PC and Memory+ Word-Based Target Memory+ Loop Unrolling in Instruction Semantics+ Virtualizable PC and Statistics+ Increased Trace Limit
SPECINT2006onARM
23X improvementover no annotations
Please see our ISPASS paperfor more details!
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Performance
10/16
Spike is an interpretive simulator with some advanced DBT features:
- Caching decoded instructions
- PC-indexed dispatch
RISC-V QEMU port was out-of-date at the time of our development
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Productivity
11/16
RISC-V encourages ISA extensions.
- Productive Development- Productive Extensibility- Productive Instrumentation
RISC-VFoundation
RISC-V
SpecializedRISC-V
SpecializedRISC-V
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin RISC-V Development
12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin RISC-V Development
12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
100+ MIPS simulatorafter 9 days of development!
Pydgin Extensibility
encodings = [# ...['andi', 'xxxxxxxxxxxxxxxxx111xxxxx0010011'], ['slli', '000000xxxxxxxxxxx001xxxxx0010011'], ['srli', '000000xxxxxxxxxxx101xxxxx0010011'], ['srai', '010000xxxxxxxxxxx101xxxxx0010011'], ['add', '0000000xxxxxxxxxx000xxxxx0110011'],# ... ['gcd', 'xxxxxxxxxxxxxxxxx000xxxxx1011011'],# ...
]
# greatest common divisor semanticsdef execute_gcd( s, inst ):
a, b = s.rf[inst.rs1], s.rf[inst.rs2]while b:a, b = b, a%b
s.rf[inst.rd] = as.pc += 4
13/16
State
PydginFramework+JITAnnot.
RPythonTranslationToolchain
DebugonPython
Interpreter
PydginInterpretiveSimulator
PydginDBT
Simulator
Encoding Semantics
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin Instrumentation
# count number of addsdef execute_addi( s, inst ):
s.rf[inst.rd] = s.rf[inst.rs1] + inst.i_imms.num_adds += 1s.pc += 4
# count misaligned storesdef execute_sw( s, inst ):
addr = trim_xlen( s.rf[inst.rs1] + inst.s_imm )if addr % 4 != 0: s.num_misaligned += 1s.mem.write( addr, 4, trim_32( s.rf[inst.rs2] ) )s.pc += 4
# record and count all executed loopsdef execute_beq( s, inst ):
if s.rf[inst.rs1] == s.rf[inst.rs2]:old_pc = s.pcs.pc = trim_xlen( s.pc + inst.sb_imm )if s.pc <= old_pc: s.loops[(s.pc, old_pc)] += 1
else:s.pc += 4
14/16
State
PydginFramework+JITAnnot.
RPythonTranslationToolchain
DebugonPython
Interpreter
PydginInterpretiveSimulator
PydginDBT
Simulator
Encoding Semantics
Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Pydgin in Our Research Group
• Statistics for software-defined regions• Data-structure specialization experimentation• Control- and memory-divergence for SIMD• Basic Block Vector generation for SimPoint• Analysis of JIT-enabled dynamic language interpreters
15/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator
Conclusions
Pydgin leverages the RPython translation toolchain into high-performance, DBT Instruction Set Simulator.
Pydgin provides a succinct architecture description language within Python to give users a productive development, extension, and instrumentation experience.
Current State: RV64IMAFD (RV64G) Bare-Metal on 64-bit host
https://github.com/cornell-brg/pydgin
Thank you to our sponsors for their support: NSF, DARPA, and donations from Intel Corporation and
Synopsys, Inc.
Pydgin
16/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator