Repository navigation
hip: remove the unused fields, methods and constants - #99
Conversation
|
One thing this PR does not change: |
🔍 Aletheore evidence diffgraph LR
n0["mod.rs"]
n1["backend.rs"]
n2["lib.rs"]
n0 --> n1
n0 --> n2
classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
class n0 changed
class n1 dependent
class n2 dependent
What changed
Aggregate deltas
|
| 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 |
There was a problem hiding this comment.
🟠 High · Correctness · 1 of 6
Removing Gpu::h and Gpu::f breaks any caller that is not in this diff. The diff deletes fn h(&self) and fn f(&self, name) on Gpu, but only the struct and constructor are shown. If any kernel-launch or accessor code elsewhere in the crate still calls self.h() or self.f("..."), the crate fails to compile. The 'unused' claim is not verified in the diff.
Prompt for your AI agent
File: src/hip/mod.rs
Line: 241
Issue: Removing Gpu::h and Gpu::f breaks any caller that is not in this diff. The diff deletes `fn h(&self)` and `fn f(&self, name)` on Gpu, but only the struct and constructor are shown. If any kernel-launch or accessor code elsewhere in the crate still calls `self.h()` or `self.f("...")`, the crate fails to compile. The 'unused' claim is not verified in the diff.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
There was a problem hiding this comment.
/dismiss Gpu::h and Gpu::f have no callers. The compiler reports them as never used, and it checks the whole crate, not only this diff. After removing them cargo build gives 0 warnings and 0 errors and the 11 hip tests pass on the RX 9070 XT. A caller anywhere in the crate would not compile.
| } | ||
| fn done(&self) -> bool { unsafe { (self.hip.event_query)(self.ev) == ffi::HIP_SUCCESS } } | ||
| } | ||
|
|
There was a problem hiding this comment.
🟠 High · Correctness · 2 of 6
Removing the event query path makes waits spin in the driver. The removed done field was documented as 'recorded by sync, so a wait can poll it instead of spinning in the driver', and Event::done used hipEventQuery. With both removed, any wait loop that depended on polling now blocks or busy-waits in the driver, costing CPU and latency. The change deletes a performance mechanism, not just dead code.
Prompt for your AI agent
File: src/hip/mod.rs
Line: 413
Issue: Removing the event query path makes waits spin in the driver. The removed `done` field was documented as 'recorded by sync, so a wait can poll it instead of spinning in the driver', and `Event::done` used `hipEventQuery`. With both removed, any wait loop that depended on polling now blocks or busy-waits in the driver, costing CPU and latency. The change deletes a performance mechanism, not just dead code.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
There was a problem hiding this comment.
/dismiss This does not remove a wait path. The done field was never recorded: on origin/main Backend::sync is self.wait(), which is hipStreamSynchronize, and nothing touches done. Its doc comment was stale. The waits that do use events (Event::new, record, hipEventSynchronize in the staging ring) are unchanged. Event::done and hipEventQuery had no caller, so no wait loop used them.
| graphs: Mutex<HashMap<u64, Graph>>, | ||
| /// 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. |
There was a problem hiding this comment.
🟠 High · Correctness · 3 of 6
The q8 cache is removed though its doc says live code uses it. The removed field doc says q8 rows of the last integer GEMM's X are cached and that SAME_X depends on it. If the GEMM path still checks or updates self.q8 anywhere, the crate does not compile. If the path instead recomputes the quantization, the cache-hit optimization is lost. Either way, the 'unused' premise conflicts with the removed comment.
Prompt for your AI agent
File: src/hip/mod.rs
Line: 49
Symbol: Gpu
Issue: The q8 cache is removed though its doc says live code uses it. The removed field doc says q8 rows of the last integer GEMM's X are cached and that `SAME_X` depends on it. If the GEMM path still checks or updates `self.q8` anywhere, the crate does not compile. If the path instead recomputes the quantization, the cache-hit optimization is lost. Either way, the 'unused' premise conflicts with the removed comment.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
There was a problem hiding this comment.
/dismiss q8 was a Mutex<(Buf, Option<[u64; 4]>)> holding a 1-byte buffer, and nothing read or wrote it, so no SAME_X cache hit depended on it. The kernels keep their own q8 rows in the buffers they are given. If any code path used self.q8 the crate would not compile; it builds with no errors and the 11 hip tests pass.
| 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) }) | ||
| } |
There was a problem hiding this comment.
🟡 Medium · Correctness · 4 of 6
The module handle is no longer stored and is never unloaded. The module field is removed from Gpu and not kept anywhere, while hipModuleUnload was also removed from ffi. The loaded HIP module therefore cannot be released by this type. Any module local left in the constructor becomes unused, which trips unused_variables and fails builds that deny warnings.
Prompt for your AI agent
File: src/hip/mod.rs
Line: 213
Symbol: new
Issue: The module handle is no longer stored and is never unloaded. The `module` field is removed from Gpu and not kept anywhere, while `hipModuleUnload` was also removed from ffi. The loaded HIP module therefore cannot be released by this type. Any `module` local left in the constructor becomes unused, which trips `unused_variables` and fails builds that deny warnings.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
There was a problem hiding this comment.
/dismiss The module local in Gpu::new is still used for the hipModuleGetFunction lookups, so there is no unused-variable warning. That the module is never unloaded was already true before this PR: nothing called hipModuleUnload, which is why the compiler flagged module_unload as unread. Adding a Drop for Gpu (stream, module, buffers, graphs) is a separate change, see my comment above.
| 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, |
There was a problem hiding this comment.
🔵 Low · Maintainability · 5 of 6
Removed FFI fields change the public Hip struct API and drop lifecycle calls. Hip has pub fields, so removing stream_destroy, module_unload, event_query and last_error breaks any downstream crate that uses them. Within this crate, nothing can now destroy a stream or unload a module through this struct, which leaves resource cleanup impossible if a later change needs it.
Prompt for your AI agent
File: src/hip/ffi.rs
Line: 81
Symbol: Hip
Issue: Removed FFI fields change the public Hip struct API and drop lifecycle calls. `Hip` has `pub` fields, so removing `stream_destroy`, `module_unload`, `event_query` and `last_error` breaks any downstream crate that uses them. Within this crate, nothing can now destroy a stream or unload a module through this struct, which leaves resource cleanup impossible if a later change needs it.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
There was a problem hiding this comment.
/dismiss ffi is a private module (mod ffi; in src/hip/mod.rs), so the pub fields of Hip are not reachable from any other crate or module outside hip. No downstream API changes. Within the crate nothing called stream_destroy, module_unload, event_query or last_error; if a later change adds the cleanup it can add the symbol lookup back.
| } | ||
|
|
||
| type Fn = unsafe extern "C" fn(); | ||
|
|
There was a problem hiding this comment.
✅ No longer detected as of 631975c8e560.
🔵 Low · Maintainability · 6 of 6
Removing type Fn leaves a doubled blank line. The type Fn = unsafe extern "C" fn(); deletion leaves two adjacent blank lines around the removed item. This is cosmetic and fails only a strict rustfmt check.
Prompt for your AI agent
File: src/hip/ffi.rs
Line: 53
Issue: Removing `type Fn` leaves a doubled blank line. The `type Fn = unsafe extern "C" fn();` deletion leaves two adjacent blank lines around the removed item. This is cosmetic and fails only a strict rustfmt check.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
There was a problem hiding this comment.
Valid, thank you. Fixed in 631975c: the second blank line is gone. The build is still clean.
Aletheore Flash Lite reviewWhat this PR does. This pull request deletes unused HIP FFI bindings, constants, struct fields, and helper methods from
1 finding(s) posted as inline review comment(s). 5 earlier finding(s) from previous pushes still open.
Review detailsReviewed 2 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 1 of 1 proposed finding(s). Fix all with your agent |
|
Went through the six inline findings. Five are dismissed with the reasoning on each thread: the build and the 11 hip tests show nothing in the crate uses the removed code, |
| 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() }; |
There was a problem hiding this comment.
🟠 High · Correctness · 1 of 1
Removing the module field drops the only record of the loaded module, and no unload path remains. Gpu::new loads a module, stores it in module, and the field is now removed. Nothing unloads it, and module_unload was also removed from ffi.rs, so every Gpu created in the process leaks its module (and the device code it holds) until exit. Creating and dropping Gpu instances repeatedly grows device memory use.
Prompt for your AI agent
File: src/hip/mod.rs
Line: 210
Symbol: new
Issue: Removing the `module` field drops the only record of the loaded module, and no unload path remains. Gpu::new loads a module, stores it in `module`, and the field is now removed. Nothing unloads it, and `module_unload` was also removed from ffi.rs, so every Gpu created in the process leaks its module (and the device code it holds) until exit. Creating and dropping Gpu instances repeatedly grows device memory use.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
Cleans up the 9 dead-code warnings in
src/hipthat were reported after #95 was merged.cargo buildnow has no warnings, and the 11 hip tests pass on an RX 9070 XT (gfx1201).Gpu: removed the unreadmodule,q8(a 1-byte buffer) anddone(an event that was never recorded), and the unusedhandf.Event::done: removed.ffi.rs: removed the unusedATTR_*constants, theFnalias, and thememset,stream_destroy,stream_wait_event,event_query,module_unloadandlast_errorpointers with their lookups.Staging.pinis renamed_pin: it owns the pinned ring throughPinnedHost, whoseDropfrees it, so it has to stay.