﻿# rocBLAS strided batches: matrix leading dimension and batch stride describe different jumps

Map rocBLAS strided-batched GEMM onto actual matrix storage, keeping leading dimensions, transpose interpretation and matrix-to-matrix strides separate.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-rocblas-strided-batch-leading-dimension/
Language: en

## Draw the stored matrix before the multiplication

A wrapper combines padded matrices into a strided batch and sets every stride from logical dimensions. The [rocBLAS GEMM reference](https://rocm.docs.amd.com/projects/rocBLAS/en/latest/reference/level-3.html) distinguishes leading dimensions from matrix-to-matrix strides. Start with the actual storage diagram, including padding. The mathematical dimensions of the multiplication describe the operation; they do not by themselves establish how the next column or next matrix is reached in memory.

## Keep transpose interpretation separate from allocation

The [HIP programming-model guide](https://rocm.docs.amd.com/projects/HIP/en/latest/understand/programming_model.html) explains rocBLAS column-major expectations and row-major interpretation. A transpose flag changes how an operand participates in the operation; it does not physically repack its allocation. Derive leading dimensions from the stored representation for the selected operation. A square, tightly packed demonstration can conceal a wrong assumption because several different size expressions happen to produce the same offset.

## Derive the batch jump independently

The [rocBLAS datatype reference](https://rocm.docs.amd.com/projects/rocBLAS/en/latest/reference/datatypes.html) defines rocblas_stride for strided-batched interfaces. Compute the jump between matrix starts using the actual layout and the interface's element-based convention, not an unexamined byte count. Padding, a larger surrounding allocation or deliberately separated matrices can make the batch jump differ from the product of logical dimensions. Keep input and output jumps independent. An output batch that overlaps unintentionally can corrupt another result even if individual GEMM arithmetic is correct.

## Choose pointer-array batching when appropriate

Strided batching describes a regular relationship between starts. If matrices have irregular addresses, do not force them into that representation by selecting a stride that fits only the first pair. Inspect the appropriate pointer-array batched interface and its device-memory requirements instead. Neither form automatically validates matrix lifetime, handle stream association or shape compatibility. The wrapper should expose its chosen layout contract rather than accept arbitrary tensor views and hope the library infers their storage.

## Validate non-square padded examples

Compare a batch of deliberately different matrices against a simple reference, using non-square dimensions and explicit padding. Check every output matrix and preserve untouched padding where required by the fixture. Related guides on [HIP portability](/journal/learn-hip-launch-portability/) and [reproducible environments](/journal/software-stack-reproducibility/) provide context. This acceptance establishes storage interpretation for the tested interface. It is distinct from scalar pointer mode, workspace configuration and algorithm tuning, which cannot repair a fundamentally incorrect address map.
