HSA programming (Heterogeneous System Architecture) is a model in which the CPU and GPU share one virtual address space and hand each other work through user-mode queues, so an inference path no longer has to copy buffers between host and device or go through the operating system kernel on every dispatch. That removes two specific costs: explicit data movement and kernel-mode dispatch overhead. Before targeting HSA, a team should profile and check whether the time it wants back is actually spent moving data or launching work.
How does HSA programming work in practice?
HSA treats the GPU as a peer of the CPU. In the HSA Foundation’s model the CPU is a latency compute unit and the GPU a throughput compute unit, and the GPU acts as a co-processor rather than a device behind a driver wall. The mechanisms that carry the model include shared virtual memory, system coherency, signals that let agents notify each other without involving the OS kernel, and user-mode queues for dispatch packets.
In practice a host program allocates memory through the HSA runtime, gives the GPU a pointer instead of a copy, writes a dispatch packet into its application’s queue, and the packet’s completion signal indicates when the job is done. The OS still has a job: the HSA kernel-mode driver registers applications, manages memory regions and creates the GPU’s process control blocks. What it no longer does is sit on the dispatch path: launches need no OS kernel transition, and allocated buffers are handed to the hardware without further system-software intervention.
How does shared virtual memory cut copy overhead compared with CUDA or OpenCL transfers?
With CUDA or OpenCL on a conventional discrete GPU, data is allocated on the host and on the device, copied across before the kernel runs and copied back afterwards. HSA requires compute devices to share page tables with the CPU, so a pointer passed from one agent to another resolves to the same physical address and no special loads or stores are needed. The program sends pointers, not data.
On older GPU stacks the driver had to flush and invalidate GPU caches before the CPU could see results, even when both sides used the same system memory. The HSA queueing tutorial states as a requirement that accesses to the global memory segment from all agents be coherent without explicit cache maintenance, and the coherent heap is the default heap. The benefit the AMD technical review names is exactly this pair: no explicit data movement and no heavyweight flush-or-invalidate synchronisation, which makes producer/consumer patterns between CPU and GPU code practical.
Coherence in HSA is scoped, not absolute. The memory model is based on release consistency (RCSC), extended to sequential consistency for heterogeneous-race-free programs. The Hot Chips 2013 tutorial on the model advises using the smallest scope that includes all producers and consumers of the shared data, which means those producers and consumers must be known at synchronisation time. In the runtime, memory regions are fine-grained (updates immediately visible to every agent that can access them) or coarse-grained (only one device has access at a time).
The sources do not fully agree on how coherent HSA is. A 2013 arXiv study of cache-coherent shared virtual memory states that HSA provides shared virtual memory and a consistency model but not coherence, while the HSA queueing tutorial states global-segment coherence as a requirement. We read the HSA material as the stronger source for what HSA requires, and the study as a reminder that scoped synchronisation and coarse-grained regions mean coherence is not something you get on every byte for free.
Zero-copy also depends on the physical memory. Where CPU and GPU have distinct physical memories, true zero-copy is impossible; HSA’s unified virtual memory lets the system pass pointers over PCI Express instead of copying whole buffers, and only unified main memory makes zero-copy operation possible.
User-mode queues and AQL packets: how the CPU and GPU hand work to each other
Dispatch in a legacy GPU model means copying the workload, patching command buffers and crossing between user mode and kernel mode repeatedly. HSA gives each application its own dispatch queue and lets a user-mode process write into it directly, with no OS kernel transition, which AMD’s technical review identifies as the fix for time spent waiting on kernel services. The HSA queueing tutorial makes the consequence explicit: lower-latency dispatch enables finer-grained offload.
The runtime creates the queue structure, its packet buffer, a completion signal and read and write indexes that start at zero. Producers update the write index only through the runtime API or HSAIL instructions (never by plain memory operations), write Architected Queuing Language (AQL) packets into the buffer directly and access the doorbell signal. Queues are either multi-producer or single-producer. Packet types include kernel dispatch and barrier-AND packets, and packets carry a completion signal handle.
Three rules from the HSA system architecture specification apply when you write a dispatcher by hand:
- AQL packets are dispatched in order but may complete in any order, and an INVALID packet in the queue blocks those after it.
- The packet processor may start on a packet once its format field is set, before the doorbell rings, so the doorbell must not be used as a gate.
- Signal waits can return sporadically, so the caller must re-check that the condition actually holds.
Dispatch also runs the other way. HSA uses queues as an asynchronous calling model across the CPU/GPU boundary, so GPU code can queue work for the CPU, and a synchronous call can be built on top. ROCm’s runtime can also create software queues whose AQL packets are processed by a host thread rather than a hardware packet processor.
HSAIL, the finalizer and the runtime, and how ROCm relates to HSA today
HSAIL is HSA’s virtual language; the HSA Programmer’s Reference Manual defines its programming model, its memory segments and the finalization, loading and execution of code objects. At dispatch, the HSA runtime calls the finalizer to convert HSAIL into the device’s real ISA; for a CPU agent the compiler back end may emit native code directly and skip HSAIL. In the HSA Runtime 1.2 reference the finalizer is an optional extension alongside images, performance counters and profile events, not a core requirement. The runtime itself reports agent information (the API defines CPU, GPU, DSP, FPGA and custom device types), creates queues, services memory requests and dispatches work.
Today AMD has folded HSA functionality into ROCm. The ROCm runtime (ROCR) is AMD’s implementation of the HSA runtime: a thin user-mode API over the AMDGPU and ROCK kernel drivers that lets host applications launch kernels directly on discrete AMD GPUs. HIP and OpenMP target offload are built on that HSA runtime layer, and calls such as hipMemcpy and hipMalloc are implemented with HSA functions underneath. ROCR’s API exposes user-mode queues, memory pools with fine- or coarse-grained access and multi-entry copy operations. For most users the HSA runtime is an implementation detail beneath HIP and OpenMP target, which is why rocprofv3’s –runtime-trace shorthand option excludes HSA API calls.
What hardware and runtime support does HSA actually require?
The HSA Platform System Architecture Specification 1.2 lists the requirements of a compliant system: shared virtual memory, cache coherency domains, flat addressing, signalling and synchronisation, atomic memory operations, a system timestamp, user-mode queuing, AQL, agent scheduling, kernel-dispatch forward progress, floating-point rules, debug infrastructure and platform topology discovery. Agents come in full and base profiles, and forward-progress guarantees are stronger for a full-profile agent.
On real AMD hardware the constraints that bite are narrower and more practical:
- Device generation. A 2022 evaluation of unified memory in HIP found that it works only on recent AMD GPUs such as Vega10 and MI100, not on older parts such as Fiji and Polaris.
- XNACK. With XNACK enabled the GPU can retry a memory access after a page fault, which allows on-demand mapping, migration and overcommitment; with it disabled, all memory must be resident and mapped before the kernel runs. That study notes XNACK was off by default and only experimentally supported, and that not all ROCm math libraries supported it.
- Discrete GPU versus APU. On MI300A the CPU and GPU share physical HBM, so page migration is neither needed nor useful, yet unified-memory code must still be built on an XNACK-enabled system. The same code compiled for MI200 triggers page migrations that cost performance.
- Fine- versus coarse-grained memory. Choosing coarse-grained regions for bandwidth means only one device owns an allocation at a time.
Which inference workloads gain from HSA’s unified memory, and which do not?
On the evidence below, unified memory pays only where data movement or launch overhead is a large share of the time, and most clearly on unified physical memory; managed memory on a discrete AMD GPU was mostly slower.
- Small offloads gain most. The 2013 coherent shared virtual memory study found the authors’ proposed cache-coherent CPU/GPU design (not HSA hardware) vastly outperformed a copy-based AMD APU running OpenCL when offloading small tasks, because launch overhead is amortised poorly over small work. The 2022 HIP evaluation found unified memory 1.07x to 2.8x faster than page-locked async copies for matrix multiply at 4 KB to 64 KB, with the advantage fading as sizes grew.
- Transfer-heavy phases gain, if transfers dominate the total. On MI300A, one application’s compute time fell 35% and total time 19% once in-loop transfers were removed; in another, compute time fell 86%, but total runtime barely changed because I/O outside the compute phase dominated.
- A kernel-dominated application did not gain. In one MI300A application where little data moved per iteration and kernels dominated, compute time was not significantly affected.
- Sparse access from both sides gains. HIP’s documentation notes only the touched parts of a buffer need to move, cutting traffic over PCIe.
For transformer inference specifically, a 2025 arXiv study of CPU-GPU coupled systems found NVIDIA’s NVLink-C2C-coupled GH200 gave 1.9x to 2.7x faster prefill than loosely coupled systems for Llama-3.2-1B at large batch sizes, but stayed CPU-bound up to 4x larger batch sizes, and CPU single-thread performance remained critical for low-batch latency. In the CPU-bound region the cost was kernel launches from eager-mode PyTorch, and kernel fusion helped there while giving no benefit once the GPU was saturated. Coupled memory did not materially help low-batch models whose bottleneck was the launching CPU.
Managed memory also carries its own costs. The 2022 HIP evaluation measured slowdowns from 3.3% to 210% across benchmarks when moving to unified memory on a discrete AMD GPU, with L2 cache hits near zero under unified memory. HIP’s own guidance is that explicit hipMalloc and hipMemcpy typically perform best for known access patterns, and NVIDIA’s CUDA guide likewise prefers explicit copies for large contiguous data because copy engines overlap transfers with host and device work. MI300A is the counter-case: on unified physical memory, the 2025 MI300A study found the unified model competitive with explicit management across six HPC applications while using up to 44% less memory.
How do I tell from a profiling baseline whether HSA addresses my bottleneck?
Profile the existing copy-based path first and split its time into copies, launches and kernel execution; HSA’s design targets the first two.
TechnoLynx’s GPU engineering work makes this call for inference paths: profiling the existing deployment, attributing time to copies, launches and compute, and estimating what a shared-memory target would realistically save before any porting starts.
On ROCm, rocprofv3 application tracing reports kernel execution, async memory copies and barrier packets, and is intended to answer how much time went to memory copy and which kernel took longest. Its copy traces capture hipMemcpy and hipMemcpyAsync through the underlying HSA async copy call, so host-to-device and device-to-host time appear as separate rows. Measure host and device time together, as the HIP unified-memory evaluation proposes for a fair comparison of code with and without unified memory.
If you trial managed memory, ROCm Systems Profiler builds reports from page-fault and page-migration events, showing faults, migration triggers and migration throughput. That throughput includes fault handling, scheduling, replay and driver overhead, so it is not raw PCIe, XGMI or HBM bandwidth. The memory_copy trace domain can sit alongside it to compare explicit copies against page migrations on one timeline.
Diagnostic table: reading the baseline
| What the trace shows | What it means | Does HSA-style unified memory help? |
|---|---|---|
| Host-to-device and device-to-host copies are a large share of end-to-end time | Data movement dominates | Likely, most of all on an APU with shared physical memory |
| Many short kernels, GPU idle between them, launch time roughly constant as batch grows | Launch-bound (CPU-bound) region | Partly: user-mode dispatch cuts dispatch overhead, and kernel fusion or graph capture cut launch counts |
| Kernel execution dominates, copies small per iteration | Compute-bound | Little or none: in the measured kernel-dominated case, compute time was not significantly affected |
| Copy time falls but total time does not | Something else (I/O, preprocessing) dominates | No |
| Page faults and migrations rise after switching to managed memory | Migration overhead replaced copies | On the discrete AMD GPU studied, tuning only partly offset migration cost; test prefetch and re-profile |
For the wider latency picture on GPU servers, where copy and launch time are only two of several factors, our guide to optimising GPU inference latency covers batching, scheduling and kernel choices in more depth.
How does an HSA target compare with a WebAssembly or native accelerator path?
An HSA target changes how a CPU and GPU in one system share memory and dispatch work. The trade-offs of a WebAssembly path are covered in our explanation of how WebAssembly works for ML inference. A native accelerator path with explicit copies (CUDA, or HIP with hipMalloc and hipMemcpy) remains the reference for known access patterns.
On the measurements above, if the baseline shows copy and launch time are small, an HSA target adds porting work without moving the bottleneck. If the model is small enough that CPU execution is competitive, the CPU inference route deserves a measurement before either accelerator option.
What should you know about HSA programming in practice?
Four practical details stand out in the sources:
- Legacy copy code still copies. Applications written for separate memories run on MI300A but keep paying for transfers between “host” and “device” buffers that no longer need to exist. On that system, hipMemcpy between malloc’d host memory and hipMalloc memory reached only 58 GB/s, against about 1,900 GB/s for GPU-to-GPU copies.
- Allocator choice matters. On MI300A, GPU bandwidth reached 3.5-3.6 TB/s with hipMalloc but 1.8-1.9 TB/s with on-demand allocators such as malloc or hipMallocManaged with XNACK on.
- Shared buffers need a synchronisation story. Merging CPU and GPU buffers into one can create data races; double buffering (swapping instead of copying) is the suggested fix. Contended atomics also cost more when both sides touch the same data.
- Regular patterns suit the model. The HSA memory-model tutorial notes HSA works well with regular data partitioning and regular synchronisation, because producers and consumers are then always known.
Placing the accelerator inside the full pipeline (storage, network, CPU stages) is the theme of GPUs being part of a larger system, and it applies here: shared memory between two processors does not help a stage neither of them owns.
When does targeting HSA make sense versus staying with an explicit copy-based model?
HSA as a standalone target has lost momentum. Phoronix reported that HSA news had been quiet and that much of HSA’s momentum went when AMD focused on ROCm, and separately noted AMD had folded HSA functionality into ROCm. What is live is HSA’s runtime and queueing model inside ROCR, with MI300A as the hardware where the unified memory model performs competitively with explicit management.
Targeting the HSA ideas makes sense when the profiled baseline shows copies or launch overhead dominate, the hardware shares physical memory (an APU such as MI300A) or at least supports XNACK-enabled unified memory, and the workload’s sharing pattern is regular. Explicit copies remain the better choice on discrete GPUs for large, known transfers, where copy engines can overlap transfers with compute.
Once a ported path reaches heterogeneous hardware in production, the questions move to rollback, monitoring and acceptance criteria, which our release-readiness decision framework covers.
FAQ
What devices are covered by HSA?
The HSA Runtime 1.2 reference defines CPU, GPU, DSP, FPGA and custom device types as agents.
Which memory is shared by all threads of one workgroup and explicitly managed by the programmer?
In HSAIL this is group memory, one of the address ranges within a work-item’s flat address space. CUDA calls the equivalent on-chip, block-level store shared memory.