DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1] gpudev: pin GPU memory
@ 2022-01-04  2:34 eagostini
  2022-01-04  2:41 ` [PATCH v2] " eagostini
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: eagostini @ 2022-01-04  2:34 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

From: Elena Agostini <eagostini@nvidia.com>

Enable the possibility to make a GPU memory area accessible from
the CPU.

GPU memory has to be allocated via rte_gpu_mem_alloc().

This patch allows the gpudev library to pin, through the GPU driver,
a chunk of GPU memory and to return a memory pointer usable
by the CPU to access the GPU memory area.

Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
 lib/gpudev/gpudev.c        | 47 +++++++++++++++++++++++++++++++++++
 lib/gpudev/gpudev_driver.h |  6 +++++
 lib/gpudev/rte_gpudev.h    | 50 ++++++++++++++++++++++++++++++++++++++
 lib/gpudev/version.map     |  2 ++
 4 files changed, 105 insertions(+)

diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 9ae36dbae9..ca627e44b3 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -634,6 +634,53 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr)
 	return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr));
 }
 
+int
+rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "pin mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_pin == NULL) {
+		GPU_LOG(ERR, "mem pinning not supported");
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL || size == 0) /* dry-run  */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_pin(dev, size, ptr));
+}
+
+int
+rte_gpu_mem_unpin(int16_t dev_id, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "unpin mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_unpin == NULL) {
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL) /* dry-run */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_unpin(dev, ptr));
+}
+
 int
 rte_gpu_wmb(int16_t dev_id)
 {
diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h
index cb7b101f2f..a616941926 100644
--- a/lib/gpudev/gpudev_driver.h
+++ b/lib/gpudev/gpudev_driver.h
@@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr);
 typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr);
 typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr);
+typedef int (rte_gpu_mem_pin_t)(struct rte_gpu *dev, size_t size, void *ptr);
+typedef int (rte_gpu_mem_unpin_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev);
 
 struct rte_gpu_ops {
@@ -46,6 +48,10 @@ struct rte_gpu_ops {
 	rte_gpu_mem_register_t *mem_register;
 	/* Unregister CPU memory from device. */
 	rte_gpu_mem_unregister_t *mem_unregister;
+        /* Pin GPU memory. */
+        rte_gpu_mem_pin_t *mem_pin;
+        /* Unpin GPU memory. */
+        rte_gpu_mem_unpin_t *mem_unpin;
 	/* Enforce GPU write memory barrier. */
 	rte_gpu_wmb_t *wmb;
 };
diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h
index fa3f3aad4f..0a9033c6e0 100644
--- a/lib/gpudev/rte_gpudev.h
+++ b/lib/gpudev/rte_gpudev.h
@@ -447,6 +447,56 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr);
 __rte_experimental
 int rte_gpu_mem_unregister(int16_t dev_id, void *ptr);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Pin a chunk of GPU memory to make it accessible from the CPU
+ * using the memory pointer returned by the function.
+ * GPU memory has to be allocated via rte_gpu_mem_alloc().
+ *
+ * @param dev_id
+ *   Device ID requiring pinned memory.
+ * @param size
+ *   Number of bytes to pin.
+ *   Requesting 0 will do nothing.
+ * @param ptr
+ *   Pointer to the GPU memory area to be pinned.
+ *   NULL is a no-op accepted value.
+
+ * @return
+ *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
+ *   - ENODEV if invalid dev_id
+ *   - EINVAL if reserved flags
+ *   - ENOTSUP if operation not supported by the driver
+ *   - E2BIG if size is higher than limit
+ *   - ENOMEM if out of space
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Unpin a chunk of GPU memory previously pinned with rte_gpu_mem_pin()
+ *
+ * @param dev_id
+ *   Reference device ID.
+ * @param ptr
+ *   Pointer to the memory area to be unpinned.
+ *   NULL is a no-op accepted value.
+ *
+ * @return
+ *   0 on success, -rte_errno otherwise:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_unpin(int16_t dev_id, void *ptr);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map
index 2e414c65cc..8fb0f4623b 100644
--- a/lib/gpudev/version.map
+++ b/lib/gpudev/version.map
@@ -21,7 +21,9 @@ EXPERIMENTAL {
 	rte_gpu_is_valid;
 	rte_gpu_mem_alloc;
 	rte_gpu_mem_free;
+	rte_gpu_mem_pin;
 	rte_gpu_mem_register;
+	rte_gpu_mem_unpin;
 	rte_gpu_mem_unregister;
 	rte_gpu_wmb;
 };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2] gpudev: pin GPU memory
  2022-01-04  2:34 [PATCH v1] gpudev: pin GPU memory eagostini
@ 2022-01-04  2:41 ` eagostini
  2022-01-04 12:51   ` Thomas Monjalon
  2022-01-08  0:04 ` [PATCH v3] gpudev: expose " eagostini
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: eagostini @ 2022-01-04  2:41 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

From: Elena Agostini <eagostini@nvidia.com>

Enable the possibility to make a GPU memory area accessible from
the CPU.

GPU memory has to be allocated via rte_gpu_mem_alloc().

This patch allows the gpudev library to pin, through the GPU driver,
a chunk of GPU memory and to return a memory pointer usable
by the CPU to access the GPU memory area.

Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
 lib/gpudev/gpudev.c        | 47 +++++++++++++++++++++++++++++++++++
 lib/gpudev/gpudev_driver.h |  6 +++++
 lib/gpudev/rte_gpudev.h    | 50 ++++++++++++++++++++++++++++++++++++++
 lib/gpudev/version.map     |  2 ++
 4 files changed, 105 insertions(+)

diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 9ae36dbae9..ca627e44b3 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -634,6 +634,53 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr)
 	return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr));
 }
 
+int
+rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "pin mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_pin == NULL) {
+		GPU_LOG(ERR, "mem pinning not supported");
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL || size == 0) /* dry-run  */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_pin(dev, size, ptr));
+}
+
+int
+rte_gpu_mem_unpin(int16_t dev_id, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "unpin mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_unpin == NULL) {
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL) /* dry-run */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_unpin(dev, ptr));
+}
+
 int
 rte_gpu_wmb(int16_t dev_id)
 {
diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h
index cb7b101f2f..13dd8dac43 100644
--- a/lib/gpudev/gpudev_driver.h
+++ b/lib/gpudev/gpudev_driver.h
@@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr);
 typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr);
 typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr);
+typedef int (rte_gpu_mem_pin_t)(struct rte_gpu *dev, size_t size, void *ptr);
+typedef int (rte_gpu_mem_unpin_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev);
 
 struct rte_gpu_ops {
@@ -46,6 +48,10 @@ struct rte_gpu_ops {
 	rte_gpu_mem_register_t *mem_register;
 	/* Unregister CPU memory from device. */
 	rte_gpu_mem_unregister_t *mem_unregister;
+	/* Pin GPU memory. */
+	rte_gpu_mem_pin_t *mem_pin;
+	/* Unpin GPU memory. */
+	rte_gpu_mem_unpin_t *mem_unpin;
 	/* Enforce GPU write memory barrier. */
 	rte_gpu_wmb_t *wmb;
 };
diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h
index fa3f3aad4f..0a9033c6e0 100644
--- a/lib/gpudev/rte_gpudev.h
+++ b/lib/gpudev/rte_gpudev.h
@@ -447,6 +447,56 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr);
 __rte_experimental
 int rte_gpu_mem_unregister(int16_t dev_id, void *ptr);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Pin a chunk of GPU memory to make it accessible from the CPU
