Skip to content

Commit

Permalink
fabtests/ze: add ZE host alloc function
Browse files Browse the repository at this point in the history
The ZE code was using the default host alloc function (malloc)
for the host device buffer. This updates ZE to use the ZE-specific
host allocation function instead.

Signed-off-by: Alexia Ingerson <[email protected]>
  • Loading branch information
aingerson authored and shefty committed Sep 30, 2023
1 parent 8b3cee1 commit 967f914
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fabtests/common/hmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ static struct ft_hmem_ops hmem_ops[] = {
.init = ft_ze_init,
.cleanup = ft_ze_cleanup,
.alloc = ft_ze_alloc,
.alloc_host = ft_default_alloc_host,
.alloc_host = ft_ze_alloc_host,
.free = ft_ze_free,
.free_host = ft_default_free_host,
.free_host = ft_ze_free,
.mem_set = ft_ze_memset,
.copy_to_hmem = ft_ze_copy,
.copy_from_hmem = ft_ze_copy,
Expand Down
17 changes: 17 additions & 0 deletions fabtests/common/hmem_ze.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ static const ze_device_mem_alloc_desc_t device_desc = {
.ordinal = 0,
};

static const ze_host_mem_alloc_desc_t host_desc = {
.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC,
.pNext = NULL,
.flags = 0,
};

static void *libze_handle;
struct libze_ops libze_ops;
int init_libze_ops(void)
Expand Down Expand Up @@ -360,6 +366,12 @@ int ft_ze_alloc(uint64_t device, void **buf, size_t size)
-FI_EINVAL : 0;
}

int ft_ze_alloc_host(void **buffer, size_t size)
{
return (*libze_ops.zeMemAllocHost)(context, &host_desc, size, 16,
buffer) ? -FI_EINVAL : FI_SUCCESS;
}

int ft_ze_free(void *buf)
{
if (!buf)
Expand Down Expand Up @@ -439,6 +451,11 @@ int ft_ze_alloc(uint64_t device, void **buf, size_t size)
return -FI_ENOSYS;
}

int ft_ze_alloc_host(void **buffer, size_t size)
{
return -FI_ENOSYS;
}

int ft_ze_free(void *buf)
{
return -FI_ENOSYS;
Expand Down
1 change: 1 addition & 0 deletions fabtests/include/hmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ int init_libze_ops(void);
int ft_ze_init(void);
int ft_ze_cleanup(void);
int ft_ze_alloc(uint64_t device, void **buf, size_t size);
int ft_ze_alloc_host(void **buf, size_t size);
int ft_ze_free(void *buf);
int ft_ze_memset(uint64_t device, void *buf, int value, size_t size);
int ft_ze_copy(uint64_t device, void *dst, const void *src, size_t size);
Expand Down

0 comments on commit 967f914

Please sign in to comment.