In this article
A queued host function follows a stream contract and callback restrictions; ordinary application-thread code is not automatically valid inside it.
Follow the callback’s execution context
A developer enqueues a host function after a GPU copy and reuses an ordinary cleanup helper inside it. The helper calls HIP to release another allocation. The launch API reference explicitly prohibits HIP API calls from hipLaunchHostFunc callbacks. Running on the CPU does not make this callback equivalent to the application’s own thread. Review indirect calls, destructors and logging helpers as well as the visible callback body.
Avoid a circular wait
A callback that waits for work requiring its own stream to advance can create a dependency cycle. Draw the callback, the awaited operation and the progress each requires. Moving a device synchronization into a general-purpose destructor does not remove that cycle. Keep the callback bounded and hand ordinary follow-up work to an application-controlled thread through a justified notification mechanism. That thread still needs an explicit ownership protocol rather than assuming a notification automatically transfers every resource safely.
Keep user data alive until use completes
userData is a pointer passed to the queued function, not automatic ownership of the pointed object. Returning from the submitting function can destroy stack data before the callback reads them. Allocate or retain the context with a lifetime covering actual callback execution, and assign its release to a known owner. A successful enqueue only records future work. It does not establish that the function already consumed its arguments or that reusing the context is safe.
Distinguish ordinary execution from capture
The HIP graph guide explains how a host function associated with a stream can become a captured node. Repeated graph launches can therefore repeat the host action, while unrelated ordinary host statements are not captured the same way. The asynchronous guide supplies stream context. Review whether callback state remains valid across every intended execution, not just during construction.
Validate the bounded host action
Use a small callback that records a host marker through a valid lifetime and synchronization design, without invoking prohibited runtime operations. Verify the point at which the application may observe and release its context. Related guides cover stream ordering and graph-capture restrictions. This is a host-function execution constraint, distinct from CUDA user-object destructor ownership. Check actual API support and return values rather than assuming a declaration guarantees implementation on every platform.
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.