Hardware-Gated Code Refinement for 2D-Material Compute Arrays

Language-model agents that write a program, run it, read the result and rewrite it have begun discovering hardware logic that people had not thought of. They have also begun cheating. When ArchAgent evolved cache policies against a microarchitecture simulator, one candidate raised its score by exploiting a simulator bug that silently dropped memory writes (ArchAgent). That kind of cheating becomes the dominant risk on emerging hardware built from atomically thin materials. Examples include transistor arrays made from a single layer of MoS₂ (Large-scale high uniform optoelectronic synapses array). On such substrates the simulator is a crude statistical guess, because the device physics depends on synthesis details nobody fully controls. An agent optimizing against such a model will learn the model's mistakes.

We propose to let an agent write the driver software for a 2D-material analog compute array: the code that turns neural-network weights into programming pulses, decides which physical devices hold which weights, and recalibrates as stored values drift. The search runs mostly in a cheap simulator, under a fixed and small budget of real-array measurements. Those measurements are used only to accept or reject candidates and to correct the simulator. The claim is that a few hundred hardware queries, spent at selection points rather than on search, remove most of the gap between simulated and measured accuracy that a simulator-only agent accumulates. We also expect the agent's program-level search to find driver strategies that tuning a fixed template cannot.

Core Claim

Agentic refinement against a simulator overfits to that simulator. The size of this effect grows with how poorly the simulator captures the device. For 2D floating-gate arrays the effect is large enough to erase the agent's apparent gains. A loop that holds out measured hardware as the acceptance test, which we call a hardware gate, keeps the gains. We define the simulation-to-silicon gap of a driver program $p$ as $G(p) = A_{\text{sim}}(p) - A_{\text{hw}}(p)$, where $A_{\text{sim}}$ and $A_{\text{hw}}$ are task accuracy predicted by the simulator and measured on the array. We predict two things. First, $G$ rises monotonically across iterations of a simulator-only agent, the same pattern seen in robots trained at zero latency (Air Learning). Second, the gated agent keeps $G$ near its iteration-zero value while improving $A_{\text{hw}}$.

The gate is chosen to fit the physics. Rollback, the safety net of code-repair agents such as MEIC, assumes that mistakes are free to undo. That assumption fails for crystal growth, where a bad precursor flux permanently ruins a film. It roughly holds for reprogramming a floating-gate transistor, apart from wear. So the proposal applies refinement at the device-control layer rather than the growth chamber. Synthesis enters as the source of the device variation the driver must absorb, and as a downstream consumer of the device characterization the loop produces.

Research Program

The substrate is a MoS₂ floating-gate array. It uses gold nanoparticles as charge traps, in the style of the 28×28 array in Large-scale high uniform optoelectronic synapses array, which reports an on/off ratio above 10⁶. That work evaluated MNIST recognition with an idealized software CNN rather than on the array. Its 96.5% figure is therefore a simulated ceiling, not a measured baseline, and our work starts exactly at that gap. The array also illustrates the open problem that it is characterized on a probe station without peripheral electronics. We will build a scripted pulse-and-read harness so that a driver program can execute against it.

The agent edits a driver program with three parts. The first is a write-verify routine that maps target conductances to pulse amplitude, width and count, with arbitrary control flow. The second is a placement routine that assigns weights to devices given per-device characterization, for example routing large-magnitude weights away from high-variance cells. The third is a refresh policy that decides when to re-read and re-program as drift accumulates. The loop follows the evolutionary program-search style of ArchAgent and A₂DEPT, which supplies the tree search and the repair of missing subroutines. Self-planning before code emission follows RTLLM.

The simulator starts as a crossbar device model of the kind used in the IBM analog toolkit setting of Hardware-aware training, which models programming noise, drift and converter quantization. We fit it to an initial sweep of the array. A candidate $p'$ that beats its parent $p$ in simulation is promoted only at gate checkpoints, and only if