+ * using the memory pointer returned by the function.
+ * GPU memory has to be allocated via rte_gpu_mem_alloc().
+ *
+ * @param dev_id
+ *   Device ID requiring pinned memory.
+ * @param size
+ *   Number of bytes to pin.
+ *   Requesting 0 will do nothing.
+ * @param ptr
+ *   Pointer to the GPU memory area to be pinned.
+ *   NULL is a no-op accepted value.
+
+ * @return
+ *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
+ *   - ENODEV if invalid dev_id
+ *   - EINVAL if reserved flags
+ *   - ENOTSUP if operation not supported by the driver
+ *   - E2BIG if size is higher than limit
+ *   - ENOMEM if out of space
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Unpin a chunk of GPU memory previously pinned with rte_gpu_mem_pin()
+ *
+ * @param dev_id
+ *   Reference device ID.
+ * @param ptr
+ *   Pointer to the memory area to be unpinned.
+ *   NULL is a no-op accepted value.
+ *
+ * @return
+ *   0 on success, -rte_errno otherwise:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_unpin(int16_t dev_id, void *ptr);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map
index 2e414c65cc..8fb0f4623b 100644
--- a/lib/gpudev/version.map
+++ b/lib/gpudev/version.map
@@ -21,7 +21,9 @@ EXPERIMENTAL {
 	rte_gpu_is_valid;
 	rte_gpu_mem_alloc;
 	rte_gpu_mem_free;
+	rte_gpu_mem_pin;
 	rte_gpu_mem_register;
+	rte_gpu_mem_unpin;
 	rte_gpu_mem_unregister;
 	rte_gpu_wmb;
 };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2] gpudev: pin GPU memory
  2022-01-04  2:41 ` [PATCH v2] " eagostini
@ 2022-01-04 12:51   ` Thomas Monjalon
  2022-01-04 13:55     ` Elena Agostini
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Monjalon @ 2022-01-04 12:51 UTC (permalink / raw)
  To: Elena Agostini; +Cc: dev

04/01/2022 03:41, eagostini@nvidia.com:
> From: Elena Agostini <eagostini@nvidia.com>
> 
> Enable the possibility to make a GPU memory area accessible from
> the CPU.
> 
> GPU memory has to be allocated via rte_gpu_mem_alloc().
> 
> This patch allows the gpudev library to pin, through the GPU driver,
> a chunk of GPU memory and to return a memory pointer usable
> by the CPU to access the GPU memory area.
> 
> Signed-off-by: Elena Agostini <eagostini@nvidia.com>
[...]
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice.
> + *
> + * Pin a chunk of GPU memory to make it accessible from the CPU

You should define what means "pin" exactly.
Which properties should we expect?

> + * using the memory pointer returned by the function.

Which function should return the pointer?
rte_gpu_mem_pin is returning an int.


> + * GPU memory has to be allocated via rte_gpu_mem_alloc().

Why pinning is not done by rte_gpu_mem_alloc()?
Should it be a flag?

> + *
> + * @param dev_id
> + *   Device ID requiring pinned memory.
> + * @param size
> + *   Number of bytes to pin.
> + *   Requesting 0 will do nothing.
> + * @param ptr
> + *   Pointer to the GPU memory area to be pinned.
> + *   NULL is a no-op accepted value.
> +
> + * @return
> + *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
> + *   - ENODEV if invalid dev_id
> + *   - EINVAL if reserved flags

Which reserved flags?

> + *   - ENOTSUP if operation not supported by the driver
> + *   - E2BIG if size is higher than limit
> + *   - ENOMEM if out of space

Is out of space relevant for pinning?

> + *   - EPERM if driver error
> + */
> +__rte_experimental
> +int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2] gpudev: pin GPU memory
  2022-01-04 12:51   ` Thomas Monjalon
@ 2022-01-04 13:55     ` Elena Agostini
  2022-01-04 17:28       ` John Alexander
  0 siblings, 1 reply; 15+ messages in thread
From: Elena Agostini @ 2022-01-04 13:55 UTC (permalink / raw)
  To: NBU-Contact-Thomas Monjalon (EXTERNAL); +Cc: dev

[-- Attachment #1: Type: text/plain, Size: 2532 bytes --]

> 04/01/2022 03:41, eagostini@nvidia.com:
> > From: Elena Agostini <eagostini@nvidia.com>
> >
> > Enable the possibility to make a GPU memory area accessible from
> > the CPU.
> >
> > GPU memory has to be allocated via rte_gpu_mem_alloc().
> >
> > This patch allows the gpudev library to pin, through the GPU driver,
> > a chunk of GPU memory and to return a memory pointer usable
> > by the CPU to access the GPU memory area.
> >
> > Signed-off-by: Elena Agostini <eagostini@nvidia.com>
> [...]
> > +/**
> > + * @warning
> > + * @b EXPERIMENTAL: this API may change without prior notice.
> > + *
> > + * Pin a chunk of GPU memory to make it accessible from the CPU
>
> You should define what means "pin" exactly.
> Which properties should we expect?
>

Thanks for reviewing, this is the kind of discussion I wanted to have.
Maybe "pin" is too GDRCopy specific oriented.
Here I want to make a GPU memory buffer visible from the CPU. In case
of NVIDIA, this means the GPU memory address has to be pinned (virtual address
doesn't change) and dma-mapped.

Maybe the name should be more like rte_gpu_mem_to_cpu() that's more
explicative and generic.

> > + * using the memory pointer returned by the function.
>
> Which function should return the pointer?
> rte_gpu_mem_pin is returning an int.

Oversight, will fix it.

>
>
> > + * GPU memory has to be allocated via rte_gpu_mem_alloc().
>
> Why pinning is not done by rte_gpu_mem_alloc()?
> Should it be a flag?

rte_gpu_mem_alloc() allocate virtual memory on the GPU that doesn't have
to be necessarily shared (pinned) to make it visible from CPU.

>
> > + *
> > + * @param dev_id
> > + *   Device ID requiring pinned memory.
> > + * @param size
> > + *   Number of bytes to pin.
> > + *   Requesting 0 will do nothing.
> > + * @param ptr
> > + *   Pointer to the GPU memory area to be pinned.
> > + *   NULL is a no-op accepted value.
> > +
> > + * @return
> > + *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
> > + *   - ENODEV if invalid dev_id
> > + *   - EINVAL if reserved flags
>
> Which reserved flags?
>
> > + *   - ENOTSUP if operation not supported by the driver
> > + *   - E2BIG if size is higher than limit
> > + *   - ENOMEM if out of space
>
> Is out of space relevant for pinning?

Yes, let me add it

>
> > + *   - EPERM if driver error
> > + */
> > +__rte_experimental
> > +int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);

