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 1EE06A0C43; Fri, 8 Oct 2021 19:43:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CFFA7410E0; Fri, 8 Oct 2021 19:43:43 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2054.outbound.protection.outlook.com [40.107.212.54]) by mails.dpdk.org (Postfix) with ESMTP id A8526407FF for ; Fri, 8 Oct 2021 19:43:42 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YIeJ9pN7RUjOfC+sC5lP+EC673nsEtw0Vu137klCGXMJolk2ufUga5ENKLqNscv64//qDPesENvjWOBwi8tmOWVHtIiNIQst2wIWJfz/BPNlzVmSBtTKaLwPDoLctTazTkoRKcSbUwsA1VzbupWDZ6wNw+EhMSHeTk1Vc9+oQpn6bI8tZxvzBJSaMVWo6gyrQ8+B2ZuiH321qID46L6gUiuJjN8hRVg7WGeiVwbFDuZ3fr7CC/H6PKdg6JtHjbuXw07gEVsvC+LRrIeFCSSutDngmljc+lUGcr0sIAVH4FBlPpARrNPLvfFQ0+EJIlwLMTHrxtCx8SjMwBwNxVc8+w== 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=xg1RFO3F5iRpuP/zcXWZ9wyWBhooDDzU6WPni/HqNbw=; b=lXmqh0j47wCYmWf9iketg4j38Gv5w+jyZGpjgt366kv4rM4MCtQ36LuhjYu7sO8Q9QEBasKKaxroF/7DLdFfkA/U2VW9eJlIgoa5X+5Xd+VULuABWQDB7Eoy6QthYlVLoUPTcrNEJYkKE3DHav7jsZs23+N6fmhZ8trSjN/o43KqQgwVjp66Mo1P1mKoBOPsA1sp/KJGcteJM5ucD5mpibCpZZihvOghNi42c+KhO+QvzDiMcGc+PcZ/iqhuuIkXt7FTYyvRnNEq2GqePjOKz3RNeMCKEsUaWXMbYljWQbA5wGMY/+r3/S/+KtySZ85dzKtumSrHJnwVA+dKJEhtdA== 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=none 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=xg1RFO3F5iRpuP/zcXWZ9wyWBhooDDzU6WPni/HqNbw=; b=IY+MfP3peISMOsRqJXhW21Sced/PzD+YCIeV5Ub8oJz2Bxmi5nazpszQEBPHtZQu1lDs57uhrrgKS2DVkdHmx6Jr9poTH+6qbiUcwH3kJBznHlftdn2CB2VkOtbKxFqOEsY9TYPD9TSHNs3FxsK96vOIo7s7sPPWmzxHHjWW1v8xAyxV7CBsJBxHoXGXhcBt2jd9eoJ050OELjohbImGTKKznuicg2y2eFHtt48mce1aQkUJ037HzEgOJwh/S8Edzt2fa7BykUBq6NTUaAIhc2uZdo8jDirxhIrLMkQz+TIvj8HONa8rBLs2EhoNd5RYpAeXQeE1JnFydrpcwEDBvA== Received: from MW4PR03CA0143.namprd03.prod.outlook.com (2603:10b6:303:8c::28) by BN7PR12MB2756.namprd12.prod.outlook.com (2603:10b6:408:29::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Fri, 8 Oct 2021 17:43:41 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::59) by MW4PR03CA0143.outlook.office365.com (2603:10b6:303:8c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Fri, 8 Oct 2021 17:43:40 +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 CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4587.18 via Frontend Transport; Fri, 8 Oct 2021 17:43:40 +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; Fri, 8 Oct 2021 17:43:37 +0000 From: To: CC: Elena Agostini , Thomas Monjalon Date: Sat, 9 Oct 2021 01:53:45 +0000 Message-ID: <20211009015349.9694-6-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211009015349.9694-1-eagostini@nvidia.com> References: <20210602203531.2288645-1-thomas@monjalon.net> <20211009015349.9694-1-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05c1a709-0ad7-46fd-18bb-08d98a832a65 X-MS-TrafficTypeDiagnostic: BN7PR12MB2756: 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: 2eGlZXuQFpB19BihnwXguEXK1xBIjgHFjFM11rcMIUqi+wae4wg8+btifJm4EuUBndALsSIyYSyK+oRHF/ukGCxSYI6vlLWxJZDq3SR9Z9Et9+WIZD39O2QX0Bpgv1vbPa8xEuLJalP3CzNxMmjn/ntOUDTjc3NcL91DJjHjxcOLjJpguvKCD1sBV4NprLSE44so8Q010rj/hLCEn9pUAzM6H8jOf3tzuTiTf+07XV/DuvnXLKFQ1K38q+HGdvhFfI2XJp9FVQ0b0CECMar/s6NEO862dBAIaH4TAtVsjRXLgWnenLqwPUJa7RprGHrO6MBOj4ZjZdUQ4IoS6/CGmTFYmLLBjKeGqWJMsExyW0loJqPykITkOngLvD25zO8FVFfPa9jnlEJRxPIcAenRX2MVn2xlc5Julz2dG4URm6n/NfgNkhqXOrvGcT3Tu8kjdxAiMjmlo4TX/WzzByYvBafM2pD0Vs11y43lOcOVvPFJAp1l+zQUflrPoP997Ng/rEN61arMlhT4gmVZUd9Kon7/5/hPwNZec20MbnTiRHGqDDBaxQgDLSrFBqaF1oagg1HPSZ+4G1GKP+ZZqlf+iKwKk/a5J2jfoL8yCciWDuIwE7hcSnI+oUnN66g4lYumo3bg3Hi5mCu9vvWFtg0LMQ7dPKVs0erYbxlML/3jcmOGEJLhBQhOO6t1mLFrLZSC 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)(2876002)(6286002)(26005)(316002)(2906002)(6916009)(86362001)(47076005)(5660300002)(36756003)(4326008)(36860700001)(30864003)(54906003)(82310400003)(8936002)(426003)(336012)(8676002)(508600001)(1076003)(83380400001)(2616005)(16526019)(6666004)(55016002)(186003)(7696005)(70586007)(356005)(7636003)(70206006); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2021 17:43:40.5103 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05c1a709-0ad7-46fd-18bb-08d98a832a65 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: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2756 Subject: [dpdk-dev] [PATCH v3 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 | 118 +++++++++++++++++++++++++ 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, 353 insertions(+) diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c index 6a73a54e84..98c02a3ee0 100644 --- a/app/test-gpudev/main.c +++ b/app/test-gpudev/main.c @@ -62,6 +62,110 @@ 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 = 0; + + 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 = 0; + + 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 +203,20 @@ 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 4986a35b50..c4ac5e3053 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -65,6 +65,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 f0690cf730..1d8318f769 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..3c276581c0 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