From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EBD02A0C4D; Mon, 8 Nov 2021 11:47:48 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 60EE84114D; Mon, 8 Nov 2021 11:47:12 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2040.outbound.protection.outlook.com [40.107.243.40]) by mails.dpdk.org (Postfix) with ESMTP id 0A78941125 for ; Mon, 8 Nov 2021 11:47:09 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lj8qvM+IpktnzMQNKc15NwnvmLzbVKAPF2SN2qLIBc5G4XwLfWy8twF+d4iumY1W2xp7SRJB9dt6qlODcjOY6g27kfSEGWBJJZH/5mZoEYfRlzWv572k4yyNJJ6wQ875xuHLRdDGPxNl/rmqj4Tr8z6yBFbuJiuqlptCPUDr1a58uEBxIkm4oBwG56gP3kNwt4Sns5Rf1t2AhXPziPYkJLKsU/Y4VnVW5VsYeLOFEnA5014VB2yhuhOeQD30sR8f4wHxjkusODH6fZrtWrt9Yr2XbAAn4wJVn6jWD1tmZdJMQoixbCuOFSWCmPQq9br3pMHMWHAgGvoF8til8pVxhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=o7CZcWUXuFO050dDNOZ4NSFEwiBgM5BtcEzCLkvL52s=; b=V+bUTi/fQYylpvteGcCbe122qfM9UjN1z3jIYhFJvx1Wc9Hz0JrYwVvV11H7jBw6zYg8AgJrX9HuO+QmTFoCxVrIrEnbYQNQ6L/XEQ51DgUQj2kPNMyRl1od5zAopqqomQxQTYMSpv6pMYegkXTSAR0IbzLLT453jDGTsTPliSqaQ9xtWXgqGrW4yUW6xtvcDuSHmhMC6RJNPIv+//EYmvGud/U35v38M04yJs15fb876KSvx/nOoKE3w4gvgdrwlwslqjKXknUgIVu7niT8xTv6WIxR46TRJU73+eeujyJZDCK/W/IxuXfW397WF6UEelLFEpRHDO4XkyV+/ZcsbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o7CZcWUXuFO050dDNOZ4NSFEwiBgM5BtcEzCLkvL52s=; b=ifmTnIebct1AXu39jkSR9zQd4QahAmMAKkKjwIzV2KiCc7jJYkZbwiP5r7Qq9RAPwdyc7ev9h0fFyvDOv0jw+dMYRZkOi97D9UxRXq+0lC21rLVBQOuobuhQ2SIda9zOcFOW9mABtDlGa1BGQyfbi3OXZqBlWsfg9J6C/9Y5AUUUEPRnVQ5TNHDfLe0g2FZD2fvc7qASk0tNHwLTYJ4F4210a7L8cjtOtN1Q2l0Fr30kw69WJpV+YBXJ7Lxiqv9rU3nwjz5EecZuhIPHVYiCgtp2gq/kDyVPHYvoerrOcgyzvLgft+aqlGJBHalgoumgfUzG8g+r0btcHlBcw/fGcw== Received: from MW2PR16CA0052.namprd16.prod.outlook.com (2603:10b6:907:1::29) by MN2PR12MB4286.namprd12.prod.outlook.com (2603:10b6:208:199::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Mon, 8 Nov 2021 10:47:07 +0000 Received: from CO1NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:907:1:cafe::64) by MW2PR16CA0052.outlook.office365.com (2603:10b6:907:1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10 via Frontend Transport; Mon, 8 Nov 2021 10:47:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT064.mail.protection.outlook.com (10.13.175.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4669.10 via Frontend Transport; Mon, 8 Nov 2021 10:47:06 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 8 Nov 2021 10:47:01 +0000 From: To: CC: Elena Agostini , Thomas Monjalon Date: Mon, 8 Nov 2021 18:58:01 +0000 Message-ID: <20211108185805.3887-6-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211108185805.3887-1-eagostini@nvidia.com> References: <20210602203531.2288645-1-thomas@monjalon.net> <20211108185805.3887-1-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60a9f966-050c-4119-6f76-08d9a2a51b6f X-MS-TrafficTypeDiagnostic: MN2PR12MB4286: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lTPpLI1gzpeNQpu8d3ukFqIm3rUXq2MAuhys0DoxKpXFhQz1K6wz03v1D64V+hjw7FkM2MaUWJGqVLq6qPuKOSQO4OIm+1vUpVXLmZ8CcSA/zx/aLazD+enU3fWer/1vP56kAhNUm/+UhMj3FsWCapKwC2T8BF3PA+fEAyxnyWaay85n034YlvM6YO1emxLBMDvXwp/I6T+Vd8qg4fpbpXibb+u9qDH4oPthjM7CQgMZshiHOrc9k/U5T6wuXKVJQbKHE4x6BGTy2QJGhFCmMA8PiNGxsSCwVF0j6Uu4WsNK3g4fUjEM8sCc2vIk4K/0Y+JbC/jXiEH+GiBXBG43zbk8QHWstZvqjk2yFaq/XsEQcbrsCHLMTlvyFBoxN/ONkRPRQQ4RE99DrJATeDBB+K2+I9hMDZTv29RV+Ah5R4MiI9jiK3Ac/y20a2Nn30eMiCzspGik/AN64JywOtDobW950hI4vDnR9oCZByNe1psPJHIglzGoDOo3ltV8N4hDcpHTZI/0gVAqlDr++N5BZtUbgMYiEe+n2ZGtLfcZ1blvr2vh+J846/M41uKiC2731ZGGQJ+HYmCcJ0yl7aNkovlQAoeT6iWi5iWmHXbUIuWG4qedUfVnUiPbN0QOXB9v+JNqET9DmmeeC/vPO4SqlQis13U1OTcfrDGznNSeTC0AaF1xEwKvvcoNWGvrAWel X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(54906003)(2876002)(336012)(55016002)(86362001)(7696005)(36860700001)(16526019)(186003)(2616005)(8936002)(6916009)(426003)(36756003)(82310400003)(26005)(316002)(8676002)(70586007)(70206006)(30864003)(508600001)(83380400001)(47076005)(356005)(1076003)(7636003)(6286002)(2906002)(4326008)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2021 10:47:06.2057 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60a9f966-050c-4119-6f76-08d9a2a51b6f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4286 Subject: [dpdk-dev] [PATCH v5 5/9] gpudev: add memory API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Elena Agostini In heterogeneous computing system, processing is not only in the CPU. Some tasks can be delegated to devices working in parallel. Such workload distribution can be achieved by sharing some memory. As a first step, the features are focused on memory management. A function allows to allocate memory inside the device, or in the main (CPU) memory while making it visible for the device. This memory may be used to save packets or for synchronization data. The next step should focus on GPU processing task control. Signed-off-by: Elena Agostini Signed-off-by: Thomas Monjalon --- app/test-gpudev/main.c | 105 +++++++++++++++++++++++++ doc/guides/gpus/features/default.ini | 3 + doc/guides/prog_guide/gpudev.rst | 19 +++++ doc/guides/rel_notes/release_21_11.rst | 1 + lib/gpudev/gpudev.c | 101 ++++++++++++++++++++++++ lib/gpudev/gpudev_driver.h | 12 +++ lib/gpudev/rte_gpudev.h | 95 ++++++++++++++++++++++ lib/gpudev/version.map | 4 + 8 files changed, 340 insertions(+) diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c index 438cfdac54..e3aca2225a 100644 --- a/app/test-gpudev/main.c +++ b/app/test-gpudev/main.c @@ -62,6 +62,98 @@ args_parse(int argc, char **argv) } } +static int +alloc_gpu_memory(uint16_t gpu_id) +{ + void *ptr_1 = NULL; + void *ptr_2 = NULL; + size_t buf_bytes = 1024; + int ret; + + printf("\n=======> TEST: Allocate GPU memory\n"); + + /* Alloc memory on GPU 0 */ + ptr_1 = rte_gpu_malloc(gpu_id, buf_bytes); + if (ptr_1 == NULL) { + fprintf(stderr, "rte_gpu_malloc GPU memory returned error\n"); + return -1; + } + printf("GPU memory allocated at 0x%p %zdB\n", ptr_1, buf_bytes); + + ptr_2 = rte_gpu_malloc(gpu_id, buf_bytes); + if (ptr_2 == NULL) { + fprintf(stderr, "rte_gpu_malloc GPU memory returned error\n"); + return -1; + } + printf("GPU memory allocated at 0x%p %zdB\n", ptr_2, buf_bytes); + + ret = rte_gpu_free(gpu_id, (uint8_t *)(ptr_1)+0x700); + if (ret < 0) { + printf("GPU memory 0x%p + 0x700 NOT freed because of memory address not recognized by driver\n", ptr_1); + } else { + fprintf(stderr, "rte_gpu_free erroneusly freed GPU memory 0x%p + 0x700\n", ptr_1); + return -1; + } + + ret = rte_gpu_free(gpu_id, ptr_2); + if (ret < 0) { + fprintf(stderr, "rte_gpu_free returned error %d\n", ret); + return -1; + } + printf("GPU memory 0x%p freed\n", ptr_2); + + ret = rte_gpu_free(gpu_id, ptr_1); + if (ret < 0) { + fprintf(stderr, "rte_gpu_free returned error %d\n", ret); + return -1; + } + printf("GPU memory 0x%p freed\n", ptr_1); + + return 0; +} + +static int +register_cpu_memory(uint16_t gpu_id) +{ + void *ptr = NULL; + size_t buf_bytes = 1024; + int ret; + + printf("\n=======> TEST: Register CPU memory\n"); + + /* Alloc memory on CPU visible from GPU 0 */ + ptr = rte_zmalloc(NULL, buf_bytes, 0); + if (ptr == NULL) { + fprintf(stderr, "Failed to allocate CPU memory.\n"); + return -1; + } + + ret = rte_gpu_register(gpu_id, buf_bytes, ptr); + if (ret < 0) { + fprintf(stderr, "rte_gpu_register CPU memory returned error %d\n", ret); + return -1; + } + printf("CPU memory registered at 0x%p %zdB\n", ptr, buf_bytes); + + ret = rte_gpu_unregister(gpu_id, (uint8_t *)(ptr)+0x700); + if (ret < 0) { + printf("CPU memory 0x%p + 0x700 NOT unregistered because of memory address not recognized by driver\n", ptr); + } else { + fprintf(stderr, "rte_gpu_free erroneusly freed GPU memory 0x%p + 0x700\n", ptr); + return -1; + } + printf("CPU memory 0x%p unregistered\n", ptr); + + ret = rte_gpu_unregister(gpu_id, ptr); + if (ret < 0) { + fprintf(stderr, "rte_gpu_unregister returned error %d\n", ret); + return -1; + } + printf("CPU memory 0x%p unregistered\n", ptr); + + return 0; +} + int main(int argc, char **argv) { @@ -99,6 +191,19 @@ main(int argc, char **argv) } printf("\n\n"); + if (nb_gpus == 0) { + fprintf(stderr, "Need at least one GPU on the system to run the example\n"); + return EXIT_FAILURE; + } + + gpu_id = 0; + + /** + * Memory tests + */ + alloc_gpu_memory(gpu_id); + register_cpu_memory(gpu_id); + /* clean up the EAL */ rte_eal_cleanup(); printf("Bye...\n"); diff --git a/doc/guides/gpus/features/default.ini b/doc/guides/gpus/features/default.ini index ec7a545eb7..87e9966424 100644 --- a/doc/guides/gpus/features/default.ini +++ b/doc/guides/gpus/features/default.ini @@ -8,3 +8,6 @@ ; [Features] Get device info = +Share CPU memory with device = +Allocate device memory = +Free memory = diff --git a/doc/guides/prog_guide/gpudev.rst b/doc/guides/prog_guide/gpudev.rst index 7694639489..9aca69038c 100644 --- a/doc/guides/prog_guide/gpudev.rst +++ b/doc/guides/prog_guide/gpudev.rst @@ -30,6 +30,8 @@ Features This library provides a number of features: - Interoperability with device-specific library through generic handlers. +- Allocate and free memory on the device. +- Register CPU memory to make it visible from the device. API Overview @@ -46,3 +48,20 @@ that will be registered internally by the driver as an additional device (child) connected to a physical device (parent). Each device (parent or child) is represented through a ID required to indicate which device a given operation should be executed on. + +Memory Allocation +~~~~~~~~~~~~~~~~~ + +gpudev can allocate on an input given GPU device a memory area +returning the pointer to that memory. +Later, it's also possible to free that memory with gpudev. +GPU memory allocated outside of the gpudev library +(e.g. with GPU-specific library) cannot be freed by the gpudev library. + +Memory Registration +~~~~~~~~~~~~~~~~~~~ + +gpudev can register a CPU memory area to make it visible from a GPU device. +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. diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index 9cf59e73bb..a4d07bda9b 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -104,6 +104,7 @@ New Features * **Introduced GPU device class with first features:** * Device information + * Memory management * **Added new RSS offload types for IPv4/L4 checksum in RSS flow.** diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index 17e371102a..d0826ec881 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -523,3 +524,103 @@ rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info) } return GPU_DRV_RET(dev->ops.dev_info_get(dev, info)); } + +void * +rte_gpu_malloc(int16_t dev_id, size_t size) +{ + struct rte_gpu *dev; + void *ptr; + int ret; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "alloc mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return NULL; + } + + if (dev->ops.mem_alloc == NULL) { + GPU_LOG(ERR, "mem allocation not supported"); + rte_errno = ENOTSUP; + return NULL; + } + + if (size == 0) /* dry-run */ + return NULL; + + ret = dev->ops.mem_alloc(dev, size, &ptr); + + switch (ret) { + case 0: + return ptr; + case -ENOMEM: + case -E2BIG: + rte_errno = -ret; + return NULL; + default: + rte_errno = -EPERM; + return NULL; + } +} + +int +rte_gpu_register(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, "alloc mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return -rte_errno; + } + + if (dev->ops.mem_register == NULL) { + GPU_LOG(ERR, "mem registration not supported"); + rte_errno = ENOTSUP; + return -rte_errno; + } + + if (size == 0 || ptr == NULL) /* dry-run */ + return -EINVAL; + + return GPU_DRV_RET(dev->ops.mem_register(dev, size, ptr)); +} + +int +rte_gpu_unregister(int16_t dev_id, void *ptr) +{ + struct rte_gpu *dev; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "unregister mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return -rte_errno; + } + + if (dev->ops.mem_unregister == NULL) { + rte_errno = ENOTSUP; + return -rte_errno; + } + return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr)); +} + +int +rte_gpu_free(int16_t dev_id, void *ptr) +{ + struct rte_gpu *dev; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "free mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return -rte_errno; + } + + if (dev->ops.mem_free == NULL) { + rte_errno = ENOTSUP; + return -rte_errno; + } + return GPU_DRV_RET(dev->ops.mem_free(dev, ptr)); +} diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h index 9459c7e30f..11015944a6 100644 --- a/lib/gpudev/gpudev_driver.h +++ b/lib/gpudev/gpudev_driver.h @@ -27,12 +27,24 @@ 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_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); struct rte_gpu_ops { /* Get device info. If NULL, info is just copied. */ rte_gpu_info_get_t *dev_info_get; /* Close device or child context. */ rte_gpu_close_t *dev_close; + /* Allocate memory in device. */ + rte_gpu_mem_alloc_t *mem_alloc; + /* Register CPU memory in device. */ + rte_gpu_mem_register_t *mem_register; + /* Free memory allocated or registered in device. */ + rte_gpu_free_t *mem_free; + /* Unregister CPU memory in device. */ + rte_gpu_mem_unregister_t *mem_unregister; }; struct rte_gpu_mpshared { diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index df75dbdbab..fee71d60e7 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -9,6 +9,7 @@ #include #include +#include #include /** @@ -292,6 +293,100 @@ int rte_gpu_callback_unregister(int16_t dev_id, enum rte_gpu_event event, __rte_experimental int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Allocate a chunk of memory usable by the device. + * + * @param dev_id + * Device ID requiring allocated memory. + * @param size + * Number of bytes to allocate. + * Requesting 0 will do nothing. + * + * @return + * A pointer to the allocated memory, 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 +void *rte_gpu_malloc(int16_t dev_id, size_t size) +__rte_alloc_size(2); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Deallocate a chunk of memory allocated with rte_gpu_malloc(). + * + * @param dev_id + * Reference device ID. + * @param ptr + * Pointer to the memory area to be deallocated. + * 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_free(int16_t dev_id, void *ptr); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Register a chunk of memory on the CPU usable by the device. + * + * @param dev_id + * Device ID requiring allocated memory. + * @param size + * Number of bytes to allocate. + * Requesting 0 will do nothing. + * @param ptr + * Pointer to the memory area to be registered. + * NULL is a no-op accepted value. + + * @return + * A pointer to the allocated memory, 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_register(int16_t dev_id, size_t size, void *ptr); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Deregister a chunk of memory previusly registered with rte_gpu_mem_register() + * + * @param dev_id + * Reference device ID. + * @param ptr + * Pointer to the memory area to be unregistered. + * 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_unregister(int16_t dev_id, void *ptr); + #ifdef __cplusplus } #endif diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map index 58dc632393..d4a65ebd52 100644 --- a/lib/gpudev/version.map +++ b/lib/gpudev/version.map @@ -8,9 +8,13 @@ EXPERIMENTAL { rte_gpu_close; rte_gpu_count_avail; rte_gpu_find_next; + rte_gpu_free; rte_gpu_info_get; rte_gpu_init; rte_gpu_is_valid; + rte_gpu_malloc; + rte_gpu_register; + rte_gpu_unregister; }; INTERNAL { -- 2.17.1