[-- Attachment #2: Type: text/html, Size: 10199 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH v2] gpudev: pin GPU memory
  2022-01-04 13:55     ` Elena Agostini
@ 2022-01-04 17:28       ` John Alexander
  2022-01-04 17:53         ` Elena Agostini
  0 siblings, 1 reply; 15+ messages in thread
From: John Alexander @ 2022-01-04 17:28 UTC (permalink / raw)
  To: Elena Agostini, NBU-Contact-Thomas Monjalon (EXTERNAL); +Cc: dev

[-- Attachment #1: Type: text/plain, Size: 3216 bytes --]

What happens when the Nvidia GPU driver kernel callback occurs to invalidate the pinned GPU memory region?  Doesn't the NIC need to cease all DMA transfers to/from that region before the kernel callback can complete?

From: Elena Agostini <eagostini@nvidia.com>
Sent: 04 January 2022 13:55
To: NBU-Contact-Thomas Monjalon (EXTERNAL) <thomas@monjalon.net>
Cc: dev@dpdk.org
Subject: Re: [PATCH v2] gpudev: pin GPU memory

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> 04/01/2022 03:41, eagostini@nvidia.com<mailto:eagostini@nvidia.com>:
> > From: Elena Agostini <eagostini@nvidia.com<mailto:eagostini@nvidia.com>>
> >
> > Enable the possibility to make a GPU memory area accessible from
> > the CPU.
> >
> > GPU memory has to be allocated via rte_gpu_mem_alloc().
> >
> > This patch allows the gpudev library to pin, through the GPU driver,
> > a chunk of GPU memory and to return a memory pointer usable
> > by the CPU to access the GPU memory area.
> >
> > Signed-off-by: Elena Agostini <eagostini@nvidia.com<mailto:eagostini@nvidia.com>>
> [...]
> > +/**
> > + * @warning
> > + * @b EXPERIMENTAL: this API may change without prior notice.
> > + *
> > + * Pin a chunk of GPU memory to make it accessible from the CPU
>
> You should define what means "pin" exactly.
> Which properties should we expect?
>

Thanks for reviewing, this is the kind of discussion I wanted to have.
Maybe "pin" is too GDRCopy specific oriented.
Here I want to make a GPU memory buffer visible from the CPU. In case
of NVIDIA, this means the GPU memory address has to be pinned (virtual address
doesn't change) and dma-mapped.

Maybe the name should be more like rte_gpu_mem_to_cpu() that's more
explicative and generic.


> > + * using the memory pointer returned by the function.
>
> Which function should return the pointer?
> rte_gpu_mem_pin is returning an int.

Oversight, will fix it.

>
>
> > + * GPU memory has to be allocated via rte_gpu_mem_alloc().
>
> Why pinning is not done by rte_gpu_mem_alloc()?
> Should it be a flag?

rte_gpu_mem_alloc() allocate virtual memory on the GPU that doesn't have
to be necessarily shared (pinned) to make it visible from CPU.

>
> > + *
> > + * @param dev_id
> > + *   Device ID requiring pinned memory.
> > + * @param size
> > + *   Number of bytes to pin.
> > + *   Requesting 0 will do nothing.
> > + * @param ptr
> > + *   Pointer to the GPU memory area to be pinned.
> > + *   NULL is a no-op accepted value.
> > +
> > + * @return
> > + *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
> > + *   - ENODEV if invalid dev_id
> > + *   - EINVAL if reserved flags
>
> Which reserved flags?
>
> > + *   - ENOTSUP if operation not supported by the driver
> > + *   - E2BIG if size is higher than limit
> > + *   - ENOMEM if out of space
>
> Is out of space relevant for pinning?

Yes, let me add it

>
> > + *   - EPERM if driver error
> > + */
> > +__rte_experimental
> > +int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);

[-- Attachment #2: Type: text/html, Size: 12796 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2] gpudev: pin GPU memory
  2022-01-04 17:28       ` John Alexander
@ 2022-01-04 17:53         ` Elena Agostini
  0 siblings, 0 replies; 15+ messages in thread
From: Elena Agostini @ 2022-01-04 17:53 UTC (permalink / raw)
  To: John Alexander, NBU-Contact-Thomas Monjalon (EXTERNAL); +Cc: dev


[-- Attachment #1.1: Type: text/plain, Size: 7311 bytes --]

This specific feature is not about NIC activity, it’s about make GPU memory visible and accessible to the CPU so there isn’t an asynchronous hidden invalidation procedure.
That’s the reason for my comment to change the name from rte_gpu_mem_pin() to rte_gpu_mem_to_cpu() (or similar).

The scenario you are proposing can happen but in a different context, this is not the case.

Thanks
EA

From: John Alexander <John.Alexander@datapath.co.uk>
Date: Tuesday, 4 January 2022 at 18:31
To: Elena Agostini <eagostini@nvidia.com>, NBU-Contact-Thomas Monjalon (EXTERNAL) <thomas@monjalon.net>
Cc: dev@dpdk.org <dev@dpdk.org>
Subject: RE: [PATCH v2] gpudev: pin GPU memory
External email: Use caution opening links or attachments

What happens when the Nvidia GPU driver kernel callback occurs to invalidate the pinned GPU memory region?  Doesn’t the NIC need to cease all DMA transfers to/from that region before the kernel callback can complete?

John Alexander​
Senior Software Engineer
[cid:image152483.jpg@5CD90415.402D82AB]<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.datapath.co.uk%2F&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9b3%2FEpEiezz%2B0nLDmm2pE5ZcLkEzNbW%2F%2BJ1o61q2J3k%3D&reserved=0>
Bemrose House, Bemrose Park, Wayzgoose Drive
,
Derby
,
DE21 6XQ
[cid:image839434.png@FD4260AC.D2B1B11C]
+44 (0)1332 294 441<tel:+44%20(0)1332%20294%20441>
 |
www.datapath.co.uk<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.datapath.co.uk%2F&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9b3%2FEpEiezz%2B0nLDmm2pE5ZcLkEzNbW%2F%2BJ1o61q2J3k%3D&reserved=0>
[LinkedIn]<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.linkedin.com%2Fcompany%2Fdatapath-ltd&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=0PTscJhiHEK27PKDjq2nNgH5oRe499xubLh4S705u4A%3D&reserved=0>
[Twitter]<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.twitter.com%2Fdatapathltd&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=CVia5Sq%2Fi2yOAGx5d8PSsF7wJsA2oVM%2BgySwg5E7p2U%3D&reserved=0>
[YouTube]<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fdatapathderby&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Obz00eF3OgTdp3YI5ux2YFRdx6Q65keqlMXVY6QNXCM%3D&reserved=0>
[cid:image974625.png@E5A3F546.B8FD2EA9]<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.datapath.co.uk%2Fevents-and-webinars%2F&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=MO6M5IE0mAymLgzIZwGqPPxqftcmzH7Gy43ZOGYHwAs%3D&reserved=0>
[Vote for Datapath]<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.datapath.co.uk%2Fdatapath-shortlisted-for-coveted-industry-award%2F&data=04%7C01%7Ceagostini%40nvidia.com%7Ce2fbb83b86ac4dc3571308d9cfa7b653%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637769142848844684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=D0wKDJVR%2B9kSzyIvtxt5yOdKZPCb%2Fd48biairPlYqt4%3D&reserved=0>
Datapath Ltd.  Registered Number: 1609392.  Registered in England at Bemrose House, Bemrose Park, Wayzgoose Drive, Derby. DE21 6XQ.
From: Elena Agostini <eagostini@nvidia.com>
Sent: 04 January 2022 13:55
To: NBU-Contact-Thomas Monjalon (EXTERNAL) <thomas@monjalon.net>
Cc: dev@dpdk.org
Subject: Re: [PATCH v2] gpudev: pin GPU memory

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> 04/01/2022 03:41, eagostini@nvidia.com<mailto:eagostini@nvidia.com>:
> > From: Elena Agostini <eagostini@nvidia.com<mailto:eagostini@nvidia.com>>
> >
> > Enable the possibility to make a GPU memory area accessible from
> > the CPU.
> >
> > GPU memory has to be allocated via rte_gpu_mem_alloc().
> >
> > This patch allows the gpudev library to pin, through the GPU driver,
> > a chunk of GPU memory and to return a memory pointer usable
> > by the CPU to access the GPU memory area.
> >
> > Signed-off-by: Elena Agostini <eagostini@nvidia.com<mailto:eagostini@nvidia.com>>
> [...]
> > +/**
> > + * @warning
> > + * @b EXPERIMENTAL: this API may change without prior notice.
> > + *
> > + * Pin a chunk of GPU memory to make it accessible from the CPU
>
> You should define what means "pin" exactly.
> Which properties should we expect?
>

Thanks for reviewing, this is the kind of discussion I wanted to have.
Maybe "pin" is too GDRCopy specific oriented.
Here I want to make a GPU memory buffer visible from the CPU. In case
of NVIDIA, this means the GPU memory address has to be pinned (virtual address
doesn't change) and dma-mapped.

Maybe the name should be more like rte_gpu_mem_to_cpu() that's more
explicative and generic.


> > + * using the memory pointer returned by the function.
>
> Which function should return the pointer?
> rte_gpu_mem_pin is returning an int.

Oversight, will fix it.

>
>
> > + * GPU memory has to be allocated via rte_gpu_mem_alloc().
>
> Why pinning is not done by rte_gpu_mem_alloc()?
> Should it be a flag?

rte_gpu_mem_alloc() allocate virtual memory on the GPU that doesn't have
to be necessarily shared (pinned) to make it visible from CPU.

>
> > + *
> > + * @param dev_id
> > + *   Device ID requiring pinned memory.
> > + * @param size
> > + *   Number of bytes to pin.
> > + *   Requesting 0 will do nothing.
> > + * @param ptr
> > + *   Pointer to the GPU memory area to be pinned.
> > + *   NULL is a no-op accepted value.
> > +
> > + * @return
> > + *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
> > + *   - ENODEV if invalid dev_id
> > + *   - EINVAL if reserved flags
>
> Which reserved flags?
>
> > + *   - ENOTSUP if operation not supported by the driver
> > + *   - E2BIG if size is higher than limit
> > + *   - ENOMEM if out of space
>
> Is out of space relevant for pinning?

Yes, let me add it

>
> > + *   - EPERM if driver error
> > + */
> > +__rte_experimental
> > +int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);

[-- Attachment #1.2: Type: text/html, Size: 32898 bytes --]

[-- Attachment #2: image152483.jpg --]
[-- Type: image/jpeg, Size: 5403 bytes --]

[-- Attachment #3: image158572.png --]
[-- Type: image/png, Size: 651 bytes --]

[-- Attachment #4: image416332.png --]
[-- Type: image/png, Size: 620 bytes --]

[-- Attachment #5: image447896.png --]
[-- Type: image/png, Size: 684 bytes --]

[-- Attachment #6: image509100.png --]
[-- Type: image/png, Size: 24194 bytes --]

[-- Attachment #7: image839434.png --]
[-- Type: image/png, Size: 335 bytes --]

[-- Attachment #8: image974625.png --]
[-- Type: image/png, Size: 20712 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3] gpudev: expose GPU memory
  2022-01-04  2:34 [PATCH v1] gpudev: pin GPU memory eagostini
  2022-01-04  2:41 ` [PATCH v2] " eagostini
@ 2022-01-08  0:04 ` eagostini
  2022-01-27  3:47 ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU eagostini
  2022-01-27  3:50 ` [PATCH v5 " eagostini
  3 siblings, 0 replies; 15+ messages in thread
From: eagostini @ 2022-01-08  0:04 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

From: Elena Agostini <eagostini@nvidia.com>

Enable the possibility to expose a GPU memory area and make it
accessible from the CPU.

GPU memory has to be allocated via rte_gpu_mem_alloc().

This patch allows the gpudev library to expose (and unexpose),
through the GPU driver, a chunk of GPU memory and to return
a memory pointer usable by the CPU to access the GPU memory area.

Changelog:
- Move to pin/unpin naming to expose/unexpose
- Minor changes to function definitions

Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
 lib/gpudev/gpudev.c        | 61 ++++++++++++++++++++++++++++++++++++++
 lib/gpudev/gpudev_driver.h |  6 ++++
 lib/gpudev/rte_gpudev.h    | 49 ++++++++++++++++++++++++++++++
 lib/gpudev/version.map     |  2 ++
 4 files changed, 118 insertions(+)

diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 9ae36dbae9..eafd5909e3 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -634,6 +634,67 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr)
 	return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr));
 }
 
