Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/physics-mv/blob/main/forge/forge_descriptor.h # physics-mv FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `physics-mv / forge / forge_descriptor.h` 146 lines ยท 5506 bytes Raw Blame History 1 #ifndef FORGE_DESCRIPTOR_H 2 #define FORGE_DESCRIPTOR_H 3 4 #include 5 #include 6 #include 7 8 #define FORGE_DESC_BDF_LEN 16 9 #define FORGE_DESC_UUID_LEN 16 10 #define FORGE_DESC_VER_LEN 32 11 #define FORGE_DESC_DIGEST_LEN 32 12 #define FORGE_DESC_SERIALIZED_LEN 208 13 14 /* Feature flags derived strictly from verified accelerator objects */ 15 #define FORGE_FEATURE_UNIFIED_MEMORY (1U << 0) 16 #define FORGE_FEATURE_COMPUTE_B (1U << 1) 17 #define FORGE_FEATURE_GPFIFO_A (1U << 2) 18 #define FORGE_FEATURE_USERMODE_A (1U << 3) 19 #define FORGE_FEATURE_PAGE_FAULTING (1U << 4) 20 21 /* Explicit observation metadata flags: records exactly what was observed vs derived */ 22 #define FORGE_OBS_PCI_IDENTITY (1U << 0) 23 #define FORGE_OBS_GPU_UUID (1U << 1) 24 #define FORGE_OBS_RM_COMPUTE_CLASS (1U << 2) 25 #define FORGE_OBS_RM_SM_VERSION (1U << 3) 26 #define FORGE_OBS_WARP_SIZE (1U << 4) 27 #define FORGE_OBS_WARPS_PER_SM (1U << 5) 28 #define FORGE_OBS_CORE_COUNT (1U << 6) 29 #define FORGE_OBS_SM_PER_TPC (1U << 7) 30 #define FORGE_OBS_DRIVER_VERSION (1U << 8) 31 #define FORGE_OBS_VBIOS_VERSION (1U << 9) 32 #define FORGE_OBS_FIRMWARE_VERSION (1U << 10) 33 #define FORGE_OBS_TOTAL_MEMORY (1U << 11) 34 #define FORGE_OBS_DMA_MASK (1U << 12) 35 #define FORGE_OBS_PAGE_SIZE (1U << 13) 36 #define FORGE_DERIVED_THREADS_PER_BLK (1U << 14) 37 #define FORGE_DERIVED_SHARED_MEM (1U << 15) 38 #define FORGE_DERIVED_FEATURES (1U << 16) 39 40 /* 41 * ForgeMachineDescriptor captures the authoritative hardware identity. 42 * Every field is either measured from a physical interface (RM ioctl, procfs, sysfs) 43 * or explicitly classified as a derived architectural property. 44 */ 45 typedef struct { 46 /* 1. Directly Observed PCI & Device Identities */ 47 uint16_t pci_vendor_id; 48 uint16_t pci_device_id; 49 uint16_t pci_subsystem_vendor_id; 50 uint16_t pci_subsystem_device_id; 51 char pci_bdf[FORGE_DESC_BDF_LEN]; 52 uint8_t gpu_uuid[FORGE_DESC_UUID_LEN]; 53 54 /* 2. Directly Observed RM Subdevice State */ 55 uint32_t rm_compute_class; 56 uint32_t rm_sm_version; 57 uint32_t warp_size; 58 uint32_t max_warps_per_sm; 59 uint32_t gpu_core_count; 60 uint32_t sm_per_tpc; 61 62 /* 3. Directly Observed Driver and Firmware Strings */ 63 char driver_version[FORGE_DESC_VER_LEN]; 64 char vbios_version[FORGE_DESC_VER_LEN]; 65 char firmware_version[FORGE_DESC_VER_LEN]; 66 67 /* 4. Directly Observed Memory and Bus Substrate */ 68 uint64_t total_system_memory_bytes; 69 uint64_t dma_mask; 70 uint32_t page_size; 71 72 /* 5. Classified Derived Architectural Invariants (derived from observed SM version) */ 73 uint32_t max_threads_per_block; 74 uint32_t shared_mem_per_block_bytes; 75 uint32_t features; 76 77 /* 6. Provenance & Observation Metadata */ 78 uint32_t observation_flags; 79 } ForgeMachineDescriptor; 80 81 /* Error codes for descriptor and probe operations */ 82 #define FORGE_PROBE_OK 0 83 #define FORGE_PROBE_ERR_SYSFS -1 84 #define FORGE_PROBE_ERR_PROCFS -2 85 #define FORGE_PROBE_ERR_NVRM -3 86 #define FORGE_PROBE_ERR_MISSING_FIELD -4 87 #define FORGE_PROBE_ERR_MALFORMED_PCI -5 88 #define FORGE_PROBE_ERR_UNSUPPORTED_CC -6 89 #define FORGE_PROBE_ERR_INVALID_ARG -7 90 #define FORGE_PROBE_ERR_DIGEST_MISMATCH -8 91 #define FORGE_PROBE_ERR_UNBOUND_ALIAS -9 92 #define FORGE_PROBE_ERR_DEVICE_MISMATCH -10 93 #define FORGE_PROBE_ERR_KAT_FAILURE -11 94 95 /* 96 * Probes authoritative direct host interfaces (sysfs, procfs, RM ioctl via Nvrm) 97 * to construct a fully measured ForgeMachineDescriptor bound to the opened GPU. 98 * Zero dependency on libcuda or libcudart. 99 */ 100 int forge_probe_hardware(ForgeMachineDescriptor *out_desc); 101 102 /* 103 * Deterministically normalizes descriptor fields: 104 * ensures zeroed trailing bytes in strings/arrays, valid value bounds. 105 */ 106 int forge_descriptor_normalize(ForgeMachineDescriptor *desc); 107 108 /* 109 * Explicit canonical binary serialization of the descriptor. 110 * Serializes integers into little-endian format and strings into fixed-width 111 * null-padded fields in a strictly frozen order (208 bytes total). 112 */ 113 size_t forge_descriptor_serialize(const ForgeMachineDescriptor *desc, uint8_t *out_buf, size_t max_len); 114 115 /* 116 * Computes canonical binary SHA-256 digest: 117 * descriptor_digest = SHA256(canonical binary serialization) 118 */ 119 int forge_descriptor_compute_digest(const ForgeMachineDescriptor *desc, uint8_t out_digest[FORGE_DESC_DIGEST_LEN]); 120 121 /* 122 * Runs the serialization Known Answer Test (KAT). 123 * Verifies that a frozen reference descriptor serializes to an exact byte stream 124 * and produces the exact frozen reference SHA-256 digest. 125 */ 126 int forge_descriptor_run_kat(void); 127 128 /* 129 * Returns derived display alias string (e.g. "sm_121") strictly based on 130 * observed rm_compute_class and rm_sm_version. Never hardcoded as truth. 131 * Returns NULL if descriptor does not map to a recognized architecture alias. 132 */ 133 const char *forge_descriptor_derived_alias(const ForgeMachineDescriptor *desc); 134 135 /* 136 * Verifies that a given display alias strictly binds to the measured descriptor. 137 * Rejects unbound, mismatched, or hardcoded alias claims. 138 */ 139 int forge_descriptor_verify_alias(const ForgeMachineDescriptor *desc, const char *alias); 140 141 /* 142 * Formats canonical digest as a lowercase 64-character hexadecimal string. 143 */ 144 void forge_descriptor_digest_hex(const uint8_t digest[FORGE_DESC_DIGEST_LEN], char out_hex[65]); 145 146 #endif /* FORGE_DESCRIPTOR_H */