67
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 University Computer Systems Laboratory

Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 2: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Motivation

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator 1 /16

Instruction-SetArchitecture

Software

Hardware

Page 3: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Motivation

1 /16

Instruction-SetSimulator

Software

Hardware

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 4: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Motivation

Instruction-SetSimulator

Software

Hardware

1-10 MIPS (1-10 days)Performance

Interpretive:

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 5: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Motivation

Instruction-SetSimulator

Software

Hardware

1-10 MIPS (1-10 days)100s MIPS (1-3 hours)

PerformanceInterpretive:Typical DBT:

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 6: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Motivation

Instruction-SetSimulator

Software

Hardware

1-10 MIPS (1-10 days)100s MIPS (1-3 hours)1000 MIPS (0.5 hours)

PerformanceInterpretive:Typical DBT:QEMU DBT:

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 7: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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:

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 8: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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:

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 9: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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:

Vendor

ProprietaryISA

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 10: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

1 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 11: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 12: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

2 /16

PerformanceProductivity

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 13: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

ArchitecturalDescriptionLanguage

InstructionSetInterpreterinC

withDBT

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 14: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

ArchitecturalDescriptionLanguage

InstructionSetInterpreterinC

withDBT

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 15: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

ArchitecturalDescriptionLanguage

InstructionSetInterpreterinC

withDBT

[SimIt-ARM2006][Wagstaff2013]

[Simit-ARM2006] J.D’Errico andW.Qin.ConstructingPortableCompiled Instruction-SetSimulators— AnADL-DrivenApproach.DATE’06.[Wagstaff2013] H.Wagstaff,M.Gould,B.Franke,andN.Topham.EarlyPartialEvaluationinaJIT-Compiled,Retargetable Instruction

SetSimulatorGeneratedfromaHigh-LevelArchitectureDescription.DAC’13.

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 16: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

InstructionSetInterpreterinC

withDBT

DynamicLanguageInterpreterinCwithJITCompiler

[SimIt-ARM2006][Wagstaff2013]

ArchitecturalDescriptionLanguage

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 17: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

InstructionSetInterpreterinC

withDBT

DynamicLanguageInterpreterinCwithJITCompiler

[SimIt-ARM2006][Wagstaff2013]

ArchitecturalDescriptionLanguage

KeyInsight:

Similarproductivity-performancechallengesforbuildinghigh-performanceinterpretersof

dynamiclanguages.(e.g.JavaScript,Python)

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 18: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

InstructionSetInterpreterinC

withDBT

DynamicLanguageInterpreterinCwithJITCompiler

[SimIt-ARM2006][Wagstaff2013]

ArchitecturalDescriptionLanguage

KeyInsight:

Similarproductivity-performancechallengesforbuildinghigh-performanceinterpretersof

dynamiclanguages.(e.g.JavaScript,Python)

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 19: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

RPythonTranslationToolchain

[SimIt-ARM2006][Wagstaff2013]

InstructionSetInterpreterinC

withDBT

Dynamic-LanguageInterpreterinRPython

DynamicLanguageInterpreterinCwithJITCompiler

ArchitecturalDescriptionLanguage

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 20: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

RPythonTranslationToolchain

[SimIt-ARM2006][Wagstaff2013]

InstructionSetInterpreterinC

withDBT

Dynamic-LanguageInterpreterinRPython

DynamicLanguageInterpreterinCwithJITCompiler

ArchitecturalDescriptionLanguage

Meta-TracingJIT:makesJITgenerationgenericacrosslanguages

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 21: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

RPythonTranslationToolchain

InstructionSetInterpreterinC

withDBT

ArchitecturalDescriptionLanguage

Pydgin

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 22: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

PerformanceProductivity

RPythonTranslationToolchain

InstructionSetInterpreterinC

withDBT

ArchitecturalDescriptionLanguage

Pydgin

2 /16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

JIT≈DBT

Page 23: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Architecture Description Language

3/16

Architectural StateInstruction EncodingInstruction Semantics

State

Encoding Semantics

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 24: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 25: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 26: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 27: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 28: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 29: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

The RPython Translation Toolchain

8/16

RPythonSource

TypeInference

Op�miza�on

CodeGenera�on

Compila�on

CompiledInterpreter

State

PydginFramework

RPythonTranslationToolchain

DebugonPython

Interpreter

Encoding Semantics

100KIPS

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 30: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

The RPython Translation Toolchain

8/16

RPythonSource

TypeInference

Op�miza�on

CodeGenera�on

Compila�on

CompiledInterpreter

State

PydginFramework

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

Encoding Semantics

