Repository navigation
feat(allowlist): add CUDA (.cu/.cuh) and HIP (.hip) review support - #1768
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
ea48ce2 to
13b6fd1
Compare
|
Rebased onto Both conflicts were the same shape —
Nothing else conflicted: Gates on
I read the rebased diff; the only change against the reviewed commit is the two test tables now holding both languages. |
There was a problem hiding this comment.
A few checks in cuda_hip.md seem worth revisiting:
__threadfence()orders memory accesses, but doesn't wait for other blocks to finish. It isn't a substitute for cross-block synchronization.__activemask()has no_syncvariant, so using it shouldn't be flagged just for lacking one.- Fast math isn't necessarily a bug when results are compared against a reference. Shouldn't this depend on whether the error exceeds the allowed tolerance?
- Two streams reading the same buffer don't necessarily need synchronization. This check should account for whether either stream writes to it.
I'm not very familiar with CUDA, so these points come from a GPT-6.1 Sol review and would benefit from confirmation by someone with CUDA experience. The changes in the other files look fine to me.
There was a problem hiding this comment.
All four points confirmed against the CUDA/HIP docs — thank you. The second one was a factual error on our side.
-
__threadfence()— the bullet no longer presents the fence as the way to carry a value across blocks. It now reads: a__syncthreads()relied on to carry a value to another block, which it cannot — the barrier covers only its own block, and cross-block ordering needs__threadfence()together with a flag or atomic in a release-acquire handshake; the fence establishes order and visibility, it does not wait for another block to arrive. What the check still flags is unchanged: a block barrier standing in for cross-block communication. -
__activemask()— removed from the missing-_synclist, which is now__shfl,__ballot,__any,__all. There is no__activemask_sync, so "used without the_syncform" was wrong; the flagging surface is now:__activemask()treated as a barrier, or its mask handed to a later_synccall as the member mask without the caller establishing that it still names the lanes that must participate. -
Two streams — narrowed to require a writer: two streams with no event or stream dependency between them where at least one of them writes a buffer the other touches, with the note that two readers of the same buffer need no ordering between them.
-
Fast math — now gated on tolerance: the deviation from the IEEE operations replaced can exceed the tolerance the comparison allows; a comparison with slack absorbs it.
Points 3 and 4 were the two bullets whose wording was wider than the document's own precision-over-recall line; that line is now what decides both. Only cuda_hip.md changed — the locale pages carry nothing but the extension mapping.
.cu, .cuh and .hip were outside supported_file_types.json, so a kernel in a diff was dropped as unsupported_ext before any rule applied. Add the three extensions, route them to a new cuda_hip.md rule doc, and document the resolution in all five locales.
13b6fd1 to
0e291bf
Compare
|
Rebased onto The only conflict was
Everything else merged cleanly:
|
|
Thanks for the submission. Like other language support PRs, you have to manually review your rule documentation and verify contents validity by looking up official sources before enqueuing. If you can use official sources it will be worth it, we AREN'T taking any risks of content generated by AI on the behalf of users who are not familiar with the language itself. |
…sources
Maintainer review asked for the rule documentation to be checked against
official sources before enqueuing, rather than taken on trust. This commit is
the result of that pass over `rule_docs/cuda_hip.md`.
Checked and kept, with the wording aligned to what the source actually says:
- `atomicAdd(double*)` — the Programming Guide states it "is not available on
devices with compute capability lower than 6.0", so the rule keeps the sm_60
floor and now uses that phrasing.
- Device-side launch — "Dynamic Parallelism is only supported by devices of
compute capability 3.5 and higher", and the guide's own example builds it
with `-rdc=true ... -lcudadevrt`. The intro now names both the capability and
the relocatable-device-code requirement instead of only sm_35.
- `_sync` shuffle/ballot intrinsics arrived in CUDA 9 (warp-vote functions are
documented with a `mask` parameter; `__activemask()` alone has no `_sync`
form).
- 1024 threads per block ("a thread block may contain up to 1024 threads").
- `cudaGetLastError()` — "returns this variable and resets it to cudaSuccess",
and kernel launches return no error code, so it has to be called right after
the launch.
- `--use_fast_math` implies `--ftz=true --prec-div=false --prec-sqrt=false
--fmad=true` (NVCC driver), which is what the fast-math and denormal rules
rest on.
- `__syncthreads*()` "are permitted in conditional code, but only if the
condition evaluates uniformly across the entire thread block".
- `__activemask()` — an instantaneous snapshot that "cannot be used to
determine which warp lanes execute a given branch".
- `__threadfence()` — a fence (order and visibility), not a wait for another
block.
Dropped, because the source does not support it: the misaligned-reinterpreted-
pointer bullet claimed a misaligned access "faults instead of degrading". The
Size and Alignment Requirement section says the opposite kind of thing — an
unaligned access compiles to multiple instructions and loses coalescing — which
is a performance effect, and the file's own preamble excludes performance
findings. The bullet is gone rather than left unverifiable.
Added a `Sources` section listing the sections each claim was checked against,
so the next reviewer can audit them.
|
Understood — and done: What the pass produced: Every architecture/version claim now maps to a named section, with the wording the source actually uses.
One rule is removed, because the source does not support it. The bullet about elements "accessed through a reinterpreted pointer whose alignment was not established, on an architecture where a misaligned access faults instead of degrading" claimed a consequence the documentation does not state: the Size and Alignment Requirement section says an unaligned access compiles to multiple instructions and loses coalescing — a performance effect, which this file's own preamble excludes from review findings. Unverifiable as written, so it is gone rather than left in. A The four points @chaojixinren raised earlier (the fence, One thing I want to be straight about rather than let the diff imply it: the verification above is source-based — every claim is anchored to a section you can check — but it is not the testimony of someone who writes CUDA kernels daily. If the bar for this language is a practitioner's confirmation of the rule selection (not just the wording), say so and I will treat the PR as blocked on that rather than push it further. |
|
Adding the quotes behind the check in
What I changed while checking: the What I could not source from NVIDIA: the HIP spellings ( |
…CUDA 9 intrinsics
|
The two wording changes the table mentions are in 5bf28b8 ( |
There was a problem hiding this comment.
@chaojixinren Can you kindly review these documentation please? I don't have time since I have to deal with other submissions.
|
I suggest adding a context-verification guideline similar to the one in The current rules cover CUDA/HIP-specific failure patterns well, but some findings depend heavily on the actual execution environment, compilation configuration, and surrounding code. Rather than encoding more architecture- or vendor-specific exceptions into the rule document, I think we should let the LLM investigate these differences using the available repository context. For example, we could add something like:
This follows the evidence-driven approach already used in I think this would improve precision and reduce false positives while keeping the CUDA/HIP rules generic and maintainable, without requiring separate rules for different GPU vendors or architectures. |
…HIP finding The rule sections depend on the actual execution environment -- the target architecture, the build configuration and the reachable path -- but nothing told the reviewer to look for it, so a construct that is merely unsafe under some configuration could be reported as a defect. Add the same instruction go.md carries, in CUDA/HIP terms: establish the kernel implementation, its launch sites, the build configuration that selects the architecture and features (-gencode/__CUDA_ARCH__, -rdc, --use_fast_math) and the reachable execution path, and report only a concrete correctness problem. Suggested by @chaojixinren in review of alibaba#1768.
|
@chaojixinren added on
Two deviations from your wording, both deliberate:
Nothing else moved: no new rules, no vendor- or architecture-specific exceptions, section list and Sources unchanged. All three flags are already covered by the Sources section (NVCC Verified: |
|
Full-suite result on |
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed the complete ten-file diff, #1767, and the existing discussion. The issue-number duplicate search returned only this PR. The allowlist, resolver mappings, case-insensitive tests and five locale rows consistently address the requested GPU-source coverage. The earlier fence, activemask, tolerance and two-reader comments have been incorporated; I am not reopening those findings.
One factual rule needs correction before this becomes built-in review guidance: the introduction and line 41 classify ordinary device-function recursion as CUDA Dynamic Parallelism and consequently require relocatable device code. The inline comment gives the distinction and NVIDIA references. This can produce false-positive build-configuration findings against valid recursive device helpers.
Validation was source and regression-test inspection plus comparison with NVIDIA's documentation. I did not run nvcc, GPU kernels, or the repository test suite. GitHub currently also reports merge conflicts; that is separate from the rule-content finding.
This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.
| - An asynchronous copy or kernel result read on the host with no synchronization, or a `cudaMemcpyAsync` that is presented as asynchronous while its host side is ordinary pageable memory | ||
| - Two streams with no event or stream dependency between them where at least one of them writes a buffer the other touches; two readers of the same buffer need no ordering between them | ||
| - Data produced on one device and consumed on another, or copied into unified memory, with no synchronization on the producing side | ||
| - A `__global__` function launched from another `__global__` function, or recursion in device code, in a translation unit not built for relocatable device code |
There was a problem hiding this comment.
[P2] Separate ordinary device recursion from device-side kernel launches
The or recursion in device code clause makes a recursive __device__ helper in a single translation unit a finding whenever the build omits -rdc=true. Ordinary function recursion does not launch a child grid and does not acquire CUDA Dynamic Parallelism's compilation/capability requirements merely by being recursive. The same conflation appears in the introduction at line 2.
NVIDIA explicitly allows recursion in __device__ and __host__ __device__ functions in its Recursion section. Its separate-compilation documentation explains that whole-program compilation is the default and that -rdc=true/-dc enables linking device code across translation units.
Please remove ordinary recursion from both dynamic-parallelism checks. Keep the child-kernel-launch requirements scoped to actual device-side launches; assess a recursive helper only when its own call/linkage context or a demonstrated stack/correctness problem warrants a finding. This is a documentation-backed distinction, not a claim that I executed a CUDA fixture.
There was a problem hiding this comment.
Fixed in c0e81be, carried through the rebase onto upstream/main in a8b8ea9.
- Introduction (line 2): the dynamic-parallelism clause is now "a device-side launch — a
__global__function called from device code —", with the recursion question moved out of it: "Recursion is a separate question and not a dynamic-parallelism finding:__device__and__host__ __device__functions may recurse under the default whole-program compilation, while__global__functions do not support recursion at all." - Host, Device, and Stream Lifetimes bullet: "or recursion in device code" is gone. The bullet now scopes
-rdc=trueto what it actually buys — device code from another translation unit being linkable — and says a recursive__device__helper does not need it. - Sources: one added line naming the two documents the distinction rests on.
You were right about the direction, and I checked it against the two pages you cited rather than taking it on trust:
- CUDA C++ Programming Guide, C++ Language Support → Recursion: "
__global__,__tile_global__and__tile__functions do not support recursion, while__device__and__host__ __device__functions do not have such restriction." (I had also missed the converse — recursion is unsupported in__global__outright, not merely gated on-rdc— so that is stated too.) - CUDA Compiler Driver NVCC, Separate Compilation of GPU Code: nvcc defaults to whole-program compilation; "either the
-rdc=trueor its alias the-dcflag must be specified on the nvcc command line to enable linking of device code from different compilation units."
No CUDA fixture was run here either — this is a documentation correction, same basis as your review.
In the same push: merged upstream/main (c469d7a) into the branch and resolved the five review-rules tables by keeping upstream's rows and re-inserting the CUDA/HIP rows in relative matching order (64 upstream patterns → 66, nothing removed, no duplicates in any locale). go test ./... is green on a8b8ea9, including TestReviewRulesGuideListsEverySystemRulePattern for en/zh/ja/ko/ru.
NVIDIA's C++ Language Support appendix allows recursion in __device__ and __host __device__ functions and restricts only __global__ ones, while -rdc=true exists to link device code across translation units. The introduction and the lifetime bullet presented ordinary recursion as CUDA Dynamic Parallelism, which would flag valid recursive device helpers as a build-configuration defect. Keep the child-kernel-launch requirement on actual device-side launches, and name the recursion rule and its sources separately.
Resolve the review-rules table conflict by keeping upstream's pattern rows and re-inserting the CUDA/HIP rows in relative matching order.
|
@SU-AN-coder Please squash your commits and rebased main. If there is no problems I think we are good to merge. @NanaseInori PTAL |
Description
Adds
.cu,.cuhand.hipto the file-type allowlist and gives CUDA and HIP kernels a dedicated rule doc, so GPU kernels are reviewed instead of being dropped before the agent sees them.Closes #1767 (the language-group proposal under the tracking issue #470).
Before / after —
ocr delegate previewon a scratch repo with one modified.cu,.cuh,.hipand.cppfile:ocr rules checkon the same files:Files changed
internal/config/allowlist/supported_file_types.json+ .cu,.cuh,.hipinternal/config/rules/system_rules.json+ "**/*.{cu,cuh}"and+ "**/*.hip"→cuda_hip.mdinternal/config/rules/rule_docs/cuda_hip.mdinternal/config/allowlist/allowed_ext_test.goIsExcludedPathcasesinternal/config/rules/system_rules_test.goResolverows plus aResolveDetailtest pinning the matched patternpages/src/content/docs/{en,zh,ja,ko,ru}/review-rules.mdDesign notes
{ml,mli}/{re,rei}→ocaml.md, and the doc preamble tells the reader to judge each finding against the header the file actually includes (cuda*versuship*).test/ortests/, and projects also keep production kernels there, so such a pattern would drop real source.allowed_ext_test.godocuments the absence with cases rather than leaving it unexplained; the generictestdata/,fixtures/andvendor/exclusions still apply to kernels and are covered too..cutocpp.md. A kernel's real defects are device-specific — a barrier not every thread reaches, an unsynchronized shuffle on Volta or later, an unchecked launch, a buffer touched by two streams, a grid-stride loop whose index wraps — and none of them appear in the C++ checklist. The rule doc is scoped to those.TestSystemRulesIntegrityalready enforces the JSON ↔ rule_docs ↔ allowlist consistency (no orphan docs, every extension glob allowlisted), so the new files are held by those invariants as well as by their own tests.Type of Change
How Has This Been Tested?
make testpasses locallyRED → GREEN. On
main(8eb8334) with only the test files applied:With the source change in place:
Manual verification. Built
mainand this branch withgo build -o ocr ./cmd/opencodereview, then ranocr delegate previewandocr rules checkagainst a scratch repository; the transcript is the before/after block in the description. Neither command makes a model call.Gates run locally
make check— "check passed" (license headers, English-only scan over 791 files,go mod tidyleaves no diff,gofmt -s,go vetacross all 25 packages)bash scripts/verify-action-pins.sh— all action references SHA-pinnedgo test -count=1 -race -coverprofile=... ./...— 25/25 packages pass with this diff applied; every package the diff touches passes; total coverage 91.5%, above the 90% CI thresholdcmd/opencodereview TestRunSessionExport_DefaultsToNewest,internal/session TestListSessions_SortsAndAggregates(both sort sessions whoseStartTimeis persisted at second resolution after atime.Sleep(1100ms)) andinternal/llm TestRawMiddleware_TimestampIsAttemptStart. They are pre-existing and load-sensitive, not related to this change: an idle run of the full suite on unmodifiedmainpasses 25/25, and a run of the full suite on unmodifiedmainwith the CPU saturated reproduces the failure —Each of the three also passes in isolation (
go test -count=20 -race -run TestListSessions_SortsAndAggregates ./internal/session/→ ok), and with this diff applied the idle full-suite run passes 25/25 (verified twice).Rule documentation verified against NVIDIA's sources
rule_docs/cuda_hip.mdwas taken through the documentation line by line against NVIDIA's own docs (commit2b076f4), after the maintainer review asked for that rather than taking the rules on trust:atomicAdd()ondoublebelow compute capability 6.0 (Programming Guide, Atomic Functions), the compute capability 3.5 floor for a device-side launch with-rdc=true(CUDA Dynamic Parallelism), the CUDA 9_syncintrinsics, the 1024-thread block limit,cudaGetLastError()resetting the error variable, and--use_fast_mathimplying--ftz=true --prec-div=false --prec-sqrt=false --fmad=true(NVCC);Sourcessection now lists the sections each claim was checked against.The verification is source-based. If the bar for this language is a practitioner's confirmation of the rule selection rather than the wording, I would rather be told that than have the diff imply experience this submission does not claim.
Checklist
go fmt,go vet)The CLA box stays open: I will sign as soon as the bot posts the link on this PR.
Model disclosure: the analysis, the diff and this description were drafted with the help of an AI coding agent (Hermes Agent by Nous Research, model
deepseek-v4.1-flash). I read every line of the diff myself, ran the RED→GREEN sequence and the manual CLI checks above myself, and I can explain every change in it unaided.Related Issues
Closes #1767. Contributes to #470.