TECHNOLOGY

rocPRIM temporary storage: a size query does not perform the scan

In this article
THE QUICK TAKE

A null temporary-storage argument requests workspace capacity; actual computation requires a suitable allocation and another operation call.

Recognize the query path

A wrapper calls a rocPRIM scan with null temporary storage and then reads the output array. The scan API reference states that this path returns required storage size without performing the scan. A successful status therefore means a successful query, not completed computation. Keep the query and execution phases visibly distinct in the wrapper, especially when a generic helper hides the temporary pointer argument from its caller.

Query the actual operation contract

Storage requirements belong to the selected operation, types, input size and configuration. Do not assume that scratch capacity from an unrelated algorithm is adequate because the input arrays have the same byte length. The versioned developer guidelines describe the common storage-query pattern. Match the installed release’s interface and query the relevant invocation. Preserve the returned byte count rather than substituting an estimate derived from output capacity or a remembered example.

Allocate and execute as separate steps

Provide device-accessible scratch of sufficient capacity, call the algorithm again with that storage, and check both submission and completed output. The rocPRIM scan source offers inspectable implementation evidence alongside the API documentation. A memory allocation succeeding does not retroactively execute the earlier query. Include the actual execution call in tracing so that an empty or unchanged output can be distinguished from a numerical scan error.

Reuse storage only after its users finish

Scratch can be reused by sequential operations when their requirements and ordering permit it. Concurrent operations on different streams must not overwrite the same scratch merely because they have separate output arrays. Treat scratch as an active algorithm resource with a final-use boundary. Preserve a per-operation allocation baseline while introducing reuse, then compare correct results under delayed and overlapping submissions. A shared scratch pointer without a dependency protocol is not a safe workspace cache.

Separate debugging synchronization from production behavior

If an operation offers a debug synchronization option, record whether it is enabled when diagnosing behavior or reporting measurements. Related guides on cross-stream dependencies and reproducible stacks explain the surrounding contract. A useful acceptance fixture checks a known scan after the execution phase and verifies safe reuse for another declared operation. It establishes correct phase and capacity handling, not a universal scratch size for future workloads or releases.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles