Stream ordered memory allocator#

static inline hipError_t hipMallocAsync(void **dev_ptr, size_t size, hipMemPool_t mem_pool, hipStream_t stream)#

C++ wrappers for allocations from a memory pool.

This section describes wrappers for stream Ordered allocation from memory pool functions of HIP runtime API.

This is an alternate C++ calls for hipMallocFromPoolAsync made available through function overloading.

Note

APIs in this section are implemented on Linux, under development on Windows.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

template<class T>
static inline hipError_t hipMallocAsync(T **dev_ptr, size_t size, hipMemPool_t mem_pool, hipStream_t stream)#

C++ wrappers for allocations from a memory pool on the stream.

This is an alternate C++ calls for hipMallocFromPoolAsync made available through function overloading.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

template<class T>
static inline hipError_t hipMallocAsync(T **dev_ptr, size_t size, hipStream_t stream)#

C++ wrappers for allocations from a memory pool.

This is an alternate C++ calls for hipMallocFromPoolAsync made available through function overloading.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

template<class T>
static inline hipError_t hipMallocFromPoolAsync(T **dev_ptr, size_t size, hipMemPool_t mem_pool, hipStream_t stream)#

C++ wrappers for allocations from a memory pool.

This is an alternate C++ calls for hipMallocFromPoolAsync made available through function overloading.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

hipError_t hipMallocAsync(void **dev_ptr, size_t size, hipStream_t stream)#

Allocates memory with stream ordered semantics.

Inserts a memory allocation operation into stream. A pointer to the allocated memory is returned immediately in *dptr. The allocation must not be accessed until the allocation operation completes. The allocation comes from the memory pool associated with the stream’s device.

Note

The default memory pool of a device contains device memory from that device.

Note

Basic stream ordering allows future work submitted into the same stream to use the allocation. Stream query, stream synchronize, and HIP events can be used to guarantee that the allocation operation completes before work submitted in a separate stream runs.

Note

During stream capture, this function results in the creation of an allocation node. In this case, the allocation is owned by the graph instead of the memory pool. The memory pool’s properties are used to set the node’s creation parameters.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • dev_ptr[out] Returned device pointer of memory allocation

  • size[in] Number of bytes to allocate

  • stream[in] The stream establishing the stream ordering contract and the memory pool to allocate from

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorNotSupported, hipErrorOutOfMemory

hipError_t hipFreeAsync(void *dev_ptr, hipStream_t stream)#

Frees memory with stream ordered semantics.

Inserts a free operation into stream. The allocation must not be used after stream execution reaches the free. After this API returns, accessing the memory from any subsequent work launched on the GPU or querying its pointer attributes results in undefined behavior.

Note

During stream capture, this function results in the creation of a free node and must therefore be passed the address of a graph allocation.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • dev_ptr[in] Pointer to device memory to free

  • stream[in] The stream, where the destruciton will occur according to the execution order

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorNotSupported

hipError_t hipMemPoolTrimTo(hipMemPool_t mem_pool, size_t min_bytes_to_hold)#

Releases freed memory back to the OS.

Releases memory back to the OS until the pool contains fewer than min_bytes_to_keep reserved bytes, or there is no more memory that the allocator can safely release. The allocator cannot release OS allocations that back outstanding asynchronous allocations. The OS allocations may happen at different granularity from the user allocations.

Note

Allocations that have not been freed count as outstanding.

Note

Allocations that have been asynchronously freed but whose completion has not been observed on the host (eg. by a synchronize) can count as outstanding.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • mem_pool[in] The memory pool to trim allocations

  • min_bytes_to_hold[in] If the pool has less than min_bytes_to_hold reserved, then the TrimTo operation is a no-op. Otherwise the memory pool will contain at least min_bytes_to_hold bytes reserved after the operation.

Returns:

hipSuccess, hipErrorInvalidValue

hipError_t hipMemPoolSetAttribute(hipMemPool_t mem_pool, hipMemPoolAttr attr, void *value)#

Sets attributes of a memory pool.

