SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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 _ ClaireRISC-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 part3Hsien-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 PrimerSasha 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 introductionMarina 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월 세미나 KossLabTaeung 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 flowMarina Kolpakova
 
How Functions Work
How Functions WorkHow Functions Work
How Functions WorkSaumil Shah
 
Code GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemCode GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemMarina Kolpakova
 
Moving NEON to 64 bits
Moving NEON to 64 bitsMoving NEON to 64 bits
Moving NEON to 64 bitsChiou-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_mentorRISC-V International
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshopjvehent
 
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 -- MulticoreHsien-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 processorsRISC-V International
 

La actualidad más candente (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 a Revelation pyconuk2016

Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.pptAakashRawat35
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
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 DriversSatpal Parmar
 
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
 
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
 
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 IntegrationTalal Khaliq
 
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 & BCCKernel 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 DisassemblyPriyanka Aash
 
Assembly Language Paper.docx
Assembly Language Paper.docxAssembly Language Paper.docx
Assembly Language Paper.docxwrite22
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxTuynLCh
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuEstelaJeffery653
 
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 VLIWHsien-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 + mappingOsaMa Hasan
 

Similar a 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
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
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
 
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
 

Más de Sarah Mount

Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in PythonSarah Mount
 
Jatrobot - real-time farm monitoring
Jatrobot - real-time farm monitoringJatrobot - real-time farm monitoring
Jatrobot - real-time farm monitoringSarah 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 snim2Sarah Mount
 
Europython lightening talk_on_open_ihm
Europython lightening talk_on_open_ihmEuropython lightening talk_on_open_ihm
Europython lightening talk_on_open_ihmSarah Mount
 
python-csp: bringing OCCAM to Python
python-csp: bringing OCCAM to Pythonpython-csp: bringing OCCAM to Python
python-csp: bringing OCCAM to PythonSarah Mount
 

Más de 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
 

Último

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 

Último (20)

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 

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