SlideShare a Scribd company logo
Simulating a CPU
with Python
or: surprising programs
you might have thought
were better written in C
Sarah Mount @snim2
Data from Stanford VLSI Group CPUdb
Left: late 1980s INMOS Transputer (image © Konstantin
Lanzet - CPU collection. Licensed under CC BY 3.0 via
Wikimedia Commons)
Right: a 2011 Parallella board, the spiritual successor to
the INMOS Transputer (image © Adapteva Inc)
Adapteva Epiphany III chip
A new style of energy-efficient manycore
computer?
● 16 / 64 cores, theoretical maximum of 4095 cores
● 1 GHz
● <2 Watts
● Whole Parallella board: 5 Watts
● 19 GFLOPS / Watt
● 32 kB RAM / core
Packing code into that small space
● Most 32-bit Epiphany core instructions have
a 16-bit equivalent
● Compiler chooses the 16-bit instruction
whenever possible
Derek Lockhart, Berkin Ilbeyi, and Christopher Batten. (2015) Pydgin: Generating Fast Instruction Set
Simulators from Simple Architecture Descriptions with Meta-Tracing JIT Compilers. IEEE International
Symposium on Performance Analysis of Systems and Software (ISPASS).
Revelation: a new Epiphany sim
● Written using the Pydgin framework in
RPython (statically typed Python)
● All instructions implemented except some
multicore
● Small code base: ~1k Source Lines of Code
● http://www.revelation-sim.org/
Still a work in progress though (i.e. don’t expect
it to work!)
● Clone pypy:
$ hg clone https://bitbucket.org/pypy/pypy
● Clone Pydgin:
$ git clone ...github.com/cornell-brg/pydgin.git
● Put Pydgin on your PYTHONPATH:
$ export PYTHONPATH=${PYTHONPATH}:.../pydgin/:
● Write a simple simulator!
Write your own Pydgin simulator!
Instruction model
Decode and implementation (add32)
Machine model
Simulator
Some oddities about the Epiphany
● The chip has a flat memory map. Everything
(registers, flags) is a location in RAM.
● Each core has 32kB local memory,
addressed as 0x0…0xFFFFF
● The same memory can be globally
addressed, and accessed by other cores, as
(COREID << 20) | local address, e.g.
0xF0408 (the PC) is globally 0x808F0408
for chip 0x808 (on row 32, column 8 of the
chip.
More oddities
● There are many instructions, almost all of
which have 16-bit and 32-bit versions. This
could lead to duplicate code.
● Thankfully, we can use closures to create all
the versions of an instruction implementation
that we need in one go:
Implementation of JUMP instructions
Test, compile, iterate
To compile your simulator (with a JIT):
$ .../rpython/bin/rpython -Ojit sim.py
To compile with the ability to print an instruction
trace:
$ .../rpython/bin/rpython -Ojit sim.py
--debug
Test, compile, iterate
To run your simulator:
$ ./pydgin-sim-jit --help
Then iterate!
But you said TEST, compile, iterate!
● Compiling is slow, so you want to avoid
compiling every time you make a change to
the code base
● That means you want to test your RPython
code dynamically (untranslated)
● Because RPython is a subset of Python, you
can use Python test tools, such as py.test,
which means you can unit tests your
untranslated simulator
Unit tests
● “Proper” unit tests, which test small program
units (such as a single instruction)
● The Epiphany Architecture Reference
Manual has many examples (1 or more for
each instruction). Each of these is written
into an assembler file and used as the basis
of a (more complex) unit test.
● Currently >500 unit and integration tests in
Revelation, testing a very tiny part of the
state space!
A “basic” unit test
An assembler file
A unit test to go with the assembler
Integration tests
● Integration tests typically load and execute a
full ELF file (compiled from C code). They
then check one or more of:
○ The machine state
○ The number of instructions executed
○ Output on STDOUT
● ELF files need to be cross-compiled with the
Epiphany SDK (e-gcc, etc.) and so are
checked into version control
Hello, world!
“Hello, world!” the integration test
Using a test oracle
● A test oracle is a source of truth, for example
an existing, complete simulator
● Adapteva e-sim:
○ https://github.com/adapteva/epiphany-cgen
○ https://github.com/adapteva/epiphany-gdb
e-sim trace file (4.5MB, 46265 lines)
0x000000 b.l 0x0000000000000100 - pc <-
0x100
0x000100 mov.l r3,0x138 - registers <-
0x138
0x000104 movt r3,0x0 - registers <-
0x138
0x000108 jalr r3 - registers <-
0x10a, pc <- 0x138
0x000138 --- _epiphany_star mov.l sp,0x7ff0 - registers <-
0x7ff0
0x00013c --- _epiphany_star movt sp,0x0 - registers <-
0x7ff0
0x000140 --- _epiphany_star mov.l fp,0x0 - registers <-
0x0
0x000144 --- _epiphany_star mov.l r0,0x58 - registers <-
0x58
0x000148 --- _epiphany_star movt r0,0x0 - registers <-
0x58
Revelation trace (6.7MB, 46096 lines)
0 000080e8 bcond32 0 AN=False AZ=False
AC=False AV=False AVS=False BN=False BZ=False BIS=False
BUS=False BV=False BVS=False
100 0012670b movimm32 1 :: WR.RF[3 ] = 00000138
104 1002600b movtimm32 2 :: RD.RF[3 ] = 00000138
:: WR.RF[3 ] = 00000138
108 00000d52 jalr16 3 :: WR.RF[14] = 0000010a
:: RD.RF[3 ] = 00000138
138 27f2be0b movimm32 4 :: WR.RF[13] = 00007ff0
13c 3002a00b movtimm32 5 :: RD.RF[13] = 00007ff0
:: WR.RF[13] = 00007ff0
140 2002e00b movimm32 6 :: WR.RF[15] = 00000000
144 00020b0b movimm32 7 :: WR.RF[0 ] = 00000058
148 1002000b movtimm32 8 :: RD.RF[0 ] = 00000058
:: WR.RF[0 ] = 00000058
Example trace diff (4.MB, 51845 lines)
Semantics of instruction at 0x44e differ:
Revelation: 44e 2f8b0417 fsub16 35097 :: RD.RF[0
] = 3f800000 :: RD.RF[1 ] = 5f800000 :: RD.RF[0 ] = 3f800000 ::
WR.RF[0 ] = 5f800000 :: RD.RF[0 ] = 5f800000 :: RD.RF[0 ] =
5f800000 :: RD.RF[1 ] = 5f800000 :: RD.RF[0 ] = 5f800000
AN=False AZ=False AC=False AV=False AVS=True BN=False BZ=False
BIS=False BUS=False BV=False BVS=False
e-sim: 0x00044e --- main fsub r0,r1,r0 -
bzbit <- 0x0, bnbit <- 0x0, bvbit <- 0x0, bvsbit <- 0x0, busbit
<- 0x0, bisbit <- 0x0, registers <- 0x5f7fffff
Registers differ. Revelation: rf<-0x5f800000 e-sim: rf<-0x5f7fffff
Semantics of instruction at 0x8e006d1e differ:
Revelation: 8e006d4c 0652268b movimm32 35845 :: WR.RF[1
] = 00006534
e-sim: 0x8e006d1e mov.l r1,0x6534
- registers <- 0x6534
Program counters differ. Revelation: 0x8e006d4c, e-sim: 0x8e006d1e
A specious difference between traces
Semantics of instruction at 0x8e009980 differ:
Revelation: 8e009980 6dda1fe2 trap16 990 :: RD.RF[3
] = 00000005 :: RD.RF[0 ] = 00000001 :: RD.RF[1 ] = 8f000008 ::
RD.RF[2 ] = 00000001 :: WR.RF[0 ] = 000
00001 :: WR.RF[3 ] = 00000000
e-sim: 0x8e009980 trap 0x7
- registers <- 0x1
Registers differ. Revelation: rf<-0x0 rf<-0x1 e-sim: rf<-0x1
A simple logger
Things I haven’t tried but might...
● American Fuzzy Lop:
○ http://lcamtuf.coredump.cx/afl/
● Hypothesis
○ http://hypothesis.works/
● ...any other form of automated testing
Thank you.
Opcode factory
New state with given contents
State checker
Using the state checker
Mock simulator
Using the mock simulator

More Related Content

What's hot

An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
RISC-V International
 
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
Hsien-Hsin Sean Lee, Ph.D.
 
Multi-threading your way out
Multi-threading your way outMulti-threading your way out
Multi-threading your way out
.NET Crowd
 
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Anne Nicolas
 
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
Hsien-Hsin Sean Lee, Ph.D.
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF Primer
Sasha Goldshtein
 
BPF - All your packets belong to me
BPF - All your packets belong to meBPF - All your packets belong to me
BPF - All your packets belong to me
_xhr_
 
Code gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introductionCode gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introduction
Marina Kolpakova
 
igorFreire_UCI_real-time-dsp_reports
igorFreire_UCI_real-time-dsp_reportsigorFreire_UCI_real-time-dsp_reports
igorFreire_UCI_real-time-dsp_reportsIgor Freire
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
Taeung Song
 
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Hsien-Hsin Sean Lee, Ph.D.
 
Code GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flowCode GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flow
Marina Kolpakova
 
How Functions Work
How Functions WorkHow Functions Work
How Functions Work
Saumil Shah
 
Code GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemCode GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory Subsystem
Marina Kolpakova
 
Moving NEON to 64 bits
Moving NEON to 64 bitsMoving NEON to 64 bits
Moving NEON to 64 bits
Chiou-Nan Chen
 
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V International
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshopjvehent
 
The Parrot VM
The Parrot VMThe Parrot VM
The Parrot VM
François Perrad
 
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- MulticoreLec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Hsien-Hsin Sean Lee, Ph.D.
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
RISC-V International
 

What's hot (20)

An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
 
Multi-threading your way out
Multi-threading your way outMulti-threading your way out
Multi-threading your way out
 
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
 
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF Primer
 
BPF - All your packets belong to me
BPF - All your packets belong to meBPF - All your packets belong to me
BPF - All your packets belong to me
 
Code gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introductionCode gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introduction
 
igorFreire_UCI_real-time-dsp_reports
igorFreire_UCI_real-time-dsp_reportsigorFreire_UCI_real-time-dsp_reports
igorFreire_UCI_real-time-dsp_reports
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
 
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
 
Code GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flowCode GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flow
 
How Functions Work
How Functions WorkHow Functions Work
How Functions Work
 
Code GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemCode GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory Subsystem
 
Moving NEON to 64 bits
Moving NEON to 64 bitsMoving NEON to 64 bits
Moving NEON to 64 bits
 
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentor
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshop
 
The Parrot VM
The Parrot VMThe Parrot VM
The Parrot VM
 
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- MulticoreLec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
 

Similar to Revelation pyconuk2016

Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.ppt
AakashRawat35
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
Ray Jenkins
 
Architecture of pentium family
Architecture of pentium familyArchitecture of pentium family
Architecture of pentium family
University of Gujrat, Pakistan
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Jagadisha Maiya
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
Satpal Parmar
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
Andriy Berestovskyy
 
Debugging 2013- Jesper Brouer
Debugging 2013- Jesper BrouerDebugging 2013- Jesper Brouer
Debugging 2013- Jesper Brouer
Mediehuset Ingeniøren Live
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
Talal Khaliq
 
Linux router
Linux routerLinux router
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-optJeff Larkin
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
Kernel TLV
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Assembly Language Paper.docx
Assembly Language Paper.docxAssembly Language Paper.docx
Assembly Language Paper.docx
write22
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
TuynLCh
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
EstelaJeffery653
 
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIWLec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Hsien-Hsin Sean Lee, Ph.D.
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Ikhwan_Fakrudin
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
OsaMa Hasan
 

Similar to Revelation pyconuk2016 (20)

Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.ppt
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Architecture of pentium family
Architecture of pentium familyArchitecture of pentium family
Architecture of pentium family
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
 
Debugging 2013- Jesper Brouer
Debugging 2013- Jesper BrouerDebugging 2013- Jesper Brouer
Debugging 2013- Jesper Brouer
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
 
Linux router
Linux routerLinux router
Linux router
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-opt
 
Highridge ISA
Highridge ISAHighridge ISA
Highridge ISA
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Assembly Language Paper.docx
Assembly Language Paper.docxAssembly Language Paper.docx
Assembly Language Paper.docx
 
Introduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSPIntroduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSP
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
 
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIWLec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
 

More from Sarah Mount

Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in Python
Sarah Mount
 
Jatrobot - real-time farm monitoring
Jatrobot - real-time farm monitoringJatrobot - real-time farm monitoring
Jatrobot - real-time farm monitoring
Sarah Mount
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
Sarah Mount
 
Mining python-software-pyconuk13
Mining python-software-pyconuk13Mining python-software-pyconuk13
Mining python-software-pyconuk13Sarah Mount
 
Marvin the paranoid laptop by his owner snim2
Marvin the paranoid laptop by his owner snim2Marvin the paranoid laptop by his owner snim2
Marvin the paranoid laptop by his owner snim2
Sarah Mount
 
Europython lightening talk_on_open_ihm
Europython lightening talk_on_open_ihmEuropython lightening talk_on_open_ihm
Europython lightening talk_on_open_ihm
Sarah Mount
 
python-csp: bringing OCCAM to Python
python-csp: bringing OCCAM to Pythonpython-csp: bringing OCCAM to Python
python-csp: bringing OCCAM to Python
Sarah Mount
 

More from Sarah Mount (7)

Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in Python
 
Jatrobot - real-time farm monitoring
Jatrobot - real-time farm monitoringJatrobot - real-time farm monitoring
Jatrobot - real-time farm monitoring
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Mining python-software-pyconuk13
Mining python-software-pyconuk13Mining python-software-pyconuk13
Mining python-software-pyconuk13
 
Marvin the paranoid laptop by his owner snim2
Marvin the paranoid laptop by his owner snim2Marvin the paranoid laptop by his owner snim2
Marvin the paranoid laptop by his owner snim2
 
Europython lightening talk_on_open_ihm
Europython lightening talk_on_open_ihmEuropython lightening talk_on_open_ihm
Europython lightening talk_on_open_ihm
 
python-csp: bringing OCCAM to Python
python-csp: bringing OCCAM to Pythonpython-csp: bringing OCCAM to Python
python-csp: bringing OCCAM to Python
 

Recently uploaded

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 

Recently uploaded (20)

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 

Revelation pyconuk2016

  • 1. Simulating a CPU with Python or: surprising programs you might have thought were better written in C Sarah Mount @snim2
  • 2. Data from Stanford VLSI Group CPUdb
  • 3. Left: late 1980s INMOS Transputer (image © Konstantin Lanzet - CPU collection. Licensed under CC BY 3.0 via Wikimedia Commons) Right: a 2011 Parallella board, the spiritual successor to the INMOS Transputer (image © Adapteva Inc)
  • 4. Adapteva Epiphany III chip A new style of energy-efficient manycore computer? ● 16 / 64 cores, theoretical maximum of 4095 cores ● 1 GHz ● <2 Watts ● Whole Parallella board: 5 Watts ● 19 GFLOPS / Watt ● 32 kB RAM / core
  • 5. Packing code into that small space ● Most 32-bit Epiphany core instructions have a 16-bit equivalent ● Compiler chooses the 16-bit instruction whenever possible
  • 6. Derek Lockhart, Berkin Ilbeyi, and Christopher Batten. (2015) Pydgin: Generating Fast Instruction Set Simulators from Simple Architecture Descriptions with Meta-Tracing JIT Compilers. IEEE International Symposium on Performance Analysis of Systems and Software (ISPASS).
  • 7. Revelation: a new Epiphany sim ● Written using the Pydgin framework in RPython (statically typed Python) ● All instructions implemented except some multicore ● Small code base: ~1k Source Lines of Code ● http://www.revelation-sim.org/ Still a work in progress though (i.e. don’t expect it to work!)
  • 8. ● Clone pypy: $ hg clone https://bitbucket.org/pypy/pypy ● Clone Pydgin: $ git clone ...github.com/cornell-brg/pydgin.git ● Put Pydgin on your PYTHONPATH: $ export PYTHONPATH=${PYTHONPATH}:.../pydgin/: ● Write a simple simulator! Write your own Pydgin simulator!
  • 13. Some oddities about the Epiphany ● The chip has a flat memory map. Everything (registers, flags) is a location in RAM. ● Each core has 32kB local memory, addressed as 0x0…0xFFFFF ● The same memory can be globally addressed, and accessed by other cores, as (COREID << 20) | local address, e.g. 0xF0408 (the PC) is globally 0x808F0408 for chip 0x808 (on row 32, column 8 of the chip.
  • 14. More oddities ● There are many instructions, almost all of which have 16-bit and 32-bit versions. This could lead to duplicate code. ● Thankfully, we can use closures to create all the versions of an instruction implementation that we need in one go:
  • 15. Implementation of JUMP instructions
  • 16. Test, compile, iterate To compile your simulator (with a JIT): $ .../rpython/bin/rpython -Ojit sim.py To compile with the ability to print an instruction trace: $ .../rpython/bin/rpython -Ojit sim.py --debug
  • 17. Test, compile, iterate To run your simulator: $ ./pydgin-sim-jit --help Then iterate!
  • 18. But you said TEST, compile, iterate! ● Compiling is slow, so you want to avoid compiling every time you make a change to the code base ● That means you want to test your RPython code dynamically (untranslated) ● Because RPython is a subset of Python, you can use Python test tools, such as py.test, which means you can unit tests your untranslated simulator
  • 19. Unit tests ● “Proper” unit tests, which test small program units (such as a single instruction) ● The Epiphany Architecture Reference Manual has many examples (1 or more for each instruction). Each of these is written into an assembler file and used as the basis of a (more complex) unit test. ● Currently >500 unit and integration tests in Revelation, testing a very tiny part of the state space!
  • 22. A unit test to go with the assembler
  • 23. Integration tests ● Integration tests typically load and execute a full ELF file (compiled from C code). They then check one or more of: ○ The machine state ○ The number of instructions executed ○ Output on STDOUT ● ELF files need to be cross-compiled with the Epiphany SDK (e-gcc, etc.) and so are checked into version control
  • 25. “Hello, world!” the integration test
  • 26. Using a test oracle ● A test oracle is a source of truth, for example an existing, complete simulator ● Adapteva e-sim: ○ https://github.com/adapteva/epiphany-cgen ○ https://github.com/adapteva/epiphany-gdb
  • 27. e-sim trace file (4.5MB, 46265 lines) 0x000000 b.l 0x0000000000000100 - pc <- 0x100 0x000100 mov.l r3,0x138 - registers <- 0x138 0x000104 movt r3,0x0 - registers <- 0x138 0x000108 jalr r3 - registers <- 0x10a, pc <- 0x138 0x000138 --- _epiphany_star mov.l sp,0x7ff0 - registers <- 0x7ff0 0x00013c --- _epiphany_star movt sp,0x0 - registers <- 0x7ff0 0x000140 --- _epiphany_star mov.l fp,0x0 - registers <- 0x0 0x000144 --- _epiphany_star mov.l r0,0x58 - registers <- 0x58 0x000148 --- _epiphany_star movt r0,0x0 - registers <- 0x58
  • 28. Revelation trace (6.7MB, 46096 lines) 0 000080e8 bcond32 0 AN=False AZ=False AC=False AV=False AVS=False BN=False BZ=False BIS=False BUS=False BV=False BVS=False 100 0012670b movimm32 1 :: WR.RF[3 ] = 00000138 104 1002600b movtimm32 2 :: RD.RF[3 ] = 00000138 :: WR.RF[3 ] = 00000138 108 00000d52 jalr16 3 :: WR.RF[14] = 0000010a :: RD.RF[3 ] = 00000138 138 27f2be0b movimm32 4 :: WR.RF[13] = 00007ff0 13c 3002a00b movtimm32 5 :: RD.RF[13] = 00007ff0 :: WR.RF[13] = 00007ff0 140 2002e00b movimm32 6 :: WR.RF[15] = 00000000 144 00020b0b movimm32 7 :: WR.RF[0 ] = 00000058 148 1002000b movtimm32 8 :: RD.RF[0 ] = 00000058 :: WR.RF[0 ] = 00000058
  • 29. Example trace diff (4.MB, 51845 lines) Semantics of instruction at 0x44e differ: Revelation: 44e 2f8b0417 fsub16 35097 :: RD.RF[0 ] = 3f800000 :: RD.RF[1 ] = 5f800000 :: RD.RF[0 ] = 3f800000 :: WR.RF[0 ] = 5f800000 :: RD.RF[0 ] = 5f800000 :: RD.RF[0 ] = 5f800000 :: RD.RF[1 ] = 5f800000 :: RD.RF[0 ] = 5f800000 AN=False AZ=False AC=False AV=False AVS=True BN=False BZ=False BIS=False BUS=False BV=False BVS=False e-sim: 0x00044e --- main fsub r0,r1,r0 - bzbit <- 0x0, bnbit <- 0x0, bvbit <- 0x0, bvsbit <- 0x0, busbit <- 0x0, bisbit <- 0x0, registers <- 0x5f7fffff Registers differ. Revelation: rf<-0x5f800000 e-sim: rf<-0x5f7fffff Semantics of instruction at 0x8e006d1e differ: Revelation: 8e006d4c 0652268b movimm32 35845 :: WR.RF[1 ] = 00006534 e-sim: 0x8e006d1e mov.l r1,0x6534 - registers <- 0x6534 Program counters differ. Revelation: 0x8e006d4c, e-sim: 0x8e006d1e
  • 30. A specious difference between traces Semantics of instruction at 0x8e009980 differ: Revelation: 8e009980 6dda1fe2 trap16 990 :: RD.RF[3 ] = 00000005 :: RD.RF[0 ] = 00000001 :: RD.RF[1 ] = 8f000008 :: RD.RF[2 ] = 00000001 :: WR.RF[0 ] = 000 00001 :: WR.RF[3 ] = 00000000 e-sim: 0x8e009980 trap 0x7 - registers <- 0x1 Registers differ. Revelation: rf<-0x0 rf<-0x1 e-sim: rf<-0x1
  • 32. Things I haven’t tried but might... ● American Fuzzy Lop: ○ http://lcamtuf.coredump.cx/afl/ ● Hypothesis ○ http://hypothesis.works/ ● ...any other form of automated testing
  • 35. New state with given contents
  • 37. Using the state checker
  • 39. Using the mock simulator