+void *
+rte_gpu_mem_expose(int16_t dev_id, size_t size, void *ptr)
+{
+	struct rte_gpu *dev;
+	void *ptr_out;
+	int ret;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "expose mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return NULL;
+	}
+
+	if (dev->ops.mem_expose == NULL) {
+		GPU_LOG(ERR, "mem exposure not supported");
+		rte_errno = ENOTSUP;
+		return NULL;
+	}
+
+	if (ptr == NULL || size == 0) /* dry-run  */
+		return NULL;
+
+	ret = GPU_DRV_RET(dev->ops.mem_expose(dev, size, ptr, &ptr_out));
+
+	switch (ret) {
+	case 0:
+		return ptr_out;
+	case -ENOMEM:
+	case -E2BIG:
+		rte_errno = -ret;
+		return NULL;
+	default:
+		rte_errno = -EPERM;
+		return NULL;
+	}
+}
+
+int
+rte_gpu_mem_unexpose(int16_t dev_id, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "unexpose mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_unexpose == NULL) {
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL) /* dry-run */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_unexpose(dev, ptr));
+}
+
 int
 rte_gpu_wmb(int16_t dev_id)
 {
diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h
index cb7b101f2f..9049d11280 100644
--- a/lib/gpudev/gpudev_driver.h
+++ b/lib/gpudev/gpudev_driver.h
@@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr);
 typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr);
 typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr);
