AI News HubLIVE
In-site rewrite2 min read

A compiler that solves Anthropic's VLIW optimization challenge

A developer created an optimizing compiler for Anthropic's take-home interview challenge, which involves optimizing a kernel on a simulated VLIW SIMD virtual machine to minimize cycle count for a tree traversal and hash computation workload. Instead of hand-optimizing, they built a compiler that compiles a high-level IR to efficient VLIW bundles.

SourceHacker News AIAuthor: uglyHaskell

Notifications You must be signed in to change notification settings

Fork 14

Star 86

BranchesTags

Open more actions menu

Folders and files

NameName

Last commit message

Last commit date

Latest commit

History

95 Commits

95 Commits

.claude/skills/debug-compiler

.claude/skills/debug-compiler

.codex

.codex

compiler

compiler

docs

docs

original_performance_takehome

original_performance_takehome

programs

programs

tests

tests

tools

tools

vm

vm

.envrc

.envrc

.gitignore

.gitignore

AGENTS.md

AGENTS.md

CLAUDE.md

CLAUDE.md

Readme.md

Readme.md

Repository files navigation

Anthropic published their original performance take-home interview challenge: optimize a kernel running on a simulated VLIW SIMD virtual machine to minimize cycle count for a tree traversal + hash computation workload.

Instead of hand-optimizing the kernel, I wrote an optimizing compiler that takes a high-level IR description of the kernel and compiles it down to efficient VLIW bundles.

Project Structure

ai-comp/ ├── compiler/ # Optimizing compiler (HIR → LIR → MIR → VLIW) │ ├── passes/ # Optimization passes (DCE, CSE, SLP vectorization, etc.) │ └── tests/ # Compiler unit and regression tests ├── programs/ # Kernel implementations using the compiler ├── vm/ # Thin wrapper around the upstream VM simulator ├── original_performance_takehome/ # Unmodified upstream challenge code ├── tests/ # Submission correctness and speed tests ├── docs/ # Architecture and design documents └── tools/ # Development utilities

Usage

Compile and run the tree hash kernel

python programs/tree_hash.py

Run submission tests (correctness must pass; speed tests are informational)

python tests/submission_tests.py

Run compiler unit tests

python -m pytest compiler/tests/ -v

Kernel Parameters

python programs/tree_hash.py --forest-height 10 --rounds 16 --batch-size 256

Flag Default Description

--forest-height 10 Height of the forest tree

--rounds 16 Number of hash rounds

--batch-size 256 Elements per batch

Compiler Diagnostics

python programs/tree_hash.py --print-after-all # Print IR after each pass python programs/tree_hash.py --print-metrics # Print pass metrics and diagnostics python programs/tree_hash.py --print-ddg-after-all # Print data dependency graphs python programs/tree_hash.py --print-vliw # Print final VLIW instructions python programs/tree_hash.py --profile-reg-pressure # Write register pressure HTML chart

Custom Pass Config

The compiler pipeline is defined in compiler/pass_config.json. To run with a different config (e.g. for A/B testing or parallel searches):

python programs/tree_hash.py --pass-config /path/to/my_config.json

This allows multiple compiler instances to run concurrently with different configurations. The config file has two sections:

pipeline — ordered list of pass names to execute (passes can appear multiple times)

passes — per-pass enabled flag and options dict

Trace Viewer

python programs/tree_hash.py --trace python original_performance_takehome/watch_trace.py

Open http://localhost:8000 and click "Open Perfetto"

About

No description, website, or topics provided.

Resources

Readme

Uh oh!

There was an error while loading. Please reload this page.

Activity

Stars

86 stars

Watchers

1 watching

Forks

14 forks

Report repository

Releases

No releases published

Packages 0

Uh oh!

There was an error while loading. Please reload this page.

Contributors

Uh oh!

There was an error while loading. Please reload this page.

Languages

Python 98.8%

HTML 1.2%