Source/Systems

GPT2.Build.Target

systems/gpt2/src/GPT2/Build/Target.alpha

137 lines26 declarations7.0 KiBSHA-256 897fac1e9ccb

Complete file · line 46

Target.alpha

Definition view
1module GPT2.Build.Target
2
3import Accelerator.SM86.Instruction
4import Accelerator.SM90.Lowering
5import Hardware.Nvidia.SM86.Command.WholeProgramPlan
6import Model.Config
7import Model.Parameter
8import Model.Word32
9import Model.Word64
10import Platform.Linux.Nvidia.DeviceBinding
11import Platform.Linux.Nvidia.PlanHost
12import Platform.RunPod.Nvidia.SM86
13import Std.Natural
14import Platform.RunPod.Nvidia.SM90
15
16-- The card the trainer's host is built for: its product record (the host
17-- refuses any other card before its first allocation; the arena's
18-- admission reads its video memory), the command-stream words late
19-- realization writes into every QMD and pushbuffer (SASS version, compute
20-- class, SPA version), the bytes each QMD occupies in the table and the
21-- driver ABI the host opens its channel with -- both cards' ABIs carry the
22-- 580 and 570 driver layouts: RunPod pods of one card run either branch,
23-- and the host selects the running driver's at startup, refusing any other
24-- branch by name (PlanHost.phSelectDriverInterface) -- and the realization
25-- each device region carries for a card that does not run SM86 words (the
26-- whole-program plan reads it only when the plan's architecture is that
27-- realization's: WholeProgramPlan's NvidiaDeviceRealization).
28family GPT2Target : Type 0
29constructor GPT2TargetValue
30field unrestricted gpt2TargetProfileValue : RunPodSM86TargetProfile
31field unrestricted gpt2TargetQMDArchitectureValue : ModelWord32
32field unrestricted gpt2TargetComputeClassValue : ModelWord32
33field unrestricted gpt2TargetSPAVersionValue : ModelWord32
34field unrestricted gpt2TargetPlanHostABIValue : NvidiaPlanHostABI
35field unrestricted gpt2TargetQMDSlotBytesValue : Nat
36field unrestricted gpt2TargetRealizationValue : (pi unrestricted program : SM86Program . unrestricted registers : Nat . NvidiaDeviceRealization)
37end-family
38
39-- An sm_86 card runs the SM86 words; its plan never reads a realization.
40def gpt2SM86WordsRealization =
41  (lambda unrestricted program : SM86Program . unrestricted registers : Nat .
42    constructor NvidiaDeviceRealization NvidiaDeviceRealizationRefused b"an sm_86 plan places the SM86 words")
43
44-- Hopper realizes each instruction on its own (Accelerator.SM90.Lowering),
45-- whatever the program and its register count.
46def gpt2SM90Realization =
47  (lambda unrestricted program : SM86Program . unrestricted registers : Nat . sm90LowerRealization)
48
49def gpt2RTX3070Target : GPT2Target =
50  (record
51    GPT2Target
52    (gpt2TargetProfileValue = runPodRTX3070TargetProfile)
53    (gpt2TargetQMDArchitectureValue = runPodSM86QMDArchitecture)
54    (gpt2TargetComputeClassValue = runPodSM86ComputeClass)
55    (gpt2TargetSPAVersionValue = runPodSM86SPAVersion)
56    (gpt2TargetPlanHostABIValue = nvidiaPlanHostAmpere)
57    (gpt2TargetQMDSlotBytesValue = runPodSM86QMDSlotBytes)
58    (gpt2TargetRealizationValue = gpt2SM86WordsRealization))
59
60-- The H100 SXM: the same typed SM86 kernels, realized on sm_90 by
61-- Accelerator.SM90.Lowering (global accesses in raw form, Hopper's branch
62-- displacements, every other word kept), launched with QMD V04 on Hopper's
63-- classes (comparisons/h100/README.md).
64def gpt2H100Target : GPT2Target =
65  (record
66    GPT2Target
67    (gpt2TargetProfileValue = runPodH100TargetProfile)
68    (gpt2TargetQMDArchitectureValue = runPodSM90QMDArchitecture)
69    (gpt2TargetComputeClassValue = runPodSM90ComputeClass)
70    (gpt2TargetSPAVersionValue = runPodSM90SPAVersion)
71    (gpt2TargetPlanHostABIValue = nvidiaPlanHostHopper)
72    (gpt2TargetQMDSlotBytesValue = runPodSM90QMDSlotBytes)
73    (gpt2TargetRealizationValue = gpt2SM90Realization))
74
75-- The H100 SXM (gpt2H100Target); gpt2RTX3070Target is the sm_86 build.  The
76-- RTX 3090 evidence under tests/observability/import/gpt2-rtx3090-* was taken
77-- with runPodRTX3090TargetProfile here.
78def gpt2Target : GPT2Target = gpt2H100Target
79
80-- 1 when the target places GPT-2's products on Hopper's tensor cores
81-- (GPT2.Build.HopperImages): set with gpt2Target, a number every module can
82-- normalize; gpt2TargetHopperProductsAgrees holds it to the target's QMD
83-- architecture (sm_90), so a build that changes one alone does not check
84def gpt2TargetHopperProducts : Nat = 1
85def gpt2TargetProfile : RunPodSM86TargetProfile =
86  (eliminate GPT2Target (lambda unrestricted current : GPT2Target . RunPodSM86TargetProfile) gpt2Target
87    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . profile))
88
89def gpt2TargetQMDArchitecture : ModelWord32 =
90  (eliminate GPT2Target (lambda unrestricted current : GPT2Target . ModelWord32) gpt2Target
91    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . architecture))
92
93def gpt2TargetComputeClass : ModelWord32 =
94  (eliminate GPT2Target (lambda unrestricted current : GPT2Target . ModelWord32) gpt2Target
95    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . computeClass))
96
97def gpt2TargetSPAVersion : ModelWord32 =
98  (eliminate GPT2Target (lambda unrestricted current : GPT2Target . ModelWord32) gpt2Target
99    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . spaVersion))
100
101def gpt2TargetPlanHostABI : NvidiaPlanHostABI =
102  (eliminate GPT2Target (lambda unrestricted current : GPT2Target . NvidiaPlanHostABI) gpt2Target
103    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . abi))
104
105def gpt2TargetQMDSlotBytes : Nat =
106  (eliminate GPT2Target (lambda unrestricted current : GPT2Target . Nat) gpt2Target
107    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . slot))
108
109-- The card the host opens: a deployment input, not a target capability
110-- (Platform.Linux.Nvidia.DeviceBinding).  A RunPod container sees only its
111-- own GPU, under the node's Linux minor -- not necessarily 0: the
112-- 2026-10-17 FineWeb pod's H100 is /dev/nvidia1, the probe pod's
113-- /dev/nvidia6 -- and a host bound to another minor refuses at `card-open`.
114-- A run builds its ELFs for the minor its pod shows (ls /dev/nvidia[0-9]*;
115-- comparisons/h100/fineweb-run/run.sh records it); the UUID is left empty
116-- (a node-only binding: the container holds one card).
117def gpt2DeviceMinor : Nat = 1
118
119def gpt2DeviceBinding : NvidiaDeviceBinding =
120  (constructor NvidiaDeviceBinding NvidiaDeviceBindingValue gpt2DeviceMinor b"")
121
122-- 1: the host runs its channel direct-RM (the resource manager alone, no
123-- /dev/nvidia-uvm: buffers placed at fixed GPU ranges by RM virtual
124-- reservations); 0: the UVM lifecycle, the arena its external range. The
125-- RTX 3070 hosts RunPod rents (2026-10-04) refuse to open /dev/nvidia-uvm.
126def gpt2TargetDirectRM : Nat = 1
127
128def gpt2TargetRealization =
129  (eliminate GPT2Target
130    (lambda unrestricted current : GPT2Target .
131      pi unrestricted program : SM86Program . unrestricted registers : Nat . NvidiaDeviceRealization)
132    gpt2Target
133    (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . realization))
134
135def gpt2TargetHopperProductsAgrees :
136  (equal Nat gpt2TargetHopperProducts (naturalEqual (modelWord32ToNatural gpt2TargetQMDArchitecture) 0x90)) =
137  (refl Nat gpt2TargetHopperProducts)

The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.