+typedef int (rte_gpu_mem_expose_t)(struct rte_gpu *dev, size_t size, void *ptr_in, void **ptr_out);
+typedef int (rte_gpu_mem_unexpose_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev);
 
 struct rte_gpu_ops {
@@ -46,6 +48,10 @@ struct rte_gpu_ops {
 	rte_gpu_mem_register_t *mem_register;
 	/* Unregister CPU memory from device. */
 	rte_gpu_mem_unregister_t *mem_unregister;
+	/* Pin GPU memory. */
+	rte_gpu_mem_expose_t *mem_expose;
+	/* Unpin GPU memory. */
+	rte_gpu_mem_unexpose_t *mem_unexpose;
 	/* Enforce GPU write memory barrier. */
 	rte_gpu_wmb_t *wmb;
 };
diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h
index fa3f3aad4f..2048133790 100644
--- a/lib/gpudev/rte_gpudev.h
+++ b/lib/gpudev/rte_gpudev.h
@@ -447,6 +447,55 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr);
 __rte_experimental
 int rte_gpu_mem_unregister(int16_t dev_id, void *ptr);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Expose a chunk of GPU memory to make it accessible from the CPU
+ * using the memory pointer returned by the function.
+ * GPU memory has to be allocated via rte_gpu_mem_alloc().
+ *
+ * @param dev_id
+ *   Device ID requiring exposed memory.
+ * @param size
+ *   Number of bytes to expose.
+ *   Requesting 0 will do nothing.
+ * @param ptr
+ *   Pointer to the GPU memory area to be exposed.
+ *   NULL is a no-op accepted value.
+
+ * @return
+ *   A pointer to the exposed GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - E2BIG if size is higher than limit
+ *   - ENOMEM if out of space
+ *   - EPERM if driver error
+ */
+__rte_experimental
+void *rte_gpu_mem_expose(int16_t dev_id, size_t size, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Unexpose a chunk of GPU memory previously exposed with rte_gpu_mem_expose()
+ *
+ * @param dev_id
+ *   Reference device ID.
+ * @param ptr
+ *   Pointer to the memory area to be unexposed.
+ *   NULL is a no-op accepted value.
+ *
+ * @return
+ *   0 on success, -rte_errno otherwise:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_unexpose(int16_t dev_id, void *ptr);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map
index 2e414c65cc..dce6085e44 100644
--- a/lib/gpudev/version.map
+++ b/lib/gpudev/version.map
@@ -20,8 +20,10 @@ EXPERIMENTAL {
 	rte_gpu_init;
 	rte_gpu_is_valid;
 	rte_gpu_mem_alloc;
+	rte_gpu_mem_expose;
 	rte_gpu_mem_free;
 	rte_gpu_mem_register;
+	rte_gpu_mem_unexpose;
 	rte_gpu_mem_unregister;
 	rte_gpu_wmb;
 };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v4 1/2] gpudev: expose GPU memory to CPU
  2022-01-04  2:34 [PATCH v1] gpudev: pin GPU memory eagostini
  2022-01-04  2:41 ` [PATCH v2] " eagostini
  2022-01-08  0:04 ` [PATCH v3] gpudev: expose " eagostini
