Repository navigation
intrinsics: add globaltimer - #52
Merged
nihalpasham merged 2 commits intoMay 27, 2026
Merged
Conversation
josephglanville
force-pushed
the
jpg/intrinsics-globaltimer
branch
from
May 13, 2026 06:01
9cf660b to
9c60086
Compare
Signed-off-by: Joseph Glanville <[email protected]>
josephglanville
force-pushed
the
jpg/intrinsics-globaltimer
branch
from
May 13, 2026 06:25
9c60086 to
4c23506
Compare
Switch `nvvm.read_ptx_sreg_globaltimer` from inline asm to the named LLVM intrinsic `llvm.nvvm.read.ptx.sreg.globaltimer`, matching how the sibling SREG reads (clock, clock64, tid, ctaid, ntid, lane, cluster) already lower. This drops the unnecessary `convergent` attribute (SREG reads are not warp-synchronous primitives) and lets LLVM model the call as a typed intrinsic instead of an opaque asm blob. Emitted PTX is byte-identical (`mov.u64 %rdN, %globaltimer;`), verified against `llc-21.1.8` (project floor). The `debug` example still runs end-to-end with correct cycle measurements. Doc/comment touch-ups for parity with the clock64 entries: - `cuda-device/src/debug.rs`: refresh the lowering hint in the `globaltimer()` stub to reference the LLVM intrinsic. - `dialect-nvvm/src/ops/debug.rs`: complete the ASCII-table row so it reads `%globaltimer / ...globaltimer` like the Clock/Clock64 rows. - `mir-lower/src/convert/intrinsics/debug.rs`: update the lowering table to reflect the new conversion. The lowering unit test is renamed to `test_globaltimer_lowers_to_intrinsic_call` and reshaped to mirror `test_intrinsic_insertion`: it asserts the `llvm_nvvm_read_ptx_sreg_globaltimer` declaration is emitted, the kernel body holds a direct call to it, and adds a regression guard that the lowering must not produce inline asm. Co-Authored-By: Joseph Glanville <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
nihalpasham
approved these changes
May 27, 2026
nihalpasham
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for adding this
I've layered a few changes on top before merging:
- Lower
nvvm.read_ptx_sreg_globaltimervia the named LLVM intrinsic
rather than inline asm.llvm.nvvm.read.ptx.sreg.globaltimer
is a real NVPTX intrinsic supported well below our LLVM 21
(verified withllc-21.1.8: emits exactly the samemov.u64 %rdN, %globaltimer;). - Going through the named intrinsic also drops the unnecessary
convergent
attribute; SREG reads don't require warp-synchronous execution, only
primitives likeshfl/vote/barrier/mbarrier/cp.async.bulkdo. - Updated the unit test to mirror the existing
test_intrinsic_insertion
pattern (assert thedeclare+ thecall, plus a regression guard that
globaltimer must not lower to inline asm).
nihalpasham
added a commit
to josephglanville/cuda-oxide
that referenced
this pull request
May 27, 2026
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
…l-actions-856a8fccb2 Bump the all-actions group with 4 updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a CUDA device-side
globaltimer()debug intrinsic that reads PTX%globaltimeras a 64-bit timer value. This complementsclock64()with a global timer source that is better suited for measurements that may span multiple SMs.Example
Implementation
cuda_device::debug::globaltimer() -> u64andcuda_device::debug::elapsed_ticks(start, end) -> u64.nvvm.read_ptx_sreg_globaltimerop todialect-nvvm, including registration and result-type verification.cuda_device::debug::globaltimerthrough MIR intrinsic dispatch.globaltimer()alongsideclock64().Validation
test_globaltimer_lowers_to_inline_asm, which verifies thatReadPtxSregGlobaltimerOplowers to the expected inline asm template and is marked convergent