module GPT2.Build.Target import Accelerator.SM86.Instruction import Accelerator.SM90.Lowering import Hardware.Nvidia.SM86.Command.WholeProgramPlan import Model.Config import Model.Parameter import Model.Word32 import Model.Word64 import Platform.Linux.Nvidia.DeviceBinding import Platform.Linux.Nvidia.PlanHost import Platform.RunPod.Nvidia.SM86 import Std.Natural import Platform.RunPod.Nvidia.SM90 -- The card the trainer's host is built for: its product record (the host -- refuses any other card before its first allocation; the arena's -- admission reads its video memory), the command-stream words late -- realization writes into every QMD and pushbuffer (SASS version, compute -- class, SPA version), the bytes each QMD occupies in the table and the -- driver ABI the host opens its channel with -- both cards' ABIs carry the -- 580 and 570 driver layouts: RunPod pods of one card run either branch, -- and the host selects the running driver's at startup, refusing any other -- branch by name (PlanHost.phSelectDriverInterface) -- and the realization -- each device region carries for a card that does not run SM86 words (the -- whole-program plan reads it only when the plan's architecture is that -- realization's: WholeProgramPlan's NvidiaDeviceRealization). family GPT2Target : Type 0 constructor GPT2TargetValue field unrestricted gpt2TargetProfileValue : RunPodSM86TargetProfile field unrestricted gpt2TargetQMDArchitectureValue : ModelWord32 field unrestricted gpt2TargetComputeClassValue : ModelWord32 field unrestricted gpt2TargetSPAVersionValue : ModelWord32 field unrestricted gpt2TargetPlanHostABIValue : NvidiaPlanHostABI field unrestricted gpt2TargetQMDSlotBytesValue : Nat field unrestricted gpt2TargetRealizationValue : (pi unrestricted program : SM86Program . unrestricted registers : Nat . NvidiaDeviceRealization) end-family -- An sm_86 card runs the SM86 words; its plan never reads a realization. def gpt2SM86WordsRealization = (lambda unrestricted program : SM86Program . unrestricted registers : Nat . constructor NvidiaDeviceRealization NvidiaDeviceRealizationRefused b"an sm_86 plan places the SM86 words") -- Hopper realizes each instruction on its own (Accelerator.SM90.Lowering), -- whatever the program and its register count. def gpt2SM90Realization = (lambda unrestricted program : SM86Program . unrestricted registers : Nat . sm90LowerRealization) def gpt2RTX3070Target : GPT2Target = (record GPT2Target (gpt2TargetProfileValue = runPodRTX3070TargetProfile) (gpt2TargetQMDArchitectureValue = runPodSM86QMDArchitecture) (gpt2TargetComputeClassValue = runPodSM86ComputeClass) (gpt2TargetSPAVersionValue = runPodSM86SPAVersion) (gpt2TargetPlanHostABIValue = nvidiaPlanHostAmpere) (gpt2TargetQMDSlotBytesValue = runPodSM86QMDSlotBytes) (gpt2TargetRealizationValue = gpt2SM86WordsRealization)) -- The H100 SXM: the same typed SM86 kernels, realized on sm_90 by -- Accelerator.SM90.Lowering (global accesses in raw form, Hopper's branch -- displacements, every other word kept), launched with QMD V04 on Hopper's -- classes (comparisons/h100/README.md). def gpt2H100Target : GPT2Target = (record GPT2Target (gpt2TargetProfileValue = runPodH100TargetProfile) (gpt2TargetQMDArchitectureValue = runPodSM90QMDArchitecture) (gpt2TargetComputeClassValue = runPodSM90ComputeClass) (gpt2TargetSPAVersionValue = runPodSM90SPAVersion) (gpt2TargetPlanHostABIValue = nvidiaPlanHostHopper) (gpt2TargetQMDSlotBytesValue = runPodSM90QMDSlotBytes) (gpt2TargetRealizationValue = gpt2SM90Realization)) -- The H100 SXM (gpt2H100Target); gpt2RTX3070Target is the sm_86 build. The -- RTX 3090 evidence under tests/observability/import/gpt2-rtx3090-* was taken -- with runPodRTX3090TargetProfile here. def gpt2Target : GPT2Target = gpt2H100Target -- 1 when the target places GPT-2's products on Hopper's tensor cores -- (GPT2.Build.HopperImages): set with gpt2Target, a number every module can -- normalize; gpt2TargetHopperProductsAgrees holds it to the target's QMD -- architecture (sm_90), so a build that changes one alone does not check def gpt2TargetHopperProducts : Nat = 1 def gpt2TargetProfile : RunPodSM86TargetProfile = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . RunPodSM86TargetProfile) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . profile)) def gpt2TargetQMDArchitecture : ModelWord32 = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . ModelWord32) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . architecture)) def gpt2TargetComputeClass : ModelWord32 = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . ModelWord32) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . computeClass)) def gpt2TargetSPAVersion : ModelWord32 = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . ModelWord32) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . spaVersion)) def gpt2TargetPlanHostABI : NvidiaPlanHostABI = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . NvidiaPlanHostABI) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . abi)) def gpt2TargetQMDSlotBytes : Nat = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . Nat) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . slot)) -- The card the host opens: a deployment input, not a target capability -- (Platform.Linux.Nvidia.DeviceBinding). A RunPod container sees only its -- own GPU, under the node's Linux minor -- not necessarily 0: the -- 2026-10-17 FineWeb pod's H100 is /dev/nvidia1, the probe pod's -- /dev/nvidia6 -- and a host bound to another minor refuses at `card-open`. -- A run builds its ELFs for the minor its pod shows (ls /dev/nvidia[0-9]*; -- comparisons/h100/fineweb-run/run.sh records it); the UUID is left empty -- (a node-only binding: the container holds one card). def gpt2DeviceMinor : Nat = 1 def gpt2DeviceBinding : NvidiaDeviceBinding = (constructor NvidiaDeviceBinding NvidiaDeviceBindingValue gpt2DeviceMinor b"") -- 1: the host runs its channel direct-RM (the resource manager alone, no -- /dev/nvidia-uvm: buffers placed at fixed GPU ranges by RM virtual -- reservations); 0: the UVM lifecycle, the arena its external range. The -- RTX 3070 hosts RunPod rents (2026-10-04) refuse to open /dev/nvidia-uvm. def gpt2TargetDirectRM : Nat = 1 def gpt2TargetRealization = (eliminate GPT2Target (lambda unrestricted current : GPT2Target . pi unrestricted program : SM86Program . unrestricted registers : Nat . NvidiaDeviceRealization) gpt2Target (branch GPT2TargetValue profile architecture computeClass spaVersion abi slot realization . realization)) def gpt2TargetHopperProductsAgrees : (equal Nat gpt2TargetHopperProducts (naturalEqual (modelWord32ToNatural gpt2TargetQMDArchitecture) 0x90)) = (refl Nat gpt2TargetHopperProducts)