Skip to content

Add Logic for Using TDM and Async Loads and Stores - #322

Merged
AtlantaPepsi merged 13 commits into
ROCm:candidate-1.68from
alex-breslow-amd:asyncOps
Jun 12, 2026
Merged

Add Logic for Using TDM and Async Loads and Stores#322
AtlantaPepsi merged 13 commits into
ROCm:candidate-1.68from
alex-breslow-amd:asyncOps

Conversation

@alex-breslow-amd

Copy link
Copy Markdown
Contributor

Motivation

Run fast on gfx1250

Technical Details

Adds simple copy kernels using TDM and async/loads and stores

Test Plan

Code has correctness testing, but I need to add more corner case testing

Test Result

Tests pass on a hardware simulator for both variants:
./TransferBench cmdline 1024K "1 4 G0 T0 G0"
./TransferBench cmdline 1024K "1 4 G0 L0 G0"

Submission Checklist

Comment thread Makefile
ROCM_PATH ?= /opt/rocm
CUDA_PATH ?= /usr/local/cuda
MPI_PATH ?= /usr/local/openmpi
# pip ROCm wheels ship bin/amdclang++ but often omit bin/amdllvm (which that stub execs).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Logic for running building and running this in a venv on WSL

@alex-breslow-amd
alex-breslow-amd marked this pull request as ready for review June 12, 2026 18:48
@alex-breslow-amd
alex-breslow-amd requested a review from a team as a code owner June 12, 2026 18:48
@alex-breslow-amd

alex-breslow-amd commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Discussed with @AtlantaPepsi and @gilbertlee-amd. The plan is to merge as is. There's some cleanup that needs to be performed however before the candidate branch can be released:

  1. Add proper gating for gfx1250
  2. Handle case where we are on an NVIDIA platform
  3. Add tunability for cache hints to TDM/async load store implementation (Let's sync on this @AtlantaPepsi)

Regarding async loads/stores, the current code is just proof of concept. The waitcnt placement and unrolling isn't optimized. Feel free to remove if you think it's best. TBH, I think this code could be rolled into the existing TransferBench kernels. I was thinking of working on that (actually what I started on before moving to TDM). TDM feels sufficiently different where this likely isn't warranted. I concur with Gilbert on that one.

Comment thread src/header/tdm.h
@@ -0,0 +1,355 @@
/*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file is a standard header but was missing from my installation of ROCm, not sure why. It can probably be removed. This is standard in CLR:

Copilot AI left a comment

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.

Pull request overview

This PR adds two new GPU executor variants intended to improve copy performance on gfx1250 by using (1) TDM-based tensor load/store operations and (2) async global load/store-to-LDS memory ops, along with CLI/help/env-var wiring and a small Makefile improvement for ROCm wheel layouts.

Changes:

  • Add new executor types EXE_GPU_ASYNC_TENSOR and EXE_GPU_ASYNC_MEMOPS with corresponding dispatch, validation, topology naming, and client stringification.
  • Introduce TDM configuration (TdmOptions, TDM_* env vars) and implement new HIP kernels for the TDM tensor path and async load/store path.
  • Improve HIP compiler discovery in the Makefile for ROCm installations where bin/amdllvm is absent.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/header/TransferBench.hpp Adds new executor types, TDM options, and implements/dispatches async GPU kernels (TDM + async LD/ST).
src/header/tdm.h Adds gfx1250 TDM register layout/bitfield definitions used by the TDM kernel path.
src/client/Utilities.hpp Extends executor-to-string mapping for the new executor types.
src/client/Presets/Help.hpp Updates help text to document new executor letters and examples.
src/client/EnvVars.hpp Adds env vars for TDM kernel tuning and wires them into ConfigOptions.
Makefile Adjusts HIP compiler selection to support ROCm wheel layouts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5146 to +5156
// Copy from global memory to LDS
for (size_t i = 0; i < elementsToProcess; i += elements_per_dwordx4_load_store) {
asyncLoadX4(srcPtr + i, shmemPtr + i);
__builtin_amdgcn_s_wait_asynccnt(0);
}

// Write back from LDS to global
for (size_t i = 0; i < elementsToProcess; i += elements_per_dwordx4_load_store){
asyncStoreX4(shmemPtr + i, dstPtr + i);
__builtin_amdgcn_s_wait_asynccnt(0);
}

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.

async l/s will undergo further changes

Comment on lines +5771 to +5772
if (rss.numBytes % sizeof(float) != 0)
return {ERR_FATAL, "Async tensor executor (TDM): numBytes (%zu) must be a multiple of %zu", rss.numBytes, sizeof(float)};

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.

this will be elevated into TransfersHaveErrors guard

Comment on lines +5778 to +5784
int maxShmem = 0;
ERR_CHECK(hipDeviceGetAttribute(&maxShmem, hipDeviceAttributeMaxSharedMemoryPerBlock, exeIndex));
maxShmem = std::min<int>(maxShmem, cfg.tdm.maxLDSBytes);
int kWavesPerWorkgroup = threads / warpSize;
int pipelineDepth = usePipelinedTensorOps ? 2 : 1;
int numFloatsPerTile = std::max<int>(1, maxShmem / (sizeof(float) * kWavesPerWorkgroup * pipelineDepth));
unsigned int shmemBytes = numFloatsPerTile * kWavesPerWorkgroup * sizeof(float) * pipelineDepth;

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.

to be further validated in next PR

Comment thread src/header/TransferBench.hpp Outdated
Comment thread src/client/Presets/Help.hpp
Comment thread src/client/Presets/Help.hpp
Comment thread src/client/EnvVars.hpp
Comment thread src/client/EnvVars.hpp
Comment thread src/header/TransferBench.hpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AtlantaPepsi
AtlantaPepsi merged commit a9b5eb2 into ROCm:candidate-1.68 Jun 12, 2026
1 check passed
nileshnegi pushed a commit that referenced this pull request Jul 10, 2026
* Put in stubs

* Add kernel and fix up

* Finalize tunability of threads per block and number of blocks.

* Implement pipelining

* Add debugging logic

* Fix segfault

* Disable debug prints

* Add missing timing information

* Add TDM_BLOCK_SIZE, TDM_MAX_LDS_BYTES, and TDM_PIPELINED env vars to control TDM kernel execution

* Not functioning but proof of concept async load/store implementation

* Fix async load store kernel MVP

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Tim <43156029+AtlantaPepsi@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
AtlantaPepsi added a commit that referenced this pull request Jul 13, 2026
* Put in stubs

* Add kernel and fix up

* Finalize tunability of threads per block and number of blocks.

* Implement pipelining

* Add debugging logic

* Fix segfault

* Disable debug prints

* Add missing timing information

* Add TDM_BLOCK_SIZE, TDM_MAX_LDS_BYTES, and TDM_PIPELINED env vars to control TDM kernel execution

* Not functioning but proof of concept async load/store implementation

* Fix async load store kernel MVP

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Tim <43156029+AtlantaPepsi@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

3 participants