﻿# rocFFT real transforms: an in-place allocation must fit the Hermitian output layout

Allocate rocFFT in-place real transforms from their physical real/Hermitian layouts, keeping logical length, padding, strides and batch distances distinct.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-rocfft-inplace-real-storage-padding/
Language: en

## Separate signal length from storage capacity

A signal buffer contains its real samples and is reused as the output of a real-to-complex transform. The [rocFFT real-data guide](https://rocm.docs.amd.com/projects/rocFFT/en/latest/how-to/real-data.html) explains the non-redundant Hermitian representation. For a contiguous logical length N, that representation contains floor(N/2)+1 complex values. Each complex value occupies real and imaginary components. Consequently, allocating only the logical real-signal length is not sufficient for the corresponding in-place interleaved output layout.

## Compute physical padding for the chosen case

For that contiguous in-place case, capacity in real scalar units must accommodate 2*(floor(N/2)+1). Even and odd lengths therefore need separate attention; a remembered rule about extra samples from an even-length example should not replace the formula. Logical signal length remains N. Padding is storage capacity, not an instruction to transform a longer signal. Keep those quantities separate in allocation, input initialization and validation of the transformed spectrum.

## Preserve input and output units

The [rocFFT API reference](https://rocm.docs.amd.com/projects/rocFFT/en/latest/reference/allapi.html) defines layout descriptions, strides and distances. Real input strides and complex output strides can express the same physical storage using different element units. Blindly copying a real-row distance into a complex-layout field can therefore describe the wrong addresses. Extend the layout diagram to batches and higher dimensions before setting custom parameters. A sufficiently large overall allocation does not repair an incorrect per-row or per-batch interpretation.

## Distinguish data padding from working memory

The [rocFFT workflow guide](https://rocm.docs.amd.com/projects/rocFFT/en/latest/how-to/working-with-rocfft.html) separately describes plan construction, execution and optional work-buffer requirements. Internal working storage is not the same resource as physical padding in the user data buffer. Query and supply the required work buffer according to the chosen plan while preserving the data layout independently. Calling a transform in-place does not promise that the library needs no additional algorithm workspace or that every input representation supports the same placement.

## Check both parity cases and known spectra

Validate an even-length and an odd-length signal with recognizable expected transforms. Inspect logical output values and memory boundaries, then extend the fixture to the intended batch layout. Related guides on [HIP portability](/journal/learn-hip-launch-portability/) and [software reproducibility](/journal/software-stack-reproducibility/) support the process. This establishes correct physical storage for a declared transform, not arbitrary Hermitian validity after spectrum modification or an automatic normalization policy for a later inverse transform.