@ 2022-01-27  3:47 ` eagostini
  2022-01-27  3:47   ` [PATCH v4 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions eagostini
  2022-01-27  6:55   ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU Wang, Haiyue
  2022-01-27  3:50 ` [PATCH v5 " eagostini
  3 siblings, 2 replies; 15+ messages in thread
From: eagostini @ 2022-01-27  3:47 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

From: Elena Agostini <eagostini@nvidia.com>

Enable the possibility to expose a GPU memory area and make it
accessible from the CPU.

GPU memory has to be allocated via rte_gpu_mem_alloc().

This patch allows the gpudev library to map (and unmap),
through the GPU driver, a chunk of GPU memory and to return
a memory pointer usable by the CPU to access the GPU memory area.

Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
 doc/guides/prog_guide/gpudev.rst |  9 +++++
 drivers/gpu/cuda/cuda.c          |  2 ++
 lib/gpudev/gpudev.c              | 61 ++++++++++++++++++++++++++++++++
 lib/gpudev/gpudev_driver.h       |  6 ++++
 lib/gpudev/rte_gpudev.h          | 49 +++++++++++++++++++++++++
 lib/gpudev/version.map           |  2 ++
 6 files changed, 129 insertions(+)

diff --git a/doc/guides/prog_guide/gpudev.rst b/doc/guides/prog_guide/gpudev.rst
index ff4626812b..b774ec77f9 100644
--- a/doc/guides/prog_guide/gpudev.rst
+++ b/doc/guides/prog_guide/gpudev.rst
@@ -73,6 +73,15 @@ Later, it's also possible to unregister that memory with gpudev.
 CPU memory registered outside of the gpudev library
 (e.g. with GPU specific library) cannot be unregistered by the gpudev library.
 
+CPU mapping
+~~~~~~~~~~~~~~~~~~~
+
+gpudev can map into the CPU address space a GPU memory address allocated with gpudev.
+gpudev returns a pointer the CPU can use to access (ready or write) GPU memory.
+Later, it's also possible to unmap that memory with gpudev.
+GPU memory CPU mapped outside of the gpudev library (e.g. with GPU specific library)
+cannot be unmapped by the gpudev library.
+
 Memory Barrier
 ~~~~~~~~~~~~~~
 
diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c
index 0ece1bb612..408b659fce 100644
--- a/drivers/gpu/cuda/cuda.c
+++ b/drivers/gpu/cuda/cuda.c
@@ -1177,6 +1177,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic
 	dev->ops.mem_free = cuda_mem_free;
 	dev->ops.mem_register = cuda_mem_register;
 	dev->ops.mem_unregister = cuda_mem_unregister;
+	dev->ops.mem_cpu_map = NULL;
+	dev->ops.mem_cpu_unmap = NULL;
 	dev->ops.wmb = cuda_wmb;
 
 	rte_gpu_complete_new(dev);
diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 59e2169292..ce92d63257 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -640,6 +640,67 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr)
 	return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr));
 }
 
+void *
+rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr)
+{
+	struct rte_gpu *dev;
+	void *ptr_out;
+	int ret;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "mem CPU map for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return NULL;
+	}
+
+	if (dev->ops.mem_cpu_map == NULL) {
+		GPU_LOG(ERR, "mem CPU map not supported");
+		rte_errno = ENOTSUP;
+		return NULL;
+	}
+
+	if (ptr == NULL || size == 0) /* dry-run  */
+		return NULL;
+
+	ret = GPU_DRV_RET(dev->ops.mem_cpu_map(dev, size, ptr, &ptr_out));
+
+	switch (ret) {
+	case 0:
+		return ptr_out;
+	case -ENOMEM:
+	case -E2BIG:
+		rte_errno = -ret;
+		return NULL;
+	default:
+		rte_errno = -EPERM;
+		return NULL;
+	}
+}
+
+int
+rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "cpu_unmap mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_cpu_unmap == NULL) {
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL) /* dry-run */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_cpu_unmap(dev, ptr));
+}
+
 int
 rte_gpu_wmb(int16_t dev_id)
 {
diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h
index 0ed7478e9b..0e55b00bfe 100644
--- a/lib/gpudev/gpudev_driver.h
+++ b/lib/gpudev/gpudev_driver.h
@@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, unsigned int
 typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr);
 typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr);
+typedef int (rte_gpu_mem_cpu_map_t)(struct rte_gpu *dev, size_t size, void *ptr_in, void **ptr_out);
+typedef int (rte_gpu_mem_cpu_unmap_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev);
 
 struct rte_gpu_ops {
@@ -46,6 +48,10 @@ struct rte_gpu_ops {
 	rte_gpu_mem_register_t *mem_register;
 	/* Unregister CPU memory from device. */
 	rte_gpu_mem_unregister_t *mem_unregister;
+	/* Map GPU memory for CPU visibility. */
+	rte_gpu_mem_cpu_map_t *mem_cpu_map;
+	/* Unmap GPU memory for CPU visibility. */
+	rte_gpu_mem_cpu_unmap_t *mem_cpu_unmap;
 	/* Enforce GPU write memory barrier. */
 	rte_gpu_wmb_t *wmb;
 };
diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h
index ff3ca78c89..5cc4eb5828 100644
--- a/lib/gpudev/rte_gpudev.h
+++ b/lib/gpudev/rte_gpudev.h
@@ -452,6 +452,55 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr);
 __rte_experimental
 int rte_gpu_mem_unregister(int16_t dev_id, void *ptr);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Map a chunk of GPU memory to make it accessible from the CPU
+ * using the memory pointer returned by the function.
+ * GPU memory has to be allocated via rte_gpu_mem_alloc().
+ *
+ * @param dev_id
+ *   Device ID requiring mapped memory.
+ * @param size
+ *   Number of bytes to map.
+ *   Requesting 0 will do nothing.
+ * @param ptr
+ *   Pointer to the GPU memory area to be mapped.
+ *   NULL is a no-op accepted value.
+
+ * @return
+ *   A pointer to the mapped GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - E2BIG if size is higher than limit
+ *   - ENOMEM if out of space
+ *   - EPERM if driver error
+ */
+__rte_experimental
+void *rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Unmap a chunk of GPU memory previously mapped with rte_gpu_mem_cpu_map()
+ *
+ * @param dev_id
+ *   Reference device ID.
+ * @param ptr
+ *   Pointer to the memory area to be unmapped.
+ *   NULL is a no-op accepted value.
+ *
+ * @return
+ *   0 on success, -rte_errno otherwise:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map
index 2e414c65cc..5bc5d154cd 100644
--- a/lib/gpudev/version.map
+++ b/lib/gpudev/version.map
@@ -20,8 +20,10 @@ EXPERIMENTAL {
 	rte_gpu_init;
 	rte_gpu_is_valid;
 	rte_gpu_mem_alloc;
+	rte_gpu_mem_cpu_map;
 	rte_gpu_mem_free;
 	rte_gpu_mem_register;
+	rte_gpu_mem_cpu_unmap;
 	rte_gpu_mem_unregister;
 	rte_gpu_wmb;
 };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v4 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions
  2022-01-27  3:47 ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU eagostini
@ 2022-01-27  3:47   ` eagostini
  2022-01-27  6:55   ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU Wang, Haiyue
  1 sibling, 0 replies; 15+ messages in thread
From: eagostini @ 2022-01-27  3:47 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v5 1/2] gpudev: expose GPU memory to CPU
  2022-01-04  2:34 [PATCH v1] gpudev: pin GPU memory eagostini
                   ` (2 preceding siblings ...)
  2022-01-27  3:47 ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU eagostini
@ 2022-01-27  3:50 ` 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
  3 siblings, 2 replies; 15+ messages in thread
From: eagostini @ 2022-01-27  3:50 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

From: Elena Agostini <eagostini@nvidia.com>

Enable the possibility to expose a GPU memory area and make it
accessible from the CPU.

GPU memory has to be allocated via rte_gpu_mem_alloc().

This patch allows the gpudev library to map (and unmap),
through the GPU driver, a chunk of GPU memory and to return
a memory pointer usable by the CPU to access the GPU memory area.

Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
 doc/guides/prog_guide/gpudev.rst |  9 +++++
 drivers/gpu/cuda/cuda.c          |  2 ++
 lib/gpudev/gpudev.c              | 61 ++++++++++++++++++++++++++++++++
 lib/gpudev/gpudev_driver.h       |  6 ++++
 lib/gpudev/rte_gpudev.h          | 49 +++++++++++++++++++++++++
 lib/gpudev/version.map           |  2 ++
 6 files changed, 129 insertions(+)

diff --git a/doc/guides/prog_guide/gpudev.rst b/doc/guides/prog_guide/gpudev.rst
index ff4626812b..b774ec77f9 100644
--- a/doc/guides/prog_guide/gpudev.rst
+++ b/doc/guides/prog_guide/gpudev.rst
@@ -73,6 +73,15 @@ Later, it's also possible to unregister that memory with gpudev.
 CPU memory registered outside of the gpudev library
 (e.g. with GPU specific library) cannot be unregistered by the gpudev library.
 
+CPU mapping
+~~~~~~~~~~~~~~~~~~~
+
+gpudev can map into the CPU address space a GPU memory address allocated with gpudev.
+gpudev returns a pointer the CPU can use to access (ready or write) GPU memory.
+Later, it's also possible to unmap that memory with gpudev.
+GPU memory CPU mapped outside of the gpudev library (e.g. with GPU specific library)
+cannot be unmapped by the gpudev library.
+
 Memory Barrier
 ~~~~~~~~~~~~~~
 
diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c
index 0ece1bb612..408b659fce 100644
--- a/drivers/gpu/cuda/cuda.c
+++ b/drivers/gpu/cuda/cuda.c
@@ -1177,6 +1177,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic
 	dev->ops.mem_free = cuda_mem_free;
 	dev->ops.mem_register = cuda_mem_register;
 	dev->ops.mem_unregister = cuda_mem_unregister;
+	dev->ops.mem_cpu_map = NULL;
+	dev->ops.mem_cpu_unmap = NULL;
 	dev->ops.wmb = cuda_wmb;
 
 	rte_gpu_complete_new(dev);
diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 59e2169292..ce92d63257 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -640,6 +640,67 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr)
 	return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr));
 }
 
+void *
+rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr)
+{
+	struct rte_gpu *dev;
+	void *ptr_out;
+	int ret;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "mem CPU map for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return NULL;
+	}
+
+	if (dev->ops.mem_cpu_map == NULL) {
+		GPU_LOG(ERR, "mem CPU map not supported");
+		rte_errno = ENOTSUP;
+		return NULL;
+	}
+
+	if (ptr == NULL || size == 0) /* dry-run  */
+		return NULL;
+
+	ret = GPU_DRV_RET(dev->ops.mem_cpu_map(dev, size, ptr, &ptr_out));
+
+	switch (ret) {
+	case 0:
+		return ptr_out;
+	case -ENOMEM:
+	case -E2BIG:
+		rte_errno = -ret;
+		return NULL;
+	default:
+		rte_errno = -EPERM;
+		return NULL;
+	}
+}
+
+int
+rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr)
+{
+	struct rte_gpu *dev;
+
+	dev = gpu_get_by_id(dev_id);
+	if (dev == NULL) {
+		GPU_LOG(ERR, "cpu_unmap mem for invalid device ID %d", dev_id);
+		rte_errno = ENODEV;
+		return -rte_errno;
+	}
+
+	if (dev->ops.mem_cpu_unmap == NULL) {
+		rte_errno = ENOTSUP;
+		return -rte_errno;
+	}
+
+	if (ptr == NULL) /* dry-run */
+		return 0;
+
+	return GPU_DRV_RET(dev->ops.mem_cpu_unmap(dev, ptr));
+}
+
 int
 rte_gpu_wmb(int16_t dev_id)
 {
diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h
index 0ed7478e9b..0e55b00bfe 100644
--- a/lib/gpudev/gpudev_driver.h
+++ b/lib/gpudev/gpudev_driver.h
@@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, unsigned int
 typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr);
 typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr);
+typedef int (rte_gpu_mem_cpu_map_t)(struct rte_gpu *dev, size_t size, void *ptr_in, void **ptr_out);
+typedef int (rte_gpu_mem_cpu_unmap_t)(struct rte_gpu *dev, void *ptr);
 typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev);
 
 struct rte_gpu_ops {
@@ -46,6 +48,10 @@ struct rte_gpu_ops {
 	rte_gpu_mem_register_t *mem_register;
 	/* Unregister CPU memory from device. */
 	rte_gpu_mem_unregister_t *mem_unregister;
+	/* Map GPU memory for CPU visibility. */
+	rte_gpu_mem_cpu_map_t *mem_cpu_map;
+	/* Unmap GPU memory for CPU visibility. */
+	rte_gpu_mem_cpu_unmap_t *mem_cpu_unmap;
 	/* Enforce GPU write memory barrier. */
 	rte_gpu_wmb_t *wmb;
 };
diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h
index ff3ca78c89..5cc4eb5828 100644
--- a/lib/gpudev/rte_gpudev.h
+++ b/lib/gpudev/rte_gpudev.h
@@ -452,6 +452,55 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr);
 __rte_experimental
 int rte_gpu_mem_unregister(int16_t dev_id, void *ptr);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Map a chunk of GPU memory to make it accessible from the CPU
+ * using the memory pointer returned by the function.
+ * GPU memory has to be allocated via rte_gpu_mem_alloc().
+ *
+ * @param dev_id
+ *   Device ID requiring mapped memory.
+ * @param size
+ *   Number of bytes to map.
+ *   Requesting 0 will do nothing.
+ * @param ptr
+ *   Pointer to the GPU memory area to be mapped.
+ *   NULL is a no-op accepted value.
+
+ * @return
+ *   A pointer to the mapped GPU memory usable by the CPU, otherwise NULL and rte_errno is set:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - E2BIG if size is higher than limit
+ *   - ENOMEM if out of space
+ *   - EPERM if driver error
+ */
+__rte_experimental
+void *rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Unmap a chunk of GPU memory previously mapped with rte_gpu_mem_cpu_map()
+ *
+ * @param dev_id
+ *   Reference device ID.
+ * @param ptr
+ *   Pointer to the memory area to be unmapped.
+ *   NULL is a no-op accepted value.
+ *
+ * @return
+ *   0 on success, -rte_errno otherwise:
+ *   - ENODEV if invalid dev_id
+ *   - ENOTSUP if operation not supported by the driver
+ *   - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map
index 2e414c65cc..5bc5d154cd 100644
--- a/lib/gpudev/version.map
+++ b/lib/gpudev/version.map
@@ -20,8 +20,10 @@ EXPERIMENTAL {
 	rte_gpu_init;
 	rte_gpu_is_valid;
 	rte_gpu_mem_alloc;
+	rte_gpu_mem_cpu_map;
 	rte_gpu_mem_free;
 	rte_gpu_mem_register;
+	rte_gpu_mem_cpu_unmap;
 	rte_gpu_mem_unregister;
 	rte_gpu_wmb;
 };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v5 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions
  2022-01-27  3:50 ` [PATCH v5 " eagostini
@ 2022-01-27  3:50   ` eagostini
  2022-02-10 15:12   ` [PATCH v5 1/2] gpudev: expose GPU memory to CPU Thomas Monjalon
  1 sibling, 0 replies; 15+ messages in thread
From: eagostini @ 2022-01-27  3:50 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

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..417f2d78b7 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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
  2022-01-27  3:47 ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU eagostini
  2022-01-27  3:47   ` [PATCH v4 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions eagostini
@ 2022-01-27  6:55   ` Wang, Haiyue
  2022-02-10 10:38     ` Elena Agostini
  1 sibling, 1 reply; 15+ messages in thread
From: Wang, Haiyue @ 2022-01-27  6:55 UTC (permalink / raw)
  To: eagostini, dev

> -----Original Message-----
> From: eagostini@nvidia.com <eagostini@nvidia.com>
> Sent: Thursday, January 27, 2022 11:47
> To: dev@dpdk.org
> Cc: Elena Agostini <eagostini@nvidia.com>
> Subject: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
> 
> From: Elena Agostini <eagostini@nvidia.com>
> 
> Enable the possibility to expose a GPU memory area and make it
> accessible from the CPU.
> 
> GPU memory has to be allocated via rte_gpu_mem_alloc().
> 
> This patch allows the gpudev library to map (and unmap),
> through the GPU driver, a chunk of GPU memory and to return
> a memory pointer usable by the CPU to access the GPU memory area.
> 
> Signed-off-by: Elena Agostini <eagostini@nvidia.com>
> ---
>  doc/guides/prog_guide/gpudev.rst |  9 +++++
>  drivers/gpu/cuda/cuda.c          |  2 ++
>  lib/gpudev/gpudev.c              | 61 ++++++++++++++++++++++++++++++++
>  lib/gpudev/gpudev_driver.h       |  6 ++++
>  lib/gpudev/rte_gpudev.h          | 49 +++++++++++++++++++++++++
>  lib/gpudev/version.map           |  2 ++
>  6 files changed, 129 insertions(+)
> 


> +__rte_experimental
> +void *rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr);

How about add some direction words like "to/from" to make it straightforward ?

For this: rte_gpu_mem_map_to_cpu ?

> +__rte_experimental
> +int rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr);
> +

And rte_gpu_mem_unmap_to_cpu ?

>  };
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
  2022-01-27  6:55   ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU Wang, Haiyue
