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 4357CA034D; Mon, 3 Jan 2022 19:05:26 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD2E640042; Mon, 3 Jan 2022 19:05:25 +0100 (CET) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by mails.dpdk.org (Postfix) with ESMTP id 4CAD24003C for ; Mon, 3 Jan 2022 19:05:24 +0100 (CET) Received: by mail-pg1-f173.google.com with SMTP id f5so1296919pgk.12 for ; Mon, 03 Jan 2022 10:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R/MiHDsKklqJhk5MPFVzmJdA6Dv+NvKpgVSDUpMg4Aw=; b=N/mX9VDtygrxma7Y7YMSp0KrMgoYyqlURdBHGHckbqu9dkXeJPJQJYtrCYzFO3q7F/ KQL4KpC61XkMD3QX7r1POZ2ZMNFh/u+BZd2DlsuQySgjH3EyfZNqxnvzeinp/tDP0qFT DyGgd99/7eLSsxSwGzRPfZCvNtwQXyVl9VH1BlAVC4e171OcDBpRZVdqV1vnrgWyhdK+ w0Xgmw9VSZWu7q8GdCPOJyicFxKZtUjlIbVDmY7GE3nABEOssSZGt8v6fW5176FYn5Fz nORYn5BMX7j5auOpHyd4GWPYkiCMmNc11Jeo980C0Bftsqb5NBhIuea0UYiUFCKFKHjC pMBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R/MiHDsKklqJhk5MPFVzmJdA6Dv+NvKpgVSDUpMg4Aw=; b=5+8gTgpCnEbJIVn8BaBR1BnUa6h9B3wiZK8J8wmFWZGFM/QUxh7j0NPcYDvm0NViXt 3CozGmomulnNAdLjzIJiwaGld3od2EHcSCeLNusNab67faSbAnCTXhxHh+Xxb92q3O1i DlZFubH1+jiP9jXaT1sb7kDvR8QnuMVtWgZ3wjQlovmJFO1hwb0IvSpxq7lttv5F2u50 AreYYG2x4nTOCTkRjX0QkslkLGU/DASlUzYxQlZ1V6jXXt4e8y5T84CKHHIanj4ExC7Z CFb9VwBj4ePpbpA5NzMl+FLq8GHCTzPKVIZeVUN9Z3R20DTZkhLkBS6zCLMEtLE7XkQF /ldQ== X-Gm-Message-State: AOAM531fvDKDsSZ1dvTc0QMEYvmciiLEUiN1toS32AVgVx4E8aXhRTue gCm+lt7tlzunY5J0S6SLB8g0u1dU38gytg== X-Google-Smtp-Source: ABdhPJzXm+gnoyhM77Jh3QaDB+NWDmulCEpDDGGDWQr+jP+5AxCsozCwiZEAhSwYefZP8pzbaTETUQ== X-Received: by 2002:a65:6a93:: with SMTP id q19mr4475409pgu.155.1641233123239; Mon, 03 Jan 2022 10:05:23 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id m3sm37984713pjz.10.2022.01.03.10.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 10:05:22 -0800 (PST) Date: Mon, 3 Jan 2022 10:05:20 -0800 From: Stephen Hemminger To: Cc: Subject: Re: [PATCH v1 3/3] gpu/cuda: mem alloc aligned memory Message-ID: <20220103100520.66677c3f@hermes.local> In-Reply-To: <20220104014721.1799-4-eagostini@nvidia.com> References: <20220104014721.1799-1-eagostini@nvidia.com> <20220104014721.1799-4-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Tue, 4 Jan 2022 01:47:21 +0000 wrote: > 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)); Posix memalign takes size_t for both size and alignment. Better to put the input parameters first, and then the resulting output parameter last for consistency; follows the Rusty API design manifesto. Alignment only makes sense if power of two. The code should check that and optimize for that.