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 67020A034D; Mon, 3 Jan 2022 18:37:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DF1E041150; Mon, 3 Jan 2022 18:37:38 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2040.outbound.protection.outlook.com [40.107.93.40]) by mails.dpdk.org (Postfix) with ESMTP id 9F5684003C for ; Mon, 3 Jan 2022 18:37:35 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MfOp7xk3gJxyu3207hGF5DG3qfNVMfJHo1QMGq1MukLQhGdoX4WKYgi1hqb7tXFRMMhD2br7UaEbvNblDlCEgselccj8ALFviaCUnbpxAZ2kUBjvJSYV+/w6/ZWnejjsPOIgJK+7GSwSOt+efaL/Iq3sZ7nRTChN5Is9+dGMSvGstqj3XA7PjzbirLm3fSNegmb+DSq5+VSwD7uwxhpIGG0rt0LZ68PODswmtUlxxEd21zc0ndcr1PiqdSsKNB2HtnXGWjMdZ5CES2CJkSIcuc06SQACDK6tAkavrj6aVxLTk7rbt8LhFNTpV0jo+gFdq09OvdAMpkKXpAk0ZfKuiQ== 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=I3/MB5AUaWPQOcM+apTD1UYyUEeMQqye6OecUY1L60k=; b=aN2kV/qiRn8meEe7cQ2h8DwnHbRrgPNAjd+PRiibO2XV/9Jnl6nLLMEOHZIVQyznW6g8NsHRSlUwf6YkF/jYDJD9nx7gBWAAvwylqEAOndjHSFIfnwuBMWTraWbpM3AXd0LuYOAuDmgYOve2FgZkIlLDD6bMz4lT7VYFHTc4MZIYEyh0h4j0v3Xr4PwurSjMht2eiTgCR6Z2wyPzxiffayGHoBxERyE8YVMLuxX6nFWM+AFwX7+RbmXgtaN1rK93Mo865etBk5qZdvNtAoUooCq+IqwDGApTSCObzLx09I8JqltvMTztDBy9CMCmICXaZgfD583EbmbnSxsUvB1Ilw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) 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=I3/MB5AUaWPQOcM+apTD1UYyUEeMQqye6OecUY1L60k=; b=qIvgeNNz78BsJubklCd++pJJCQEBWie5UKsdAlW/ysrF5K0g/4wr+F7eIH8a+QvjNzpm/wBfxMaVUguawjFZz/Gz2JQWcN0EPmOPB4Aw/m6fXqVFYusowWLRP6Mijggsf64Osj1P/OXIhKX+8fPyJo1sOkRi5oiTOwBXl360DeAM3xDJPQPW+sS3maTr1pbsoBfPf7MMEZly9Fbo5bmtkBVVi5tOfTiKGvY7Vo4SIsNxzrZfnI5jADpdFEbeyjvptqwxEgRGReLEBH1WRqhvgwOPuMrFEXP9JGKZ/fwsbKIBzRA0NUXEMCns3INYjT/NPsQ2Q8284StJWY1IXK/YZQ== Received: from MW4P223CA0006.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::11) by CH2PR12MB4264.namprd12.prod.outlook.com (2603:10b6:610:a4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.19; Mon, 3 Jan 2022 17:37:33 +0000 Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:303:80:cafe::d1) by MW4P223CA0006.outlook.office365.com (2603:10b6:303:80::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.13 via Frontend Transport; Mon, 3 Jan 2022 17:37:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4844.14 via Frontend Transport; Mon, 3 Jan 2022 17:37:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 3 Jan 2022 17:37:32 +0000 Received: from nvidia.com (172.20.187.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.986.9; Mon, 3 Jan 2022 09:37:32 -0800 From: To: CC: Elena Agostini Subject: [PATCH v1 3/3] gpu/cuda: mem alloc aligned memory Date: Tue, 4 Jan 2022 01:47:21 +0000 Message-ID: <20220104014721.1799-4-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220104014721.1799-1-eagostini@nvidia.com> References: <20220104014721.1799-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 rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e42c60e-ef65-47e0-0a28-08d9cedfb97d X-MS-TrafficTypeDiagnostic: CH2PR12MB4264:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:428; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LVOmw97Fe0s8i8koqVHo67GLBUI4JxbUwDlyxdiMzS+UjBUNog96aWPd6vxZTeoMw9CXG/6yecicyVYN7gr/KWNDIkTRGiaN5UBruo4LLozmkxd3Fi5mmu7+jWc9aK31xSfjXkq6r33D+I2Sv9H2XU2Nf4abVjv3EPL4pvrlBplX3h5Pjb/TxfeEsrfQuuCYH03dJW8OxJiOI6m5pzCsuU2y7O4v6zSB3NxbTb8NAv4Dw7caXmkg5aTL+9rwGI7iSPxaO10pECqs9yZNFPUq+1/GU6dME5TwXDxfg/8SKinmQk1Ot9lvy06JUwHxI6DAPb8W6jADWXDyVConpduKP+6WF9nwmUpMBtyjcfZYS7kKkjbPSiD79QOyepdKlOfQTmLo6pMBRUPu9oN6vP71+ArD2J6KgmiZAaOSZ93uspifExjdZeY491Yehfee1zNM2Us6OQWHtjahnpc033f4fW51cqFWb9ImeTy/xctjw6Ovy0wHdVh95Yv7VMiDa2DaJW2moO7Ndun6ZQCnPIkXQv4wUz9jkYUcgLZzS6UmATVhJ+uj/f7/OVPHrFqlMSEbaC+PKXekMcTUIUYIFrr8DiWVNgk8ffHudFOYZKAaWAYFqZovpfM5xD7fumoYjHbTV213ePgmfFo59VX148P8galWKtHp5XDzBeRF4fKKQGAeJls4zoVEfvdn+ebkXPcxp5o+OAFCtFMVsa/YIskBb+wR5eGH7UHAvPTH3pKTWEyWpSJLNYn+b7pW4jqNbIjk9TW8FQNBet9QdmeQqYzmbSq6vmoF4ytA8V++kzBq1TM= X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(40470700002)(36840700001)(46966006)(47076005)(8676002)(186003)(36756003)(83380400001)(6666004)(36860700001)(81166007)(86362001)(26005)(7696005)(336012)(2876002)(70206006)(1076003)(5660300002)(4326008)(40460700001)(356005)(107886003)(8936002)(6286002)(16526019)(2616005)(55016003)(70586007)(82310400004)(2906002)(508600001)(426003)(316002)(6916009)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2022 17:37:33.3550 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e42c60e-ef65-47e0-0a28-08d9cedfb97d 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.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4264 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 Implement aligned GPU memory allocation in GPU CUDA driver. Signed-off-by: Elena Agostini --- drivers/gpu/cuda/cuda.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c index 882df08e56..4ad3f5fc90 100644 --- a/drivers/gpu/cuda/cuda.c +++ b/drivers/gpu/cuda/cuda.c @@ -139,8 +139,10 @@ typedef uintptr_t cuda_ptr_key; /* Single entry of the memory list */ struct mem_entry { CUdeviceptr ptr_d; + CUdeviceptr ptr_orig_d; void *ptr_h; size_t size; + size_t size_orig; struct rte_gpu *dev; CUcontext ctx; cuda_ptr_key pkey; @@ -569,7 +571,7 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) */ static int -cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) +cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr, unsigned int align) { CUresult res; const char *err_string; @@ -610,8 +612,10 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) /* Allocate memory */ mem_alloc_list_tail->size = size; - res = pfn_cuMemAlloc(&(mem_alloc_list_tail->ptr_d), - mem_alloc_list_tail->size); + mem_alloc_list_tail->size_orig = size + align; + + res = pfn_cuMemAlloc(&(mem_alloc_list_tail->ptr_orig_d), + mem_alloc_list_tail->size_orig); if (res != 0) { pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent current failed with %s", @@ -620,6 +624,13 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) return -rte_errno; } + + /* Align memory address */ + mem_alloc_list_tail->ptr_d = mem_alloc_list_tail->ptr_orig_d; + if (align && ((uintptr_t)mem_alloc_list_tail->ptr_d) % align) + mem_alloc_list_tail->ptr_d += (align - + (((uintptr_t)mem_alloc_list_tail->ptr_d) % align)); + /* GPUDirect RDMA attribute required */ res = pfn_cuPointerSetAttribute(&flag, CU_POINTER_ATTRIBUTE_SYNC_MEMOPS, @@ -634,7 +645,6 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) mem_alloc_list_tail->pkey = get_hash_from_ptr((void *)mem_alloc_list_tail->ptr_d); mem_alloc_list_tail->ptr_h = NULL; - mem_alloc_list_tail->size = size; mem_alloc_list_tail->dev = dev; mem_alloc_list_tail->ctx = (CUcontext)((uintptr_t)dev->mpshared->info.context); mem_alloc_list_tail->mtype = GPU_MEM; @@ -761,6 +771,7 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) mem_alloc_list_tail->dev = dev; mem_alloc_list_tail->ctx = (CUcontext)((uintptr_t)dev->mpshared->info.context); mem_alloc_list_tail->mtype = CPU_REGISTERED; + mem_alloc_list_tail->ptr_orig_d = mem_alloc_list_tail->ptr_d; /* Restore original ctx as current ctx */ res = pfn_cuCtxSetCurrent(current_ctx); @@ -796,7 +807,7 @@ cuda_mem_free(struct rte_gpu *dev, void *ptr) } if (mem_item->mtype == GPU_MEM) { - res = pfn_cuMemFree(mem_item->ptr_d); + res = pfn_cuMemFree(mem_item->ptr_orig_d); if (res != 0) { pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuMemFree current failed with %s", -- 2.17.1