From: Elena Agostini <eagost...@nvidia.com>

Update gpudev app to test GPU memory aligned allocation.

Signed-off-by: Elena Agostini <eagost...@nvidia.com>
---
 app/test-gpudev/main.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c
index 5c1aa3d52f..f36f46cbca 100644
--- a/app/test-gpudev/main.c
+++ b/app/test-gpudev/main.c
@@ -69,11 +69,12 @@ alloc_gpu_memory(uint16_t gpu_id)
        void *ptr_2 = NULL;
        size_t buf_bytes = 1024;
        int ret;
+       unsigned align = 4096;
 
        printf("\n=======> TEST: Allocate GPU memory\n\n");
 
-       /* Alloc memory on GPU 0 */
-       ptr_1 = rte_gpu_mem_alloc(gpu_id, buf_bytes);
+       /* Alloc memory on GPU 0 without any specific alignment */
+       ptr_1 = rte_gpu_mem_alloc(gpu_id, buf_bytes, 0);
        if (ptr_1 == NULL) {
                fprintf(stderr, "rte_gpu_mem_alloc GPU memory returned 
error\n");
                goto error;
@@ -81,7 +82,8 @@ alloc_gpu_memory(uint16_t gpu_id)
        printf("GPU memory allocated at 0x%p size is %zd bytes\n",
                        ptr_1, buf_bytes);
 
-       ptr_2 = rte_gpu_mem_alloc(gpu_id, buf_bytes);
+       /* Alloc memory on GPU 0 with 4kB alignment */
+       ptr_2 = rte_gpu_mem_alloc(gpu_id, buf_bytes, align);
        if (ptr_2 == NULL) {
                fprintf(stderr, "rte_gpu_mem_alloc GPU memory returned 
error\n");
                goto error;
@@ -89,6 +91,11 @@ alloc_gpu_memory(uint16_t gpu_id)
        printf("GPU memory allocated at 0x%p size is %zd bytes\n",
                        ptr_2, buf_bytes);
 
+       if (((uintptr_t)ptr_2) % align) {
+               fprintf(stderr, "Memory address 0x%p is not aligned to %u\n", 
ptr_2, align);
+               goto error;
+       }
+
        ret = rte_gpu_mem_free(gpu_id, (uint8_t *)(ptr_1)+0x700);
        if (ret < 0) {
                printf("GPU memory 0x%p NOT freed: GPU driver didn't find this 
memory address internally.\n",
-- 
2.17.1

Reply via email to