malloc Functions#

sycl::malloc_device#

void* sycl::malloc_device(size_t numBytes,
                          const device& syclDevice,
                          const context& syclContext,
                          const property_list &propList = {})
template <typename T>
T* sycl::malloc_device(size_t count,
                       const device& syclDevice,
                       const context& syclContext,
                       const property_list &propList = {})
void* sycl::malloc_device(size_t numBytes,
                          const queue& syclQueue,
                          const property_list &propList = {})
template <typename T>
T* sycl::malloc_device(size_t count,
                       const queue& syclQueue,
                       const property_list &propList = {})
void* sycl::aligned_alloc_device(size_t alignment,
                                 size_t numBytes,
                                 const device& syclDevice,
                                 const context& syclContext,
                                 const property_list &propList = {})
template <typename T>
T* sycl::aligned_alloc_device(size_t alignment,
                              size_t count,
                              const device& syclDevice,
                              const context& syclContext,
                              const property_list &propList = {})

Parameters

alignment

alignment of allocated data

numBytes

allocation size in bytes

count

number of elements

syclDevice

See sycl::device

syclQueue

See sycl::queue

syclContext

See sycl::context

propList

Returns a pointer to the newly allocated memory on the specified device on success. This memory is not accessible on the host. Memory allocated by sycl::malloc_device must be deallocated with sycl::free to avoid memory leaks. If ctxt is a host context, it should behave as if calling sycl::malloc_host. On failure, returns nullptr.

The host may not directly reference the memory, but can read and write the memory with sycl::queue member functions (memset, memcpy, fill) or sycl::handler member functions (memset, memcpy, and fill).

See Example 1 for usage.

sycl::malloc_host#

void* sycl::malloc_host(size_t numBytes,
                        const context& syclContext,
                        const property_list &propList = {})
template <typename T>
T* sycl::malloc_host(size_t count,
                     const context& syclContext,
                     const property_list &propList = {})
void* sycl::malloc_host(size_t numBytes,
                        const queue& syclQueue,
                        const property_list &propList = {})
template <typename T>
T* sycl::malloc_host(size_t count,
                     const queue& syclQueue,
                     const property_list &propList = {})
void* sycl::aligned_alloc_host(size_t alignment,
                               size_t numBytes,
                               const context& syclContext,
                               const property_list &propList = {})
template <typename T>
T* sycl::aligned_alloc_host(size_t alignment,
                            size_t count,
                            const context& syclContext,
                            const property_list &propList = {})
void* sycl::aligned_alloc_host(size_t alignment,
                               size_t numBytes,
                               const queue& syclQueue,
                               const property_list &propList = {})
template <typename T>
void* sycl::aligned_alloc_host(size_t alignment,
                               size_t count,
                               const queue& syclQueue,
                               const property_list &propList = {})

Parameters

alignment

alignment of allocated data

numBytes

allocation size in bytes

count

number of elements

syclDevice

See sycl::device

syclQueue

See sycl::queue

syclContext

See sycl::context

propList

Returns a pointer to the newly allocated host memory on success. Host and device may reference the memory. Memory allocated by sycl::malloc_host must be deallocated with sycl::free to avoid memory leaks. On failure, returns nullptr.

sycl::malloc_shared#

void* sycl::malloc_shared(size_t numBytes,
                          const device& syclDevice,
                          const context& syclContext,
                          const property_list &propList = {})
template <typename T>
T* sycl::malloc_shared(size_t count,
                       const device& syclDevice,
                       const context& syclContext,
                       const property_list &propList = {})
void* sycl::malloc_shared(size_t numBytes,
                          const queue& syclQueue,
                          const property_list &propList = {})
template <typename T>
T* sycl::malloc_shared(size_t count,
                       const queue& syclQueue,
                       const property_list &propList = {})
void* sycl::aligned_alloc_shared(size_t alignment,
                                 size_t numBytes,
                                 const device& syclDevice,
                                 const context& syclContext,
                                 const property_list &propList = {})
template <typename T>
T* sycl::aligned_alloc_shared(size_t alignment,
                              size_t count,
                              const device& syclDevice,
                              const context& syclContext,
                              const property_list &propList = {})
void* sycl::aligned_alloc_shared(size_t alignment,
                                 size_t numBytes,
                                 const queue& syclQueue,
                                 const property_list &propList = {})
template <typename T>
T* sycl::aligned_alloc_shared(size_t alignment,
                              size_t count,
                              const queue& syclQueue,
                              const property_list &propList = {})

Parameters

alignment

alignment of allocated data

numBytes

allocation size in bytes

count

number of elements

syclDevice

See sycl::device

syclQueue

See sycl::queue

syclContext

See sycl::context

propList

Returns a pointer to the newly allocated shared memory on the specified device on success. The SYCL runtime may migrate the data between host and device to optimize access. Memory allocated by sycl::malloc_shared must be deallocated with sycl::free to avoid memory leaks. If ctxt is a host context, should behave as if calling sycl::malloc_host. On failure, returns nullptr.

sycl::malloc#

void *malloc(size_t numBytes,
             const sycl::device& syclDevice,
             const sycl::context& syclContext,
             sycl::usm::alloc kind,
             const sycl::property_list &propList = {})
template <typename T>
T *malloc(size_t count,
          const sycl::device& syclDevice,
          const sycl::context& syclContext,
          sycl::usm::alloc kind,
          const sycl::property_list &propList = {})
void *malloc(size_t numBytes,
             const sycl::queue& syclQueue,
             sycl::usm::alloc kind,
             const sycl::property_list &propList = {})
template <typename T>
T *malloc(size_t count,
          const sycl::queue& syclQueue,
          sycl::usm::alloc kind,
          const sycl::property_list &propList = {})
void *aligned_alloc(size_t alignment,
                    size_t numBytes,
                    const sycl::device& syclDevice,
                    const sycl::context& syclContext,
                    sycl::usm::alloc kind,
                    const sycl::property_list &propList = {})
template <typename T>
T* aligned_alloc(size_t alignment,
                 size_t count,
                 const sycl::device& syclDevice,
                 const sycl::context& syclContext,
                 sycl::usm::alloc kind,
                 const sycl::property_list &propList = {})
void *aligned_alloc(size_t alignment,
                    size_t numBytes,
                    const sycl::queue& syclQueue,
                    sycl::usm::alloc kind,
                    const sycl::property_list &propList = {})
template <typename T>
T* aligned_alloc(size_t alignment,
                 size_t count,
                 const sycl::queue& syclQueue,
                 sycl::usm::alloc kind,
                 const sycl::property_list &propList = {})

Parameters

alignment

alignment of allocated data

numBytes

allocation size in bytes

count

number of elements

syclDevice

See sycl::device

syclQueue

See sycl::queue

syclContext

See sycl::context

kind

See sycl::usm::alloc

propList

sycl::free#

void free(void* ptr, sycl::context& context);
void free(void* ptr, sycl::queue& q);

Free memory allocated by sycl::malloc_device, sycl::malloc_host, or sycl::malloc_shared.

See Example 1 for usage.