Skip to content

hip: remove the unused fields, methods and constants - #99

Merged
Vasyl-Trefilov merged 1 commit into
RustingStudio:mainfrom
hun:hip-dead-code
Nov 25, 2026
Merged

Vasyl-Trefilov merged 1 commit into
RustingStudio:mainfrom
hun:hip-dead-code

Conversation

@hun

@hun hun commented Nov 24, 2026

Copy link
Copy Markdown

Cleans up the 9 dead-code warnings in src/hip that were reported after #95 was merged. cargo build now has no warnings, and the 11 hip tests pass on an RX 9070 XT (gfx1201).

  • Gpu: removed the unread module, q8 (a 1-byte buffer) and done (an event that was never recorded), and the unused h and f.
  • Event::done: removed.
  • ffi.rs: removed the unused ATTR_* constants, the Fn alias, and the memset, stream_destroy, stream_wait_event, event_query, module_unload and last_error pointers with their lookups.
  • Staging.pin is renamed _pin: it owns the pinned ring through PinnedHost, whose Drop frees it, so it has to stay.

@hun

hun commented Nov 24, 2026

Copy link
Copy Markdown
Author

One thing this PR does not change: Gpu has no Drop, so its stream is never destroyed and its module is never unloaded. That was already the case; the stream_destroy and module_unload pointers removed here were never called. It matters little while one Gpu lives for the whole process, but a Drop for Gpu (destroy the stream, unload the module, and free am, the rope tables and the graphs in a defined order) would make it correct. I left it out to keep this PR to the warnings. I can send it as a separate PR if you want it.

@aletheore

aletheore Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🔍 Aletheore evidence diff

graph 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
Loading

What changed
Deterministic, computed from this commit's real scan and import graph - posted on every run, whether or not Flash Review found anything.

  • src/hip/ffi.rs · modified · +0/-17
  • src/hip/mod.rs · modified · +6/-21 · -3 functions · 2 other dependents

Aggregate deltas

  • Modules: +0
  • Dependency graph edges: +0
  • Commits: 1

Comment thread src/hip/mod.rs
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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.

Comment thread src/hip/mod.rs
}
fn done(&self) -> bool { unsafe { (self.hip.event_query)(self.ev) == ffi::HIP_SUCCESS } }
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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.

Comment thread src/hip/mod.rs
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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.

Comment thread src/hip/mod.rs
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) })
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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.

Comment thread src/hip/ffi.rs
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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.

Comment thread src/hip/ffi.rs Outdated
}

type Fn = unsafe extern "C" fn();

@aletheore aletheore Bot Nov 24, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, thank you. Fixed in 631975c: the second blank line is gone. The build is still clean.

@aletheore

aletheore Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Aletheore Flash Lite review

What this PR does. This pull request deletes unused HIP FFI bindings, constants, struct fields, and helper methods from src/hip/ffi.rs and src/hip/mod.rs, including the q8 scratch buffer, the done event, and the module handle. It also renames the staging ring's pin field to _pin so the pinned allocation stays alive without being read. The change mainly affects maintainers of the crate's HIP GPU backend, since nothing should change at runtime, but any code that still referenced the removed items would fail to compile.

Merge confidence Review effort Merge risk
2 / 5 1 / 5 Medium
Area Files Lines
src/hip 2 +6 −38

1 finding(s) posted as inline review comment(s). 5 earlier finding(s) from previous pushes still open.

# Severity Category Where
1 🟠 High Correctness mod.rs:210 Removing the module field drops the only record of the loaded module, and no unload path remains. Gpu::new…
- 🟠 High Correctness mod.rs:241 Earlier finding, still open
- 🟠 High Correctness mod.rs:413 Earlier finding, still open
- 🟠 High Correctness mod.rs:49 Earlier finding, still open
- 🟡 Medium Correctness mod.rs:213 Earlier finding, still open
- 🔵 Low Maintainability ffi.rs:81 Earlier finding, still open
Review details

Reviewed 2 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 1 of 1 proposed finding(s).

Fix all with your 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.

@hun

hun commented Nov 24, 2026

Copy link
Copy Markdown
Author

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, done was never recorded (sync is just hipStreamSynchronize), ffi is a private module, and the missing unload is not new. The sixth (a doubled blank line in ffi.rs) was valid and is fixed in 631975c. The PR is still one commit.

Comment thread src/hip/mod.rs
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() };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

@Vasyl-Trefilov
Vasyl-Trefilov merged commit 0011b0e into RustingStudio:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants