DPDK patches and discussions
 help / color / mirror / Atom feed
From: <eagostini@nvidia.com>
To: <dev@dpdk.org>
Cc: Elena Agostini <eagostini@nvidia.com>
Subject: [PATCH v2 2/3] app/test-gpudev: test aligned memory allocation
Date: Sat, 8 Jan 2022 00:20:02 +0000	[thread overview]
Message-ID: <20220108002003.21153-2-eagostini@nvidia.com> (raw)
In-Reply-To: <20220108002003.21153-1-eagostini@nvidia.com>

From: Elena Agostini <eagostini@nvidia.com>

Update gpudev app to test GPU memory aligned allocation.

Signed-off-by: Elena Agostini <eagostini@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	other threads:[~2022-01-07 16:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04  1:47 [PATCH v1 0/3] GPU memory aligned eagostini
2022-01-04  1:47 ` [PATCH v1 1/3] gpudev: mem alloc aligned memory eagostini
2022-01-04  1:47 ` [PATCH v1 2/3] app/test-gpudev: test aligned memory allocation eagostini
2022-01-04  1:47 ` [PATCH v1 3/3] gpu/cuda: mem alloc aligned memory eagostini
2022-01-03 18:05   ` Stephen Hemminger
2022-01-03 18:15     ` Elena Agostini
2022-01-03 18:17       ` Stephen Hemminger
2022-01-03 18:22         ` Elena Agostini
2022-01-08  0:20 ` [PATCH v2 1/3] gpudev: " eagostini
2022-01-08  0:20   ` eagostini [this message]
2022-01-08  0:20   ` [PATCH v2 3/3] gpu/cuda: " eagostini
2022-01-21 10:34   ` [PATCH v2 1/3] gpudev: " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220108002003.21153-2-eagostini@nvidia.com \
    --to=eagostini@nvidia.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).