Area OpenCL Implementation API

group aml_area_opencl

OpenCL Implementation of Areas.

#include <aml/area/opencl.h>

OpenCL implementation of AML areas. This building block relies on OpenCL implementation of device memory allocation to provide mmap/munmap on device memory. Additional documentation of OpenCL memory model can be found here:

Functions

int aml_area_opencl_create(struct aml_area **area, cl_context context, const cl_mem_flags flags)

This will spawn areas mapping device side or host side only memory. This area creator does not allow mapping of memory regions where OpenCL is responsible for synchronization with other APIs.

Parameters:
  • area[out] A pointer to the area to allocate.

  • context[in] A valid OpenCL context.

  • flags[in] Flags to pass to clCreateBuffer().

Returns:

AML_SUCCESS on success.

Returns:

-AML_ENOMEM if there were not enough memory available to allocate area.

void *aml_area_opencl_mmap(const struct aml_area_data *area_data, size_t size, struct aml_area_mmap_options *options)

OpenCL implementation of mmap operation for aml area created with aml_area_opencl_create().

See also

aml_area

Parameters:
  • area_data[in] Area data of type struct aml_area_opencl_data where flag field contains cl_mem_flags.

  • size[in] The size to allocate.

  • options[in] NULL or host pointer if area flags contain CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR or CL_MEM_COPY_HOST_PTR.

Returns:

A valid cl_mem casted into (void *) on success.

Returns:

NULL on error with aml_errno set to:

  • -AML_EINVAL if size is 0, area flags are not valid or options is NULL while flags specify use of host pointer.

  • -AML_ENOMEM if their was not enough memory on host or device to fulfill the request.

int aml_area_opencl_munmap(const struct aml_area_data *area_data, void *ptr, const size_t size)

munmap hook for aml area created with aml_area_opencl_create().

Parameters:
  • area_data[in] Area data of type struct aml_area_opencl_data where flag field contains cl_mem_flags.

  • ptr[in] A pointer created with aml_area_opencl_mmap() and same type of area_data.

  • size[in] Allocation size.

Returns:

AML_SUCCESS on success.

Returns:

-AML_EINVAL if ptr is not a valid cl_mem buffer.

Returns:

-AML_ENOMEM if their was not enough memory on host or device to fulfill the request.

int aml_area_opencl_svm_create(struct aml_area **area, cl_context context, const cl_svm_mem_flags flags, cl_uint alignement)

This will spawn areas mapping shared virtual memory, i.e aml_area_mmap() on these areas will create a pointer usable both on host and device.

See also

https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_API.html#shared-virtual-memory This area creator does not allow mapping of memory regions where OpenCL is responsible for synchronization with other APIs.

Parameters:
  • area[out] A pointer to the area to allocate.

  • context[in] A valid OpenCL context.

  • flags[in] Flags to pass to clSVMalloc().

  • alignement[in] The minimum alignment in bytes that is required for the newly created buffer’s memory region.

Returns:

AML_SUCCESS on success.

Returns:

-AML_ENOMEM if there were not enough memory available to allocate area.

void *aml_area_opencl_svm_mmap(const struct aml_area_data *area_data, size_t size, struct aml_area_mmap_options *options)

OpenCL implementation of mmap operation for aml area created with aml_area_opencl_svm_create().

See also

aml_area

Parameters:
Returns:

A valid SVM pointer on success.

Returns:

NULL on error. This maybe the result of unsupported flags in area.

int aml_area_opencl_svm_munmap(const struct aml_area_data *area_data, void *ptr, const size_t size)

munmap hook for aml area created with aml_area_opencl_svm_create().

Parameters:
Returns:

AML_SUCCESS

void aml_area_opencl_destroy(struct aml_area **area)

OpenCL area destruction.

Destroy (finalize and free resources) a struct aml_area created by aml_area_opencl_create() or aml_area_opencl_svm_create().

Parameters:

area[inout] is NULL after this call.

Variables

struct aml_area_ops aml_area_opencl_ops

aml OpenCL area hooks (no SVM).

struct aml_area_ops aml_area_opencl_svm_ops

aml OpenCL SVM area hooks.

struct aml_area_opencl_svm_flags
#include <opencl.h>

Flags and parameter passed to clSVMalloc.

struct aml_area_opencl_data
#include <opencl.h>

Implementation of aml_area_data for cuda areas.