Baseline JPEG encoder core from description to GDSII
- Tools
- Verilator, libjpeg-turbo, OpenROAD-flow-scripts
- Time limit
- 2.5 hours
Agent is asked to design a baseline JPEG encoder core and take it all the way to GDSII.
Agent Input
What the agent is given: the instruction and its input files.
Design a baseline JPEG encoder core and take it all the way to GDSII.
The workspace is /app; start with /app/README.md, then
/app/docs/INTERFACE_CONTRACT.md and /app/docs/SCORING.md.
- What to build: implement
module jpeg_encbehind the frozen interface in/app/rtl: RGB pixels in MCU order in, baseline JPEG entropy-coded scan data out (color conversion, 4:2:0 downsampling, forward DCT, quantization, Huffman coding, byte stuffing and restart markers), for grayscale and YCbCr 4:2:0 frames. List your sources in/app/rtl/design.mk. - Functional verification: for every image, table and configuration in the
conformance, stress and random suites, the scan data must be byte-identical to
libjpeg-turbo 3.2.1's, with no interface protocol violation (
make eval). - Performance: at least 0.98 pixels per cycle on the throughput corpus
(
make throughput). - Physical design: take
jpeg_enc_pnrfrom RTL to GDSII with OpenROAD-flow-scripts on ASAP7 at the TT corner usingmake pd, with your settings in/app/pd/config.mk. Sign-off must be clean: no detailed-route DRC or antenna violations, no hold or max slew/cap/fanout violations, and a fully constrained design. - Fmax: must be at least 5850 MHz, where Fmax = 1 / (clock period − worst
setup slack) from
make pdsign-off. - Die area: the routed
jpeg_enc_pnrmust be at most 7700 µm² (make pdreports it). - Netlist binding: the netlist that ORFS builds must behave identically to
the RTL you verified (
make check-netlist). - RTL content: no file in
/app/rtlmay use DPI imports or exports,$system,$fopen,$readmemh/$readmemb,$writememh/$writememb,$dump*, Verilator$c, or`systemc_*blocks.
Only /app/rtl and /app/pd are collected. The grader re-runs the functional
suites (including random cases from its own seed), make throughput, make pd
and make check-netlist from a clean copy of the workspace with your rtl/ and
pd/; make pd gets 8 CPUs and fails if it has not finished within 3.5 hours.
The design must meet every requirement above.
You have 9000 seconds to complete this task. ps -o etimes= -p 1 prints the
seconds elapsed since your environment started; check it regularly rather than
estimating. If any requirement is still unmet, do not stop: keep working until
the time is nearly used up. Keep /app/rtl and /app/pd ready to submit, since
they are collected as they stand when time runs out. Do not cheat by using
online solutions or hints specific to this task.
jpegenc task
Task
Implement a baseline JPEG encoder core, module jpeg_enc: RGB pixels in MCU
order in, entropy-coded scan data out, byte-identical to libjpeg-turbo 3.2.1.
Verify it with the provided suites and take it from RTL to a DRC-clean GDSII
with OpenROAD-flow-scripts (ORFS) on ASAP7 at the TT corner.
The same design must also meet these requirements:
- Pixels/cycle ≥ 0.98 on the throughput corpus (
make throughput); the interface fixes the rate at one pixel per clock. - Fmax ≥ 5850 MHz, where Fmax = 1 / (clock period − worst setup slack) from
sign-off STA of the routed design (
make pd). - Die area ≤ 7700 µm² for the routed
jpeg_enc_pnr(make pd).
Quickstart
source env/setup_env.sh # pin the toolchain on PATH (libjpeg-turbo in $LIBJPEG_TURBO/bin)
make check-env # hard-gate tool versions vs VERSIONS.lock (fails loudly on drift)
make smoke # RTL-free sign of life with the shipped stub (<1 min)
# after implementing `module jpeg_enc` and listing its sources in rtl/design.mk:
make encode IMG=noise64 MODE=420 # one image: byte compare + first differing coefficient
make eval # conformance + conformance-stress + random + throughput
make pd # RTL -> GDSII + sign-off (route DRC, antenna, STA) -> build/pd/pd_report.json
make check-netlist # the ORFS-elaborated netlist matches the RTL cycle-for-cycle
Every command assumes source env/setup_env.sh was run first. make help lists
all targets.
What you implement
The body of module jpeg_enc (replace rtl/jpeg_enc_stub.sv, or add your
own files), honoring docs/INTERFACE_CONTRACT.md:
valid/ready pixel and output streams, programmable quantization tables, frame
configuration (grayscale or YCbCr 4:2:0, MCU count, restart interval), and the
exact arithmetic of libjpeg-turbo's color conversion, downsampling, ISLOW DCT,
quantization and Huffman coding with the standard tables. jpeg_pkg.sv and
jpeg_enc_pnr.sv are provided complete — do not change their public API
(jpeg_enc_pnr.sv is replaced by the original at grading).
The libjpeg-turbo source, which defines the arithmetic, is at
/opt/libjpeg-turbo/src; the contract names the functions to read.
rtl/design.mk is the single description of your design used by every flow and
by the grader: RTL_SRCS (your sources under rtl/, in compile order, including
rtl/jpeg_pkg.sv). pd/config.mk holds your ORFS settings. Only rtl/ and
pd/ are collected for grading; everything else in the workspace is restored
to its original state.
Functional verification
Each suite encodes images twice — with jpeg_enc in the Verilator harness
(sim/tb_top.cpp) and with libjpeg-turbo (ref/ref_enc) — and compares the
scan data byte for byte. On a mismatch, ref/jpeg_diff decodes both streams
and reports the first differing MCU, component, block and zigzag coefficient,
plus the first differing byte; build/suite/<suite>/runs/ holds the DUT
stream wrapped as a viewable JPEG.
make conformance: directed images (flat, gradients, checkerboards, impulses, DCT basis patterns, color bars, DC staircases, noise) in both modes, qualities 1–100 and custom tables, restart intervals, and edge sizes (one MCU, one MCU row or column, 512-pixel strips).make conformance-stress: the same cases as multi-frame jobs without reset between frames, with pixel gaps, output stalls (including long ones) and junk on every don't-care input.make random SEED=N: random images, tables and configurations; the grader uses its own seed.make throughput: the throughput corpus with an ideal source and sink, and the throughput scorecard (docs/SCORING.md).
The harness also checks the interface protocol on every cycle (stable output
while stalled, busy window, no output outside a frame, ...) and stops with a
FATAL on a violation. With the shipped stub every suite stops at the first
frame with busy not asserted after frame_start.
make selftest checks the kit itself without your RTL: the golden encoder
against stock cjpeg, the comparator, the job files, and the harness against a
replay fixture.
Physical design
make pd (scripts/pd/run_pd.py) runs ORFS on jpeg_enc_pnr exactly as the
grader does:
- platform
asap7,CORNER=TC(typical libraries), NLDM, the slang SystemVerilog front end (-D SYNTHESIS), ORFS logic-equivalence checking (LEC_CHECK=1) between the synthesized and final netlists; - sources and include dir come from
rtl/design.mk; - the SDC is generated: clock
clkwith periodCLOCK_PERIOD_PS;jpeg_enc_pnrforwards it on itsio_clkoutput (a generated clock), and all other inputs and the outputs have a 50 ps external delay againstio_clkas it leaves the core: inputs are valid 50 ps after its edge, and outputs must arrive 50 ps before the next one;rstis a false path; pd/config.mkmay set only the knobs inKNOBSinscripts/pd/run_pd.py(clock period, synthesis options, utilization/density, VT selection viaASAP7_USE_VT, repair and CTS options, ...). No Tcl hooks, extra files, or extra libraries/macros are accepted (so no SRAM macros). Unless set,SLEW_MARGINandCAP_MARGINdefault to 50 and 25: the percent by which ORFSrepair_designover-fixes slew and capacitance, since it works from pre-route parasitic estimates that run below the extracted values sign-off uses;- outputs go to
build/pd/(ORFSresults/,reports/,logs/under it).--keep(make pd PD_ARGS=--keep) reuses an existing run directory so ORFS only redoes out-of-date steps; the grader always starts clean. For experiments you can also drive ORFS directly with the generatedbuild/pd/config.mk.
Sign-off (scripts/pd/signoff.tcl, on the routed design with OpenRCX parasitics)
requires all of: the flow completes and writes a GDS; zero detailed-route DRC
violations (OpenROAD's router checks against the ASAP7 tech LEF rules, which is
ORFS's DRC sign-off for this platform); zero antenna violations; hold slack ≥ 0;
zero max slew/capacitance/fanout violations; and a fully constrained design
(check_setup reports nothing: every register clocked by clk, no
combinational loops). Fmax is then 1e6 / (CLOCK_PERIOD_PS − setup WNS) MHz.
Sign-off STA uses the propagated clock tree: register-to-register paths include
clock skew, and I/O paths are timed against the actual io_clk edge at its
port, which leaves through the clock tree like any register clock.
The die area (die_area_um2 in pd_report.json) is the area of the routed
design's die box, which CORE_UTILIZATION, CORE_ASPECT_RATIO and
CORE_MARGIN size from the synthesized cell area.
make check-netlist (scripts/pd/check_netlist.py) proves that what ORFS builds
is what you verified: it takes ORFS's own elaboration of jpeg_enc_pnr (same
front end and defines), flattens it to a generic gate netlist and replays every
conformance, conformance-stress and throughput job on it in tb_top. Every
output transfer, its cycle, and the per-frame handshake cycles must match the
RTL jpeg_enc simulation exactly. Latches are rejected, and synthesis ignores
initial values (reset state explicitly). Logic that differs between simulation
and synthesis (e.g. ifdef SYNTHESIS) fails this check.
Grading
The grader starts from a clean copy of this workspace plus your rtl/ and pd/,
then runs make conformance, make conformance-stress, make random with its
own seed, make throughput, make pd, and make check-netlist. make pd gets
8 CPUs and fails if it has not finished within 3.5 hours. The task passes only
if every requirement is met.
Toolchain (pinned; gated by make check-env, authoritative strings in VERSIONS.lock)
| Tool | Version |
|---|---|
| Verilator | 5.032 |
| libjpeg-turbo | 3.2.1 (WITH_SIMD=0, static, at /opt/libjpeg-turbo) |
| python3 | 3.14.4 |
| pip | 25.2 |
| ORFS (OpenROAD, Yosys, KLayout) | openroad/orfs:26Q4-421-g73c804d45 at /OpenROAD-flow-scripts |
The self-eval flows use only the Python standard library; images are read by the libjpeg-turbo tools — no Pillow, numpy, or cocotb.
Layout
env/ version/PATH gate (check_env.sh, setup_env.sh); VERSIONS.lock (repo root) pins versions
rtl/ jpeg_pkg.sv, jpeg_enc_stub.sv (replace), jpeg_enc_pnr.sv, design.mk (your source list)
pd/ config.mk (your ORFS knobs)
ref/ golden encoder (ref_enc), comparator (jpeg_diff), job format (jpegjob.h)
sim/ Verilator harness (tb_top.cpp), suites (run_suite.py), test images (mkimages.py), self-test
docs/ interface contract and scoring
scripts/ pd/ (ORFS flow, sign-off, netlist check)
| Doc | Covers |
|---|---|
docs/INTERFACE_CONTRACT.md | the binding jpeg_enc interface (ports, handshakes, pixel order, output format, reset, bit-exact arithmetic, supported modes) |
docs/SCORING.md | how pixels/cycle is measured: harness counters, corpus, scorecard, valid-score gate (task grading is under "Grading" above) |
Grading & Reference Solution
How the submission is scored, and a human expert-authored reference solution.
Gates
rtl/ and pd/ well formed; RTL uses no forbidden construct.
- design.mk valid · Sets only RTL_SRCS, listing existing .sv/.v sources under rtl/.
- config.mk valid · Sets CLOCK_PERIOD_PS and only allowed ORFS knobs, each in range; no Tcl hooks, extra files or libraries.
- RTL content rules · No DPI, $system, $fopen, $writemem*, $dump*, Verilator $c or `systemc_* in rtl/ (comments ignored).
Encodes byte-exact with libjpeg-turbo; clean sign-off; ORFS netlist is the verified RTL.
- Conformance suite · Directed images, grayscale and 4:2:0, quality 1–100 and custom tables, restart intervals, edge sizes.
- Conformance stress · Same cases as multi-frame jobs with no reset, pixel gaps, long output stalls, junk don't-care inputs.
- Random suite · Random images, tables and configurations from a hidden grader seed.
- Throughput corpus valid · Every corpus frame (quality 75 and 90, grayscale and 4:2:0, no restart markers).
- Flow completes · make pd: OpenROAD-flow-scripts on jpeg_enc_pnr (ASAP7, typical corner) through GDSII and sign-off.
- Route DRC clean · Detailed-route DRC violations against the ASAP7 tech LEF rules.
- Antenna clean · Nets with antenna violations.
- Hold met · Sign-off hold slack on the routed design with OpenRCX parasitics.
- No design-rule violations · Max slew, max capacitance and max fanout violations at sign-off.
- Fully constrained · check_setup: no unconstrained paths, every register clocked by clk, no combinational loops.
- Fmax measured · Fmax = 1e6 / (CLOCK_PERIOD_PS − setup WNS) MHz, from sign-off slack.
- Netlist matches RTL · ORFS gate netlist runs conformance, stress and throughput jobs; must equal RTL simulation.
Pixels per clock on the throughput corpus.
- Throughput · Total pixels / total cycles over corpus frames, first pixel to out_last, ideal source and sink.
Scored Categories
Clock rate and area, in one check.
- Fmax and die area · Fmax from sign-off setup slack (only if sign-off clean); die area of routed jpeg_enc_pnr.