100KIPS

10MIPS

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 31: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

The RPython Translation Toolchain

8/16

RPythonSource

TypeInference

Op�miza�on

CodeGenera�on

Compila�on

JITGenerator

CompiledInterpreterwithJIT

State

PydginFramework

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

Encoding Semantics

100KIPS

10MIPS

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 32: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

The RPython Translation Toolchain

8/16

RPythonSource

TypeInference

Op�miza�on

CodeGenera�on

Compila�on

JITGenerator

CompiledInterpreterwithJIT

State

PydginFramework

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

PydginDBT

Simulator

Encoding Semantics

100KIPS

10MIPS <10MIPS

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 33: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

SPECINT2006onARMPydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 34: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 35: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Performance

10/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 36: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Performance

10/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 37: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Performance

10/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 38: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Performance

10/16

Spike is an interpretive simulator with some advanced DBT features:

- Caching decoded instructions

- PC-indexed dispatch

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 39: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 40: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Productivity

11/16

RISC-V encourages ISA extensions.

RISC-VFoundation

RISC-V

SpecializedRISC-V

SpecializedRISC-V

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 41: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 42: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 43: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 44: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 45: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 46: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 47: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 48: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 49: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 50: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 51: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin RISC-V Development

12/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

100+ MIPS simulatorafter 9 days of development!

Page 52: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Extensibility

encodings = [# ...['andi', 'xxxxxxxxxxxxxxxxx111xxxxx0010011'], ['slli', '000000xxxxxxxxxxx001xxxxx0010011'], ['srli', '000000xxxxxxxxxxx101xxxxx0010011'], ['srai', '010000xxxxxxxxxxx101xxxxx0010011'], ['add', '0000000xxxxxxxxxx000xxxxx0110011'],# ... ['custom2', 'xxxxxxxxxxxxxxxxx000xxxxx1011011'], # ...

]

# greatest common divisor semanticsdef execute_gcd( s, inst ):

13/16

State

PydginFramework+JITAnnot.

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

PydginDBT

Simulator

Encoding Semantics

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 53: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Extensibility

encodings = [# ...['andi', 'xxxxxxxxxxxxxxxxx111xxxxx0010011'], ['slli', '000000xxxxxxxxxxx001xxxxx0010011'], ['srli', '000000xxxxxxxxxxx101xxxxx0010011'], ['srai', '010000xxxxxxxxxxx101xxxxx0010011'], ['add', '0000000xxxxxxxxxx000xxxxx0110011'],# ... ['gcd', 'xxxxxxxxxxxxxxxxx000xxxxx1011011'],# ...

]

# greatest common divisor semanticsdef execute_gcd( s, inst ):

13/16

State

PydginFramework+JITAnnot.

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

PydginDBT

Simulator

Encoding Semantics

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 54: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 55: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin Instrumentation

# count number of addsdef execute_addi( s, inst ):

s.rf[inst.rd] = s.rf[inst.rs1] + inst.i_imm

s.pc += 4

# count misaligned storesdef 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

# record and count all executed loopsdef 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

14/16

State

PydginFramework+JITAnnot.

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

PydginDBT

Simulator

Encoding Semantics

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 56: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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 )

s.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]:

s.pc = trim_xlen( s.pc + inst.sb_imm )

else:s.pc += 4

14/16

State

PydginFramework+JITAnnot.

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

PydginDBT

Simulator

Encoding Semantics

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 57: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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]:

s.pc = trim_xlen( s.pc + inst.sb_imm )

else:s.pc += 4

14/16

State

PydginFramework+JITAnnot.

RPythonTranslationToolchain

DebugonPython

Interpreter

PydginInterpretiveSimulator

PydginDBT

Simulator

Encoding Semantics

Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 58: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 59: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin in Our Research Group

• Statistics for software-defined regions

15/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 60: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin in Our Research Group

• Statistics for software-defined regions• Data-structure specialization experimentation

15/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 61: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Pydgin in Our Research Group

• Statistics for software-defined regions• Data-structure specialization experimentation• Control- and memory-divergence for SIMD

15/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 62: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

15/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 63: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

Page 64: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

Conclusions

Pydgin leverages the RPython translation toolchain into high-performance, DBT Instruction Set Simulator.

16/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 65: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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.

16/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 66: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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

16/16Pydgin forRISC-V:AFastandProductiveInstruction-SetSimulator

Page 67: Pydginfor RISC-V: A Fast and Productive Instruction …...Cornell University Computer Systems Laboratory Pydginfor RISC-V: A Fast and Productive Instruction -Set Simulator Berkin Ilbeyi

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