16.1. The SUNMemoryHelper API
This API consists of three new SUNDIALS types: SUNMemoryType,
SUNMemory, and SUNMemoryHelper:
-
typedef struct SUNMemory_ *SUNMemory
The
SUNMemorytype is a pointer the structure-
struct SUNMemory_
-
void *ptr;
The actual data.
-
SUNMemoryType type;
The data memory type.
-
sunbooleantype own;
A flag indicating ownership.
-
size_t bytes;
The size of the data allocated.
-
size_t stride;
Added in version 7.3.0.
The stride of the data.
-
void *ptr;
-
struct SUNMemory_
-
SUNMemory SUNMemoryNewEmpty(SUNContext sunctx)
This function returns an empty
SUNMemoryobject.- Parameters:
sunctx – the
SUNContextobject.
- Returns:
an uninitialized
SUNMemoryobject
Changed in version 7.0.0: The function signature was updated to add the
SUNContextargument.
-
enum SUNMemoryType
The
SUNMemoryTypetype is an enumeration that defines the supported memory types:-
enumerator SUNMEMTYPE_HOST
Pageable memory accessible on the host
-
enumerator SUNMEMTYPE_PINNED
Page-locked memory accessible on the host
-
enumerator SUNMEMTYPE_DEVICE
Memory accessible from the device
-
enumerator SUNMEMTYPE_UVM
Memory accessible from the host or device
-
enumerator SUNMEMTYPE_HOST
-
typedef struct SUNMemoryHelper_ *SUNMemoryHelper
The
SUNMemoryHelpertype is a pointer to the structure-
struct SUNMemoryHelper_
-
void *content;
Pointer to the implementation-specific member data
-
void *queue;
Pointer to the implementation-specific queue (e.g., a
cudaStream_t*) to use by default when one is not provided for an operationAdded in version 7.3.0.
-
SUNMemoryHelper_Ops ops;
A virtual method table of member functions
-
SUNContext sunctx;
The SUNDIALS simulation context
-
void *content;
-
struct SUNMemoryHelper_
-
typedef struct SUNMemoryHelper_Ops_ *SUNMemoryHelper_Ops
The
SUNMemoryHelper_Opstype is defined as a pointer to the structure containing the function pointers to the member function implementations. This structure is define as-
struct SUNMemoryHelper_Ops_
-
SUNErrCode (*alloc)(SUNMemoryHelper, SUNMemory *memptr, size_t mem_size, SUNMemoryType mem_type, void *queue)
The function implementing
SUNMemoryHelper_Alloc()
-
SUNErrCode (*allocstrided)(SUNMemoryHelper, SUNMemory *memptr, size_t mem_size, size_t stride, SUNMemoryType mem_type, void *queue)
The function implementing
SUNMemoryHelper_AllocStrided()Added in version 7.3.0.
-
SUNErrCode (*dealloc)(SUNMemoryHelper, SUNMemory mem, void *queue)
The function implementing
SUNMemoryHelper_Dealloc()
-
SUNErrCode (*copy)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
The function implementing
SUNMemoryHelper_Copy()
-
SUNErrCode (*copyasync)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
The function implementing
SUNMemoryHelper_CopyAsync()
-
SUNErrCode (*getallocstats)(SUNMemoryHelper, SUNMemoryType mem_type, unsigned long *num_allocations, unsigned long *num_deallocations, size_t *bytes_allocated, size_t *bytes_high_watermark)
The function implementing
SUNMemoryHelper_GetAllocStats()
-
SUNMemoryHelper (*clone)(SUNMemoryHelper)
The function implementing
SUNMemoryHelper_Clone()
-
SUNErrCode (*destroy)(SUNMemoryHelper)
The function implementing
SUNMemoryHelper_Destroy()
-
SUNErrCode (*alloc)(SUNMemoryHelper, SUNMemory *memptr, size_t mem_size, SUNMemoryType mem_type, void *queue)
-
struct SUNMemoryHelper_Ops_
16.1.1. Implementation defined operations
The SUNMemory API defines the following operations that an implementation to must define:
-
SUNMemory SUNMemoryHelper_Alloc(SUNMemoryHelper helper, SUNMemory *memptr, size_t mem_size, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.mem_type – the
SUNMemoryTypeof theptr.queue – typically a handle for an object representing an alternate execution stream (e.g., a CUDA/HIP stream or SYCL queue), but it can also be any implementation specific data.
- Returns:
A new
SUNMemoryobject
-
SUNMemory SUNMemoryHelper_AllocStrided(SUNMemoryHelper helper, SUNMemory *memptr, size_t mem_size, size_t stride, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes with the specified stride, and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.stride – the stride of the memory in bytes.
mem_type – the
SUNMemoryTypeof theptr.queue – typically a handle for an object representing an alternate execution stream (e.g., a CUDA/HIP stream or SYCL queue), but it can also be any implementation specific data.
- Returns:
A new
SUNMemoryobject
Added in version 7.3.0.
-
SUNErrCode SUNMemoryHelper_Dealloc(SUNMemoryHelper helper, SUNMemory mem, void *queue)
Deallocates the
mem->ptrfield if it is owned bymem, and then deallocates thememobject.- Parameters:
helper – the
SUNMemoryHelperobject.mem – the
SUNMemoryobject.queue – typically a handle for an object representing an alternate execution stream (e.g., a CUDA/HIP stream or SYCL queue), but it can also be any implementation specific data.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_Copy(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Synchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject should use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – typically a handle for an object representing an alternate execution stream (e.g., a CUDA/HIP stream or SYCL queue), but it can also be any implementation specific data.
- Returns:
A
SUNErrCodeindicating success or failure.
16.1.2. Utility Functions
The SUNMemoryHelper API defines the following functions which do not require a SUNMemoryHelper instance:
-
SUNMemory SUNMemoryHelper_Alias(SUNMemoryHelper helper, SUNMemory mem1)
Returns a
SUNMemoryobject whoseptrfield points to the same address asmem1. The new object will not have ownership ofptr, therefore, it will not freeptrwhenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – a
SUNMemoryHelperobject.mem1 – a
SUNMemoryobject.
- Returns:
A
SUNMemoryobject orNULLif an error occurs.
Changed in version 7.0.0: The
SUNMemoryHelperargument was added to the function signature.
-
SUNMemory SUNMemoryHelper_Wrap(SUNMemoryHelper helper, void *ptr, SUNMemoryType mem_type)
Returns a
SUNMemoryobject whoseptrfield points to theptrargument passed to the function. The new object will not have ownership ofptr, therefore, it will not freeptrwhenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – a
SUNMemoryHelperobject.ptr – the data pointer to wrap in a
SUNMemoryobject.mem_type – the
SUNMemoryTypeof theptr.
- Returns:
A
SUNMemoryobject orNULLif an error occurs.
Changed in version 7.0.0: The
SUNMemoryHelperargument was added to the function signature.
-
SUNMemoryHelper SUNMemoryHelper_NewEmpty(SUNContext sunctx)
Returns an empty
SUNMemoryHelper. This is useful for building customSUNMemoryHelperimplementations.- Parameters:
helper – a
SUNMemoryHelperobject.
- Returns:
A
SUNMemoryHelperobject orNULLif an error occurs.
Changed in version 7.0.0: The
SUNMemoryHelperargument was added to the function signature.
-
SUNErrCode SUNMemoryHelper_CopyOps(SUNMemoryHelper src, SUNMemoryHelper dst)
Copies the
opsfield ofsrcto theopsfield ofdst. This is useful for building customSUNMemoryHelperimplementations.- Parameters:
src – the object to copy from.
dst – the object to copy to.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_GetAllocStats(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long *num_allocations, unsigned long *num_deallocations, size_t *bytes_allocated, size_t *bytes_high_watermark)
Returns statistics about the allocations performed with the helper.
- Parameters:
helper – the
SUNMemoryHelperobject.mem_type – the
SUNMemoryTypeto get stats for.num_allocations – (output argument) number of allocations done through the helper.
num_deallocations – (output argument) number of deallocations done through the helper.
bytes_allocated – (output argument) total number of bytes allocated through the helper at the moment this function is called.
bytes_high_watermark – (output argument) max number of bytes allocated through the helper at any moment in the lifetime of the helper.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_SetDefaultQueue(SUNMemoryHelper helper, void *queue)
Sets the default queue for the helper.
- Parameters:
helper – the
SUNMemoryHelperobject.queue – pointer to the queue to use by default.
- Returns:
A
SUNErrCodeindicating success or failure.
Added in version 7.3.0.
16.1.3. Implementation overridable operations with defaults
In addition, the SUNMemoryHelper API defines the following optionally overridable operations which an implementation may define:
-
SUNErrCode SUNMemoryHelper_CopyAsync(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Asynchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject should use the memory types ofdstandsrcto determine the appropriate transfer type necessary. Thectxargument is used when a different execution stream needs to be provided to perform the copy in, e.g. withCUDAthis would be acudaStream_t.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – typically a handle for an object representing an alternate execution stream (e.g., a CUDA/HIP stream or SYCL queue), but it can also be any implementation specific data.
An
intflag indicating success (zero) or failure (non-zero).Note
If this operation is not defined by the implementation, then
SUNMemoryHelper_Copy()will be used.
-
SUNMemoryHelper SUNMemoryHelper_Clone(SUNMemoryHelper helper)
Clones the
SUNMemoryHelperobject itself.- Parameters:
helper – the
SUNMemoryHelperobject to clone.
- Returns:
A
SUNMemoryHelperobject.
Note
If this operation is not defined by the implementation, then the default clone will only copy the
SUNMemoryHelper_Opsstructure stored inhelper->ops, and not thehelper->contentfield.
-
SUNErrCode SUNMemoryHelper_Destroy(SUNMemoryHelper helper)
Destroys (frees) the
SUNMemoryHelperobject itself.- Parameters:
helper – the
SUNMemoryHelperobject to destroy.
- Returns:
A
SUNErrCodeindicating success or failure.
Note
If this operation is not defined by the implementation, then the default destroy will only free the
helper->opsfield and thehelperitself. Thehelper->contentfield will not be freed.
16.1.4. Implementing a custom SUNMemoryHelper
A particular implementation of the SUNMemoryHelper API must:
Define and implement the required operations. Note that the names of these routines should be unique to that implementation in order to permit using more than one SUNMemoryHelper module in the same code.
Optionally, specify the content field of SUNMemoryHelper.
Optionally, define and implement additional user-callable routines acting on the newly defined SUNMemoryHelper.
An example of a custom SUNMemoryHelper is given in
examples/utilities/custom_memory_helper.h.
16.2. The SUNMemoryHelper_Sys Implementation
The SUNMemoryHelper_Sys module is an implementation of the SUNMemoryHelper.
API that interfaces with standard library memory management through malloc/free.
The implementation defines the constructor
-
SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx)
Allocates and returns a
SUNMemoryHelperobject for handling system memory if successful. Otherwise, it returnsNULL.
16.2.1. SUNMemoryHelper_Sys API Functions
The implementation provides the following operations defined by the
SUNMemoryHelper API:
Note
The SUNMemoryHelper_Sys always supports SUNMEMTYPE_HOST. If your system also
supports allocating unified/coherent memory between CPU and GPU device with malloc,
then SUNMEMTYPE_UVM is also supported.
16.3. The SUNMemoryHelper_Cuda Implementation
The SUNMemoryHelper_Cuda module is an implementation of the SUNMemoryHelper
API that interfaces to the NVIDIA [5] library. The
implementation defines the constructor
-
SUNMemoryHelper SUNMemoryHelper_Cuda(SUNContext sunctx)
Allocates and returns a
SUNMemoryHelperobject for handling CUDA memory if successful. Otherwise it returnsNULL.- Parameters:
sunctx – the current
SUNContextobject.
- Returns:
if successful, a usable
SUNMemoryHelperobject; otherwise it will returnNULL.
16.3.1. SUNMemoryHelper_Cuda API Functions
The implementation provides the following operations defined by the
SUNMemoryHelper API:
-
SUNMemory SUNMemoryHelper_Alloc_Cuda(SUNMemoryHelper helper, SUNMemory memptr, size_t mem_size, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.mem_type – the
SUNMemoryTypeof theptr. Supported values are: *SUNMEMTYPE_HOST– memory is allocated with a call tomalloc. *SUNMEMTYPE_PINNED– memory is allocated with a call tocudaMallocHost. *SUNMEMTYPE_DEVICE– memory is allocated with a call tocudaMalloc. *SUNMEMTYPE_UVM– memory is allocated with a call tocudaMallocManaged.queue – currently unused.
- Returns:
A new
SUNMemoryobject.
-
SUNMemory SUNMemoryHelper_AllocStrided_Cuda(SUNMemoryHelper helper, SUNMemory memptr, size_t mem_size, size_t stride, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.stride – the number of bytes between elements in the array.
mem_type – the
SUNMemoryTypeof theptr.queue – currently unused.
- Returns:
A new
SUNMemoryobject.
Added in version 7.3.0.
-
SUNErrCode SUNMemoryHelper_Dealloc_Cuda(SUNMemoryHelper helper, SUNMemory mem, void *queue)
Deallocates the
mem->ptrfield if it is owned bymem, and then deallocates thememobject.- Parameters:
helper – the
SUNMemoryHelperobject.mem – the
SUNMemoryobject.queue – currently unused.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_Copy_Cuda(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Synchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject will use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – currently unused.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_CopyAsync_Cuda(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Asynchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject will use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – the
cudaStream_thandle for the stream that the copy will be performed on.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_GetAllocStats_Cuda(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long *num_allocations, unsigned long *num_deallocations, size_t *bytes_allocated, size_t *bytes_high_watermark)
Returns statistics about memory allocations performed with the helper.
- Parameters:
helper – the
SUNMemoryHelperobject.mem_type – the
SUNMemoryTypeto get stats for.num_allocations – (output argument) number of memory allocations done through the helper.
num_deallocations – (output argument) number of memory deallocations done through the helper.
bytes_allocated – (output argument) total number of bytes allocated through the helper at the moment this function is called.
bytes_high_watermark – (output argument) max number of bytes allocated through the helper at any moment in the lifetime of the helper.
- Returns:
A
SUNErrCodeindicating success or failure.
16.4. The SUNMemoryHelper_Hip Implementation
The SUNMemoryHelper_Hip module is an implementation of the SUNMemoryHelper
API that interfaces to the AMD ROCm HIP library [2]. The
implementation defines the constructor
-
SUNMemoryHelper SUNMemoryHelper_Hip(SUNContext sunctx)
Allocates and returns a
SUNMemoryHelperobject for handling HIP memory if successful. Otherwise it returnsNULL.- Parameters:
sunctx – the current
SUNContextobject.
- Returns:
if successful, a usable
SUNMemoryHelperobject; otherwise it will returnNULL.
16.4.1. SUNMemoryHelper_Hip API Functions
The implementation provides the following operations defined by the
SUNMemoryHelper API:
-
SUNMemory SUNMemoryHelper_Alloc_Hip(SUNMemoryHelper helper, SUNMemory memptr, size_t mem_size, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.mem_type – the
SUNMemoryTypeof theptr. Supported values are: *SUNMEMTYPE_HOST– memory is allocated with a call tomalloc. *SUNMEMTYPE_PINNED– memory is allocated with a call tohipMallocHost. *SUNMEMTYPE_DEVICE– memory is allocated with a call tohipMalloc. *SUNMEMTYPE_UVM– memory is allocated with a call tohipMallocManaged.queue – currently unused.
- Returns:
A new
SUNMemoryobject.
-
SUNMemory SUNMemoryHelper_AllocStrided_Hip(SUNMemoryHelper helper, SUNMemory memptr, size_t mem_size, size_t stride, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.stride – the number of bytes between elements in the array.
mem_type – the
SUNMemoryTypeof theptr.queue – currently unused.
- Returns:
A new
SUNMemoryobject.
Added in version 7.3.0.
-
SUNErrCode SUNMemoryHelper_Dealloc_Hip(SUNMemoryHelper helper, SUNMemory mem, void *queue)
Deallocates the
mem->ptrfield if it is owned bymem, and then deallocates thememobject.- Parameters:
helper – the
SUNMemoryHelperobject.mem – the
SUNMemoryobject.queue – currently unused.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_Copy_Hip(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Synchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject will use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – currently unused.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_CopyAsync_Hip(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Asynchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject will use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – the
hipStream_thandle for the stream that the copy will be performed on.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_GetAllocStats_Hip(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long *num_allocations, unsigned long *num_deallocations, size_t *bytes_allocated, size_t *bytes_high_watermark)
Returns statistics about memory allocations performed with the helper.
- Parameters:
helper – the
SUNMemoryHelperobject.mem_type – the
SUNMemoryTypeto get stats for.num_allocations – (output argument) number of memory allocations done through the helper.
num_deallocations – (output argument) number of memory deallocations done through the helper.
bytes_allocated – (output argument) total number of bytes allocated through the helper at the moment this function is called.
bytes_high_watermark – (output argument) max number of bytes allocated through the helper at any moment in the lifetime of the helper.
- Returns:
A
SUNErrCodeindicating success or failure.
16.5. The SUNMemoryHelper_Sycl Implementation
The SUNMemoryHelper_Sycl module is an implementation of the SUNMemoryHelper
API that interfaces to the SYCL abstraction
layer. The implementation defines the constructor
-
SUNMemoryHelper SUNMemoryHelper_Sycl(SUNContext sunctx)
Allocates and returns a
SUNMemoryHelperobject for handling SYCL memory using the provided queue. Otherwise it returnsNULL.- Parameters:
sunctx – the current
SUNContextobject.
- Returns:
if successful, a usable
SUNMemoryHelperobject; otherwise it will returnNULL.
16.5.1. SUNMemoryHelper_Sycl API Functions
The implementation provides the following operations defined by the
SUNMemoryHelper API:
-
SUNMemory SUNMemoryHelper_Alloc_Sycl(SUNMemoryHelper helper, SUNMemory memptr, size_t mem_size, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.mem_type – the
SUNMemoryTypeof theptr. Supported values are: *SUNMEMTYPE_HOST– memory is allocated with a call tomalloc. *SUNMEMTYPE_PINNED– memory is allocated with a call tosycl::malloc_host. *SUNMEMTYPE_DEVICE– memory is allocated with a call tosycl::malloc_device. *SUNMEMTYPE_UVM– memory is allocated with a call tosycl::malloc_shared.queue – the
sycl::queuehandle for the stream that the allocation will be performed on.
- Returns:
A new
SUNMemoryobject.
-
SUNMemory SUNMemoryHelper_AllocStrided_Sycl(SUNMemoryHelper helper, SUNMemory memptr, size_t mem_size, size_t stride, SUNMemoryType mem_type, void *queue)
Allocates a
SUNMemoryobject whoseptrfield is allocated formem_sizebytes and is of typemem_type. The new object will have ownership ofptrand will be deallocated whenSUNMemoryHelper_Dealloc()is called.- Parameters:
helper – the
SUNMemoryHelperobject.memptr – pointer to the allocated
SUNMemory.mem_size – the size in bytes of the
ptr.stride – the number of bytes between elements in the array.
mem_type – the
SUNMemoryTypeof theptr.queue – the
sycl::queuehandle for the stream that the allocation will be performed on.
- Returns:
A new
SUNMemoryobject.
Added in version 7.3.0.
-
SUNErrCode SUNMemoryHelper_Dealloc_Sycl(SUNMemoryHelper helper, SUNMemory mem, void *queue)
Deallocates the
mem->ptrfield if it is owned bymem, and then deallocates thememobject.- Parameters:
helper – the
SUNMemoryHelperobject.mem – the
SUNMemoryobject.queue – the
sycl::queuehandle for the queue that the deallocation will be performed on.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_Copy_Sycl(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Synchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject will use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – the
sycl::queuehandle for the queue that the copy will be performed on.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_CopyAsync_Sycl(SUNMemoryHelper helper, SUNMemory dst, SUNMemory src, size_t mem_size, void *queue)
Asynchronously copies
mem_sizebytes from the the source memory to the destination memory. The copy can be across memory spaces, e.g. host to device, or within a memory space, e.g. host to host. Thehelperobject will use the memory types ofdstandsrcto determine the appropriate transfer type necessary.- Parameters:
helper – the
SUNMemoryHelperobject.dst – the destination memory to copy to.
src – the source memory to copy from.
mem_size – the number of bytes to copy.
queue – the
sycl::queuehandle for the queue that the copy will be performed on.
- Returns:
A
SUNErrCodeindicating success or failure.
-
SUNErrCode SUNMemoryHelper_GetAllocStats_Sycl(SUNMemoryHelper helper, SUNMemoryType mem_type, unsigned long *num_allocations, unsigned long *num_deallocations, size_t *bytes_allocated, size_t *bytes_high_watermark)
Returns statistics about memory allocations performed with the helper.
- Parameters:
helper – the
SUNMemoryHelperobject.mem_type – the
SUNMemoryTypeto get stats for.num_allocations – (output argument) number of memory allocations done through the helper.
num_deallocations – (output argument) number of memory deallocations done through the helper.
bytes_allocated – (output argument) total number of bytes allocated through the helper at the moment this function is called.
bytes_high_watermark – (output argument) max number of bytes allocated through the helper at any moment in the lifetime of the helper.
- Returns:
A
SUNErrCodeindicating success or failure.