@ 2022-02-10 10:38     ` Elena Agostini
  2022-02-11  4:46       ` Wang, Haiyue
  0 siblings, 1 reply; 15+ messages in thread
From: Elena Agostini @ 2022-02-10 10:38 UTC (permalink / raw)
  To: Wang, Haiyue, dev

[-- Attachment #1: Type: text/plain, Size: 2100 bytes --]

> From: Wang, Haiyue <haiyue.wang@intel.com>
> Date: Thursday, 27 January 2022 at 07:56
> To: Elena Agostini <eagostini@nvidia.com>, dev@dpdk.org <dev@dpdk.org>
> Subject: RE: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
> External email: Use caution opening links or attachments
>
>
> > -----Original Message-----
> > From: eagostini@nvidia.com <eagostini@nvidia.com>
> > Sent: Thursday, January 27, 2022 11:47
> > To: dev@dpdk.org
> > Cc: Elena Agostini <eagostini@nvidia.com>
> > Subject: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
> >
> > From: Elena Agostini <eagostini@nvidia.com>
> >
> > Enable the possibility to expose a GPU memory area and make it
> > accessible from the CPU.
> >
> > GPU memory has to be allocated via rte_gpu_mem_alloc().
> >
> > This patch allows the gpudev library to map (and unmap),
> > through the GPU driver, a chunk of GPU memory and to return
> > a memory pointer usable by the CPU to access the GPU memory area.
> >
> > Signed-off-by: Elena Agostini <eagostini@nvidia.com>
> > ---
> >  doc/guides/prog_guide/gpudev.rst |  9 +++++
> >  drivers/gpu/cuda/cuda.c          |  2 ++
> >  lib/gpudev/gpudev.c              | 61 ++++++++++++++++++++++++++++++++
> >  lib/gpudev/gpudev_driver.h       |  6 ++++
> >  lib/gpudev/rte_gpudev.h          | 49 +++++++++++++++++++++++++
> >  lib/gpudev/version.map           |  2 ++
> >  6 files changed, 129 insertions(+)
> >
>
>
> > +__rte_experimental
> > +void *rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr);
>
> How about add some direction words like "to/from" to make it straightforward ?
>
> For this: rte_gpu_mem_map_to_cpu ?
>
> > +__rte_experimental
> > +int rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr);
> > +
>
> And rte_gpu_mem_unmap_to_cpu ?
>
> >  };
> > --
> > 2.17.1

Motivation behind the name is to be compliant with
rte_*_dma_map/unmap() functions where the entity comes first
(DMA) and the action later (map/unmap).

I think your proposal is more readable but it's also too
verbose for an API (map_to_cpu/unmap_from_cpu).

[-- Attachment #2: Type: text/html, Size: 8510 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v5 1/2] gpudev: expose GPU memory to CPU
  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   ` Thomas Monjalon
  1 sibling, 0 replies; 15+ messages in thread
From: Thomas Monjalon @ 2022-02-10 15:12 UTC (permalink / raw)
  To: Elena Agostini; +Cc: dev

27/01/2022 04:50, eagostini@nvidia.com:
> From: Elena Agostini <eagostini@nvidia.com>
> 
> Enable the possibility to expose a GPU memory area and make it
> accessible from the CPU.
> 
> GPU memory has to be allocated via rte_gpu_mem_alloc().
> 
> This patch allows the gpudev library to map (and unmap),
> through the GPU driver, a chunk of GPU memory and to return
> a memory pointer usable by the CPU to access the GPU memory area.
> 
> Signed-off-by: Elena Agostini <eagostini@nvidia.com>

Squashed and applied, thanks.




^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
  2022-02-10 10:38     ` Elena Agostini
@ 2022-02-11  4:46       ` Wang, Haiyue
  0 siblings, 0 replies; 15+ messages in thread
From: Wang, Haiyue @ 2022-02-11  4:46 UTC (permalink / raw)
  To: Elena Agostini, dev

From: Elena Agostini <eagostini@nvidia.com> 
Sent: Thursday, February 10, 2022 18:38
To: Wang, Haiyue <haiyue.wang@intel.com>; dev@dpdk.org
Subject: Re: [PATCH v4 1/2] gpudev: expose GPU memory to CPU

> From: Wang, Haiyue <mailto:haiyue.wang@intel.com>
> Date: Thursday, 27 January 2022 at 07:56
> To: Elena Agostini <mailto:eagostini@nvidia.com>, mailto:dev@dpdk.org <mailto:dev@dpdk.org>
> Subject: RE: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
> External email: Use caution opening links or attachments
> 
> 
> > -----Original Message-----
> > From: mailto:eagostini@nvidia.com <mailto:eagostini@nvidia.com>
> > Sent: Thursday, January 27, 2022 11:47
> > To: mailto:dev@dpdk.org
> > Cc: Elena Agostini <mailto:eagostini@nvidia.com>
> > Subject: [PATCH v4 1/2] gpudev: expose GPU memory to CPU
> >
> > From: Elena Agostini <mailto:eagostini@nvidia.com>
> >
> > Enable the possibility to expose a GPU memory area and make it
> > accessible from the CPU.
> >
> > GPU memory has to be allocated via rte_gpu_mem_alloc().
> >
> > This patch allows the gpudev library to map (and unmap),
> > through the GPU driver, a chunk of GPU memory and to return
> > a memory pointer usable by the CPU to access the GPU memory area.
> >
> > Signed-off-by: Elena Agostini <mailto:eagostini@nvidia.com>
> > ---
> >  doc/guides/prog_guide/gpudev.rst |  9 +++++
> >  drivers/gpu/cuda/cuda.c          |  2 ++
> >  lib/gpudev/gpudev.c              | 61 ++++++++++++++++++++++++++++++++
> >  lib/gpudev/gpudev_driver.h       |  6 ++++
> >  lib/gpudev/rte_gpudev.h          | 49 +++++++++++++++++++++++++
> >  lib/gpudev/version.map           |  2 ++
> >  6 files changed, 129 insertions(+)
> >
> 
> 
> > +__rte_experimental
> > +void *rte_gpu_mem_cpu_map(int16_t dev_id, size_t size, void *ptr);
> 
> How about add some direction words like "to/from" to make it straightforward ?
> 
> For this: rte_gpu_mem_map_to_cpu ?
> 
> > +__rte_experimental
> > +int rte_gpu_mem_cpu_unmap(int16_t dev_id, void *ptr);
> > +
> 
> And rte_gpu_mem_unmap_to_cpu ?
> 
> >  };
> > --
> > 2.17.1

> Motivation behind the name is to be compliant with 
> rte_*_dma_map/unmap() functions where the entity comes first
> (DMA) and the action later (map/unmap).


> I think your proposal is more readable but it's also too
> verbose for an API (map_to_cpu/unmap_from_cpu).

Then just ' rte_gpu_mem_map' & ' rte_gpu_mem_umap', since DPDK is running on CPU. ;-)


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-02-11  4:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` [PATCH v4 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions eagostini
2022-01-27  6:55   ` [PATCH v4 1/2] gpudev: expose GPU memory to CPU 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

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).