Supported attributes are:

  • hipMemPoolAttrReleaseThreshold: (value type = cuuint64_t) Amount of reserved memory in bytes to hold onto before trying to release memory back to the OS. When more than the release threshold bytes of memory are held by the memory pool, the allocator will try to release memory back to the OS on the next call to stream, event or context synchronize. (default 0)

  • hipMemPoolReuseFollowEventDependencies: (value type = int) Allow hipMallocAsync to use memory asynchronously freed in another stream as long as a stream ordering dependency of the allocating stream on the free action exists. HIP events and null stream interactions can create the required stream ordered dependencies. (default enabled)

  • hipMemPoolReuseAllowOpportunistic: (value type = int) Allow reuse of already completed frees when there is no dependency between the free and allocation. (default enabled)

  • hipMemPoolReuseAllowInternalDependencies: (value type = int) Allow hipMallocAsync to insert new stream dependencies in order to establish the stream ordering required to reuse a piece of memory released by hipFreeAsync (default enabled).

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • mem_pool[in] The memory pool to modify

  • attr[in] The attribute to modify

  • value[in] Pointer to the value to assign

Returns:

hipSuccess, hipErrorInvalidValue

hipError_t hipMemPoolGetAttribute(hipMemPool_t mem_pool, hipMemPoolAttr attr, void *value)#

Gets attributes of a memory pool.

Supported attributes are:

  • hipMemPoolAttrReleaseThreshold: (value type = cuuint64_t) Amount of reserved memory in bytes to hold onto before trying to release memory back to the OS. When more than the release threshold bytes of memory are held by the memory pool, the allocator will try to release memory back to the OS on the next call to stream, event or context synchronize. (default 0)

  • hipMemPoolReuseFollowEventDependencies: (value type = int) Allow hipMallocAsync to use memory asynchronously freed in another stream as long as a stream ordering dependency of the allocating stream on the free action exists. HIP events and null stream interactions can create the required stream ordered dependencies. (default enabled)

  • hipMemPoolReuseAllowOpportunistic: (value type = int) Allow reuse of already completed frees when there is no dependency between the free and allocation. (default enabled)

  • hipMemPoolReuseAllowInternalDependencies: (value type = int) Allow hipMallocAsync to insert new stream dependencies in order to establish the stream ordering required to reuse a piece of memory released by hipFreeAsync (default enabled).

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • mem_pool[in] The memory pool to get attributes of

  • attr[in] The attribute to get

  • value[in] Retrieved value

Returns:

hipSuccess, hipErrorInvalidValue

hipError_t hipMemPoolSetAccess(hipMemPool_t mem_pool, const hipMemAccessDesc *desc_list, size_t count)#

Controls visibility of the specified pool between devices.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • mem_pool[in] Memory pool for acccess change

  • desc_list[in] Array of access descriptors. Each descriptor instructs the access to enable for a single gpu

  • count[in] Number of descriptors in the map array.

Returns:

hipSuccess, hipErrorInvalidValue

hipError_t hipMemPoolGetAccess(hipMemAccessFlags *flags, hipMemPool_t mem_pool, hipMemLocation *location)#

Returns the accessibility of a pool from a device.

Returns the accessibility of the pool’s memory from the specified location.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • flags[out] Accessibility of the memory pool from the specified location/device

  • mem_pool[in] Memory pool being queried

  • location[in] Location/device for memory pool access

Returns:

hipSuccess, hipErrorInvalidValue

hipError_t hipMemPoolCreate(hipMemPool_t *mem_pool, const hipMemPoolProps *pool_props)#

Creates a memory pool.

Creates a HIP memory pool and returns the handle in mem_pool. The pool_props determines the properties of the pool such as the backing device and IPC capabilities.

By default, the memory pool will be accessible from the device it is allocated on.

Note

Specifying hipMemHandleTypeNone creates a memory pool that will not support IPC.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • mem_pool[out] Contains createed memory pool

  • pool_props[in] Memory pool properties

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorNotSupported

hipError_t hipMemPoolDestroy(hipMemPool_t mem_pool)#

Destroys the specified memory pool.

If any pointers obtained from this pool haven’t been freed or the pool has free operations that haven’t completed when hipMemPoolDestroy is invoked, the function will return immediately and the resources associated with the pool will be released automatically once there are no more outstanding allocations.

Destroying the current mempool of a device sets the default mempool of that device as the current mempool for that device.

Note

A device’s default memory pool cannot be destroyed.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:

mem_pool[in] Memory pool for destruction

Returns:

hipSuccess, hipErrorInvalidValue

