From patchwork Thu Jan 27 03:47:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Agostini X-Patchwork-Id: 106589 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 59D00A04A3; Wed, 26 Jan 2022 20:38:05 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B1EF542752; Wed, 26 Jan 2022 20:38:04 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2078.outbound.protection.outlook.com [40.107.93.78]) by mails.dpdk.org (Postfix) with ESMTP id BD7354274B for ; Wed, 26 Jan 2022 20:38:03 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eL5SXyvW+7w32DumATv3hEoRuAMHkFDZCOxBC4W3oC4u1C/1u4hsGLobyUoPAuLxhLNsLU5z5d7v0cSnwwkSd8P8t1s1B/SDo5RRcPcPo4WbOmgUD6CQPhzyzgLrXw6yjILAS92GBUvbcVzkKSRnk6yx0jTDloJBqZxsJqHe+3fvixR3fZt2SnjyAyaNtjM2o0clX0dq4dM0HeRDhhgmeGbv5bQX0J5VUzsTw2NEJ6T0oa9N0DOUaiDBJpyNhvnepg1lCsKtsPfWs1nh3h+noZFkj7APobGD1d8fBgk/c30IHIn1Tp6TsWlmiUuN41PJgY4Ily4XnKWZokvnU1X8LQ== 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=DUPe0WzwxwtBdIYx+A93wM8KHuIJtsQ2RF+nZBIRHz3QSYrbZKrHDq26sW1Bz4hnDOzFtc2KGf4jo2Wp8tiJHNQh4DtnyEco9/ydaF3UlajrSdaKK5UY2UzGZtxhFICl8uz+mEP0nlvaH94W6yWPyk86jUXS9I1lpC+yDdc7Gg0g+A0VjmsnzwnvnSfAW2Wcg+R2fBahFCju3s5ghHM7ONhH2m/6//I5U8bGmKWNLR90TjhRh9qmJqvc8aXOT0cm5g+biZF1IAM+Y0HY6eUGL9vtOeL/FEmAw86IHW11yPowbSd3+TTpkDqkpubYgm5svxldH3ngqPMlr7DxNH+Cxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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=rL6tmkgHzRAjl8KjqTw1Z5s4nVGykuk+Pkqr+9DatWWzwF2EyWd7lX9xNvm/q5kxmUxRacvfEOosXi5EOyHZan6EBp2Wk92zUbRCc59nrUEaIyONvo7LvR2z9k+tfSud9UYrr461Y0HeaK1M39i5RqIS1usw5YPatxRGg1eNztzHdGgy0qf8dcUX6dtFB+CJRnhrKL7rOoNM/bcjqb8AY12tYA8RC0RLonhwLahgBhO/xDNqUKElW5yJzL5YgB7QCM3TkfCdkBzHfVBay1Qjn25UPivn4wgrNdc8tn2mncq42LdLANhHSyeh+IDglmXtjYXYh0A2dwWiHiroh99UwQ== Received: from BN9PR03CA0957.namprd03.prod.outlook.com (2603:10b6:408:108::32) by MN2PR12MB4488.namprd12.prod.outlook.com (2603:10b6:208:24e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Wed, 26 Jan 2022 19:38:02 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:408:108:cafe::ac) by BN9PR03CA0957.outlook.office365.com (2603:10b6:408:108::32) 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:38:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) 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:38:01 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 26 Jan 2022 19:37:52 +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:37:51 -0800 From: To: CC: Elena Agostini Subject: [PATCH v4 1/2] gpudev: expose GPU memory to CPU Date: Thu, 27 Jan 2022 03:47:15 +0000 Message-ID: <20220127034716.12497-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: 2ac5f6db-7474-48e9-9cea-08d9e1035d72 X-MS-TrafficTypeDiagnostic: MN2PR12MB4488: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: CGE0PIDpoNgEYqIW50M7jKSPXe3ryPfTMKhTgAorXkMwBxqfE58Yde3vm2HPPnLMmoo5C3Mrmkmd3SPtdNCK3k3p3uIY5JSADmmOmHEkPGFAxuPpVt8/ZlTv8mY+V4SyFqx05tRhjoI5rOKKZYrFbfaDec4BqS4iEkZdIjnSJagH0u/t2ic+II0wdOPK18dncEFReeftUwAEkFoG693JGI0PzamBSu8q7qDyFAyX6dqr8pg6JQMOXmk0dYZh3ONMsB8hQ7jQOE/Hm2rZyYr+k/7naFHcYRR+CNPMVVNubCbQOlNqrwhBgpf/cmPocn7UVo0H1ajsWluiW/jNP2mAuFIJ5PSqOBrPYqWvriygPx1MpsrM38LILpmSO0Gw/CD+IW/+gRWciajaoCHEegVxDrROWPengSkZxOSGJys4Ai/uN63HchPdNnE2yYPyMqL7JuxiNaDrT1K24xL54AeW8eJustiiPOLKvz1pXb3HFaWZSuls5toEtBsFlyNXq2H1zQlRTxHdeUIySAAiGUhMfsE7cqnTZEID5Oz/4z5LoBgjYqiFfma1rQrPsZNzKbowEoMHm+6fj1+qSXN0oKCFYUoJn7XYuGnCddm5u15DXEafzDBvD/hcb0IMct0ZRO+a62mO8Ej99qJJsCUKkS08pmNk3x536+qczZom5S/Kl5UN6ClF2l1j06Zka4pPrMs/t7D+qStjZihXFEK3QACj3A== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(36860700001)(36756003)(2876002)(70586007)(70206006)(2616005)(2906002)(7696005)(508600001)(5660300002)(6666004)(356005)(81166007)(55016003)(4326008)(8676002)(26005)(426003)(82310400004)(107886003)(6286002)(336012)(316002)(40460700003)(6916009)(83380400001)(8936002)(16526019)(1076003)(47076005)(186003)(86362001)(36900700001)(20210929001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 19:38:01.6704 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ac5f6db-7474-48e9-9cea-08d9e1035d72 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.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4488 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:47:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Agostini X-Patchwork-Id: 106590 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 835D9A04A3; Wed, 26 Jan 2022 20:38:13 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81DB242759; Wed, 26 Jan 2022 20:38:08 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2083.outbound.protection.outlook.com [40.107.220.83]) by mails.dpdk.org (Postfix) with ESMTP id 90A5E4274B for ; Wed, 26 Jan 2022 20:38:04 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OHuPpbiee3JO4tYYro026vd5VwmTu7M+uD1ecd//bIw4vGsnhNTQC1BOmopLmXsqOzi5sAYzSAEBCOyKfOTM12wJqcmk+XylD3XmnsY0+hX1+j37UUvk78QKozgscBIo9l0Qqvz/LA3TmWbUFVtEqqOkcvEfhUcbtNo8l2LxsdCj5RxpyX84/lur5GxmjY6cxlqxp1G7ASCsGk+yYbEu0iKNtvL2mbTLUtmsk3WArAQc/a7Fn7qGrXvVeLpD+QN3gZlVo7Q5qAYkLzAWFJ4oGYndzij5CADtmct8dOJKXR0mYX388k9RmbX9eq/3SREWSE07zVDt1t0XlC+Oq2lJ0Q== 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=jgFkEsnPmwdTi6jN8hQIKhpHMH+1/2wsaKtt3N9yXv0=; b=PK8nFjY9z0BjmR+ym2r7Rh7PD3u8aHYU86KejVpmsQ8dnLXYmENl2vH5uJUbRqZBmn/bON0Dp3Y63icSsl4GSlRch0+6eFOXlcHf9bw/UYgYDyPBMoeNNa1+V1mmo2RrD01ti3O5AXe8PqT59QwoeA6pDjrWcFIWXcK+mlCNDfiR2wcOToRH5T5Yt1j4kSSXMKZwBofLYWpwiqUZUrO5iHd+IdGk5mcgiKQKsA/WR3+93ujUSmsEC2dl8ko4JZvw5/WVldro58xJXsdJcnOuH2I+LHojmdXLRjSfI/v/auO5L9mBXl+fK7ylQBtpX+bkI37R1tEjVSsTV4kQJ+rsVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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=jgFkEsnPmwdTi6jN8hQIKhpHMH+1/2wsaKtt3N9yXv0=; b=Jn237umRFiyoR897HhzVauvOPGU6qqYLGjQMdgKa+mZyNfHcXFlU4ojnHwbeJhFdD0js/3qABjIKlIeDDjBvyQ5tMFaVnlNdTdeq0pRxZwwfeudBsAWatvwjJ+m9Xc0Fe3JAcDZUDqn+5w+p3bPeL5sk2rIPwZ7B1hEb5LzD71gVoT5DmDd3YYHsdXOQ6htc1vPAf5ERiQ8nwLlA5xdnhK6W6uMRVsCjOYewxlb+3UYHWU60YRoL7yGqq0Md/l04d2Yz1oCD0tOy9/Z1lL+PzEkEXUZarc8kwR06S/9ZsEwCXHkEjFC1JSXSHu2M2MSHboj2UCCCIoKwRTJv2rZgtg== Received: from BN9PR03CA0949.namprd03.prod.outlook.com (2603:10b6:408:108::24) by BYAPR12MB3381.namprd12.prod.outlook.com (2603:10b6:a03:df::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Wed, 26 Jan 2022 19:38:02 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:408:108:cafe::86) by BN9PR03CA0949.outlook.office365.com (2603:10b6:408:108::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17 via Frontend Transport; Wed, 26 Jan 2022 19:38:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) 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:38:02 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 26 Jan 2022 19:37:52 +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:37:52 -0800 From: To: CC: Elena Agostini Subject: [PATCH v4 2/2] app/test-gpudev: test cpu_map/cpu_unmap functions Date: Thu, 27 Jan 2022 03:47:16 +0000 Message-ID: <20220127034716.12497-2-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220127034716.12497-1-eagostini@nvidia.com> References: <20220104023408.13379-1-eagostini@nvidia.com> <20220127034716.12497-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: 4b6b4937-fcf1-4059-bd14-08d9e1035dd6 X-MS-TrafficTypeDiagnostic: BYAPR12MB3381: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: wCmI9Ybvtb4LHfF2MLNAsWq5Ta2FOmbFfY63rQlhK1gqRzrgNzXgLhKcLRDxikl7vIElsaA6+TB92bVxueQT46AvQFS+EO/hwXZ/4vJNjkA2VM2vN9rDg7G89TeKeUCxHTPgNl+Pce1OfO7jbwJYSHGZIaQjZRD2Bg1/R00vg6Az/Buzc2d6g+zOFk4ZYHdfs1/GXGhA+qu+300YQzSO9Q70+RXRcS84QDj4UgU6xsaemcp2mABGOTo5bDaN5zh6Z7+7gCC0pYOYv2M3+hanIfOIPlPCirIyxyyIsXBymdzj40ZnDEwRaIPBGyFgWjFVoza6qBMsBXCPKDZ1pWmQph/jQ0OB70UwlROjLi+W/KVgXccAEHGrSAWJkPAIx9nC1RPSChFzPA/MVOy0G1UJDXxcNbHbxwV72DIgHh4Suuli1BTx0Z9IcmguzwoBJnlERz4Epahl9bdygTH7QU8hZCRJDpj+P3PZ0EXCBNF9w4w2yskHhEmYptvLvqZjxWk7TBn7fxYNGkkBpYW5RUit5N1H3pnI0zyjOFQpBy8FaJ7dcc1ptLcZAhlQc/bmJqCPdC3gtjqtYx5fIdkrqP9l0+V3YBrMxzRjjpdXEHvhG718laWAYkNs/ik2pCw7RlO8c5i2coHu5WTMc9+mtrfKgiFbT8CS0+8ARQ5F3M35GoTC6J43ci0SXW/b0kbQi71/a8cRWyvuEYto7atIbNuUng== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(336012)(36860700001)(16526019)(2616005)(1076003)(186003)(426003)(107886003)(6286002)(2876002)(2906002)(356005)(70586007)(36756003)(4326008)(8676002)(70206006)(5660300002)(55016003)(8936002)(26005)(508600001)(86362001)(82310400004)(47076005)(7696005)(6666004)(316002)(81166007)(40460700003)(83380400001)(6916009)(36900700001)(20210929001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 19:38:02.3266 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b6b4937-fcf1-4059-bd14-08d9e1035dd6 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.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3381 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..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