Skip to content

moe-cache: fix pre-existing HIP nodiscard errors blocking the -Werror gate - #302

Merged
TheTom merged 1 commit into
feature/turboquant-kv-cachefrom
fix/hip-nodiscard-moe-cache
Aug 18, 2026
Merged

TheTom merged 1 commit into
feature/turboquant-kv-cachefrom
fix/hip-nodiscard-moe-cache

Conversation

@TheTom

@TheTom TheTom commented Aug 17, 2026

Copy link
Copy Markdown
Owner

What

ubuntu-22-hip-quality-check builds with -Werror and fails on 19 discarded-return CUDA runtime calls in moe-cache.cu:

error: ignoring return value of type 'hipError_t' declared with 'nodiscard' attribute [-Werror,-Wunused-value]

HIP declares hipError_t as [[nodiscard]]. CUDA does not mark cudaError_t that way, so these compile clean under nvcc and hard-error under HIP. Nothing here is new. The gate has been red on every PR in the repo for this reason, and contributors keep being asked to look at a failure that is not theirs.

I confirmed it is pre-existing rather than introduced by any open PR. Against #300, which touches this file, the reported line numbers are exactly the base-branch sites plus that PR's insertions:

base 813,1013,1072,1146,1147,1150,1267,1285,1294  ->  CI 824,1024,1083,1157,1158,1161,1278,1296,1305   (+11)
base 1649,1653,1660,1665,1670,1675                ->  CI 1661,1665,1672,1677,1682,1687                 (+12)

The fix

(void) on all 19, which is the idiom this file already uses. There are six pre-existing (void)cudaGetLastError(); sites in moe-cache.cu (lines 771, 796, 1062, 1077, 1254, 2495), so this is matching local convention rather than introducing one.

Deliberately not CUDA_CHECK. That macro calls ggml_cuda_error, which is [[noreturn]] and aborts. All 19 sites are teardown, rollback, or best-effort drain, and eight of them are inside moe_cache_free_device, which is called from moe_cache_session_destroy. Converting those to CUDA_CHECK would introduce aborts during shutdown, which is a behavior change and a worse one. The file's own moe_cache_cuda_ok(...) soft-check helper was also considered and rejected for the same reason: none of these sites were checked before, and making them checked is a separate decision from making them compile.

Every hunk is a single-statement (void) wrap. No reordering, no control flow change, no statements added or removed. This is compile-time only and CUDA behavior is bit-for-bit identical.

Verification

I have no HIP or CUDA toolchain on this machine, so the HIP build itself was not run locally. This needs the CI job to confirm green. Being explicit about that rather than implying it was tested.

What I did verify locally, since the whole fix rests on one assumption:

enum [[nodiscard]] fakeError_t { ok = 0 };
fakeError_t doThing();
void bare()   { doThing(); }        // error
void voided() { (void)doThing(); }  // clean
$ clang++ -std=c++17 -Wall -Wunused-value -Wunused-result -Werror -fsyntax-only
nd.cpp:3:17: error: ignoring return value of type 'fakeError_t' declared with 'nodiscard' attribute [-Werror,-Wunused-value]

That reproduces the CI diagnostic exactly, same wording and same -Wunused-value flag, and the (void) form compiles clean under the same flags. So the suppression mechanism is confirmed even though the real HIP compile is not.

Also swept the file for all 47 cuda*( occurrences and classified each as assigned, wrapped in moe_cache_cuda_ok, already (void), or bare. The 19 bare ones are the ones changed here, and none remain.

HIP marks hipError_t [[nodiscard]] (CUDA does not mark cudaError_t
this way), so the ubuntu-22-hip-quality-check -Werror build fails on
every discarded-return CUDA runtime call in this file. All affected
sites are best-effort cleanup/rollback/teardown calls whose result was
already intentionally ignored, matching the file's existing
(void)cudaGetLastError() idiom. Explicitly void the results rather
than introducing new error checks, so CUDA runtime behavior is
unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant