Message ID | 20220308113059.688551-1-abidh@codesourcery.com |
---|---|
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4716B385AC3E for <patchwork@sourceware.org>; Tue, 8 Mar 2022 11:31:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 0DFB2385B83C; Tue, 8 Mar 2022 11:31:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0DFB2385B83C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.90,164,1643702400"; d="scan'208";a="72843960" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 08 Mar 2022 03:31:17 -0800 IronPort-SDR: 3GbAGWVPnnwuoe5RnKlgX5NYds0TG6HQqD+t+IH4jSWVqG/D4MyWsQ7CEfSK0epjd/7tpmJG5G j1RvTD3xB9Krsl1EoH/Z+TyvKypSKIIK5QjY0cfhZAal9LqpA0BPmTtDJjbUrq/E5I3sE/sMjY +QNurD4Hayf+2t+yQrz0qytEs1kWRwyrS9WkwnVwePRLCnjjLba30cV+V4iTrKy2OeMd2Z6Cky 9bZJ+BqeLZJ+K9jof/XA46TSOAZXConSQnAnzZOHb8bFAXm8S1tiSkRhOayDVs/tgbJI8JJ84J aJU= From: Hafiz Abid Qadeer <abidh@codesourcery.com> To: <gcc-patches@gcc.gnu.org>, <fortran@gcc.gnu.org> Subject: [PATCH 0/5] openmp: Handle pinned and unified shared memory. Date: Tue, 8 Mar 2022 11:30:54 +0000 Message-ID: <20220308113059.688551-1-abidh@codesourcery.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-07.mgc.mentorg.com (139.181.222.7) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Cc: jakub@redhat.com, ams@codesourcery.com, joseph@codesourcery.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
openmp: Handle pinned and unified shared memory.
|
|
Message
Abid Qadeer
March 8, 2022, 11:30 a.m. UTC
This patch series add support for unified shared memory (USM) and pinned memory. The support in libgomp is for nvptx offloading only. A new command line option -foffload-memory allows user to choose either USM or pinned memory. The USM can also be enabled using requires construct. When USM us in use, calls to memory allocation function like malloc are changed to omp_alloc with appropriate allocator. No transformations are required for the pinned memory which is implemented using mlockall so is only available on Linux. Andrew Stubbs (4): openmp: Add -foffload-memory openmp: allow requires unified_shared_memory openmp, nvptx: ompx_unified_shared_mem_alloc openmp: -foffload-memory=pinned Hafiz Abid Qadeer (1): openmp: Use libgomp memory allocation functions with unified shared memory. gcc/c/c-parser.cc | 13 +- gcc/common.opt | 16 ++ gcc/coretypes.h | 7 + gcc/cp/parser.cc | 13 +- gcc/doc/invoke.texi | 16 +- gcc/fortran/openmp.cc | 10 +- gcc/omp-low.cc | 220 ++++++++++++++++++ gcc/passes.def | 1 + .../c-c++-common/gomp/alloc-pinned-1.c | 28 +++ gcc/testsuite/c-c++-common/gomp/usm-1.c | 4 + gcc/testsuite/c-c++-common/gomp/usm-2.c | 34 +++ gcc/testsuite/c-c++-common/gomp/usm-3.c | 32 +++ gcc/testsuite/g++.dg/gomp/usm-1.C | 32 +++ gcc/testsuite/g++.dg/gomp/usm-2.C | 30 +++ gcc/testsuite/g++.dg/gomp/usm-3.C | 38 +++ gcc/testsuite/gfortran.dg/gomp/usm-1.f90 | 6 + gcc/testsuite/gfortran.dg/gomp/usm-2.f90 | 16 ++ gcc/testsuite/gfortran.dg/gomp/usm-3.f90 | 13 ++ gcc/tree-pass.h | 1 + libgomp/allocator.c | 13 +- libgomp/config/linux/allocator.c | 70 ++++-- libgomp/config/nvptx/allocator.c | 6 + libgomp/libgomp-plugin.h | 3 + libgomp/libgomp.h | 6 + libgomp/libgomp.map | 5 + libgomp/omp.h.in | 4 + libgomp/omp_lib.f90.in | 8 + libgomp/plugin/plugin-nvptx.c | 45 +++- libgomp/target.c | 70 ++++++ libgomp/testsuite/libgomp.c++/usm-1.C | 54 +++++ libgomp/testsuite/libgomp.c/alloc-pinned-7.c | 66 ++++++ libgomp/testsuite/libgomp.c/usm-1.c | 24 ++ libgomp/testsuite/libgomp.c/usm-2.c | 32 +++ libgomp/testsuite/libgomp.c/usm-3.c | 35 +++ libgomp/testsuite/libgomp.c/usm-4.c | 36 +++ libgomp/testsuite/libgomp.c/usm-5.c | 28 +++ libgomp/testsuite/libgomp.c/usm-6.c | 70 ++++++ 37 files changed, 1075 insertions(+), 30 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/alloc-pinned-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/usm-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/usm-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/usm-3.c create mode 100644 gcc/testsuite/g++.dg/gomp/usm-1.C create mode 100644 gcc/testsuite/g++.dg/gomp/usm-2.C create mode 100644 gcc/testsuite/g++.dg/gomp/usm-3.C create mode 100644 gcc/testsuite/gfortran.dg/gomp/usm-1.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/usm-2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/usm-3.f90 create mode 100644 libgomp/testsuite/libgomp.c++/usm-1.C create mode 100644 libgomp/testsuite/libgomp.c/alloc-pinned-7.c create mode 100644 libgomp/testsuite/libgomp.c/usm-1.c create mode 100644 libgomp/testsuite/libgomp.c/usm-2.c create mode 100644 libgomp/testsuite/libgomp.c/usm-3.c create mode 100644 libgomp/testsuite/libgomp.c/usm-4.c create mode 100644 libgomp/testsuite/libgomp.c/usm-5.c create mode 100644 libgomp/testsuite/libgomp.c/usm-6.c
Comments
This patch adjusts the testcases, previously proposed, to allow for testing on machines with varying page sizes and default amounts of lockable memory. There turns out to be more variation than I had thought. This should go on mainline at the same time as the previous patches in this thread. I'll commit it to OG11 shortly. Andrew libgomp: autodetect page sizes in pinned memory tests There's not one number that works everywhere. This also fixes the failure mode on non-Linux hosts. libgomp/ChangeLog: * testsuite/libgomp.c/alloc-pinned-1.c: Autodetect page size. * testsuite/libgomp.c/alloc-pinned-2.c: Likewise. * testsuite/libgomp.c/alloc-pinned-3.c: Likewise. * testsuite/libgomp.c/alloc-pinned-4.c: Likewise. * testsuite/libgomp.c/alloc-pinned-5.c: Likewise. * testsuite/libgomp.c/alloc-pinned-6.c: Likewise. * testsuite/libgomp.c/alloc-pinned-7.c: Clean up. diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c index 0a6360cda29..79792b16d83 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c @@ -4,13 +4,23 @@ /* Test that pinned memory works. */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> +#include <sys/resource.h> + +#define PAGE_SIZE sysconf(_SC_PAGESIZE) +#define CHECK_SIZE(SIZE) { \ + struct rlimit limit; \ + if (getrlimit (RLIMIT_MEMLOCK, &limit) \ + || limit.rlim_cur <= SIZE) \ + fprintf (stderr, "unsufficient lockable memory; please increase ulimit\n"); \ + } int get_pinned_mem () @@ -34,6 +44,9 @@ get_pinned_mem () abort (); } #else +#define PAGE_SIZE 1 /* unknown */ +#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n"); + int get_pinned_mem () { @@ -43,12 +56,13 @@ get_pinned_mem () #include <omp.h> -/* Allocate more than a page each time, but stay within the ulimit. */ -#define SIZE 10*1024 - int main () { + /* Allocate at least a page each time, but stay within the ulimit. */ + const int SIZE = PAGE_SIZE; + CHECK_SIZE (SIZE*3); + const omp_alloctrait_t traits[] = { { omp_atk_pinned, 1 } }; diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c index 8fdb4ff5cfd..228c656b715 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c @@ -4,13 +4,23 @@ /* Test that pinned memory works (pool_size code path). */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> +#include <sys/resource.h> + +#define PAGE_SIZE sysconf(_SC_PAGESIZE) +#define CHECK_SIZE(SIZE) { \ + struct rlimit limit; \ + if (getrlimit (RLIMIT_MEMLOCK, &limit) \ + || limit.rlim_cur <= SIZE) \ + fprintf (stderr, "unsufficient lockable memory; please increase ulimit\n"); \ + } int get_pinned_mem () @@ -34,6 +44,9 @@ get_pinned_mem () abort (); } #else +#define PAGE_SIZE 1 /* unknown */ +#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n"); + int get_pinned_mem () { @@ -43,12 +56,13 @@ get_pinned_mem () #include <omp.h> -/* Allocate more than a page each time, but stay within the ulimit. */ -#define SIZE 10*1024 - int main () { + /* Allocate at least a page each time, but stay within the ulimit. */ + const int SIZE = PAGE_SIZE; + CHECK_SIZE (SIZE*3); + const omp_alloctrait_t traits[] = { { omp_atk_pinned, 1 }, { omp_atk_pool_size, SIZE*8 } diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c index 943dfea5c9b..90539ffe3e0 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c @@ -2,15 +2,18 @@ /* Test that pinned memory fails correctly. */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> #include <sys/resource.h> +#define PAGE_SIZE sysconf(_SC_PAGESIZE) + int get_pinned_mem () { @@ -45,6 +48,8 @@ set_pin_limit (int size) } #else int +#define PAGE_SIZE 10000*1024 /* unknown */ + get_pinned_mem () { return 0; @@ -58,12 +63,12 @@ set_pin_limit () #include <omp.h> -/* This should be large enough to cover multiple pages. */ -#define SIZE 10000*1024 - int main () { + /* This needs to be large enough to cover multiple pages. */ + const int SIZE = PAGE_SIZE*4; + /* Pinned memory, no fallback. */ const omp_alloctrait_t traits1[] = { { omp_atk_pinned, 1 }, diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c index d9cb8dfe1fd..534e49eefc4 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c @@ -2,15 +2,18 @@ /* Test that pinned memory fails correctly, pool_size code path. */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> #include <sys/resource.h> +#define PAGE_SIZE sysconf(_SC_PAGESIZE) + int get_pinned_mem () { @@ -45,6 +48,8 @@ set_pin_limit (int size) } #else int +#define PAGE_SIZE 10000*1024 /* unknown */ + get_pinned_mem () { return 0; @@ -58,12 +63,12 @@ set_pin_limit () #include <omp.h> -/* This should be large enough to cover multiple pages. */ -#define SIZE 10000*1024 - int main () { + /* This needs to be large enough to cover multiple pages. */ + const int SIZE = PAGE_SIZE*4; + /* Pinned memory, no fallback. */ const omp_alloctrait_t traits1[] = { { omp_atk_pinned, 1 }, diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c index 8355ca83790..315c7161a39 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c @@ -4,13 +4,23 @@ /* Test that ompx_pinned_mem_alloc works. */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> +#include <sys/resource.h> + +#define PAGE_SIZE sysconf(_SC_PAGESIZE) +#define CHECK_SIZE(SIZE) { \ + struct rlimit limit; \ + if (getrlimit (RLIMIT_MEMLOCK, &limit) \ + || limit.rlim_cur <= SIZE) \ + fprintf (stderr, "unsufficient lockable memory; please increase ulimit\n"); \ + } int get_pinned_mem () @@ -34,6 +44,9 @@ get_pinned_mem () abort (); } #else +#define PAGE_SIZE 1 /* unknown */ +#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n"); + int get_pinned_mem () { @@ -43,12 +56,13 @@ get_pinned_mem () #include <omp.h> -/* Allocate more than a page each time, but stay within the ulimit. */ -#define SIZE 10*1024 - int main () { + /* Allocate at least a page each time, but stay within the ulimit. */ + const int SIZE = PAGE_SIZE; + CHECK_SIZE (SIZE*3); + // Sanity check if (get_pinned_mem () != 0) abort (); diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-6.c b/libgomp/testsuite/libgomp.c/alloc-pinned-6.c index 80fd37ab875..bbe20c04875 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-6.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-6.c @@ -2,15 +2,18 @@ /* Test that ompx_pinned_mem_alloc fails correctly. */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> #include <sys/resource.h> +#define PAGE_SIZE sysconf(_SC_PAGESIZE) + int get_pinned_mem () { @@ -44,6 +47,8 @@ set_pin_limit (int size) abort (); } #else +#define PAGE_SIZE 10000*1024 /* unknown */ + int get_pinned_mem () { @@ -58,12 +63,12 @@ set_pin_limit () #include <omp.h> -/* This should be large enough to cover multiple pages. */ -#define SIZE 10000*1024 - int main () { + /* Allocate at least a page each time, but stay within the ulimit. */ + const int SIZE = PAGE_SIZE*4; + /* Ensure that the limit is smaller than the allocation. */ set_pin_limit (SIZE/2); diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-7.c b/libgomp/testsuite/libgomp.c/alloc-pinned-7.c index 6fd19b46a5c..8dc19055038 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-7.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-7.c @@ -5,11 +5,12 @@ /* Test that pinned memory works. */ +#include <stdio.h> +#include <stdlib.h> + #ifdef __linux__ #include <sys/types.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/mman.h> @@ -28,7 +29,6 @@ get_pinned_mem () int val; if (sscanf (buf, "VmLck: %d", &val)) { - printf ("lock %d\n", val); fclose (proc); return val; } @@ -47,9 +47,6 @@ get_pinned_mem () #include <omp.h> -/* Allocate more than a page each time, but stay within the ulimit. */ -#define SIZE 10*1024 - int main () {