[v2,1/3] gpudev: mem alloc aligned memory
Checks
Commit Message
From: Elena Agostini <eagostini@nvidia.com>
Similarly to rte_malloc, rte_gpu_mem_alloc accept as
input the memory alignment size.
GPU driver should return GPU memory address aligned
with the input value.
Changelog:
- rte_gpu_mem_alloc parameters order
Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
lib/gpudev/gpudev.c | 10 ++++++++--
lib/gpudev/gpudev_driver.h | 2 +-
lib/gpudev/rte_gpudev.h | 10 +++++++---
3 files changed, 16 insertions(+), 6 deletions(-)
Comments
08/01/2022 01:20, eagostini@nvidia.com:
> From: Elena Agostini <eagostini@nvidia.com>
>
> Similarly to rte_malloc, rte_gpu_mem_alloc accept as
> input the memory alignment size.
>
> GPU driver should return GPU memory address aligned
> with the input value.
>
> Changelog:
> - rte_gpu_mem_alloc parameters order
>
> Signed-off-by: Elena Agostini <eagostini@nvidia.com>
Squashed and applied, thanks.
@@ -527,7 +527,7 @@ rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info)
}
void *
-rte_gpu_mem_alloc(int16_t dev_id, size_t size)
+rte_gpu_mem_alloc(int16_t dev_id, size_t size, unsigned int align)
{
struct rte_gpu *dev;
void *ptr;
@@ -549,7 +549,13 @@ rte_gpu_mem_alloc(int16_t dev_id, size_t size)
if (size == 0) /* dry-run */
return NULL;
- ret = dev->ops.mem_alloc(dev, size, &ptr);
+ if (align && !rte_is_power_of_2(align)) {
+ GPU_LOG(ERR, "requested alignment is not a power of two %u", align);
+ rte_errno = EINVAL;
+ return NULL;
+ }
+
+ ret = dev->ops.mem_alloc(dev, size, align, &ptr);
switch (ret) {
case 0:
@@ -27,7 +27,7 @@ enum rte_gpu_state {
struct rte_gpu;
typedef int (rte_gpu_close_t)(struct rte_gpu *dev);
typedef int (rte_gpu_info_get_t)(struct rte_gpu *dev, struct rte_gpu_info *info);
-typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr);
+typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, unsigned int align, 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);
@@ -364,18 +364,22 @@ int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info);
* @param size
* Number of bytes to allocate.
* Requesting 0 will do nothing.
- *
+ * @param align
+ * If 0, the return is a pointer that is suitably aligned for any kind of
+ * variable (in the same manner as malloc()).
+ * Otherwise, the return is a pointer that is a multiple of *align*. In
+ * this case, it must obviously be a power of two.
* @return
* A pointer to the allocated memory, otherwise NULL and rte_errno is set:
* - ENODEV if invalid dev_id
- * - EINVAL if reserved flags
+ * - EINVAL if align is not a power of two
* - 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_alloc(int16_t dev_id, size_t size)
+void *rte_gpu_mem_alloc(int16_t dev_id, size_t size, unsigned int align)
__rte_alloc_size(2);
/**