Skip to content

perf(clr): Write AQL packets with non-temporal stores - #284

Open
saleelk wants to merge 2 commits into
ROCm:release/rocm-rel-6.3.0.1from
saleelk:users/saleelk/ntAqlWrite_63
Open

saleelk wants to merge 2 commits into
ROCm:release/rocm-rel-6.3.0.1from
saleelk:users/saleelk/ntAqlWrite_63

Conversation

@saleelk

@saleelk saleelk commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Assigning a packet into its ring buffer slot pulls that slot's cache line in for ownership and dirties it, which buys nothing: the packet processor is the only other reader and it fetches the slot over the fabric anyway.

Copy the 60 body bytes with non-temporal stores instead, so they land straight in the write-combining buffer, and keep publishing the header with the existing release store once an sfence has drained that buffer. The header dword stays out of the copy, so the slot holds the invalid header the packet processor left behind until the body has arrived. Covers kernel dispatch, barrier-AND and barrier-value packet submission.

Associated JIRA ticket number/Github issue number

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Continuous Integration

What were the changes?

Why are these changes needed?

Updated CHANGELOG?

  • Yes
  • No, Does not apply to this PR.

Added/Updated documentation?

  • Yes
  • No, Does not apply to this PR.

Additional Checks

  • I have added tests relevant to the introduced functionality, and the unit tests are passing locally.
  • Any dependent changes have been merged.

Assigning a packet into its ring buffer slot pulls that slot's cache line
in for ownership and dirties it, which buys nothing: the packet processor
is the only other reader and it fetches the slot over the fabric anyway.

Copy the 60 body bytes with non-temporal stores instead, so they land
straight in the write-combining buffer, and keep publishing the header
with the existing release store once an sfence has drained that buffer.
The header dword stays out of the copy, so the slot holds the invalid
header the packet processor left behind until the body has arrived. Covers
kernel dispatch, barrier-AND and barrier-value packet submission.
MOVDIR64B stores all 64 bytes of a packet as one atomic write, so the
packet processor can only observe the slot's old invalid header or the
complete new packet -- there is no window where a valid header sits over a
body that has not landed yet. It also collapses the non-temporal path's
body copy, sfence and separate header store into a single instruction.

Detect it from CPUID leaf 7 sub-leaf 0 (ECX bit 28), cache the result, and
take that path whenever DEBUG_CLR_USE_MOVDIR64B is non-zero, which it is
by default. Hosts without the instruction keep the non-temporal stores.
Neither path needs a fence before the doorbell, since ROCr sfences before
it writes the hardware doorbell.
Comment thread rocclr/device/rocm/rocvirtual.cpp
// ================================================================================================
static inline bool useMovdir64b() {
#if defined(ATI_ARCH_X86) && defined(_LP64)
static const bool enabled = DEBUG_CLR_USE_MOVDIR64B != 0 && Os::hasMovdir64b();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be good to add a log info so we know what was detected by the runtime.

static auto enabled = []() {
  auto flag = DEBUG_CLR_USE_MOVDIR64B != 0 && Os::hasMovdir64b();
  LOG_INFO ...
  return flag;
  }();

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