Skip to content

Latest commit

 

History

History
65 lines (62 loc) · 3.38 KB

MEMORY_LAYOUT_AUDIT.md

File metadata and controls

65 lines (62 loc) · 3.38 KB

// Memory Layout Audit Report // ============================================ // CRITICAL ISSUES FOUND - Will cause GPU kernel crashes // ============================================

// ISSUE #1: Command struct size mismatch // ============================================ // CUDA Command struct: // struct align(32) Command { // CommandType type; // offset 0, 4 bytes // uint32_t id; // offset 4, 4 bytes // uint64_t timestamp; // offset 8, 8 bytes // union { // offset 16 // struct { uint32_t padding; } noop; // 4 bytes // struct { float a, b, result; } add; // 12 bytes // struct { float a, b, result; } multiply; // 12 bytes // struct { float* data; uint32_t count; float* output; } batch; // 24 bytes! // } data; // offset 16-40 (24 bytes, largest is batch) // uint32_t result_code; // offset 40, 4 bytes // }; // TOTAL: 44 bytes → padded to 48 bytes for alignment // // CURRENT Rust Command struct (WRONG): // #[repr(C)] // pub struct Command { // pub cmd_type: u32, // offset 0, 4 bytes // pub id: u32, // offset 4, 4 bytes // pub timestamp: u64, // offset 8, 8 bytes // pub data_a: f32, // offset 16, 4 bytes <-- WRONG: only 8 bytes here // pub data_b: f32, // offset 20, 4 bytes <-- WRONG: should be 24 bytes total // pub result: f32, // offset 24, 4 bytes // pub result_code: u32, // offset 28, 4 bytes // } // TOTAL: 32 bytes <-- WRONG SIZE! // // The union in CUDA is 24 bytes (batch struct with 2 pointers + uint32), // but Rust only has 12 bytes (3 floats). // // FIX: Add padding to match 24-byte union size

// ISSUE #2: CommandQueue struct size mismatch // ============================================ // CUDA CommandQueue struct: // struct align(128) CommandQueue { // volatile QueueStatus status; // offset 0, 4 bytes // Command commands[16]; // offset 4, 1640=640 bytes // volatile uint32_t head; // offset 644, 4 bytes // volatile uint32_t tail; // offset 648, 4 bytes // volatile uint64_t commands_processed; // offset 652, 8 bytes // volatile uint64_t total_cycles; // offset 660, 8 bytes // volatile uint64_t idle_cycles; // offset 668, 8 bytes // volatile PollingStrategy current_strategy; // offset 676, 4 bytes // volatile uint32_t consecutive_commands; // offset 680, 4 bytes // volatile uint32_t consecutive_idle; // offset 684, 4 bytes // volatile uint64_t last_command_cycle; // offset 688, 8 bytes // volatile uint64_t avg_command_latency_cycles; // offset 696, 8 bytes // uint8_t padding[64]; // offset 704, 64 bytes // }; // TOTAL: 768 bytes → aligned to 1286=768 // // CURRENT Rust CommandQueueHost struct (WRONG): // Has Command at 32 bytes instead of 40 bytes // This makes the commands array: 16 * 32 = 512 bytes instead of 640 bytes // Total size: ~640 bytes instead of 768 bytes // // FIX: Fix Command struct first, then CommandQueue will be correct

// CORRECTED STRUCTURES BELOW