hipError_t hipMallocFromPoolAsync(void **dev_ptr, size_t size, hipMemPool_t mem_pool, hipStream_t stream)#

Allocates memory from a specified pool with stream ordered semantics.

Inserts an allocation operation into stream. A pointer to the allocated memory is returned immediately in dev_ptr. The allocation must not be accessed until the allocation operation completes. The allocation comes from the specified memory pool.

Basic stream ordering allows future work submitted into the same stream to use the allocation. Stream query, stream synchronize, and HIP events can be used to guarantee that the allocation operation completes before work submitted in a separate stream runs.

Note

The specified memory pool may be from a device different than that of the specified stream.

Note

During stream capture, this function results in the creation of an allocation node. In this case, the allocation is owned by the graph instead of the memory pool. The memory pool’s properties are used to set the node’s creation parameters.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • dev_ptr[out] Returned device pointer

  • size[in] Number of bytes to allocate

  • mem_pool[in] The pool to allocate from

  • stream[in] The stream establishing the stream ordering semantic

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorNotSupported, hipErrorOutOfMemory

hipError_t hipMemPoolExportToShareableHandle(void *shared_handle, hipMemPool_t mem_pool, hipMemAllocationHandleType handle_type, unsigned int flags)#

Exports a memory pool to the requested handle type.

Given an IPC capable mempool, create an OS handle to share the pool with another process. A recipient process can convert the shareable handle into a mempool with hipMemPoolImportFromShareableHandle. Individual pointers can then be shared with the hipMemPoolExportPointer and hipMemPoolImportPointer APIs. The implementation of what the shareable handle is and how it can be transferred is defined by the requested handle type.

Note

To create an IPC capable mempool, create a mempool with a hipMemAllocationHandleType other than hipMemHandleTypeNone.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • shared_handle[out] Pointer to the location in which to store the requested handle

  • mem_pool[in] Pool to export

  • handle_type[in] The type of handle to create

  • flags[in] Must be 0

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorOutOfMemory

hipError_t hipMemPoolImportFromShareableHandle(hipMemPool_t *mem_pool, void *shared_handle, hipMemAllocationHandleType handle_type, unsigned int flags)#

Imports a memory pool from a shared handle.

Specific allocations can be imported from the imported pool with hipMemPoolImportPointer.

Note

Imported memory pools do not support creating new allocations. As such imported memory pools may not be used in hipDeviceSetMemPool or hipMallocFromPoolAsync calls.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • mem_pool[out] Returned memory pool

  • shared_handle[in] OS handle of the pool to open

  • handle_type[in] The type of handle being imported

  • flags[in] Must be 0

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorOutOfMemory

hipError_t hipMemPoolExportPointer(hipMemPoolPtrExportData *export_data, void *dev_ptr)#

Export data to share a memory pool allocation between processes.

Constructs export_data for sharing a specific allocation from an already shared memory pool. The recipient process can import the allocation with the hipMemPoolImportPointer api. The data is not a handle and may be shared through any IPC mechanism.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • export_data[out] Returned export data

  • dev_ptr[in] Pointer to memory being exported

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorOutOfMemory

hipError_t hipMemPoolImportPointer(void **dev_ptr, hipMemPool_t mem_pool, hipMemPoolPtrExportData *export_data)#

Import a memory pool allocation from another process.

Returns in dev_ptr a pointer to the imported memory. The imported memory must not be accessed before the allocation operation completes in the exporting process. The imported memory must be freed from all importing processes before being freed in the exporting process. The pointer may be freed with hipFree or hipFreeAsync. If hipFreeAsync is used, the free must be completed on the importing process before the free operation on the exporting process.

Note

The hipFreeAsync api may be used in the exporting process before the hipFreeAsync operation completes in its stream as long as the hipFreeAsync in the exporting process specifies a stream with a stream dependency on the importing process’s hipFreeAsync.

Note

This API is implemented on Linux and is under development on Microsoft Windows.

Warning

This API is marked as Beta. While this feature is complete, it can change and might have outstanding issues.

Parameters:
  • dev_ptr[out] Pointer to imported memory

  • mem_pool[in] Memory pool from which to import a pointer

  • export_data[in] Data specifying the memory to import

Returns:

hipSuccess, hipErrorInvalidValue, hipErrorNotInitialized, hipErrorOutOfMemory