From 631975c8e5606d14e3b153b8a9b6c546d9115dab Mon Sep 17 00:00:00 2001 From: Hannes Klas Date: Tue, 24 Nov 2026 18:38:54 +0100 Subject: [PATCH] hip: remove the unused fields, methods and constants --- src/hip/ffi.rs | 17 ----------------- src/hip/mod.rs | 27 ++++++--------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/hip/ffi.rs b/src/hip/ffi.rs index 076fc18..3166768 100644 --- a/src/hip/ffi.rs +++ b/src/hip/ffi.rs @@ -31,9 +31,6 @@ pub const ATTR_MAX_DYNAMIC_SHARED: c_int = 8; pub const ATTR_SHARED_PER_BLOCK_OPTIN: c_int = 75; pub const ATTR_SHARED_PER_BLOCK: c_int = 74; pub const ATTR_WARP_SIZE: c_int = 87; -pub const ATTR_INTEGRATED: c_int = 16; -pub const ATTR_MULTIPROCESSOR_COUNT: c_int = 63; -pub const ATTR_MAX_THREADS_PER_BLOCK: c_int = 56; /// Room for `hipDeviceProp_t`, which `hipGetDeviceProperties` writes whole. ROCm 7's `hipDeviceProp_tR0600` is 1472 /// bytes; the size is not exported and changes between versions, so the buffer leaves ample room for a larger one. @@ -53,8 +50,6 @@ fn find_gfx(bytes: &[u8]) -> Option { None } -type Fn = unsafe extern "C" fn(); - /// Library names to try, in order. `STRATA_HIP` (a path or a name) replaces the whole list. fn candidates(vars: Option, default_suffix: &[&str]) -> Vec { if let Some(p) = vars { return vec![p]; } @@ -76,14 +71,11 @@ pub struct Hip { pub mem_get_info: unsafe extern "C" fn(*mut usize, *mut usize) -> c_int, pub malloc: unsafe extern "C" fn(*mut *mut c_void, usize) -> c_int, pub free: unsafe extern "C" fn(*mut c_void) -> c_int, - pub memset: unsafe extern "C" fn(*mut c_void, c_int, usize) -> c_int, pub memset_async: unsafe extern "C" fn(*mut c_void, c_int, usize, Stream) -> c_int, pub memcpy: unsafe extern "C" fn(*mut c_void, *const c_void, usize, c_int) -> c_int, pub memcpy_async: unsafe extern "C" fn(*mut c_void, *const c_void, usize, c_int, Stream) -> c_int, pub stream_create: unsafe extern "C" fn(*mut Stream, u32) -> c_int, - pub stream_destroy: unsafe extern "C" fn(Stream) -> c_int, pub stream_sync: unsafe extern "C" fn(Stream) -> c_int, - pub stream_wait_event: unsafe extern "C" fn(Stream, Event, u32) -> c_int, pub stream_begin_capture: unsafe extern "C" fn(Stream, c_int) -> c_int, pub stream_end_capture: unsafe extern "C" fn(Stream, *mut Graph) -> c_int, pub stream_is_capturing: unsafe extern "C" fn(Stream, *mut c_int) -> c_int, @@ -94,18 +86,15 @@ pub struct Hip { pub event_create: unsafe extern "C" fn(*mut Event, u32) -> c_int, pub event_record: unsafe extern "C" fn(Event, Stream) -> c_int, pub event_sync: unsafe extern "C" fn(Event) -> c_int, - pub event_query: unsafe extern "C" fn(Event) -> c_int, pub event_destroy: unsafe extern "C" fn(Event) -> c_int, pub host_malloc: unsafe extern "C" fn(*mut *mut c_void, usize, u32) -> c_int, pub host_free: unsafe extern "C" fn(*mut c_void) -> c_int, pub host_device_ptr: unsafe extern "C" fn(*mut *mut c_void, *mut c_void, u32) -> c_int, pub module_load: unsafe extern "C" fn(*mut Module, *const c_void) -> c_int, - pub module_unload: unsafe extern "C" fn(Module) -> c_int, pub function: unsafe extern "C" fn(*mut Func, Module, *const c_char) -> c_int, pub launch: unsafe extern "C" fn(Func, u32, u32, u32, u32, u32, u32, u32, Stream, *mut *mut c_void, *mut *mut c_void) -> c_int, pub func_set_attribute: unsafe extern "C" fn(*const c_void, c_int, c_int) -> c_int, pub error_string: unsafe extern "C" fn(c_int) -> *const c_char, - pub last_error: unsafe extern "C" fn() -> c_int, _lib: Library, } @@ -142,14 +131,11 @@ impl Hip { mem_get_info: g!("hipMemGetInfo"), malloc: g!("hipMalloc"), free: g!("hipFree"), - memset: g!("hipMemset"), memset_async: g!("hipMemsetAsync"), memcpy: g!("hipMemcpy"), memcpy_async: g!("hipMemcpyAsync"), stream_create: g!("hipStreamCreateWithFlags"), - stream_destroy: g!("hipStreamDestroy"), stream_sync: g!("hipStreamSynchronize"), - stream_wait_event: g!("hipStreamWaitEvent"), stream_begin_capture: g!("hipStreamBeginCapture"), stream_end_capture: g!("hipStreamEndCapture"), stream_is_capturing: g!("hipStreamIsCapturing"), @@ -160,18 +146,15 @@ impl Hip { event_create: g!("hipEventCreateWithFlags"), event_record: g!("hipEventRecord"), event_sync: g!("hipEventSynchronize"), - event_query: g!("hipEventQuery"), event_destroy: g!("hipEventDestroy"), host_malloc: g!("hipHostMalloc"), host_free: g!("hipHostFree"), host_device_ptr: g!("hipHostGetDevicePointer"), module_load: g!("hipModuleLoadData"), - module_unload: g!("hipModuleUnload"), function: g!("hipModuleGetFunction"), launch: g!("hipModuleLaunchKernel"), func_set_attribute: g!("hipFuncSetAttribute"), error_string: g!("hipGetErrorString"), - last_error: g!("hipGetLastError"), _lib: lib, }) } diff --git a/src/hip/mod.rs b/src/hip/mod.rs index 235e99d..fa0c04e 100644 --- a/src/hip/mod.rs +++ b/src/hip/mod.rs @@ -35,7 +35,6 @@ pub struct Gpu { hip: Arc, device: usize, stream: ffi::Stream, - module: ffi::Module, fns: HashMap, /// "gfx1201": the target hiprtc compiled for. arch: String, @@ -45,13 +44,8 @@ pub struct Gpu { max_smem: usize, /// `argmax_rows` partials. am: Buf, - /// q8 rows of the last integer GEMM's X (see quant_q8 in kernels.cu) and which x they hold; `None` after a call - /// without `SAME_X` that did not quantize. - q8: Mutex<(Buf, Option<[u64; 4]>)>, /// Recorded graphs by `Backend::graph` key. graphs: Mutex>, - /// Recorded by `sync`, so a wait can poll it instead of spinning in the driver. - done: ffi::Event, /// Rope frequency tables, `base` and `n_rot` to the device buffer that holds them. fr: Mutex<(HashMap<(u32, usize), Buf>, Vec<(f32, usize)>)>, /// Pinned staging for large `htod`, used as a ring: the copy returns before its DMA, so the host fills the next @@ -208,21 +202,16 @@ impl Gpu { } // argmax_part writes an int2 (8 bytes) per partial: AMAX_PARTS per row, up to 64 rows. let am_buf = alloc_raw(&hip, 64 * AMAX_PARTS * 8)?; - let q8_buf = alloc_raw(&hip, 1)?; // Pinned ring for large host-to-device copies. let mut host: *mut c_void = std::ptr::null_mut(); hip.check(unsafe { (hip.host_malloc)(&mut host, RING, ffi::HOST_MALLOC_PORTABLE | ffi::HOST_MALLOC_MAPPED) }, "hipHostMalloc(ring)")?; let mut dev: *mut c_void = std::ptr::null_mut(); hip.check(unsafe { (hip.host_device_ptr)(&mut dev, host, 0) }, "hipHostGetDevicePointer(ring)")?; - let staging = Staging { pin: Buf::new(dev as u64, RING, PinnedHost { hip: hip.clone(), p: host }), host: host.cast(), head: 0, busy: VecDeque::new() }; - let mut done: ffi::Event = std::ptr::null_mut(); - hip.check(unsafe { (hip.event_create)(&mut done, ffi::EVENT_DISABLE_TIMING) }, "hipEventCreate")?; - Ok(Gpu { hip, device, stream, module, fns, arch, kv_q8, max_smem, am: am_buf, q8: Mutex::new((q8_buf, None)), - graphs: Mutex::new(HashMap::new()), done, fr: Mutex::new((HashMap::new(), Vec::new())), staging: Mutex::new(staging) }) + let staging = Staging { _pin: Buf::new(dev as u64, RING, PinnedHost { hip: hip.clone(), p: host }), host: host.cast(), head: 0, busy: VecDeque::new() }; + Ok(Gpu { hip, device, stream, fns, arch, kv_q8, max_smem, am: am_buf, + graphs: Mutex::new(HashMap::new()), fr: Mutex::new((HashMap::new(), Vec::new())), staging: Mutex::new(staging) }) } - fn h(&self) -> &ffi::Hip { &self.hip } - pub fn arch(&self) -> &str { &self.arch } /// Launch kernel `name` with `cfg`; `args` are the kernel parameters, in order, read from the given addresses. @@ -249,10 +238,6 @@ impl Gpu { fn ptr(&self, b: &Buf) -> u64 { b.addr() } - fn f(&self, name: &str) -> anyhow::Result { - self.fns.get(name).copied().ok_or_else(|| anyhow::anyhow!("HIP kernel {name} is not loaded")) - } - /// qwen35moe and the other models this backend targets dequantize in the kernel, so the ops below are the /// generic ones. fn float_ty(ty: GgmlType) -> bool { matches!(ty, GgmlType::F32 | GgmlType::BF16) } @@ -405,13 +390,14 @@ impl Drop for PinnedHost { /// Pinned host memory used as a ring for `htod`: a region is free again once the copy that read it has completed. struct Staging { - pin: Buf, + /// Owns the pinned allocation; dropping it frees the ring. + _pin: Buf, host: *mut u8, head: usize, busy: VecDeque<(usize, usize, Event)>, } -/// A `hipEvent_t` that destroys itself; `query` reports completion. +/// A `hipEvent_t` that destroys itself. struct Event { hip: Arc, ev: ffi::Event } impl Event { @@ -423,7 +409,6 @@ impl Event { fn record(&self, stream: ffi::Stream) -> anyhow::Result<()> { self.hip.check(unsafe { (self.hip.event_record)(self.ev, stream) }, "hipEventRecord") } - fn done(&self) -> bool { unsafe { (self.hip.event_query)(self.ev) == ffi::HIP_SUCCESS } } } impl Drop for Event {