A compiler that solves Anthropic's VLIW optimization challenge

uglyHaskell1 pts1 comments

GitHub - fiigii/ai-comp · GitHub

/" data-turbo-transient="true" />

Skip to content

Search or jump to...

Search code, repositories, users, issues, pull requests...

-->

Search

Clear

Search syntax tips

Provide feedback

--><br>We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel

Submit feedback

Saved searches

Use saved searches to filter your results more quickly

-->

Name

Query

To see all available qualifiers, see our documentation.

Cancel

Create saved search

Sign in

/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up

Appearance settings

Resetting focus

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

fiigii

ai-comp

Public

Notifications<br>You must be signed in to change notification settings

Fork<br>14

Star<br>85

main

BranchesTags

Go to file

CodeOpen more actions menu

Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit

History<br>95 Commits<br>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

View all files

Repository files navigation

AI-Comp (Anthropic Interview Compiler)

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

Usage

# Compile and run the tree hash kernel<br>python programs/tree_hash.py

# Run submission tests (correctness must pass; speed tests are informational)<br>python tests/submission_tests.py

# Run compiler unit tests<br>python -m pytest compiler/tests/ -v

Kernel Parameters

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

Flag<br>Default<br>Description

--forest-height<br>10<br>Height of the forest tree

--rounds<br>16<br>Number of hash rounds

--batch-size<br>256<br>Elements per batch

Compiler Diagnostics

python programs/tree_hash.py --print-after-all # Print IR after each pass<br>python programs/tree_hash.py --print-metrics # Print pass metrics and diagnostics<br>python programs/tree_hash.py --print-ddg-after-all # Print data dependency graphs<br>python programs/tree_hash.py --print-vliw # Print final VLIW instructions<br>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<br>python original_performance_takehome/watch_trace.py<br># 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

85<br>stars

Watchers

watching

Forks

14<br>forks

Report repository

Releases

No releases published

Packages

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<br>98.8%

HTML<br>1.2%

You can’t perform that action at this time.

compiler python programs tests tree_hash print

Related Articles