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 v4 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions
Date: Thu, 27 Jan 2022 03:47:16 +0000	[thread overview]
Message-ID: <20220127034716.12497-2-eagostini@nvidia.com> (raw)
In-Reply-To: <20220127034716.12497-1-eagostini@nvidia.com>

From: Elena Agostini <eagostini@nvidia.com>

New test case added to test the gpudev cpu_map/cpu_unmap functions.

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

diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c
index 4500a8660b..3d0c17d8fd 100644
--- a/app/test-gpudev/main.c
+++ b/app/test-gpudev/main.c
@@ -185,6 +185,68 @@ register_cpu_memory(uint16_t gpu_id)
 	return -1;
 }
 
+static int
+gpu_mem_cpu_map(uint16_t gpu_id)
+{
+	void *ptr_gpu = NULL;
+	void *ptr_cpu = NULL;
+	size_t buf_bytes = 1024;
+	unsigned int align = 4096;
+	int ret;
+
+	printf("\n=======> TEST: Map GPU memory for CPU visibility\n\n");
+
+	/* Alloc memory on GPU 0 with 4kB alignment */
+	ptr_gpu = rte_gpu_mem_alloc(gpu_id, buf_bytes, align);
+	if (ptr_gpu == NULL) {
+		fprintf(stderr, "rte_gpu_mem_alloc GPU memory returned error\n");
+		goto error;
+	}
+	printf("GPU memory allocated at 0x%p size is %zd bytes\n",
+			ptr_gpu, buf_bytes);
+
+	ptr_cpu = rte_gpu_mem_cpu_map(gpu_id, buf_bytes, ptr_gpu);
+	if (ptr_cpu == NULL) {
+		fprintf(stderr, "rte_gpu_mem_cpu_map returned error\n");
+		goto error;
+	}
+	printf("GPU memory mapped for CPU access at 0x%p\n", ptr_cpu);
+
+	((uint8_t*)ptr_cpu)[0] = 0x4;
+	((uint8_t*)ptr_cpu)[1] = 0x5;
+	((uint8_t*)ptr_cpu)[2] = 0x6;
+
+	printf("GPU memory first 3 bytes set from CPU: %x %x %x\n",
+			((uint8_t*)ptr_cpu)[0],
+			((uint8_t*)ptr_cpu)[1],
+			((uint8_t*)ptr_cpu)[2]);
+
+	ret = rte_gpu_mem_cpu_unmap(gpu_id, ptr_cpu);
+	if (ret < 0) {
+		fprintf(stderr, "rte_gpu_mem_cpu_unmap returned error %d\n", ret);
+		goto error;
+	}
+	printf("GPU memory mapped for CPU access at 0x%p\n", ptr_cpu);
+
+	ret = rte_gpu_mem_free(gpu_id, ptr_gpu);
+	if (ret < 0) {
+		fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret);
+		goto error;
+	}
+	printf("GPU memory 0x%p freed\n", ptr_gpu);
+
+	printf("\n=======> TEST: PASSED\n");
+	return 0;
+
+error:
+
+	rte_gpu_mem_cpu_unmap(gpu_id, ptr_cpu);
+	rte_gpu_mem_free(gpu_id, ptr_gpu);
+
+	printf("\n=======> TEST: FAILED\n");
+	return -1;
+}
+
 static int
 create_update_comm_flag(uint16_t gpu_id)
 {
@@ -402,6 +464,7 @@ main(int argc, char **argv)
 	 */
 	alloc_gpu_memory(gpu_id);
 	register_cpu_memory(gpu_id);
+	gpu_mem_cpu_map(gpu_id);
 
 	/**
 	 * Communication items test
-- 
2.17.1


  reply	other threads:[~2022-01-26 19:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04  2:34 [PATCH v1] gpudev: pin GPU memory eagostini
2022-01-04  2:41 ` [PATCH v2] " eagostini
2022-01-04 12:51   ` Thomas Monjalon
2022-01-04 13:55     ` Elena Agostini
2022-01-04 17:28       ` John Alexander
2022-01-04 17:53         ` Elena Agostini
2022-01-08  0:04 ` [PATCH v3] gpudev: expose " eagostini
2022-01-27  3:47 ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU eagostini
2022-01-27  3:47   ` eagostini [this message]
2022-01-27  6:55   ` Wang, Haiyue
2022-02-10 10:38     ` Elena Agostini
2022-02-11  4:46       ` Wang, Haiyue
2022-01-27  3:50 ` [PATCH v5 " eagostini
2022-01-27  3:50   ` [PATCH v5 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions eagostini
2022-02-10 15:12   ` [PATCH v5 1/2] gpudev: expose GPU memory to CPU 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=20220127034716.12497-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).