$$A_{\text{hw}}(p') - A_{\text{hw}}(p) > \delta,$$

where $\delta$ is the measured run-to-run standard error of hardware accuracy. Every gate evaluation does three further things. It returns a structured discrepancy report to the agent, showing which layers, which devices and which pulse regimes the simulator mispredicted. It refits the simulator's per-device parameters. It counts as an "escape" any candidate whose simulated gain was not reproduced on hardware.

This makes the mechanism cheaper than the cascade ArchAgent used, which screened on short traces and confirmed on long ones. ArchAgent's confirmation stage was still a simulator. Ours is the physical device. The hardware budget is fixed in advance: we budget a few hundred full-array evaluations, which also bounds device wear.

To separate the scientific question from the logistics of a single physical array, we first run a controlled stand-in, Stage A. Search uses a simplified noise model. The "silicon" is a richer held-out model with drift, IR-drop along metal lines and nonuniform noise, evaluated on CIFAR-100 with Wide ResNet-28, so results can be compared against Accuracy and Resiliency of Analog CIM. Stage A lets us measure escapes with a known ground truth. Stage B repeats the study on the fabricated MoS₂ array with MNIST and a small CNN that fits its capacity.

Baselines

The naive reference point is direct mapping: digital weights programmed with a single open-loop pulse per target conductance and no refresh. On CIFAR-100 this is the regime where Accuracy and Resiliency of Analog CIM reports standard training falling to about 71% at 6% device noise and about 14% at 10%. On MNIST and the MoS₂ array we have no reported measured number from Lacuna. We will establish it ourselves, and every method is reported as a gain over it.

The strongest existing method for the network side is noise-robust training. For CIFAR-100, Hessian-aware SGD reports 88.47% at 6% noise and 61.67% at 10% (Accuracy and Resiliency of Analog CIM). Hardware-aware training reaches within 1% of floating-point accuracy on five of eleven workloads (Hardware-aware training). We combine these with a standard iterative write-verify driver. Our agent's drivers run on top of the same robustly trained weights, so the comparison isolates the driver. Beating this baseline means a statistically reliable gain in measured accuracy at equal pulse count and equal refresh energy.

The strongest competitor on the search side is Bayesian optimization over a parameterized write-verify-plus-refresh template. This is the approach already used for growth recipes in Bayesian optimization in MBE of SrRuO₃. It gets the same hardware-query budget and the same simulator, and can use the same gate. The closest agentic baseline is an ArchAgent-style loop with simulator-only fitness and identical model, token and simulator budgets.

Two ablations isolate the key ingredient. One keeps the gate but withholds the discrepancy report from the agent, so the hardware is used purely for selection. The other refits the simulator from gate data but promotes candidates on simulated score alone. The proposal wins only if the full method beats both ablations on measured accuracy, and also beats Bayesian optimization.

Why not just…?

Why not just tune a fixed write-verify template with Bayesian optimization? This is the real threat. If good drivers differ only in a handful of continuous parameters, Bayesian optimization will be more sample-efficient than an LLM. The evidence that program structure matters comes from other domains. A₂DEPT reduced the normalized optimality gap by 9.8% over template-bound heuristic design by changing algorithm structure (A₂DEPT). ArchAgent found new tracking mechanisms rather than better constants. Neither shows this for device drivers. Our head-to-head at equal hardware budget settles it. If the agent's gain disappears once Bayesian optimization is gated the same way, we will report that the gate, not the language model, carries the effect.

Why not just do better hardware-aware training and keep a standard driver? Robust training changes the weights. It cannot route weights around specific bad devices or schedule refreshes against measured drift, and HA-SGD still loses over 25 points at 10% noise. Because our drivers run on top of robustly trained weights, any gain we measure is additive to this baseline rather than a replacement for it.

Why not just build a higher-fidelity simulator and search against that? A more detailed model raises evaluation cost, and ArchAgent already needed over 12 hours per full-length run. More importantly, a richer model is still a model with its own exploitable holes, as Policy12 showed. The ablation that refits the simulator from gate data but selects in simulation is exactly this alternative made as strong as we can make it. If it matches the full method, the simple answer wins.

Proposed Experiments

In Stage A we run every method for a matched budget on CIFAR-100 under the held-out "silicon" model at several noise levels. We plot $A_{\text{sim}}$, $A_{\text{hw}}$ and $G$ against iteration, together with the cumulative escape count. The first decisive check is whether the simulator-only agent shows growing $G$. If it does not, simulator overfitting is not the bottleneck and the gate is unnecessary. The second check is whether the gated agent's final $A_{\text{hw}}$ exceeds HA-SGD plus standard write-verify, which starts from the reported 88.47% at 6% noise, and also exceeds gated Bayesian optimization. We then sweep the hardware budget to find the smallest number of queries that recovers most of the benefit.

Stage B repeats the comparison on the fabricated MoS₂ array with MNIST. Results are reported against the measured direct-mapping baseline and against the 96.5% simulated ceiling from the array's original paper. Accuracy is re-measured after a held-out drift interval, to test whether the refresh policies the agent discovers generalize beyond the drift seen during search. We will also transfer the final driver to a second array from a different growth batch. This tests whether the agent learned device physics or memorized one chip. A large transfer drop would itself be a finding about how synthesis variation limits software compensation, and the per-device discrepancy logs would go back to the growers as a characterization of that variation.