CPU Experiment at the University of Tokyo
"CPU Experiment" at the University of Tokyo (UT) CS undergrad course is one of the most famous (either in a good way or bad way) programmes among those who are concerned. Here, I want to introduce what the programme is, and what kind of exciting stuff are going on there.
I note in passing that this is NOT based on my personal experience because I was not a CS student at UT. So apologies if I'm not very accurate in some details but I hope I don't miss the big picture.
What's CPU Experiment
The programme is held in the autumn-winter term in the third year. CS undergrads are divided into a group of 3–5 people, and they'll be given a credit if they can successfully run the ray-tracing app written in MinCaml (a subset of OCaml), which is handed out at the introduction, at the end term presentation.
The rules and conditions have changed over time but basically what they need to do are:
- define ISA (original or based on PowerPC, MIPS, RISC-V, etc.)
- build a CPU core on a provided FPGA (KCU105)
- write an assembler
- extend a MinCaml compiler so it can compile the given ray-tracing app
- write a simulator to debug the compiler/assembler
- compile & run the required ray-tracing app on the self-built CPU
Each team member is assigned to one of the four tasks: CPU (core), FPU, simulator, and compiler. Conventionally the assembler seems to be done by a member who is responsible for the simulator.
What's cool about this on-the-job style programme I think is not only you can learn how to integrate the computer science knowledge you learned through the course, but also you need to finish the project in time collaborating with other team members.
That's not the end of the story
This is where things get even more exciting.
For most of them it's not very difficult to run the required ray-tracing app, and actually they succeed in running the app in less than 3months.
How do they spend the rest of the term?
It's up to them how to use the time: Most of the teams try to optimise the system to amaze people by how fast they can run the app at the end term presentation.
The optimisation ideas include:
- design richer ISA
- introduce pipelining
- optimise compiler to reduce the number of instructions
- and so on
The current record seems to be 5s, which was made in 2017(*), and generally speaking under 20s is considered to be brazing fast.
(* The team realised multi-core CPU & the compiler that utilises it.)
However, some teams decide to venture into the wild adventure…
Creative (crazy) ideas they try
As long as the ray-tracing app works, you can be credited for the course. There's nothing to prevent them from tackling their creative ideas such as:
- run an OS such as xv6, Linux, or even write an original OS
- run the ray-tracing app on the OS
- implement a single instruction that runs the ray-tracing
There are lots of things involved to achieve these: To run an OS you'll need much richer ISA than just running the ray-tracing app. If you want to run the existing OS written in C on your original ISA, you'll need a C compiler that targets the ISA …and so on.
Some of them were realised by their exhaustive effort, while the others are yet to come true. So exciting, aren't they?
Why am I writing this?
Some may wonder why I'm writing a post to introduce something I didn't do. Well, there are two reasons:
First of all, I think the programme is very cool and worth sharing. There are lots of blog posts written by students but most of them are in Japanese (see the next section), and only few resources are available in English for their cool stuff.
And the second one, rather personal one, is that I'm interested in tracing this "CPU Experiment" as my personal project. I've been working as a software engineer for almost 7 years. Thankfully I could grow a lot in this space, yet I've been feeling I missed chances to learn computer science basics. I thought it's a great idea to follow what they do to fill this gap.
I hope I can give updates on my project soon:)
Even though most of them are written in Japanese, I'll leave some links for those who are interested so you can at least have a look at their code:)
- CPU 実験で自作 CPU に UNIX ライク OS (xv6) を移植した話
- [EN]how we ran a unix-like os (xv6) on our home-built cpu with our home-built c compiler
- This is basically the same article as the one above but in English.
- 自作 CPU 向け C コンパイラをつくって OS 動かした話 (CPU 実験まとめ)