Skip to content

Conversation

@zcbenz
Copy link
Collaborator

@zcbenz zcbenz commented Jan 27, 2026

For 4090 there is no hardware cpu/gpu coherency, so we can not synchronize between CPU and GPU by sharing atomics. This PR provides a fallback implementation of AtomicEvent for this case: we store the atomic in device-only memory, and do CPU waiting with a busy-wait loop that reads the value with cudaMemcpy.

This is a very inefficient fallback but it mostly serves to make tests pass, AtomicEvent has always been a slow fallback from CudaEvent for infrequent use cases.

Also includes some small changes:

  • Use uint32 instead of uint64 as the latter has more hardware requirements for atomic ops.
  • Use atomic_ref instead of atomic to make initialization easier for device-only memory.

Comment on lines +222 to +225
// 2. hostNativeAtomicSupported == true
// => use cuda::atom_ref on pinned host memory
// 2. no hardware cpu/gpu coherency
// => use cuda::atom_ref on device memory
Copy link
Member

Choose a reason for hiding this comment

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

Which category (2 or 3) do typical consumer gpus fall into (4090, 5090 etc)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

4090 is cat 3, I don't know about 5090. Cat 2 is probably only theoretically possible, but it is very simple to support.

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@zcbenz zcbenz merged commit 2ac18ed into ml-explore:main Jan 28, 2026
16 checks passed
@zcbenz zcbenz deleted the fallback-event branch January 28, 2026 01:43
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