From patchwork Thu Jan 27 03:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Agostini X-Patchwork-Id: 106591 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 39D11A04A3; Wed, 26 Jan 2022 20:40:49 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CC44842751; Wed, 26 Jan 2022 20:40:48 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2064.outbound.protection.outlook.com [40.107.220.64]) by mails.dpdk.org (Postfix) with ESMTP id 3A0D24274B for ; Wed, 26 Jan 2022 20:40:47 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EbAvtWQmSxoJ0D3EKA11RnxmFdC6vPdhTUhiMEQfw5OhA8gAEueV/FzRQuI0siZlEpdQGmYYrpwWpZ3mPtA8cGuKetmTGHPNBH2G+XceotdNZUz6tBUCxWM1rxiIfNAJN0o1Ao8nAUoc7WDSX92fYbYFRW7OX0iXabxUG2ahIASV2C/ugUtFrFh3c6IGa7+ttt8giabHCB/jlp4ZJw5Qs9m4XwuEkbvDyK3AG9sJNkRZ7aLlX020dUBvJExQEVbOLgYMgdpRjIOkpPox7aY7WyQ2lWiHo4P0AprzevM3JSofOG+/zgB+fC7P8evh0R0a7+wrPyamJpEWNcIfKnfJyA== 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=jgkZjzReSpwX9Iamekp5aDjgvu256BHfz9qbcApptzo=; b=iC2dVmfuTlHuLN9KOAuZlf6v6O6Or2KR4JFN39GOqp4egUQeMeSX/OoNISgSAvm+RuzTdM0LdYDgUJ+AP5LP20ITp77wFfQSwLdQNOIB2ZFARbnSGWB+5T/Jcs25juUinMcWfi9kb0Vn0Dm2j/UH3unlWmX/fTa2xpVwrklLAlxuTcylrguBKLRUYwPE5nRWcodzcpdK5YHzraqZwWQu+AtoO1gjjdncbVFAjdFjXi4hBojVlox5fk0fOUwONICYU5Qek4o9YVCKE9k4UX0iYl3g5t6F4gwZYqv+N+/ZxTdAeCYh++UiKynswRIq88jTUYfUNfWQBN4j0C8sqFJfzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=jgkZjzReSpwX9Iamekp5aDjgvu256BHfz9qbcApptzo=; b=It5zaOImHQhJdIyEDQ7krG1kqqcX6jyK3gqjAdHO2P5ShVUaFkduAwe8TkFz1lVyTK3MEx/zAgHSiXB7aOjfKhkF1TaV7E01P/HYi0CzBh3E3i6hZEyZ4cbOm9+NFutoHvXXCiGG0XlWj61q0bb4nW2mzEZJdSUVBr6SxzZVixoPhTqi/Ouls0QYFZeSoL1ParhEzFcOFpCcaradxiYB0TFa59N1h5jwr+4PvJNHsNi3YOwuwGEert1ZTYdO49CMf6rNqDI53fVDmc8vOb1SNk5Ts0oltnH2pCyLCN7ti3mQ8d4hbJHoMUfDDmk9bbarUx0U4L+NVAg595m+pBmuOg== Received: from DS7PR03CA0108.namprd03.prod.outlook.com (2603:10b6:5:3b7::23) by SJ0PR12MB5609.namprd12.prod.outlook.com (2603:10b6:a03:42c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.13; Wed, 26 Jan 2022 19:40:45 +0000 Received: from DM6NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b7:cafe::6f) by DS7PR03CA0108.outlook.office365.com (2603:10b6:5:3b7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17 via Frontend Transport; Wed, 26 Jan 2022 19:40:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT017.mail.protection.outlook.com (10.13.172.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Wed, 26 Jan 2022 19:40:45 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 26 Jan 2022 19:40:44 +0000 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Wed, 26 Jan 2022 11:40:43 -0800 From: To: CC: Elena Agostini Subject: [PATCH v5 1/2] gpudev: expose GPU memory to CPU Date: Thu, 27 Jan 2022 03:50:28 +0000 Message-ID: <20220127035029.12920-1-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220104023408.13379-1-eagostini@nvidia.com> References: <20220104023408.13379-1-eagostini@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: drhqmail202.nvidia.com (10.126.190.181) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ec8a66f-1537-4684-556c-08d9e103bf22 X-MS-TrafficTypeDiagnostic: SJ0PR12MB5609:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /STD93JfqioFYDqkRWt7EMfvpPszgAHr+oldjOEL8q7aCoEhQId1fsbJddra6LZuXPFGkfQg7wSILuKobrTDV9td5NKoSju0EHq8mTUL7IDtZ+UhKJQ4QanqxC68w+fLKqOExURsCWSE9r0xbakP7v5jyfOh3qQFCwuoejVTwjCn1epRMJLzLKEFKPfwX65uzn0w2O3VDWKCYx1BE+qgwOBBnnfNBF1z2/x/uyylroZVeevQTepVskWgkadiB7waKz69bp5T6gL0fnHNqg3ppe/ikL20cWymJYbdcopwN1IEjgImM9UsVOOA6MFfqdjxksNTFmTzQBta+8yI4Qj+8PqIqrpC/2u/lTRDUZ6gQA3b5scpxOqup9eq21ogC0ITgQPUf3tOvoHI/IL1a9UDxyY8HOz3j+UQD6dkWM+7YXX2nFjTWZOd2zrNhvZCA9pWyBtvUSCyXghbWgAi0ivqAztcv76b0sNzB6nGy5F4WbvQRUQTLOlzIGSTlygmKtkm0NuUlR+gaQzGKc81rWMPN2+5hLsLtJxWH4Z3UZ7LzNnlQ5wwb2Xb30Zye3SZukPlssDhhJDk10mwZxvgMkqWUt9H/rU+PY34p+MftzMPK7UArAMHsj7fDPSJSAus1+89hRR/K7EvkMIUYxZ0liMWQw/tV2XrCr9KFwc1i0JYFF2DimOybc+eiSbWVLeC4VAwOaRat3CwJtd2/0esSZey/WeNg9XJWc09EmbHPlI/CYqNJrGESJ77mcwBkqHfla/TyngFxWl477vDbrx9sG2TaAR6wekD9vADLth5LkdxzFE= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(40470700004)(36840700001)(46966006)(40460700003)(70206006)(316002)(47076005)(82310400004)(8936002)(5660300002)(81166007)(86362001)(26005)(83380400001)(508600001)(336012)(16526019)(70586007)(6666004)(4326008)(107886003)(1076003)(36756003)(6916009)(186003)(356005)(36860700001)(55016003)(8676002)(2876002)(7696005)(2906002)(2616005)(6286002)(426003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 19:40:45.6079 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0ec8a66f-1537-4684-556c-08d9e103bf22 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5609 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 From: Elena Agostini 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 --- 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; }; From patchwork Thu Jan 27 03:50:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Agostini X-Patchwork-Id: 106592 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8FBA5A04A3; Wed, 26 Jan 2022 20:40:53 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7E514275D; Wed, 26 Jan 2022 20:40:51 +0100 (CET) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2068.outbound.protection.outlook.com [40.107.100.68]) by mails.dpdk.org (Postfix) with ESMTP id C8F034275C for ; Wed, 26 Jan 2022 20:40:49 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gt3pbM+yLeqkSaOJN9GKmGJNGPopWQkC26cpr/n+KrztnvM+A8afCIczZhVIROYNbYwOi3EfSjxkK9SFzf2hXgfXaLITtHF7HEbFOpfYSFs5xiVRcsS808f2YykAQnRwnYAE7f01Djx97ODY9vhoCx0pPbt6s2gOimqTcuW0UBMmAay+T7ALyoFuzbxpGr9P3/9TvP5fdjoSD1z0MgKAEqUwApyD4d+3VJbB5fDQyUM94pmh2OGMVvCLLZ9FosnISnXn1SBH5Gry8wYJPE7czJ6jrl1rPLgKeUU9lrt3DOCcOUJr1kqAG9hU+zqpWf8yjef2Zemjq/TypgEP0nFzjg== 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=xOiLs/pfJin1CsOlUbjfSHdZj6BOOPyBCgQmg5q+SOI=; b=L4zoBB3qymuaByqzBmylW0bC7khZiztsCBJO3Z2fxB1h4xfNCNKWgfecdhnxa1goQkvac68ZTxgyfZT2/OuIj3rlUSQYs8Jp92pkQp8qBCYFkXs6GAe6njDRVMZTfgJD5kVPyGYA9kjO6SmizNiRy9+edvhpb6PtrdaBlTM2rRuHCLcSs3MeroTw6s5Gb1Qz9nYtSl6nYyVD8lN4DfAnz0M5ARt/Yv9+QJs+WqJ63F4krkNRaIgISBQzGjn0zVMMSGZRyLRW26R4fCNxWd0bLY+yFCVL5NQ96hNMwO6HrHIFkG7GB2obAnkEw8LjubKFvCh5v/Bi0pLxaynOYFqFBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=xOiLs/pfJin1CsOlUbjfSHdZj6BOOPyBCgQmg5q+SOI=; b=boqENzBV97CGQZxcc2TLu1ooL271inpRH7/fDgiX0+gC/oVwAQBrJwY6Y/xmxZIKRHZorH1Jm/cKlcc4i6GmgPPhTYaXDQQ0AIaKwjeSeZ7VP/ZWZ7rJr05Ckg9TsNBMir+qEcbHI1q381ZbJi7MyWTPUvYzY+ey3koMntVWjb7s40QhjzqhqF+sF3AhR2pkITBGMhrh3o7BqO6g8jU9hRQ0wlcQ5v2RW9wteFoBUWhUtppWP/1/Y8eH63/5ZqGFpOqL3L2ixFYr/tlU0h+q4mYVpnmYONafUBmBc2z5f5BiAG9XKyfnTNwgcNmABqrZ86zcnsp167vQ7c+3ZD1Kjw== Received: from MW4PR04CA0168.namprd04.prod.outlook.com (2603:10b6:303:85::23) by DM5PR12MB1387.namprd12.prod.outlook.com (2603:10b6:3:6c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.13; Wed, 26 Jan 2022 19:40:47 +0000 Received: from CO1NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::42) by MW4PR04CA0168.outlook.office365.com (2603:10b6:303:85::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Wed, 26 Jan 2022 19:40:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT045.mail.protection.outlook.com (10.13.175.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Wed, 26 Jan 2022 19:40:47 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 26 Jan 2022 19:40:44 +0000 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Wed, 26 Jan 2022 11:40:44 -0800 From: To: CC: Elena Agostini Subject: [PATCH v5 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions Date: Thu, 27 Jan 2022 03:50:29 +0000 Message-ID: <20220127035029.12920-2-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220127035029.12920-1-eagostini@nvidia.com> References: <20220104023408.13379-1-eagostini@nvidia.com> <20220127035029.12920-1-eagostini@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: drhqmail202.nvidia.com (10.126.190.181) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 429723e8-6316-4d5c-d0a1-08d9e103c02c X-MS-TrafficTypeDiagnostic: DM5PR12MB1387:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 06qb4QTLrGEexvY32Pltu9T3bcoFo/huMFiZCMiK9cNeEalbyHTfGY1EP9PPL4Rlu2qkYvmjzRzU7oRh1NoxmIncwROhysC3yBh80/2fnjD4HDwSKv8A64d/IC/FCD7NEDo5yv+qTSutkb2S32fvRldMMgzZxFUFx9lcjktC81stC4wv7p1b+M8dIx953P6VEemFOyo9ZenbkAEken2VHHUMWgc20OJ5ODVxGhE1NShmJ2oZLZw0+XBcywVcIyk4ciTobV80qdGMS8ed07Yvyd+HdOF2L16FF1lxhG4i/Q+G8qTPxbz5djwxPJTJ2lyCC3DjTkvB2d5A6RI5UtxKULuF0pFBJJRYZsEAUpm5bPGDfcYsWLkmcl8I69CP3X6k6A9nvYnviIXPk5k81ReBCOOgwwsjdleKPJz5+uVYdDLTF+RiQfmBpUyHOUwhmJC5eUSkVyZegS3QERbcN4OkMGr2ECmYgu7cUb79yqIsznjPSvqu/Xb56gZleNTVQMaHME7QIlSH/ijJSJcy63J50U0S/A6wShP2qiRYKSHMvvgA2Ivu1anM91fqFs84Cf0tMXekiYdBWjA4OQ5mpN0FJGmOpFXDp/n5xXkXh5hNz2320o2tgqBmWhsNMERkuj0UVoDnQrFj5F81RMPYi/o66dqpppSCuBMF+WWBsU9OLdUgiD2BeRziQcPdtlSAG4xuqf3GuCdDcJ9N5Ep3iWuU2dQPbWHm2jk5BgqlSQlkB7r7LxSgnm8w39CQluYqD3JIfY+QJoJcqSm3KtJQ+SMlLKADDG1NC3B6nzgOiHgUReg= X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(40470700004)(36840700001)(46966006)(81166007)(8936002)(2906002)(356005)(426003)(26005)(8676002)(336012)(2616005)(6286002)(2876002)(316002)(508600001)(7696005)(55016003)(36860700001)(82310400004)(6916009)(5660300002)(40460700003)(86362001)(1076003)(36756003)(47076005)(16526019)(70586007)(4326008)(83380400001)(6666004)(70206006)(186003)(107886003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 19:40:47.3699 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 429723e8-6316-4d5c-d0a1-08d9e103c02c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1387 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 From: Elena Agostini New test case added to test the gpudev cpu_map/cpu_unmap functions. Signed-off-by: Elena Agostini --- 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