From caad2e4f8207a32a0fc0d3350588ac693981eb7f Mon Sep 17 00:00:00 2001 From: Axiom Wang Date: Mon, 20 Jul 2026 14:28:30 +0000 Subject: [PATCH] use cmake for configuration and reorganize README to markdown format --- CMakeLists.txt | 122 +++++ README.md | 782 +++++++++++++++++++++++++++++++++ cmake/GasNetAtomics.cmake | 43 ++ cmake/GasNetCompiler.cmake | 282 ++++++++++++ cmake/GasNetConduit.cmake | 242 ++++++++++ cmake/GasNetConfig.cmake.in | 13 + cmake/GasNetConfigHeader.cmake | 306 +++++++++++++ cmake/GasNetDebugMalloc.cmake | 32 ++ cmake/GasNetInstall.cmake | 82 ++++ cmake/GasNetMembar.cmake | 24 + cmake/GasNetMemoryKinds.cmake | 40 ++ cmake/GasNetOptions.cmake | 141 ++++++ cmake/GasNetPSHM.cmake | 54 +++ cmake/GasNetPlatform.cmake | 166 +++++++ cmake/GasNetPthreads.cmake | 68 +++ cmake/GasNetTimer.cmake | 56 +++ cmake/gasnet_config.h.in | 184 ++++++++ conduits/CMakeLists.txt | 56 +++ conduits/ibv/CMakeLists.txt | 21 + conduits/mpi/CMakeLists.txt | 16 + conduits/ofi/CMakeLists.txt | 18 + conduits/smp/CMakeLists.txt | 8 + conduits/ucx/CMakeLists.txt | 18 + conduits/udp/CMakeLists.txt | 11 + extended-ref/CMakeLists.txt | 27 ++ other/CMakeLists.txt | 127 ++++++ tests/CMakeLists.txt | 105 +++++ 27 files changed, 3044 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 cmake/GasNetAtomics.cmake create mode 100644 cmake/GasNetCompiler.cmake create mode 100644 cmake/GasNetConduit.cmake create mode 100644 cmake/GasNetConfig.cmake.in create mode 100644 cmake/GasNetConfigHeader.cmake create mode 100644 cmake/GasNetDebugMalloc.cmake create mode 100644 cmake/GasNetInstall.cmake create mode 100644 cmake/GasNetMembar.cmake create mode 100644 cmake/GasNetMemoryKinds.cmake create mode 100644 cmake/GasNetOptions.cmake create mode 100644 cmake/GasNetPSHM.cmake create mode 100644 cmake/GasNetPlatform.cmake create mode 100644 cmake/GasNetPthreads.cmake create mode 100644 cmake/GasNetTimer.cmake create mode 100644 cmake/gasnet_config.h.in create mode 100644 conduits/CMakeLists.txt create mode 100644 conduits/ibv/CMakeLists.txt create mode 100644 conduits/mpi/CMakeLists.txt create mode 100644 conduits/ofi/CMakeLists.txt create mode 100644 conduits/smp/CMakeLists.txt create mode 100644 conduits/ucx/CMakeLists.txt create mode 100644 conduits/udp/CMakeLists.txt create mode 100644 extended-ref/CMakeLists.txt create mode 100644 other/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..0bd3aa6fe --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,122 @@ +#============================================================================= +# GASNet-EX CMake Build System +#============================================================================= +cmake_minimum_required(VERSION 3.16) + +#--------------------------------------------------------------------- +# Project definition +#--------------------------------------------------------------------- +project(GASNet + VERSION 2025.8.1 + DESCRIPTION "Global-Address Space Networking (GASNet-EX) communication system" + HOMEPAGE_URL "https://gasnet.lbl.gov" + LANGUAGES C CXX +) + +include(GNUInstallDirs) + +#--------------------------------------------------------------------- +# Version numbers (from configure.in) +#--------------------------------------------------------------------- +set(GASNET_RELEASE_VERSION_MAJOR 2025) +set(GASNET_RELEASE_VERSION_MINOR 8) +set(GASNET_RELEASE_VERSION_PATCH 1) + +set(GASNETEX_SPEC_VERSION_MAJOR 0) +set(GASNETEX_SPEC_VERSION_MINOR 19) + +set(GASNET_SPEC_VERSION_MAJOR 1) +set(GASNET_SPEC_VERSION_MINOR 8) + +set(GASNETT_SPEC_VERSION_MAJOR 1) +set(GASNETT_SPEC_VERSION_MINOR 20) + +set(GASNET_RELEASE_VERSION "${GASNET_RELEASE_VERSION_MAJOR}.${GASNET_RELEASE_VERSION_MINOR}.${GASNET_RELEASE_VERSION_PATCH}") + +#--------------------------------------------------------------------- +# CMake module path +#--------------------------------------------------------------------- +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +#--------------------------------------------------------------------- +# Build type and defaults +#--------------------------------------------------------------------- +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE) +endif() + +#--------------------------------------------------------------------- +# Installation paths +#--------------------------------------------------------------------- +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "/usr/local/gasnet" CACHE PATH "Install prefix" FORCE) +endif() + +#--------------------------------------------------------------------- +# Top-level options +#--------------------------------------------------------------------- +include(GasNetOptions) + +#--------------------------------------------------------------------- +# Platform and compiler detection +#--------------------------------------------------------------------- +include(GasNetPlatform) +include(GasNetCompiler) + +#--------------------------------------------------------------------- +# Feature detection +#--------------------------------------------------------------------- +include(GasNetPthreads) +include(GasNetAtomics) +include(GasNetTimer) +include(GasNetMembar) +include(GasNetDebugMalloc) + +#--------------------------------------------------------------------- +# PSHM support +#--------------------------------------------------------------------- +include(GasNetPSHM) + +#--------------------------------------------------------------------- +# Memory kinds support +#--------------------------------------------------------------------- +include(GasNetMemoryKinds) + +#--------------------------------------------------------------------- +# Generate gasnet_config.h +#--------------------------------------------------------------------- +include(GasNetConfigHeader) + +#--------------------------------------------------------------------- +# Build gasnet_tools library (conduit-independent) +#--------------------------------------------------------------------- +add_subdirectory(other) + +#--------------------------------------------------------------------- +# Build extended-ref library objects +#--------------------------------------------------------------------- +add_subdirectory(extended-ref) + +#--------------------------------------------------------------------- +# Build conduits +#--------------------------------------------------------------------- +add_subdirectory(conduits) + +#--------------------------------------------------------------------- +# Build tests +#--------------------------------------------------------------------- +if(GASNET_ENABLE_TESTS) + enable_testing() + # Tests disabled by default during CMake port - enable when conduit libs stabilize + # add_subdirectory(tests) +endif() + +#--------------------------------------------------------------------- +# Install +#--------------------------------------------------------------------- +include(GasNetInstall) diff --git a/README.md b/README.md new file mode 100644 index 000000000..f2254a360 --- /dev/null +++ b/README.md @@ -0,0 +1,782 @@ +# GASNet-EX Software Release + +GASNet-EX is the next generation of the GASNet-1 communication system. The GASNet interfaces are being redesigned to accommodate the emerging needs of exascale supercomputing, providing communication services to a variety of PGAS programming models on current and future HPC architectures. + +GASNet-EX is a work-in-progress. Many features remain to be specified, implemented, and/or tuned. + +Users interested in learning what's new in GASNet-EX are recommended to peruse the [ChangeLog](ChangeLog) for a summary of recent developments. The [GASNet-EX specification](docs/GASNet-EX.txt) provides more detailed information about the evolving EX specification. + +GASNet-EX notably includes a backwards-compatibility layer to assist in migration of current GASNet-1 client software. Existing GASNet clients can get started by relying on this layer (provided in `gasnet.h`), and incrementally add calls to the new `gex_*` interfaces (defined in `gasnetex.h`, which is automatically included by `gasnet.h`) to access new EX features and capabilities. For details, see [docs/gasnet1_differences.md](docs/gasnet1_differences.md). + +Feedback or questions on any matters related to the GASNet-EX project are welcomed at: [gasnet-devel@lbl.gov](mailto:gasnet-devel@lbl.gov) + +--- + +# README file for GASNet + +**https://gasnet.lbl.gov** + +This is a user manual for GASNet. Anyone planning on using GASNet (either directly or indirectly) should consult this file for usage instructions. + +## Other Documentation + +- In this README the "docs directory" means either `docs/` in the source directory or `${prefix}/share/doc/gasnet/` in an installation of GASNet. +- For GASNet licensing and usage terms, see [license.txt](license.txt). +- For documentation on a particular GASNet conduit, see the README file in the conduit directory (also installed as `README-` in the docs directory). +- For documentation on job spawning mechanisms, see the README file in the corresponding `other/*-spawner` directory (also installed as `README-*-spawner` in the docs directory). +- For documentation on the communication-independent GASNet-tools library, see [README-tools](README-tools). +- Additional information, including the GASNet specification and our bug tracking database, is available from [https://gasnet.lbl.gov](https://gasnet.lbl.gov). +- Anyone planning to modify or add to the GASNet code base should also read the developer documents, available in the GASNet git repository at [https://github.com/BerkeleyLab/gasnet/tree/develop](https://github.com/BerkeleyLab/gasnet/tree/develop): + - [README-devel](README-devel): GASNet design information and coding standards + - [README-git](README-git): Rules developers are expected to follow when committing + - [template-conduit](template-conduit/): A fill-in-the-blanks conduit code skeleton + +## Table of Contents + +1. [Introduction](#introduction) +2. [System Requirements](#system-requirements) +3. [Building and Installing GASNet](#building-and-installing-gasnet) +4. [Manual Control over Compile and Link Flags](#manual-control-over-compile-and-link-flags) +5. [Basic Usage Information](#basic-usage-information) +6. [Conduit Status](#conduit-status) +7. [Launching/Running GASNet Applications](#launchingrunning-gasnet-applications) +8. [Single-node Development Options](#single-node-development-options) +9. [Supported Platforms](#supported-platforms) +10. [Recognized Environment Variables](#recognized-environment-variables) +11. [GASNet exit](#gasnet-exit) +12. [GASNet Tracing & Statistical Collection](#gasnet-tracing--statistical-collection) +13. [GASNet Collectives](#gasnet-collectives) +14. [GASNet Debug Malloc Services](#gasnet-debug-malloc-services) +15. [GASNet inter-Process SHared Memory (PSHM)](#gasnet-inter-process-shared-memory-pshm) +16. [MPI Interoperability](#mpi-interoperability) +17. [Contact Info and Support](#contact-info-and-support) + +--- + +## Introduction + +GASNet is a language-independent, low-level networking layer that provides network-independent, high-performance communication primitives tailored for implementing parallel global address space SPMD languages and libraries such as UPC, UPC++, Co-Array Fortran, Legion, Chapel, and many others. The interface is primarily intended as a compilation target and for use by runtime library writers (as opposed to end users), and the primary goals are high performance, interface portability, and expressiveness. GASNet stands for "Global-Address Space Networking". + +The GASNet API is defined in the specification, which is included with this archive in `docs/`, and the definitive version is located on the GASNet webpage: + +> [https://gasnet.lbl.gov/](https://gasnet.lbl.gov/) + +This README accompanies the GASNet source distribution, which includes implementations of the GASNet API for various popular HPC and general-purpose network hardwares. We use the term **"conduit"** to refer to any complete implementation of the GASNet API which targets a specific network device or lower-level networking layer. A conduit is comprised of any required headers, source files and supporting libraries necessary to provide the functionality of the GASNet API to GASNet clients. This distribution additionally includes a library of communication-independent portability tools called the "GASNet tools", which are used in the conduit implementations and also made available to clients (see [README-tools](README-tools) for details). + +## System Requirements + +GASNet is extremely portable, and runs on most systems that are relevant to HPC production or development (and many that are not). + +The minimum system requirements are: + +- A POSIX-like environment, e.g. Linux or another version of Unix. + - For Mac systems, the free **Xcode command-line tools** from the Apple Store. + - For Windows systems one needs either of two options: + - The free **Cygwin** toolkit ([https://www.cygwin.com/](https://www.cygwin.com/)) + - **Windows 10 Subsystem for Linux (WSL)** ([docs](https://docs.microsoft.com/en-us/windows/wsl/)) +- **GNU make** (version 3.79 or newer) +- **Perl** (version 5.005 or newer) +- Standard Unix tools: `awk`, `sed`, `env`, `basename`, `dirname`, and a Bourne-compatible shell (e.g. bash) +- A **C compiler** with at least minimal C99 support + +We explicitly support most OS's, architectures and compilers in widespread use today. See the [Supported Platforms](#supported-platforms) section for details on systems we've recently validated. + +Most distributed-memory GASNet conduits have additional requirements, based on their interactions with network hardware and other implementation details. For example: + +- mpi-conduit requires an MPI-1.1 or newer compliant MPI implementation. +- udp-conduit requires POSIX socket libraries and a C++98 or newer compiler. + +See each conduit README for additional details on system requirements. + +## Building and Installing GASNet + +### Step 0 (optional): `./Bootstrap` + +Runs the autoconf tools to build a configure script (this can be done on any system and may already have been done for you). If you are keeping a copy of the GASNet sources in your own source control repository, please also see "Source Control and GASNet" in [README-devel](README-devel). + +### Step 1: `./configure (options)` + +Generate the Makefiles tailored to your system, creating a build tree in the current working directory. You can run configure from a different directory to place your build files somewhere other than inside the source tree (a nice option when maintaining several build trees on the same source tree). + +Any compiler flags required for correct operation on your system (e.g. to select the correct ABI) should be included in the values of `CC`, `CXX` and `MPI_CC`. For example to build 32-bit code when your gcc and g++ default to 64-bit: + +```sh +configure CC='gcc -m32' CXX='g++ -m32' MPI_CC='mpicc -m32' +``` + +or similarly, if you want libgasnet to contain debugging symbols: + +```sh +configure CC='gcc -g' CXX='g++ -g' # however also see --enable-debug, below +``` + +#### Useful configure options + +| Option | Description | +|--------|-------------| +| `--help` | Display all available configure options | +| `--prefix=/install/path` | Set the directory where GASNet will be installed | +| `--enable-debug` | Build GASNet in a debugging mode. Turns on C-level debugger options and enables extensive error and sanity checking system-wide, which is highly recommended for developing and debugging GASNet clients (but should **never** be used for performance testing). `--enable-debug` also implies `--enable-{trace,stats,debug-malloc}`, but these can still be selectively `--disable`'d. | +| `--enable-trace` | Turn on GASNet tracing (see [usage info below](#gasnet-tracing--statistical-collection)) | +| `--enable-stats` | Turn on GASNet statistical collection (see [usage info below](#gasnet-tracing--statistical-collection)) | +| `--enable-debug-malloc` | Use GASNet debugging malloc (see [usage info below](#gasnet-debug-malloc-services)) | +| `--enable-segment-{fast,large,everything}` | Select a GASNet segment configuration (see the GASNet spec for more info) | +| `--enable-pshm` | Build GASNet with inter-Process SHared Memory (PSHM) support. See [GASNet PSHM](#gasnet-inter-process-shared-memory-pshm) below. | +| `--with-max-segsize=` | Configure-time default value for `GASNET_MAX_SEGSIZE` | + +Configure will detect various interesting features about your system and compilers, including which GASNet conduits are supported. + +#### Cross-compilation + +For cross-compilation support, look for an appropriate cross configure script in `other/contrib/` and link it into your top-level source directory and invoke it in place of configure. Example for the Cray XC with slurm: + +```sh +cd +ln -s other/contrib/cross-configure-cray-xc-slurm . +cd +/cross-configure-cray-xc-slurm (configure_options) +``` + +#### Platform-specific recommendations + +**HPE Cray EX (Shasta) systems:** + +```sh +--with-cc=cc --with-cxx=CC --with-mpi-cc=cc +``` + +Additionally, exactly one of the following is recommended for ofi-conduit: +- Slingshot-10 (100Gbps) NICs: `--with-ofi-provider=verbs` +- Slingshot-11 (200Gbps) NICs: `--with-ofi-provider=cxi` +- BOTH NIC types: `--with-ofi-provider=generic` + +**Linux clusters with Omni-Path networks** (Intel or Cornelis Networks): + +```sh +--disable-ibv --enable-ofi --with-ofi-provider=psm2 +``` + +**Linux InfiniBand clusters with InfiniPath/True Scale HCAs:** + +```sh +--enable-mpi --disable-ibv --disable-ofi +``` + +### Step 2: `make all` + +Build the GASNet libraries. A number of other useful makefile targets are available from the top-level: + +| Command | Description | +|---------|-------------| +| `make {seq,par,parsync}` | Build the conduit libraries in a given mode | +| `make tests-{seq,par,parsync}` | Build all the GASNet tests in a given mode | +| `make run-tests-{seq,par,parsync}` | Build and run all the GASNet tests in a given mode | +| `make (run-)tests-installed-{seq,par,parsync}` | Use the installed library to build (and run) all the GASNet tests | +| `make run-tests` | Run whatever tests are already built in the conduit directories | +| `make run-tests TESTS="test1 test2..."` | Run specifically-listed tests that are already built | +| `make DO_WHAT=""` | Build selected makefile target in all supported conduit directories | + +Each conduit directory also has several useful makefile targets: + +| Command | Description | +|---------|-------------| +| `make {seq,par,parsync}` | Build the conduit libraries in a given mode | +| `make tests-{seq,par,parsync}` | Build the conduit tests in a given mode | +| `make testXXX` | Build just testXXX, in SEQ mode | +| `make testXXX-{seq,par,parsync}` | Build just testXXX, in a given mode | +| `make run-tests-{seq,par,parsync}` | Build and run the conduit tests in a given mode | +| `make run-tests TESTS="test1 test2..."` | Run specifically-listed tests in the conduit directory | +| `make run-testexit` | Build a script to run the testexit tester and run it | + +Manual compilation and linker flags can be augmented from the command-line: + +| Variable | Purpose | +|----------|---------| +| `MANUAL_CFLAGS=...` | Flags to add on the C compile | +| `MANUAL_CXXFLAGS=...` | Flags to add on the C++ compile | +| `MANUAL_MPICFLAGS=...` | Flags to add on the mpicc compile | +| `MANUAL_DEFINES=...` | Flags to add on all compiles | +| `MANUAL_LDFLAGS=...` | Linker flags to add | +| `MANUAL_LIBS=...` | Linker library flags to add | + +> **Note:** This feature should be used sparingly, as some flags can invalidate the results of tests performed at configure time. The preferred way to add arbitrary flags is in the `$CC`, `$CXX` and `$MPI_CC` variables passed to configure. + +Miscellaneous make variables: + +- `make SEPARATE_CC=1` — Build libgasnet using separate C compiler invocations +- `make KEEPTMPS=1` — Keep temporary files generated by the C compiler, if supported + +### Step 3 (optional): `make install` + +Install GASNet to the directory chosen at configure time. This will create an include directory with a sub-directory for each supported conduit, and a lib directory containing a library file for each supported conduit, as well as any supporting libraries. + +GASNet may also be used directly from the build directory, as a convenience to eliminate steps if you are making changes to GASNet or its configuration. + +## Manual Control over Compile and Link Flags + +As described in the previous section, the recommended mechanism for passing flags to the compilers used by GASNet is to include them in the definition of the compiler variable itself (e.g. `CC='gcc -m64'`). These will be followed on the command line by flags chosen by GASNet's configure script instead of using the standard `CFLAGS` and `CXXFLAGS` make variables. + +If there is a need to pass flags that override ones chosen by configure, then one may set `MANUAL_CFLAGS`, `MANUAL_CXXFLAGS` and `MANUAL_MPICFLAGS` on the `make` command line, and these are guaranteed to appear on the compilation command line after the ones chosen by configure. Additionally, `MANUAL_DEFINES` is provided to pass flags to all three compilers. + +Note that GASNet does not assume that `MPI_CC` is the same compiler as `CC` (though that is recommended), and therefore invokes it using a distinct `MANUAL_MPICFLAGS`, instead of `MANUAL_CFLAGS`. + +All of the `MANUAL_*` make variables described above are honored by the Makefile infrastructure used to build GASNet's libraries and tests. Additionally, the makefile fragments (next section) use these variables when compiling client code. + +## Basic Usage Information + +See the README for each GASNet conduit implementation for specific usage information, but generally client programs should `#include ` (and nothing else), and use the conduit-provided compilation settings. + +The best way to get the correct compiler flags for your GASNet client is to `include` the appropriate makefile fragment for the conduit and configuration you want in your Makefile, and use the variables it defines in the Makefile rules for your GASNet client code. + +**Example:** + +```makefile +include $(gasnet_prefix)/include/mpi-conduit/mpi-seq.mak + +.c.o: + $(GASNET_CC) $(GASNET_CPPFLAGS) $(GASNET_CFLAGS) -c -o $@ $< + +.cc.o: + $(GASNET_CXX) $(GASNET_CXXCPPFLAGS) $(GASNET_CXXFLAGS) -c -o $@ $< + +myprog: myprog.o + $(GASNET_LD) $(GASNET_LDFLAGS) -o $@ $< $(GASNET_LIBS) +``` + +### Variable breakdown + +| Variable | Content | +|----------|---------| +| `GASNET_CFLAGS` | `$(GASNET_OPT_CFLAGS) $(GASNET_MISC_CFLAGS)` | +| `GASNET_CPPFLAGS` | `$(GASNET_MISC_CPPFLAGS) $(GASNET_DEFINES) $(GASNET_INCLUDES)` | +| `GASNET_CXXFLAGS` | `$(GASNET_OPT_CXXFLAGS) $(GASNET_MISC_CXXFLAGS)` | +| `GASNET_CXXCPPFLAGS` | `$(GASNET_MISC_CXXCPPFLAGS) $(GASNET_DEFINES) $(GASNET_INCLUDES)` | + +Guidelines: +- `GASNET_[CC,CXX]` contain the configure-detected C and C++ compilers +- `GASNET_INCLUDES` contains only `-I` preprocessor flags +- `GASNET_DEFINES` contains only `-D` or `-U` preprocessor flags +- `GASNET_OPT_*` contain compiler-specific flags controlling the debug/opt level +- `GASNET_MISC_*` contain other needed compiler-specific compile-time flags +- `GASNET_LD` contains the compiler to use for linking +- `GASNET_LIBS` contains `-L` or `-l` link-time flags +- `GASNET_LDFLAGS` contains other needed link-time flags + +### Using GASNet with pkg-config + +As a convenience, the same variables are also available via the UNIX pkg-config utility. For example: + +```sh +pkg-config gasnet-udp-seq --variable=GASNET_CC +``` + +Complete example using pkg-config in a Makefile: + +```makefile +PKG_CONFIG_PATH = $(gasnet_prefix)/lib/pkgconfig +pkg = gasnet-udp-seq + +.c.o: + `pkg-config $(pkg) --variable=GASNET_CC` `pkg-config $(pkg) --cflags` -c -o $@ $< + +.cc.o: + `pkg-config $(pkg) --variable=GASNET_CXX` `pkg-config $(pkg) --variable=GASNET_CXXCPPFLAGS` \ + `pkg-config $(pkg) --variable=GASNET_CXXFLAGS` -c -o $@ $< + +myprog: myprog.o + `pkg-config $(pkg) --variable=GASNET_LD` -o $@ $< `pkg-config $(pkg) --libs` +``` + +## Conduit Status + +The GASNet distribution includes multiple complete implementations of the GASNet API targeting particular lower-level networking layers. Each of these implementations is called a **conduit**. The corresponding GASNet conduits can be loosely categorized as either **native** or **portable**. + +### Portable Conduits + +**smp-conduit** — SMP loopback (shared memory) +: The conduit of choice for GASNet operation within a single shared-memory node. Rigorously tested and supported on all current platforms. + +**udp-conduit** — UDP/IP (part of the TCP/IP protocol suite) +: The conduit of choice for GASNet over Ethernet, supported on any TCP/IP-compliant network. Rigorously tested over Ethernet and supported on most current platforms. + +**mpi-conduit** — MPI (Message Passing Interface) +: A portable implementation of GASNet over MPI-1.1 or later. Intended as a reference implementation for systems lacking native conduit support. Rigorously tested and supported on most current platforms. + +**ucx-conduit** — Unified Communication X framework \[EXPERIMENTAL\] +: GASNet over the Unified Communication X framework (UCX). This conduit is experimental, and is not yet carefully tuned for performance. It has only been validated on NVIDIA/Mellanox InfiniBand devices starting from ConnectX-5. + +**ofi-conduit** — Open Fabrics Interfaces (most providers) +: GASNet over the Open Fabrics Interface framework (libfabric). This conduit is functionally complete but not yet carefully tuned for performance. With the exception of Slingshot and Omni-Path networks (where ofi-conduit is either the best or only option and considered "native"), users are advised to use other conduits compatible with their hardware. + +### Native, High-Performance Conduits + +**ibv-conduit** — InfiniBand Verbs +: GASNet over the OpenFabrics Verbs API. Rigorously tested and supported over InfiniBand hardware on all supported systems. + +**ofi-conduit** — Open Fabrics Interfaces (select providers/networks) +: On **Slingshot** and **Omni-Path** networks, ofi-conduit is either the best or only option available. On only those systems, ofi-conduit is categorized as a native, high-performance conduit. + +## Launching/Running GASNet Applications + +Often, runtimes or frameworks which are clients of GASNet provide their own utilities for application launch (aka spawning). Users of such utilities should refer to their respective documentation. + +| Conduit | Spawning Mechanism | Documentation | +|---------|-------------------|---------------| +| smp | Conduit-specific | `smp-conduit/README` | +| udp | Multiple options | `udp-conduit/README` | +| mpi | MPI-based | `mpi-conduit/README`, `other/mpi-spawner/README` | +| ibv, ofi, ucx | ssh, MPI, or PMI | `*-conduit/README`, `other/ssh-spawner/README`, `other/mpi-spawner/README`, `other/pmi-spawner/README` | + +When installed, documents are located in `$prefix/share/doc/GASNet` as `README-[topic]`. + +## Single-node Development Options + +GASNet supports hardware configurations ranging from HPC supercomputers to individual workstations and laptops. The configure option `--enable-debug` is highly recommended for finding bugs when developing GASNet client code. + +### Option 1: smp-conduit +A pure shared-memory implementation — the fastest and easiest option. Works "out of the box" on common laptop, desktop, and workstation environments, including Linux, macOS, Windows with Cygwin, WSL, and Solaris. + +### Option 2: udp-conduit +By default a shared-memory implementation indistinguishable from smp-conduit. One can disable shared memory (`--disable-pshm` at configure time or `GASNET_SUPERNODE_MAXSIZE=1` at runtime) for more realistic multi-node behavior testing. + +### Option 3: mpi-conduit +If you have MPI installed, everything said for udp-conduit holds, with the addition of shared-memory communication via MPI internals, giving multi-node-like isolation at the GASNet level with shared-memory performance. + +## Supported Platforms + +Platforms where GASNet and Berkeley UPC have been successfully tested include: + +| Platform | Conduits | Notes | +|----------|----------|-------| +| Linux/x86-Ethernet/{gcc,clang}/32 | smp, mpi, udp | | +| Linux/x86-InfiniBand/gcc/32 | smp, mpi, udp, ibv | | +| Linux/x86/IntelC/32 | smp, mpi, udp | | +| Linux/x86/PortlandGroupC/32 | smp, mpi, udp | | +| Linux/x86_64-Ethernet/{gcc,clang,PGI}/{32,64} | smp, mpi, udp, ofi | | +| Linux/x86_64-InfiniBand/{gcc,clang,PathScale,NVHPC,IntelC,Intel oneAPI}/64 | smp, mpi, udp, ibv | | +| Linux/x86_64-Omni-Path/gcc/64 | smp, mpi, udp, ofi | | +| Linux/PowerPC-Ethernet/{gcc,clang}/{32,64} | smp, mpi, udp | | +| Linux/PPC64le/{gcc,clang,pgi,NVHPC,xlc}/64 | smp, mpi, udp, ibv | | +| Linux/MIPS/gcc/{32,n32,64} | smp, udp | # | +| FreeBSD/{x86,amd64}/{gcc,clang}/{32,64} | smp, mpi, udp | | +| OpenBSD/{x86,amd64}/{gcc,clang}/{32,64} | smp, mpi, udp | | +| NetBSD/{x86,amd64}/{gcc,clang}/{32,64} | smp, mpi, udp | | +| Solaris10/SPARC/gcc/{32,64} | smp, udp, mpi | | +| Solaris10/x86/gcc/{32,64} | smp, udp, mpi | | +| MSWindows-Cygwin/{x86,x86_64}/{gcc,clang}/{32,64} | smp, udp, mpi | OpenMPI | +| MSWindows10-Linux(WSL)/{gcc,clang}/64 | smp, udp, mpi | | +| macOS/{x86,x86_64}/{gcc,clang}/{32,64} | smp, udp, mpi | | +| macOS/AARCH64/{gcc,clang}/64 | smp, udp | # | +| CNL/Cray-XT/{gcc,PGI,PathScale,Intel}/64 | smp, mpi | & | +| CNL/HPE-Cray-EX/{gcc,Cray}/64 | smp, mpi, ofi | | +| Linux/AARCH64/{gcc,clang}/64 | smp, udp, mpi | | + +> **Legend:** +> - \# = We have not tested MPI but have no reasons to doubt that mpi-conduit would work. +> - & = System has not been tested in recent releases due to lack of access. Reports encouraged. +> - **BETA** = Support for this system is in beta state. + +### Supported Compilers + +| Compiler | Minimum Version | +|----------|----------------| +| GNU (gcc) | 3.0+ | +| LLVM (clang) | 3.6+ | +| Apple (Xcode) | 7.1+ | +| PGI (pgcc) | 11.0 to 20.4 | +| NVHPC | 20.9+ | +| Intel (icc) | 16+ | +| Intel oneAPI (icx) | 21+ | +| IBM XL (xlc) | 13+ | +| Cray (CCE) | 8.6+ | + +## Recognized Environment Variables + +In the following descriptions, a **Boolean** setting is one which accepts `1`, `y`, `yes` as TRUE and `0`, `n`, `no` as FALSE (all case-insensitive). + +### General Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_VERBOSEENV` | Output information about environment variable settings read by the conduit | +| `GASNET_FREEZE` | Pause and wait for a debugger to attach on startup | +| `GASNET_FREEZE_ON_ERROR` | Pause and wait for a debugger on any fatal errors or fatal signals | +| `GASNET_FREEZE_SIGNAL` | Signal name (e.g. `SIGINT`, `SIGUSR1`) to trigger freeze | +| `GASNET_TRACEFILE` | File name to receive trace output (see [Tracing](#gasnet-tracing--statistical-collection)) | +| `GASNET_TRACEMASK` | Types of trace messages to report | +| `GASNET_STATSFILE` | File name to receive statistical output | +| `GASNET_STATSMASK` | Types of statistics to collect and report | +| `GASNET_TRACEFLUSH` | Force file system flush after every trace write | +| `GASNET_TRACELOCAL` | Control whether local (loopback) trace messages are recorded | +| `GASNET_TRACENODES` | Nodes on which to generate tracing output | +| `GASNET_STATSNODES` | Nodes on which to generate statistical output | +| `GASNET_TEST_POLITE_SYNC` | Enable polite-mode synchronization for tests | + +### Segment & Memory Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_MAX_SEGSIZE` | Upper limit for FAST/LARGE segment size. Format: `size_spec ( / opt_suffix )` where size is an absolute memory size (`[0-9]+{KB,MB,GB}`) or fraction of physical memory (`0.85`). Suffix `P` = per-process, `H` = host-wide. Default: `"0.85/H"` | +| `GASNET_DISABLE_MUNMAP` | Disable mmap-based allocation for satisfying malloc (workaround for firehose bug 495) | +| `GASNET_USE_HUGEPAGES` | Enable/disable use of huge pages. Default: `1` if `HUGETLB_DEFAULT_PAGE_SIZE` is set, `0` otherwise | + +### Thread & Process Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_MAX_THREADS` | Per-node limit on GASNet client pthreads in PAR/PARSYNC modes | +| `GASNET_SUPERNODE_MAXSIZE` | Maximum number of processes grouped into a shared-memory supernode (0 = no limit) | +| `GASNET_USE_PSHM_SINGLETON` | Control shared memory use in singleton neighborhoods (default: `0`) | +| `GASNET_PSHM_BARRIER_HIER` | Enable/disable hierarchical shared-memory barrier (default: enabled) | + +### Barrier Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_BARRIER` | Barrier algorithm: `AMDISSEM`, `RDMADISSEM`, `DISSEM` (auto, default), or `AMCENTRAL` (debug) | +| `GASNET_PSHM_BARRIER_RADIX` | Radix for intra-node barrier tree (default: `0` = linear) | +| `GASNET_PSHM_NETWORK_DEPTH` | Depth of intra-node AM network (default: `32`, minimum: `4`) | + +### Error Handling & Diagnostics + +| Variable | Description | +|----------|-------------| +| `GASNET_CATCH_EXIT` | Set to `0` to prevent GASNet from forcing global job termination on `exit()` | +| `GASNET_NO_CATCH_SIGNAL` | Comma-separated list of signals to exclude from default handling | +| `GASNET_BACKTRACE` | Generate stack backtraces on most fatal errors | +| `GASNET_BACKTRACE_NODES` | Nodes on which to permit backtraces (e.g. `"0,2-4,6"`) | +| `GASNET_BACKTRACE_SIGNAL` | Signal to trigger an immediate backtrace | +| `GASNET_BACKTRACE_TYPE` | Ordered list of backtrace mechanisms to try | +| `GASNET_BACKTRACE_MT` | Enable multi-threaded backtraces | +| `GASNET_FS_SYNC` | Enable `sync()` call at exit time (default: `0`) | + +### VIS & Collective Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_VIS_AMPIPE` | Enable AM pipelining for non-contiguous put/gets | +| `GASNET_VIS_{PUT,GET}_MAXCHUNK` | Max contiguous chunk size for AM pipelining | +| `GASNET_VIS_MAXCHUNK` | Default for `GASNET_VIS_{PUT,GET}_MAXCHUNK` | +| `GASNET_VIS_REMOTECONTIG` | Enable pack & RDMA for gather puts and scatter gets | +| `GASNET_COLL_SCRATCH_SIZE` | Scratch space size per rank for collectives (default: 2MB) | +| `GASNET_COLL_ENABLE_SEARCH` | Enable autotuning of collectives | +| `GASNET_COLL_TUNING_FILE` | File for collective autotuning data | + +### Debug Settings (debug build only) + +| Variable | Description | +|----------|-------------| +| `GASNET_SD_INIT` | Initialize buffers at Prepare time with canary (default: `1` in debug) | +| `GASNET_SD_INITVAL` | Initialization pattern (default: `"NAN"`) | +| `GASNET_SD_INITLEN` | Length of canary pattern (default: `128`) | + +### Networking & Topology Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_HOST_DETECT` | Host identifier: `"gethostid"`, `"hostname"`, or `"conduit"` | +| `GASNET_NODEMAP_EXACT` | Enable exact algorithm for shared-memory node discovery (default: `1`) | +| `GASNET_SPAWN_VERBOSE` | Enable console debugging of job creation/teardown | +| `GASNET_TMPDIR` | Directory for temporary files | + +### Exit-Timeout Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_EXITTIMEOUT` | Exit-coordination timeout value | +| `GASNET_EXITTIMEOUT_MAX` | Maximum exit timeout | +| `GASNET_EXITTIMEOUT_MIN` | Minimum exit timeout | +| `GASNET_EXITTIMEOUT_FACTOR` | Per-node factor for timeout computation | + +Formula: `GASNET_EXITTIMEOUT = min(MAX, MIN + nodes * FACTOR)` + +### Thread Stack Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_THREAD_STACK_MIN` | Minimum stack size for internal threads | +| `GASNET_THREAD_STACK_PAD` | Padding added to default stack size | + +Formula: `stack_size = MAX(MIN, PAD + default)` + +### Topology-Aware Environment Variables + +Some conduits are capable of applying intelligence to NIC selection based on job and host topology: + +- ibv-conduit: `GASNET_IBV_PORTS_TYPE` (default: `"Socket"`) +- ofi-conduit: `GASNET_OFI_DEVICE_TYPE` (default: `"Socket"`) + +Valid types name either a GASNet-defined property or hwloc-defined object type: + +| Type | Description | +|------|-------------| +| `JRank` | Process's jobrank | +| `HRank` | Process's host-relative rank | +| `NRank` | Process's nbrhd-relative rank | +| `Core` | CPU core(s) to which process is bound | +| `Node` / `NUMANode` | NUMA node(s) to which process is bound | +| `Socket` / `Package` | CPU package(s) to which process is bound | + +Each process uses its type value to construct a computed variable name like `[BASE]_0`, `[BASE]_0_2`, etc. Arithmetic operations `/[N]` (division) and `%[N]` (modulo) can be appended after the type. + +### HWLOC Query Settings + +| Variable | Description | +|----------|-------------| +| `GASNET_HWLOC_QUERY` | `"thread"` (uses `HWLOC_CPUBIND_THREAD`, default) or `"process"` (uses `HWLOC_CPUBIND_PROCESS`) | + +See conduit-specific documentation in conduit directories for more settings. + +## GASNet exit + +GASNet clients desiring robustness and portability should **not** call `_exit()`. Normal process termination should be done using `gasnet_exit()`, `exit()` or return from `main()`. Use of these paths allows GASNet to ensure proper shutdown, including efforts to avoid zombie/orphan processes and proper release of network resources. + +## GASNet Tracing & Statistical Collection + +GASNet includes an extensive tracing and statistical collection utility. To use: + +```sh +configure --enable-stats --enable-trace # or --enable-debug +``` + +Then set the environment variables below. + +> **Performance note:** System performance is likely to be degraded even when output is disabled. Production builds should not enable tracing/stats at configure time. + +### Tracing Environment Variables + +| Variable | Description | +|----------|-------------| +| `GASNET_TRACEFILE` | File name to receive trace output (also `"stdout"` or `"stderr"`). `%` replaced by node number at runtime (e.g. `"mytrace-%"`). Unset/empty disables output. | +| `GASNET_TRACENODES` | Optional list of nodes to generate tracing output (e.g. `"0,2-4,6"`). `*` = all. | +| `GASNET_STATSFILE` | File name for statistical output (operates analogously to `GASNET_TRACEFILE`) | +| `GASNET_STATSNODES` | Limit nodes for statistical output (analogous to `GASNET_TRACENODES`) | +| `GASNET_TRACEMASK` | Types of trace messages to report | +| `GASNET_STATSMASK` | Types of statistics to collect and report | +| `GASNET_TRACEFLUSH` | Force file system flush after every write to tracefile | +| `GASNET_TRACELOCAL` | Control recording of local (loopback) put/get operations | + +### Trace/Stats Mask Letters + +| Letter | Event Type | +|--------|-----------| +| `G` | Gets | +| `P` | Puts | +| `R` | Remote atomics | +| `S` | Non-blocking synchronization | +| `W` | Collective operations (excluding barriers) | +| `B` | Barriers | +| `L` | Locks | +| `A` | AM requests/replies (and handler execution) | +| `X` | AMPoll | +| `I` | Informational messages / performance alerts | +| `O` | Object creation, modification and destruction | +| `C` | Conduit-specific (low-level) messages | +| `D` | Detailed message data for gets/puts/AMreqrep | +| `N` | Line number information from client source files | +| `H` | High-level messages from the client | +| `U` | Unsuppressable messages (always output — use with caution) | + +Use `^` as the first character to invert the mask (e.g. `"^X"` enables all except AMPoll). + +## GASNet Collectives + +GASNet includes interfaces for collective operations. The design for the interfaces is located in `docs/collective_notes.txt`. Anyone planning to implement a client that uses these collectives should contact us first at [gasnet-devel@lbl.gov](mailto:gasnet-devel@lbl.gov). + +GASNet introduces a mechanism for auto-tuning of collectives in which a variety of algorithms are tried for each collective operation and the best choice can be recorded in a file for use in future runs. For more information, see the file `autotuner.txt` in the docs directory. + +## GASNet Debug Malloc Services + +GASNet includes a debug malloc implementation for finding local heap corruption bugs. To use: + +```sh +configure --enable-debug-malloc # or --enable-debug +``` + +GASNet will regularly scan the heap for corruption at malloc events and AMPoll's and report any detected problems. Client writers can use `gasnett_debug_malloc` functions in `gasnet_tools.h` to tie into these services. + +> **Note:** The debug malloc implementation imposes CPU and memory consumption overhead relative to the system malloc implementation. + +### Debug Malloc Environment Variables + +| Variable | Description | +|----------|-------------| +| `GASNET_MALLOC_INIT` | Initialize every byte of allocated memory to `GASNET_MALLOC_INITVAL` | +| `GASNET_MALLOC_CLOBBER` | Overwrite every byte of freed memory with `GASNET_MALLOC_CLOBBERVAL` | +| `GASNET_MALLOC_INITVAL` | Value for allocation init: decimal, hex (`0x...`), `NAN`, `sNAN`, or `qNAN` (default: `"NAN"`) | +| `GASNET_MALLOC_CLOBBERVAL` | Value for free clobbering (same format, default: `"NAN"`) | +| `GASNET_MALLOC_LEAKALL` | Leak all freed objects (don't re-allocate) | +| `GASNET_MALLOC_SCANFREED` | Scan freed objects for write-after-free errors (implies LEAKALL + CLOBBER) | +| `GASNET_MALLOC_EXTRACHECK` | More frequent corruption checking (costs performance) | +| `GASNET_MALLOCFILE` | File to receive malloc report at process exit (also `"stdout"`, `"stderr"`) | +| `GASNET_MALLOCNODES` | Limit which nodes generate malloc reports | + +## GASNet inter-Process SHared Memory (PSHM) + +GASNet's PSHM support provides mechanisms to communicate through shared memory among processes on the same compute node. Inter-process communication through shared memory is usually the fastest way for co-located processes to communicate. + +PSHM support is **enabled by default** unless cross-compiling or running Cygwin prior to version 2.0. It can be disabled with `--disable-pshm` at configure time. The environment variable `GASNET_SUPERNODE_MAXSIZE` limits the number of processes grouped into a shared-memory "supernode" (set to `1` to disable shared memory at runtime). + +### PSHM Mechanisms + +The PSHM support can operate via three generic mechanisms: + +1. **POSIX shared memory** — Recommended as the best option in most cases +2. **SystemV shared memory** — Next-best option; default on Solaris +3. **mmap()ed disk files** — Fallback; may have significant performance degradation + +| Usage | Flags | +|-------|-------| +| OFF | `--disable-pshm` | +| POSIX | no flags required (default except cross-compiling) | +| SYSV | `--disable-pshm-posix --enable-pshm-sysv` | +| FILE | `--disable-pshm-posix --enable-pshm-file` | + +Unless PSHM is disabled, configure probes for support via exactly one preferred mechanism (POSIX on most platforms, SystemV on Solaris). If the preferred mechanism is not supported, there is **no automatic fallback** — you must explicitly disable the default and enable the desired mechanism. + +#### Platform-Specific Mechanisms + +- **Cray XE, XK, XC**: PSHM-over-XPMEM enabled automatically by cross-configure scripts +- **SGI Altix**: `--enable-pshm --disable-pshm-posix --enable-pshm-xpmem` +- **Linux hugetlbfs** (experimental): `--disable-pshm-posix --enable-pshm-hugetlbfs` + +### System Settings for POSIX Shared Memory + +On most systems, POSIX shared memory allocations reside in a pseudo-filesystem (tmpfs, mfs, etc.). Insufficient space leads to startup failures or SIGBUS/SIGSEGV later. + +| Platform | Location | Configuration | +|----------|----------|---------------| +| Linux | `/dev/shm` (tmpfs) | Distribution-specific; may not respect `/etc/fstab` | +| macOS | No settings required | Default is sufficient | +| FreeBSD | `/tmp` (tmpfs) | Sized in `/etc/fstab` via `tmpfs(5)` | +| NetBSD | `/var/shm` (tmpfs) | Sized in `/etc/fstab` via `mount_tmpfs(8)` | +| OpenBSD | `/tmp` (mfs) | Sized in `/etc/fstab` via `mount_mfs(8)` | + +### System Settings for SystemV Shared Memory + +Controlled by kernel parameters: `shmmax` (max segment size), `shmall` (total allocatable memory in pages), `shmmni` (max number of segments). + +Configuration examples for 64-bit systems (add to `/etc/sysctl.conf`): + +**Linux:** +``` +kernel.shmmax=1099511627776 +kernel.shmall=268435456 +kernel.shmmni=128 +``` + +**macOS:** +``` +kern.sysv.shmmax=1099511627776 +kern.sysv.shmall=268435456 +kern.sysv.shmmni=128 +``` + +**FreeBSD:** +``` +kern.ipc.shmmax=1099511627776 +kern.ipc.shmall=268435456 +``` + +For 32-bit systems, use `2147483647` for `shmmax` to avoid potential overflow. + +### macOS Warning + +There is evidence of a kernel bug in all releases of macOS through at least 10.12 (Sierra) which leads to a small leak of kernel memory each time POSIX or SystemV shared memory is used. In normal usage, reboots for software updates happen frequently enough that this leak will not impact normal users. + +### Cleaning PSHM Objects + +If a GASNet application using PSHM is terminated before the initialization phase completes, shared memory objects may remain in the system: + +| Type | Location | Prefix | Cleanup Command | +|------|----------|--------|----------------| +| POSIX (Linux) | `/dev/shm` | `GASNT` | `rm` | +| POSIX (Cygwin) | `/dev/shm` | `GASNT` | `rm` | +| POSIX (Solaris) | `/tmp` | `.SHMDGASNT` | `rm` | +| POSIX (OpenBSD) | `/tmp` | random `.shm` suffix | `rm` | +| POSIX (NetBSD) | `/var/shm` | `.shmobj_GASNT` | `rm` | +| mmap'd files | `$TMPDIR` or `/tmp` | `GASNT` | `rm` | +| hugetlbfs | hugetlbfs mount (`/dev/hugepages`) | — | `rm` | +| SystemV | System-wide | — | `ipcs` / `ipcrm` | + +## MPI Interoperability + +GASNet is **compatible** with MPI — both can be used together within the same network and even within the same program. GASNet does NOT use MPI for performing communication (except mpi-conduit), but may use MPI to assist in job creation and termination. + +### Initialization Protocol + +MPI requires exactly one initialization call before MPI communication can be used. Since GASNet may or may not automatically initialize MPI depending on the conduit and configuration, processes using both must be prepared to handle either situation: + +```c +int isMPIinit; +int main(int argc, char **argv) { + size_t segment_size = 64*1024*1024; /* want 64MB segment */ + size_t segment_max; + + gasnet_init(&argc, &argv); + + segment_max = gasnet_getMaxGlobalSegmentSize(); + if (segment_size > segment_max) segment_size = segment_max; + + gasnet_attach(NULL, 0, segment_size, 0); + + gasnet_barrier_notify(0, GASNET_BARRIERFLAG_ANONYMOUS); + gasnet_barrier_wait(0, GASNET_BARRIERFLAG_ANONYMOUS); + + if (MPI_Initialized(&isMPIinit) != MPI_OK) { + fprintf(stderr, "Error calling MPI_Initialized()\n"); + abort(); + } + if (!isMPIinit) MPI_Init(argc, argv); /* MPI not init, so do it */ + + /* ... use MPI as usual ... */ + MPI_Barrier(MPI_COMM_WORLD); + /* ... use GASNet as usual ... */ + gasnet_barrier_notify(0, GASNET_BARRIERFLAG_ANONYMOUS); + gasnet_barrier_wait(0, GASNET_BARRIERFLAG_ANONYMOUS); + + if (!isMPIinit) MPI_Finalize(); + return 0; +} +``` + +An extensive example is available in `tests/testmpi.c`. + +### Time-Phasing Protocol + +To prevent deadlock when interleaving MPI and GASNet communication, follow this protocol: + +1. When starting, the first MPI or GASNet call from any node puts the application in **MPI mode** or **GASNet mode** respectively. +2. To switch from MPI to GASNet: execute `MPI_Barrier()` as the last MPI call before any GASNet communication. +3. To switch from GASNet to MPI: execute `gasnet_barrier_notify()` + `gasnet_barrier_wait()` as the last GASNet operations before any MPI calls. + +### Important Caveats + +- GASNet must be configured with `MPI_CC` set to the **exact same** MPI installation used by client code. +- GASNet and MPI both number processes with a unique non-negative index. Every attempt is made to ensure this numbering matches, but clients should use a collective (e.g. AllGather) to build a translation table for portability. +- GASNet language clients using pthreads should ensure they use a **pthread-safe** implementation of MPI. +- See each conduit README for network-specific MPI interoperability discussion. + +## Contact Info and Support + +For the latest GASNet downloads, publications, and specifications: + +> [https://gasnet.lbl.gov](https://gasnet.lbl.gov) + +For bug reports and feature requests, please submit a ticket in the GASNet Bugzilla: + +> [https://gasnet-bugs.lbl.gov](https://gasnet-bugs.lbl.gov) + +**Mailing lists:** + +| List | Purpose | +|------|---------| +| [gasnet-users@lbl.gov](mailto:gasnet-users@lbl.gov) | General questions or inquiries regarding installation or use of GASNet | +| [gasnet-devel@lbl.gov](mailto:gasnet-devel@lbl.gov) | GASNet developers list (multi-institution) | +| [gasnet-announce@lbl.gov](mailto:gasnet-announce@lbl.gov) | GASNet release announcements | + +--- + +> The canonical version of this document is located at: [https://github.com/BerkeleyLab/gasnet/blob/main/README](https://github.com/BerkeleyLab/gasnet/blob/main/README) +> +> For more information, please email: [gasnet-users@lbl.gov](mailto:gasnet-users@lbl.gov) or visit the GASNet home page at: [https://gasnet.lbl.gov](https://gasnet.lbl.gov) diff --git a/cmake/GasNetAtomics.cmake b/cmake/GasNetAtomics.cmake new file mode 100644 index 000000000..76feda95a --- /dev/null +++ b/cmake/GasNetAtomics.cmake @@ -0,0 +1,43 @@ +#============================================================================= +# GasNetAtomics.cmake - Atomic operations detection +#============================================================================= +# Values from gasnet_atomic_fwd.h: +# GASNETI_ATOMIC_IMPL_GENERIC=0, NATIVE=1, OS=2, SYNC=3, HYBRID=4, SPECIAL=5 +include(CheckCSourceCompiles) + +# Force options override +if(GASNET_FORCE_GENERIC_ATOMICOPS) + set(GASNETI_ATOMIC_IMPL_CONFIGURE 0) + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 0) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 0) + return() +endif() +if(GASNET_FORCE_OS_ATOMICOPS) + set(GASNETI_ATOMIC_IMPL_CONFIGURE 2) + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 2) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 2) + return() +endif() +if(GASNET_FORCE_COMPILER_ATOMICOPS) + set(GASNETI_ATOMIC_IMPL_CONFIGURE 3) + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 3) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 3) + return() +endif() + +# Choose best: NATIVE for known architectures with GCC/Clang, else SYNC, else GENERIC +if(GASNETI_HAVE_CC_GCC_ASM AND (GASNET_PLATFORM_ARCH STREQUAL "X86_64" OR + GASNET_PLATFORM_ARCH STREQUAL "X86" OR GASNET_PLATFORM_ARCH STREQUAL "AARCH64" OR + GASNET_PLATFORM_ARCH STREQUAL "PPC64" OR GASNET_PLATFORM_ARCH STREQUAL "ARM")) + set(GASNETI_ATOMIC_IMPL_CONFIGURE 1) # NATIVE + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 1) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 1) +elseif(GASNETI_HAVE_CC_SYNC_ATOMICS_32) + set(GASNETI_ATOMIC_IMPL_CONFIGURE 3) # SYNC + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 3) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 3) +else() + set(GASNETI_ATOMIC_IMPL_CONFIGURE 0) # GENERIC + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 0) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 0) +endif() diff --git a/cmake/GasNetCompiler.cmake b/cmake/GasNetCompiler.cmake new file mode 100644 index 000000000..f92c0faeb --- /dev/null +++ b/cmake/GasNetCompiler.cmake @@ -0,0 +1,282 @@ +#============================================================================= +# GasNetCompiler.cmake - Compiler detection and feature probing for GASNet +# +# GASNet probes THREE compilers independently (CC, CXX, MPI_CC) and +# cross-references their detected features at compile time via gasnet_basic.h. +#============================================================================= + +include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) +include(CheckIncludeFile) + +#--------------------------------------------------------------------- +# Compiler identification - map CMake compiler ID to GASNet family +#--------------------------------------------------------------------- +function(gasnet_detect_compiler_family lang_var family_var subfamily_var) + if(CMAKE_${lang_var}_COMPILER_ID STREQUAL "GNU") + set(${family_var} "GNU" PARENT_SCOPE) + set(${subfamily_var} "" PARENT_SCOPE) + elseif(CMAKE_${lang_var}_COMPILER_ID STREQUAL "Clang" OR CMAKE_${lang_var}_COMPILER_ID STREQUAL "AppleClang") + set(${family_var} "Clang" PARENT_SCOPE) + if(CMAKE_${lang_var}_COMPILER_ID STREQUAL "AppleClang") + set(${subfamily_var} "APPLE" PARENT_SCOPE) + else() + set(${subfamily_var} "" PARENT_SCOPE) + endif() + elseif(CMAKE_${lang_var}_COMPILER_ID STREQUAL "Intel" OR CMAKE_${lang_var}_COMPILER_ID STREQUAL "IntelLLVM") + set(${family_var} "Intel" PARENT_SCOPE) + set(${subfamily_var} "" PARENT_SCOPE) + elseif(CMAKE_${lang_var}_COMPILER_ID STREQUAL "PGI" OR CMAKE_${lang_var}_COMPILER_ID STREQUAL "NVHPC") + set(${family_var} "NVHPC" PARENT_SCOPE) + set(${subfamily_var} "" PARENT_SCOPE) + else() + set(${family_var} "Unknown" PARENT_SCOPE) + set(${subfamily_var} "" PARENT_SCOPE) + endif() +endfunction() + +gasnet_detect_compiler_family("C" CC_FAMILY CC_SUBFAMILY) +gasnet_detect_compiler_family("CXX" CXX_FAMILY CXX_SUBFAMILY) + +#--------------------------------------------------------------------- +# Platform compiler identity (must match gasnet_portable_platform.h) +# In the current version, PLATFORM_COMPILER_ID == PLATFORM_COMPILER_FAMILYID +#--------------------------------------------------------------------- +if(CC_FAMILY STREQUAL "GNU") + set(GASNET_CC_FAMILYID 1) +elseif(CC_FAMILY STREQUAL "Intel") + set(GASNET_CC_FAMILYID 2) +elseif(CC_FAMILY STREQUAL "NVHPC") + set(GASNET_CC_FAMILYID 4) +elseif(CC_FAMILY STREQUAL "XLC") + set(GASNET_CC_FAMILYID 5) +elseif(CC_FAMILY STREQUAL "Sun") + set(GASNET_CC_FAMILYID 7) +elseif(CC_FAMILY STREQUAL "Cray") + set(GASNET_CC_FAMILYID 10) +elseif(CC_FAMILY STREQUAL "Clang") + set(GASNET_CC_FAMILYID 19) +else() + set(GASNET_CC_FAMILYID 1) +endif() +set(GASNET_CC_PLATFORM_ID ${GASNET_CC_FAMILYID}) + +if(CXX_FAMILY STREQUAL "GNU") + set(GASNET_CXX_FAMILYID 1) +elseif(CXX_FAMILY STREQUAL "Clang") + set(GASNET_CXX_FAMILYID 19) +else() + set(GASNET_CXX_FAMILYID 1) +endif() +set(GASNET_CXX_PLATFORM_ID ${GASNET_CXX_FAMILYID}) + +#--------------------------------------------------------------------- +# Extract actual compiler version from gasnet_portable_platform.h +# We use try_run because the version encoding differs per compiler family +#--------------------------------------------------------------------- +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cmake_try/plat_ver.c" +"#include +#include \"${PROJECT_SOURCE_DIR}/other/gasnet_portable_platform.h\" +int main(void) { + FILE *f = fopen(\"${CMAKE_CURRENT_BINARY_DIR}/cmake_try/plat_ver.txt\", \"w\"); + fprintf(f, \"%d\\n%d\\n\", (int)PLATFORM_COMPILER_VERSION, (int)PLATFORM_COMPILER_FAMILYID); + fclose(f); + return 0; +} +") + +try_run(GASNET_PLAT_VER_RUN GASNET_PLAT_VER_COMPILE + "${CMAKE_CURRENT_BINARY_DIR}/cmake_try" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_try/plat_ver.c" + COMPILE_OUTPUT_VARIABLE _plat_out +) + +if(GASNET_PLAT_VER_COMPILE AND GASNET_PLAT_VER_RUN EQUAL 0) + file(READ "${CMAKE_CURRENT_BINARY_DIR}/cmake_try/plat_ver.txt" _plat_ver) + string(REGEX MATCH "^([0-9]+)" _vm "${_plat_ver}") + set(GASNET_CC_VERSION "${CMAKE_MATCH_1}") + if(NOT GASNET_CC_VERSION) + set(GASNET_CC_VERSION 0) + endif() +else() + set(GASNET_CC_VERSION 0) + message(WARNING "Cannot extract PLATFORM_COMPILER_VERSION; compilation may fail") +endif() +set(GASNET_CXX_VERSION ${GASNET_CC_VERSION}) + +#--------------------------------------------------------------------- +# C99 feature support +#--------------------------------------------------------------------- +check_c_source_compiles(" + int main(void) { + // C++/C99 comment + for (int i = 0; i < 10; i++) { int x = i; } + long long ll = 0x1234567812345678LL + 0x8765432187654321ULL; + return (int)ll; + } +" GASNET_C99_SUBSET_OK) + +if(NOT GASNET_C99_SUBSET_OK) + message(FATAL_ERROR "C compiler does not support GASNet-required ISO C99 subset") +endif() + +# __VA_ARGS__ support (required for gasnet_ammacros.h) +check_c_source_compiles(" + #define GASNETI_AMNUMARGS(...) GASNETI_AMNUMARGS_(__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0) + #define GASNETI_AMNUMARGS_(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,N,...) N + int b[GASNETI_AMNUMARGS(1)+1]; + int c[GASNETI_AMNUMARGS(1,2)+1]; + int d[GASNETI_AMNUMARGS(1,2,3)+1]; + int main(void) { return b[0] + c[0] + d[0]; } +" GASNET_VA_ARGS_OK) + +if(NOT GASNET_VA_ARGS_OK) + message(FATAL_ERROR "C compiler does not support __VA_ARGS__") +endif() + +#--------------------------------------------------------------------- +# Inline assembly support +#--------------------------------------------------------------------- +check_c_source_compiles(" + int main(void) { + __asm__ __volatile__ (\"nop\" : : : \"memory\"); + return 0; + } +" GASNETI_HAVE_CC_GCC_ASM) + +check_cxx_source_compiles(" + int main() { + __asm__ __volatile__ (\"nop\" : : : \"memory\"); + return 0; + } +" GASNETI_HAVE_CXX_GCC_ASM) + +#--------------------------------------------------------------------- +# Compiler builtins +#--------------------------------------------------------------------- +check_c_source_compiles(" + int main(void) { int x = 0; if (__builtin_expect(x, 0)) return 1; return 0; } +" GASNETI_HAVE_CC_BUILTIN_EXPECT) + +check_c_source_compiles(" + int main(void) { int x = 1; if (__builtin_constant_p(x)) return 1; return 0; } +" GASNETI_HAVE_CC_BUILTIN_CONSTANT_P) + +check_c_source_compiles(" + int main(void) { char buf[64]; __builtin_prefetch(buf); return 0; } +" GASNETI_HAVE_CC_BUILTIN_PREFETCH) + +check_c_source_compiles(" + int main(void) { __builtin_unreachable(); return 0; } +" GASNETI_HAVE_CC_BUILTIN_UNREACHABLE) + +check_c_source_compiles(" + unsigned int bswap32(unsigned int x) { return __builtin_bswap32(x); } + int main(void) { return bswap32(0x12345678); } +" GASNETI_HAVE_CC_BUILTIN_BSWAP32) + +check_c_source_compiles(" + unsigned long long bswap64(unsigned long long x) { return __builtin_bswap64(x); } + int main(void) { return (int)bswap64(0x1234567812345678ULL); } +" GASNETI_HAVE_CC_BUILTIN_BSWAP64) + +check_c_source_compiles(" + int main(void) { return __builtin_clz(1) + __builtin_clzl(1L) + __builtin_clzll(1LL); } +" GASNETI_HAVE_CC_BUILTIN_CLZ) + +check_c_source_compiles(" + int main(void) { return __builtin_ctz(2) + __builtin_ctzl(2L) + __builtin_ctzll(2LL); } +" GASNETI_HAVE_CC_BUILTIN_CTZ) + +# C99 format specifiers +check_c_source_compiles(" + #include + #include + int main(void) { uint64_t x = 0; printf(\"%\" PRIu64, x); return 0; } +" HAVE_C99_FORMAT_SPECIFIERS) + +#--------------------------------------------------------------------- +# __sync atomics support +#--------------------------------------------------------------------- +check_c_source_compiles(" + int main(void) { + int x = 0; + return __sync_bool_compare_and_swap(&x, 0, 1) ? __sync_fetch_and_add(&x, 1) : 0; + } +" GASNETI_HAVE_CC_SYNC_ATOMICS_32) + +check_c_source_compiles(" + int main(void) { + long long x = 0; + return __sync_bool_compare_and_swap(&x, 0LL, 1LL) ? (int)__sync_fetch_and_add(&x, 1LL) : 0; + } +" GASNETI_HAVE_CC_SYNC_ATOMICS_64) + +check_c_source_compiles(" + int main(void) { __sync_synchronize(); return 0; } +" GASNETI_HAVE_CC_SYNC_SYNCHRONIZE) + +#--------------------------------------------------------------------- +# CPU-specific features +#--------------------------------------------------------------------- +if(GASNET_PLATFORM_ARCH STREQUAL "X86_64") + check_c_source_compiles(" + int main(void) { + unsigned long long old_lo = 0, old_hi = 0, new_lo = 1, new_hi = 0; + __uint128_t old_val = 0, new_val = 1; + __asm__ __volatile__(\"lock cmpxchg16b %1\" : \"+A\"(old_val) : \"m\"(*((__uint128_t*)&old_lo)), \"b\"(new_lo), \"c\"(new_hi)); + return 0; + } + " GASNETI_HAVE_X86_CMPXCHG16B) +endif() + +if(GASNET_PLATFORM_ARCH STREQUAL "AARCH64") + check_c_source_compiles(" + int main(void) { + unsigned long val; + __asm__ __volatile__(\"mrs %0, CNTVCT_EL0\" : \"=r\"(val)); + return 0; + } + " GASNETI_HAVE_AARCH64_CNTVCT_EL0) +endif() + +# PIC detection +check_c_source_compiles(" + #ifndef __PIC__ + #error not PIC + #endif + int main(void) { return 0; } +" GASNETI_CONFIGURED_PIC) + +# TLS support +check_c_source_compiles(" + __thread int tls_var = 0; + int main(void) { return tls_var; } +" GASNETI_HAVE_TLS_SUPPORT) + +#--------------------------------------------------------------------- +# Optimization flags +#--------------------------------------------------------------------- +if(GASNET_ENABLE_DEBUG) + set(GASNET_OPT_CFLAGS "-g -O0" CACHE STRING "Optimization C flags for debug build") +else() + set(GASNET_OPT_CFLAGS "-O2" CACHE STRING "Optimization C flags for release build") +endif() + +#--------------------------------------------------------------------- +# Developer warnings +#--------------------------------------------------------------------- +if(GASNET_ENABLE_DEV_WARNINGS) + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + set(DEVWARN_CFLAGS "-Wall;-Wextra;-Wno-unused-parameter" CACHE STRING "Developer warning flags") + endif() +else() + set(DEVWARN_CFLAGS "" CACHE STRING "Developer warning flags") +endif() + +#--------------------------------------------------------------------- +# RPATH +#--------------------------------------------------------------------- +if(GASNET_ENABLE_RPATH) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +endif() diff --git a/cmake/GasNetConduit.cmake b/cmake/GasNetConduit.cmake new file mode 100644 index 000000000..7e9d82d81 --- /dev/null +++ b/cmake/GasNetConduit.cmake @@ -0,0 +1,242 @@ +#============================================================================= +# GasNetConduit.cmake - Shared conduit build logic +# +# Each conduit includes this module and calls gasnet_conduit_setup(). +# This handles building the three threading-mode library variants, +# generating pkg-config files, and setting up tests. +#============================================================================= + +#--------------------------------------------------------------------- +# gasnet_conduit_setup( [SOURCES ] [EXTRA_FLAGS ] +# [LINK_LIBS ] [KINDS ] +# [SPAWNER ] [RUN_CMD ]) +# +# Creates the three library targets: +# gasnet--seq +# gasnet--par +# gasnet--parsync +#--------------------------------------------------------------------- +function(gasnet_conduit_setup CONDUIT_NAME) + set(options "") + set(oneValueArgs RUN_CMD SPAWNER SRC_DIR) + set(multiValueArgs SOURCES EXTRA_FLAGS LINK_LIBS KINDS BOOTSTRAP_SOURCES) + cmake_parse_arguments(COND "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + #------------------------------------------------------------------- + # Common include directories for all conduit libraries + #------------------------------------------------------------------- + set(CONDUIT_INCLUDES + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}" + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/other" + "${PROJECT_SOURCE_DIR}/other/kinds" + "${PROJECT_SOURCE_DIR}/extended-ref" + "${PROJECT_SOURCE_DIR}/extended-ref/coll" + "${PROJECT_SOURCE_DIR}/extended-ref/vis" + "${PROJECT_SOURCE_DIR}/extended-ref/ratomic" + ) + + # Add conduit-specific source directory + if(COND_SRC_DIR) + list(APPEND CONDUIT_INCLUDES "${COND_SRC_DIR}") + endif() + + #------------------------------------------------------------------- + # Common source files shared across ALL conduits + #------------------------------------------------------------------- + set(GASNET_COMMON_SOURCES + "${PROJECT_SOURCE_DIR}/gasnet_tools.c" + "${PROJECT_SOURCE_DIR}/gasnet_trace.c" + "${PROJECT_SOURCE_DIR}/gasnet_event.c" + "${PROJECT_SOURCE_DIR}/gasnet_legacy.c" + "${PROJECT_SOURCE_DIR}/gasnet_internal.c" + "${PROJECT_SOURCE_DIR}/gasnet_am.c" + "${PROJECT_SOURCE_DIR}/gasnet_mmap.c" + "${PROJECT_SOURCE_DIR}/gasnet_tm.c" + "${PROJECT_SOURCE_DIR}/gasnet_diagnostic.c" + # extended-ref sources + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_refcoll.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_putget.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_eager.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_rvous.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_team.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_hashtable.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_reduce.c" + "${PROJECT_SOURCE_DIR}/extended-ref/coll/gasnet_bootstrap.c" + "${PROJECT_SOURCE_DIR}/extended-ref/vis/gasnet_refvis.c" + "${PROJECT_SOURCE_DIR}/extended-ref/ratomic/gasnet_refratomic.c" + "${PROJECT_SOURCE_DIR}/other/kinds/gasnet_refkinds.c" + ) + + # PSHM source (if enabled) + if(GASNET_PSHM_ENABLED) + list(APPEND GASNET_COMMON_SOURCES "${PROJECT_SOURCE_DIR}/gasnet_pshm.c") + endif() + + # Combine all sources + set(ALL_SOURCES ${COND_SOURCES} ${GASNET_COMMON_SOURCES} ${COND_BOOTSTRAP_SOURCES}) + + #------------------------------------------------------------------- + # Build three library variants: SEQ, PAR, PARSYNC + #------------------------------------------------------------------- + foreach(THREAD_MODE SEQ PAR PARSYNC) + string(TOLOWER "${THREAD_MODE}" mode_lc) + set(lib_name "gasnet-${CONDUIT_NAME}-${mode_lc}") + + if(THREAD_MODE STREQUAL "PAR" OR THREAD_MODE STREQUAL "PARSYNC") + if(NOT GASNET_HAVE_PTHREADS) + continue() + endif() + if(THREAD_MODE STREQUAL "PAR" AND NOT GASNET_BUILD_PAR) + continue() + endif() + if(THREAD_MODE STREQUAL "PARSYNC" AND NOT GASNET_BUILD_PARSYNC) + continue() + endif() + else() + if(NOT GASNET_BUILD_SEQ) + continue() + endif() + endif() + + # Create static library + add_library(${lib_name} STATIC ${ALL_SOURCES}) + + # Threading define + target_compile_definitions(${lib_name} PRIVATE + -DGASNET_${THREAD_MODE} + -DGASNETI_BUILDING_CONDUIT + -D_GNU_SOURCE=1 + ) + + # Debug/NDEBUG + if(GASNET_ENABLE_DEBUG) + target_compile_definitions(${lib_name} PRIVATE -DGASNET_DEBUG) + else() + target_compile_definitions(${lib_name} PRIVATE -DGASNET_NDEBUG) + endif() + + # Trace/stats/debug-malloc + if(GASNET_ENABLE_TRACE) + target_compile_definitions(${lib_name} PRIVATE -DGASNET_TRACE) + endif() + if(GASNET_ENABLE_STATS) + target_compile_definitions(${lib_name} PRIVATE -DGASNET_STATS) + endif() + if(GASNET_ENABLE_DEBUG_MALLOC) + target_compile_definitions(${lib_name} PRIVATE -DGASNET_DEBUGMALLOC) + endif() + if(GASNET_ENABLE_SRCLINES) + target_compile_definitions(${lib_name} PRIVATE -DGASNET_SRCLINES) + endif() + + # Segment config + if(GASNET_SEGMENT_CONFIG STREQUAL "FAST") + target_compile_definitions(${lib_name} PRIVATE -DGASNET_SEGMENT_FAST) + elseif(GASNET_SEGMENT_CONFIG STREQUAL "LARGE") + target_compile_definitions(${lib_name} PRIVATE -DGASNET_SEGMENT_LARGE) + elseif(GASNET_SEGMENT_CONFIG STREQUAL "EVERYTHING") + target_compile_definitions(${lib_name} PRIVATE -DGASNET_SEGMENT_EVERYTHING) + endif() + + # PSHM + if(GASNET_PSHM_ENABLED) + target_compile_definitions(${lib_name} PRIVATE -DGASNETI_PSHM_ENABLED) + if(GASNET_PSHM_POSIX_ENABLED) + target_compile_definitions(${lib_name} PRIVATE -DGASNETI_PSHM_POSIX) + endif() + endif() + + # Thread-specific defines + if(THREAD_MODE STREQUAL "PAR" OR THREAD_MODE STREQUAL "PARSYNC") + if(GASNET_THREAD_DEFINES) + target_compile_definitions(${lib_name} PRIVATE ${GASNET_THREAD_DEFINES}) + endif() + if(GASNET_THREAD_LIBS) + target_link_libraries(${lib_name} PRIVATE ${GASNET_THREAD_LIBS}) + endif() + endif() + + # Include directories + target_include_directories(${lib_name} PRIVATE ${CONDUIT_INCLUDES}) + + # Extra flags from conduit + if(COND_EXTRA_FLAGS) + target_compile_options(${lib_name} PRIVATE ${COND_EXTRA_FLAGS}) + endif() + + # Link libraries + if(COND_LINK_LIBS) + target_link_libraries(${lib_name} PRIVATE ${COND_LINK_LIBS}) + endif() + + # Developer warnings + if(GASNET_ENABLE_DEV_WARNINGS AND DEVWARN_CFLAGS) + target_compile_options(${lib_name} PRIVATE ${DEVWARN_CFLAGS}) + endif() + + # Set C standard + set_target_properties(${lib_name} PROPERTIES + C_STANDARD 11 + C_STANDARD_REQUIRED ON + POSITION_INDEPENDENT_CODE ON + ) + + # Install + install(TARGETS ${lib_name} + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ) + + # Memory kinds (GPU support) - special objects + foreach(kind ${COND_KINDS}) + if(kind STREQUAL "cuda_uva" AND GASNET_KIND_CUDA_UVA_ENABLED) + target_compile_definitions(${lib_name} PRIVATE -DGASNETI_MK_CLASS_CUDA_UVA_ENABLED) + elseif(kind STREQUAL "hip" AND GASNET_KIND_HIP_ENABLED) + target_compile_definitions(${lib_name} PRIVATE -DGASNETI_MK_CLASS_HIP_ENABLED) + elseif(kind STREQUAL "ze" AND GASNET_KIND_ZE_ENABLED) + target_compile_definitions(${lib_name} PRIVATE -DGASNETI_MK_CLASS_ZE_ENABLED) + endif() + endforeach() + + # Generate pkg-config file + gasnet_gen_pkgconfig("${CONDUIT_NAME}" "${mode_lc}" "${lib_name}") + + message(STATUS " Created library: ${lib_name}") + endforeach() + + #------------------------------------------------------------------- + # Install conduit headers + #------------------------------------------------------------------- + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${CONDUIT_NAME}-conduit" + FILES_MATCHING + PATTERN "*.h" + PATTERN "*_internal.h" EXCLUDE + PATTERN "CMakeLists.txt" EXCLUDE + ) +endfunction() + +#--------------------------------------------------------------------- +# gasnet_gen_pkgconfig - Generate pkg-config .pc file for a conduit +#--------------------------------------------------------------------- +function(gasnet_gen_pkgconfig CONDUIT_NAME THREAD_MODEL LIB_NAME) + set(pc_file "${CMAKE_CURRENT_BINARY_DIR}/gasnet-${CONDUIT_NAME}-${THREAD_MODEL}.pc") + set(pc_content "prefix=${CMAKE_INSTALL_PREFIX} +exec_prefix=\${prefix} +libdir=\${prefix}/${CMAKE_INSTALL_LIBDIR} +includedir=\${prefix}/${CMAKE_INSTALL_INCLUDEDIR} + +Name: GASNet ${CONDUIT_NAME}-conduit (${THREAD_MODEL}) +Description: GASNet-EX ${CONDUIT_NAME} conduit (${THREAD_MODEL} mode) +Version: ${GASNET_RELEASE_VERSION} +URL: https://gasnet.lbl.gov + +Requires: +Libs: -L\${libdir} -lgasnet-${CONDUIT_NAME}-${THREAD_MODEL} +Cflags: -I\${includedir} -I\${includedir}/${CONDUIT_NAME}-conduit +") + file(WRITE "${pc_file}" "${pc_content}") + install(FILES "${pc_file}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endfunction() diff --git a/cmake/GasNetConfig.cmake.in b/cmake/GasNetConfig.cmake.in new file mode 100644 index 000000000..463776ef5 --- /dev/null +++ b/cmake/GasNetConfig.cmake.in @@ -0,0 +1,13 @@ +# GasNetConfig.cmake - CMake package configuration for GASNet-EX +# Generated by CMake + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/GasNetTargets.cmake" OPTIONAL) + +# This file provides imported targets: +# gasnet_tools-seq - Tools library (single-threaded) +# gasnet_tools-par - Tools library (thread-safe) +# gasnet--seq/par/parsync - Per-conduit libraries + +check_required_components(GasNet) diff --git a/cmake/GasNetConfigHeader.cmake b/cmake/GasNetConfigHeader.cmake new file mode 100644 index 000000000..e4f57927c --- /dev/null +++ b/cmake/GasNetConfigHeader.cmake @@ -0,0 +1,306 @@ +#============================================================================= +# GasNetConfigHeader.cmake - Compute variables and generate gasnet_config.h +#============================================================================= + +#--------------------------------------------------------------------- +# Compute all template variables +#--------------------------------------------------------------------- + +# Debug/optimization +if(GASNET_ENABLE_DEBUG) + set(GASNET_DEBUG_DEFINE "#define GASNET_DEBUG 1") + set(GASNET_NDEBUG_DEFINE "/* #undef GASNET_NDEBUG */") +else() + set(GASNET_DEBUG_DEFINE "/* #undef GASNET_DEBUG */") + set(GASNET_NDEBUG_DEFINE "#define GASNET_NDEBUG 1") +endif() + +# Trace/stats/srclines/debug-malloc/verbose/valgrind +foreach(_opt TRACE STATS SRCLINES DEBUGMALLOC DEBUG_VERBOSE VALGRIND) + string(TOUPPER "GASNET_ENABLE_${_opt}" _var) + if(${_var}) + set(_def "GASNET_${_opt}_DEFINE" "#define GASNET_${_opt} 1" CACHE INTERNAL "") + if(_opt STREQUAL "VALGRIND") + set(_def "GASNETI_${_opt}_DEFINE" "#define GASNETI_${_opt} 1" CACHE INTERNAL "") + endif() + else() + set(_def "GASNET_${_opt}_DEFINE" "/* #undef GASNET_${_opt} */" CACHE INTERNAL "") + if(_opt STREQUAL "VALGRIND") + set(_def "GASNETI_${_opt}_DEFINE" "/* #undef GASNETI_${_opt} */" CACHE INTERNAL "") + endif() + endif() +endforeach() + +# Handle trace/stats/srclines/debug-malloc/debug-verbose/valgrind properly +if(GASNET_ENABLE_TRACE) + set(GASNET_TRACE_DEFINE "#define GASNET_TRACE 1") +else() + set(GASNET_TRACE_DEFINE "/* #undef GASNET_TRACE */") +endif() +if(GASNET_ENABLE_STATS) + set(GASNET_STATS_DEFINE "#define GASNET_STATS 1") +else() + set(GASNET_STATS_DEFINE "/* #undef GASNET_STATS */") +endif() +if(GASNET_ENABLE_SRCLINES) + set(GASNET_SRCLINES_DEFINE "#define GASNET_SRCLINES 1") +else() + set(GASNET_SRCLINES_DEFINE "/* #undef GASNET_SRCLINES */") +endif() +if(GASNET_ENABLE_DEBUG_MALLOC) + set(GASNET_DEBUGMALLOC_DEFINE "#define GASNET_DEBUGMALLOC 1") +else() + set(GASNET_DEBUGMALLOC_DEFINE "/* #undef GASNET_DEBUGMALLOC */") +endif() +if(GASNET_ENABLE_DEBUG_VERBOSE) + set(GASNET_DEBUG_VERBOSE_DEFINE "#define GASNET_DEBUG_VERBOSE 1") +else() + set(GASNET_DEBUG_VERBOSE_DEFINE "/* #undef GASNET_DEBUG_VERBOSE */") +endif() +if(GASNET_ENABLE_VALGRIND) + set(GASNETI_VALGRIND_DEFINE "#define GASNETI_VALGRIND 1") +else() + set(GASNETI_VALGRIND_DEFINE "/* #undef GASNETI_VALGRIND */") +endif() + +# Segment +if(GASNET_SEGMENT_CONFIG STREQUAL "FAST") + set(GASNET_SEGMENT_DEFINE "#define GASNET_SEGMENT_FAST 1") +elseif(GASNET_SEGMENT_CONFIG STREQUAL "LARGE") + set(GASNET_SEGMENT_DEFINE "#define GASNET_SEGMENT_LARGE 1") +else() + set(GASNET_SEGMENT_DEFINE "#define GASNET_SEGMENT_EVERYTHING 1") +endif() +if(NOT GASNET_ENABLE_ALIGNED_SEGMENTS) + set(GASNETI_DISABLE_ALIGNED_SEGMENTS_DEFINE "#define GASNETI_DISABLE_ALIGNED_SEGMENTS 1") +else() + set(GASNETI_DISABLE_ALIGNED_SEGMENTS_DEFINE "/* #undef GASNETI_DISABLE_ALIGNED_SEGMENTS */") +endif() + +# Compiler identity is set by GasNetCompiler.cmake +# If not set, provide defaults +if(NOT DEFINED GASNET_CC_FAMILYID) + set(GASNET_CC_FAMILYID 1) +endif() +if(NOT DEFINED GASNET_CC_PLATFORM_ID) + set(GASNET_CC_PLATFORM_ID ${GASNET_CC_FAMILYID}) +endif() +if(NOT DEFINED GASNET_CC_VERSION) + set(GASNET_CC_VERSION 0) +endif() +if(NOT DEFINED GASNET_CXX_FAMILYID) + set(GASNET_CXX_FAMILYID 1) +endif() +if(NOT DEFINED GASNET_CXX_PLATFORM_ID) + set(GASNET_CXX_PLATFORM_ID ${GASNET_CXX_FAMILYID}) +endif() +if(NOT DEFINED GASNET_CXX_VERSION) + set(GASNET_CXX_VERSION 0) +endif() + +# Compiler versions (match gasnet_portable_platform.h encoding) +if(DEFINED GASNET_CC_VERSION) + set(GASNET_CC_VERSION "${GASNET_CC_VERSION}") +else() + set(GASNET_CC_VERSION 0) +endif() +if(DEFINED GASNET_CXX_VERSION) + set(GASNET_CXX_VERSION "${GASNET_CXX_VERSION}") +else() + set(GASNET_CXX_VERSION 0) +endif() +set(GASNET_CC_LANGLVL 201112) +set(GASNET_CXX_LANGLVL 201402) + +# Endianness (must use #undef for 0, NOT #define to 0 - see gasnet_portable_platform.h:1070) +if(WORDS_BIGENDIAN) + set(WORDS_BIGENDIAN_VAL "1") +else() + set(WORDS_BIGENDIAN_VAL "/* #undef WORDS_BIGENDIAN */") +endif() + +# Atomics (numeric values 0-5 from gasnet_atomic_fwd.h) +if(NOT DEFINED GASNETI_ATOMIC_IMPL_CONFIGURE) + set(GASNETI_ATOMIC_IMPL_CONFIGURE 1) +endif() +if(NOT DEFINED GASNETI_ATOMIC32_IMPL_CONFIGURE) + set(GASNETI_ATOMIC32_IMPL_CONFIGURE 1) +endif() +if(NOT DEFINED GASNETI_ATOMIC64_IMPL_CONFIGURE) + set(GASNETI_ATOMIC64_IMPL_CONFIGURE 1) +endif() + +# Thread info opt +if(NOT DEFINED GASNETI_THREADINFO_OPT_CONFIGURE) + set(GASNETI_THREADINFO_OPT_CONFIGURE 0) +endif() + +# PSHM (must use #define/#undef pattern since code uses #if VAR check) +if(GASNET_PSHM_ENABLED) + set(GASNETI_PSHM_ENABLED_VAL "#define GASNETI_PSHM_ENABLED 1") + if(GASNET_PSHM_POSIX_ENABLED) + set(GASNETI_PSHM_POSIX_VAL "#define GASNETI_PSHM_POSIX 1") + set(GASNETI_PSHM_SYSV_VAL "/* #undef GASNETI_PSHM_SYSV */") + set(GASNETI_PSHM_XPMEM_VAL "/* #undef GASNETI_PSHM_XPMEM */") + set(GASNETI_PSHM_HUGETLBFS_VAL "/* #undef GASNETI_PSHM_HUGETLBFS */") + set(GASNETI_PSHM_FILE_VAL "/* #undef GASNETI_PSHM_FILE */") + else() + set(GASNETI_PSHM_POSIX_VAL "/* #undef GASNETI_PSHM_POSIX */") + endif() +else() + set(GASNETI_PSHM_ENABLED_VAL "/* #undef GASNETI_PSHM_ENABLED */") +endif() + +# Default PSHM values if not set +if(NOT DEFINED GASNETI_PSHM_POSIX_VAL) + set(GASNETI_PSHM_POSIX_VAL "/* #undef GASNETI_PSHM_POSIX */") +endif() +if(NOT DEFINED GASNETI_PSHM_SYSV_VAL) + set(GASNETI_PSHM_SYSV_VAL "/* #undef GASNETI_PSHM_SYSV */") +endif() +if(NOT DEFINED GASNETI_PSHM_XPMEM_VAL) + set(GASNETI_PSHM_XPMEM_VAL "/* #undef GASNETI_PSHM_XPMEM */") +endif() +if(NOT DEFINED GASNETI_PSHM_HUGETLBFS_VAL) + set(GASNETI_PSHM_HUGETLBFS_VAL "/* #undef GASNETI_PSHM_HUGETLBFS */") +endif() +if(NOT DEFINED GASNETI_PSHM_FILE_VAL) + set(GASNETI_PSHM_FILE_VAL "/* #undef GASNETI_PSHM_FILE */") +endif() + +# GASNETI_COMMON - tentative definitions attribute +# Must always be defined (even if empty) since it's used as a type attribute +set(GASNETI_COMMON_VAL "#define GASNETI_COMMON") + +# GASNETI_MAX_SEGSIZE_CONFIGURE - default max segment size +set(GASNETI_MAX_SEGSIZE_CONFIGURE "\"0.8\"") + +# For features checked with #ifdef (not #if), must produce #define or /*#undef*/ +# NOT #define to 0 which would still pass #ifdef +foreach(_f PR_SET_PDEATHSIG PR_SET_PTRACER) + if(${HAVE_${_f}}) + set(HAVE_${_f}_VAL "#define HAVE_${_f} 1") + else() + set(HAVE_${_f}_VAL "/* #undef HAVE_${_f} */") + endif() +endforeach() + +# GASNETI_SYSTEM_TUPLE +set(GASNETI_SYSTEM_TUPLE "\"${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}\"") + +# Build identification strings +set(GASNETI_SYSTEM_NAME "\"${CMAKE_SYSTEM_NAME}\"") +set(GASNETI_BUILD_ID "\"cmake-build\"") +set(GASNETI_CONFIGURE_ARGS "\"cmake\"") + +# CONFIGURE_ARGS (legacy) +set(CONFIGURE_ARGS "\"cmake\"") + +# Page/cache sizes +if(NOT DEFINED GASNETI_PAGESIZE OR GASNETI_PAGESIZE EQUAL 0) + set(GASNETI_PAGESIZE 4096) + set(GASNETI_PAGESHIFT 12) +endif() + +# C99 format specifiers +if(HAVE_C99_FORMAT_SPECIFIERS) + set(HAVE_C99_FORMAT_SPECIFIERS 1) +else() + set(HAVE_C99_FORMAT_SPECIFIERS 0) +endif() + +# Pause instruction +if(GASNETI_HAVE_PAUSE) + # Already set by GasNetMembar.cmake +else() + set(GASNETI_PAUSE_INSTRUCTION "\"\"") +endif() + +# Force options +foreach(_f GENERIC_ATOMICOPS OS_ATOMICOPS COMPILER_ATOMICOPS YIELD_MEMBARS SLOW_MEMBARS GETTIMEOFDAY POSIX_REALTIME) + if(GASNET_FORCE_${_f}) + set(GASNETI_FORCE_${_f}_DEFINE "#define GASNETI_FORCE_${_f} 1") + else() + set(GASNETI_FORCE_${_f}_DEFINE "/* #undef GASNETI_FORCE_${_f} */") + endif() +endforeach() + +# BUG1389 workaround +if(GASNET_ENABLE_CONSERVATIVE_LOCAL_COPY) + set(GASNETI_BUG1389_WORKAROUND_DEFINE "#define GASNETI_BUG1389_WORKAROUND 1") +else() + set(GASNETI_BUG1389_WORKAROUND_DEFINE "/* #undef GASNETI_BUG1389_WORKAROUND */") +endif() + +# Cross-compiling +if(CMAKE_CROSSCOMPILING) + set(GASNETI_CROSS_COMPILING 1) +endif() + +# Apple GCC +if(CC_FAMILY STREQUAL "Clang" AND CC_SUBFAMILY STREQUAL "APPLE") + set(GASNETI_GCC_APPLE 1) +endif() + +# Inline modifier +set(GASNETI_CC_INLINE_MODIFIER "inline") +set(GASNETI_CXX_INLINE_MODIFIER "inline") + +# SIZEOF_SIZE_T +if(NOT DEFINED SIZEOF_SIZE_T OR SIZEOF_SIZE_T STREQUAL "") + set(SIZEOF_SIZE_T 8) +endif() + +# GASNETI_TM0_ALIGN - thread model alignment +if(NOT DEFINED GASNETI_TM0_ALIGN) + set(GASNETI_TM0_ALIGN 16) +endif() + +# GASNETC_SMP_SPAWNER_CONF - spawner for smp conduit +set(GASNETC_SMP_SPAWNER_CONF "\"fork\"") +set(GASNETC_IBV_SPAWNER_CONF "\"ssh\"") +set(GASNETC_OFI_SPAWNER_CONF "\"ssh\"") +set(GASNETC_UCX_SPAWNER_CONF "\"ssh\"") +set(GASNETC_MPI_SPAWNER_CONF "\"mpi\"") + +# Enabled conduits list +set(_conduits "") +if(GASNET_ENABLE_SMP) + list(APPEND _conduits "smp") +endif() +if(GASNET_ENABLE_UDP) + list(APPEND _conduits "udp") +endif() +if(GASNET_ENABLE_MPI) + list(APPEND _conduits "mpi") +endif() +if(GASNET_ENABLE_IBV) + list(APPEND _conduits "ibv") +endif() +if(GASNET_ENABLE_OFI) + list(APPEND _conduits "ofi") +endif() +if(GASNET_ENABLE_UCX) + list(APPEND _conduits "ucx") +endif() +string(JOIN " " _g_conduits ${_conduits}) +set(GASNETI_CONDUITS "\"${_g_conduits}\"") + +# Restrict keyword (GCC/Clang support __restrict__) +set(GASNETI_CC_RESTRICT "__restrict__") +set(GASNETI_CXX_RESTRICT "__restrict__") + +#--------------------------------------------------------------------- +# Generate the config header +#--------------------------------------------------------------------- +set(GASNET_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/gasnet_config.h") +set(GASNET_CONFIG_H_IN "${CMAKE_CURRENT_SOURCE_DIR}/cmake/gasnet_config.h.in") + +configure_file( + "${GASNET_CONFIG_H_IN}" + "${GASNET_CONFIG_H}" + @ONLY +) + +include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}") +message(STATUS "Generated gasnet_config.h in ${CMAKE_CURRENT_BINARY_DIR}") diff --git a/cmake/GasNetDebugMalloc.cmake b/cmake/GasNetDebugMalloc.cmake new file mode 100644 index 000000000..f8f38dcaa --- /dev/null +++ b/cmake/GasNetDebugMalloc.cmake @@ -0,0 +1,32 @@ +#============================================================================= +# GasNetDebugMalloc.cmake - Debug malloc configuration +#============================================================================= + +option(GASNET_ENABLE_SYSTEM_DEBUG_MALLOC "Use system-specific debugging malloc" OFF) + +if(GASNET_ENABLE_DEBUG_MALLOC) + set(GASNETI_MALLOC_CONFIG "debugmalloc") +else() + set(GASNETI_MALLOC_CONFIG "nodebugmalloc") +endif() + +if(GASNET_ENABLE_SYSTEM_DEBUG_MALLOC) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # glibc MALLOC_CHECK_ support + set(GASNET_DEBUGMALLOC_VAR "MALLOC_CHECK_") + set(GASNET_DEBUGMALLOC_VAL "3") + elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + set(GASNET_DEBUGMALLOC_VAR "MALLOC_OPTIONS") + set(GASNET_DEBUGMALLOC_VAL "AJ") + elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") + set(GASNET_DEBUGMALLOC_VAR "MALLOC_OPTIONS") + set(GASNET_DEBUGMALLOC_VAL "AFGJ") + endif() +endif() + +# ptmalloc detection +include(CheckCSourceCompiles) +check_c_source_compiles(" + #include + int main(void) { return mallopt(M_MMAP_THRESHOLD, 128*1024); } +" HAVE_PTMALLOC) diff --git a/cmake/GasNetInstall.cmake b/cmake/GasNetInstall.cmake new file mode 100644 index 000000000..9b1b64846 --- /dev/null +++ b/cmake/GasNetInstall.cmake @@ -0,0 +1,82 @@ +#============================================================================= +# GasNetInstall.cmake - Installation rules for GASNet +#============================================================================= + +#--------------------------------------------------------------------- +# Install top-level public headers +#--------------------------------------------------------------------- +install(FILES + "${PROJECT_SOURCE_DIR}/gasnetex.h" + "${PROJECT_SOURCE_DIR}/gasnet.h" + "${PROJECT_SOURCE_DIR}/gasnet_ammacros.h" + "${PROJECT_SOURCE_DIR}/gasnet_trace.h" + "${PROJECT_SOURCE_DIR}/gasnet_fwd.h" + "${PROJECT_SOURCE_DIR}/gasnet_asm.h" + "${PROJECT_SOURCE_DIR}/gasnet_atomicops.h" + "${PROJECT_SOURCE_DIR}/gasnet_atomic_bits.h" + "${PROJECT_SOURCE_DIR}/gasnet_atomic_fwd.h" + "${PROJECT_SOURCE_DIR}/gasnet_basic.h" + "${PROJECT_SOURCE_DIR}/gasnet_help.h" + "${PROJECT_SOURCE_DIR}/gasnet_membar.h" + "${PROJECT_SOURCE_DIR}/gasnet_timer.h" + "${PROJECT_SOURCE_DIR}/gasnet_tools.h" + "${PROJECT_SOURCE_DIR}/gasnet_toolhelp.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +# Install kinds header +install(FILES + "${PROJECT_SOURCE_DIR}/other/kinds/gasnet_mk.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +#--------------------------------------------------------------------- +# Install documentation +#--------------------------------------------------------------------- +install(FILES + "${PROJECT_SOURCE_DIR}/README" + "${PROJECT_SOURCE_DIR}/README-tools" + "${PROJECT_SOURCE_DIR}/ChangeLog" + "${PROJECT_SOURCE_DIR}/license.txt" + DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/GASNet" +) + +install(FILES + "${PROJECT_SOURCE_DIR}/docs/GASNet-EX.txt" + "${PROJECT_SOURCE_DIR}/docs/gasnet1_differences.md" + "${PROJECT_SOURCE_DIR}/docs/implementation_defined.md" + "${PROJECT_SOURCE_DIR}/docs/memory_kinds_implementation.md" + "${PROJECT_SOURCE_DIR}/docs/memory_kinds.pdf" + DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/GASNet" +) + +#--------------------------------------------------------------------- +# Install gasnet_config.h +#--------------------------------------------------------------------- +install(FILES + "${PROJECT_BINARY_DIR}/gasnet_config.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +#--------------------------------------------------------------------- +# Export CMake package (for find_package) +#--------------------------------------------------------------------- +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/GasNetConfig.cmake.in" + "${PROJECT_BINARY_DIR}/GasNetConfig.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/GasNet" +) + +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/GasNetConfigVersion.cmake" + VERSION ${GASNET_RELEASE_VERSION} + COMPATIBILITY SameMajorVersion +) + +install(FILES + "${PROJECT_BINARY_DIR}/GasNetConfig.cmake" + "${PROJECT_BINARY_DIR}/GasNetConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/GasNet" +) diff --git a/cmake/GasNetMembar.cmake b/cmake/GasNetMembar.cmake new file mode 100644 index 000000000..a9285ed57 --- /dev/null +++ b/cmake/GasNetMembar.cmake @@ -0,0 +1,24 @@ +#============================================================================= +# GasNetMembar.cmake - Memory barrier configuration +#============================================================================= + +include(CheckCSourceCompiles) + +#--------------------------------------------------------------------- +# Detect pause instruction (x86 rep;nop / aarch64 yield / arm yield) +#--------------------------------------------------------------------- +if(GASNET_PLATFORM_ARCH STREQUAL "X86_64" OR GASNET_PLATFORM_ARCH STREQUAL "X86") + check_c_source_compiles(" + int main(void) { __asm__ __volatile__(\"rep; nop\" : : : \"memory\"); return 0; } + " GASNETI_HAVE_PAUSE) + if(GASNETI_HAVE_PAUSE) + set(GASNETI_PAUSE_INSTRUCTION "\"rep; nop\"") + endif() +elseif(GASNET_PLATFORM_ARCH STREQUAL "AARCH64") + check_c_source_compiles(" + int main(void) { __asm__ __volatile__(\"yield\" : : : \"memory\"); return 0; } + " GASNETI_HAVE_PAUSE) + if(GASNETI_HAVE_PAUSE) + set(GASNETI_PAUSE_INSTRUCTION "\"yield\"") + endif() +endif() diff --git a/cmake/GasNetMemoryKinds.cmake b/cmake/GasNetMemoryKinds.cmake new file mode 100644 index 000000000..0036d1dfa --- /dev/null +++ b/cmake/GasNetMemoryKinds.cmake @@ -0,0 +1,40 @@ +#============================================================================= +# GasNetMemoryKinds.cmake - GPU memory kinds detection +#============================================================================= + +if(NOT GASNET_ENABLE_MEMORY_KINDS) + set(GASNET_MEMORY_KINDS_ENABLED FALSE) + return() +endif() + +set(GASNET_MEMORY_KINDS_ENABLED TRUE) + +# CUDA UVA +if(GASNET_ENABLE_KIND_CUDA_UVA) + find_package(CUDA QUIET) + if(CUDA_FOUND) + set(GASNET_KIND_CUDA_UVA_ENABLED TRUE) + else() + message(STATUS "CUDA not found; disabling CUDA UVA memory kind") + endif() +endif() + +# HIP +if(GASNET_ENABLE_KIND_HIP) + find_package(hip QUIET) + if(hip_FOUND OR DEFINED ENV{ROCM_PATH}) + set(GASNET_KIND_HIP_ENABLED TRUE) + else() + message(STATUS "HIP not found; disabling HIP memory kind") + endif() +endif() + +# Level Zero +if(GASNET_ENABLE_KIND_ZE) + find_package(LevelZero QUIET) + if(LevelZero_FOUND) + set(GASNET_KIND_ZE_ENABLED TRUE) + else() + message(STATUS "Level Zero not found; disabling ZE memory kind") + endif() +endif() diff --git a/cmake/GasNetOptions.cmake b/cmake/GasNetOptions.cmake new file mode 100644 index 000000000..f40d9938a --- /dev/null +++ b/cmake/GasNetOptions.cmake @@ -0,0 +1,141 @@ +#============================================================================= +# GasNetOptions.cmake - Top-level build options for GASNet +#============================================================================= +include(CMakeDependentOption) + +#--------------------------------------------------------------------- +# Threading model selection +#--------------------------------------------------------------------- +set(GASNET_THREAD_MODEL "SEQ" CACHE STRING "GASNet threading model: SEQ, PAR, or PARSYNC") +set_property(CACHE GASNET_THREAD_MODEL PROPERTY STRINGS "SEQ" "PAR" "PARSYNC") + +option(GASNET_BUILD_SEQ "Build SEQ (single-threaded) libraries" ON) +option(GASNET_BUILD_PAR "Build PAR (multi-threaded) libraries" ON) +option(GASNET_BUILD_PARSYNC "Build PARSYNC (multi-threaded, serialized) libraries" ON) + +#--------------------------------------------------------------------- +# Debug and diagnostics +#--------------------------------------------------------------------- +option(GASNET_ENABLE_DEBUG "Build in debugging mode with extensive error/sanity checks" OFF) +cmake_dependent_option(GASNET_ENABLE_TRACE "Build with tracing enabled" ON "GASNET_ENABLE_DEBUG" OFF) +cmake_dependent_option(GASNET_ENABLE_STATS "Build with statistical collection enabled" ON "GASNET_ENABLE_DEBUG" OFF) +cmake_dependent_option(GASNET_ENABLE_DEBUG_MALLOC "Build with debugging malloc" ON "GASNET_ENABLE_DEBUG" OFF) +cmake_dependent_option(GASNET_ENABLE_SRCLINES "Build with source line tracing support" ON "GASNET_ENABLE_TRACE" OFF) +option(GASNET_ENABLE_DEBUG_VERBOSE "Enable verbose debug status messages from GASNet lib" OFF) + +#--------------------------------------------------------------------- +# Compiler warnings +#--------------------------------------------------------------------- +option(GASNET_ENABLE_DEV_WARNINGS "Enable developer compiler warnings for library and tests" ON) + +#--------------------------------------------------------------------- +# Segment configuration +#--------------------------------------------------------------------- +set(GASNET_SEGMENT_CONFIG "FAST" CACHE STRING "Segment configuration: FAST, LARGE, or EVERYTHING") +set_property(CACHE GASNET_SEGMENT_CONFIG PROPERTY STRINGS "FAST" "LARGE" "EVERYTHING") + +option(GASNET_ENABLE_ALIGNED_SEGMENTS "Enable aligned segment support" ON) + +#--------------------------------------------------------------------- +# PSHM (inter-Process Shared Memory) +#--------------------------------------------------------------------- +option(GASNET_ENABLE_PSHM "Enable inter-Process Shared Memory support" ON) +option(GASNET_ENABLE_PSHM_POSIX "Enable PSHM via POSIX shared memory" ON) +option(GASNET_ENABLE_PSHM_XPMEM "Enable PSHM via XPMEM" OFF) +option(GASNET_ENABLE_PSHM_HUGETLBFS "Enable PSHM via hugetlbfs" OFF) + +#--------------------------------------------------------------------- +# Memory kinds support +#--------------------------------------------------------------------- +option(GASNET_ENABLE_MEMORY_KINDS "Enable memory kinds support" ON) +option(GASNET_ENABLE_KIND_CUDA_UVA "Enable CUDA UVA memory kind" OFF) +option(GASNET_ENABLE_KIND_HIP "Enable HIP memory kind" OFF) +option(GASNET_ENABLE_KIND_ZE "Enable Level Zero memory kind" OFF) + +#--------------------------------------------------------------------- +# Valgrind support +#--------------------------------------------------------------------- +option(GASNET_ENABLE_VALGRIND "Build valgrind-friendly library (disables some optimizations)" OFF) + +#--------------------------------------------------------------------- +# RPATH +#--------------------------------------------------------------------- +option(GASNET_ENABLE_RPATH "Build libraries using RPATH for dependent libraries" OFF) + +#--------------------------------------------------------------------- +# Pthreads +#--------------------------------------------------------------------- +set(GASNET_PTHREADS_MODE "AUTO" CACHE STRING "Pthreads support: AUTO, ON, or OFF") +set_property(CACHE GASNET_PTHREADS_MODE PROPERTY STRINGS "AUTO" "ON" "OFF") + +#--------------------------------------------------------------------- +# Misc options +#--------------------------------------------------------------------- +option(GASNET_ENABLE_CONSERVATIVE_LOCAL_COPY "Enable slower conservative local data movement" OFF) +option(GASNET_ENABLE_GASNET_VERBOSE "Build with verbose debug status messages in library" OFF) +option(GASNET_ENABLE_AUTO_CONDUIT_DETECT "Automatically detect supported network conduits" ON) + +#--------------------------------------------------------------------- +# Conduit selection +#--------------------------------------------------------------------- +option(GASNET_ENABLE_SMP "Enable SMP (shared memory) conduit" ON) +option(GASNET_ENABLE_UDP "Enable UDP conduit" OFF) +option(GASNET_ENABLE_MPI "Enable MPI conduit" OFF) +option(GASNET_ENABLE_IBV "Enable InfiniBand Verbs conduit" OFF) +option(GASNET_ENABLE_OFI "Enable Open Fabrics Interfaces conduit" OFF) +option(GASNET_ENABLE_UCX "Enable UCX conduit" OFF) + +#--------------------------------------------------------------------- +# MPI compatibility (required by some conduits) +#--------------------------------------------------------------------- +option(GASNET_ENABLE_MPI_COMPAT "Enable MPI compatibility support" ON) + +#--------------------------------------------------------------------- +# Conduit-specific options +#--------------------------------------------------------------------- +# IBV +option(GASNET_IBV_ODP "Enable On-Demand Paging for ibv-conduit" OFF) +option(GASNET_IBV_XRC "Enable XRC support for ibv-conduit" OFF) +option(GASNET_IBV_FENCED_PUTS "Enable fenced puts for ibv-conduit" ON) +set(GASNET_IBV_MAX_HCAS "1" CACHE STRING "Max HCAs for ibv-conduit") +set(GASNET_IBV_MAX_MEDIUM "4096" CACHE STRING "Max medium size for ibv-conduit") + +# OFI +set(GASNET_OFI_PROVIDER "auto" CACHE STRING "libfabric provider for ofi-conduit (auto=sockets;verbs;ofi_rxm)") +option(GASNET_OFI_LEGACY_EXTENDED "Enable legacy extended endpoint support" OFF) +set(GASNET_OFI_MAX_MEDIUM "4096" CACHE STRING "Max medium size for ofi-conduit") + +# UCX +set(GASNET_UCX_MAX_MEDIUM "4096" CACHE STRING "Max medium size for ucx-conduit") + +#--------------------------------------------------------------------- +# Advanced options +#--------------------------------------------------------------------- +set(GASNET_MAX_SEGSIZE "auto" CACHE STRING "Default max segment size (auto = 0.8 * physical memory)") +set(GASNET_WITH_SSH_CMD "" CACHE STRING "SSH command for ssh-spawner") +set(GASNET_WITH_SSH_OPTIONS "" CACHE STRING "SSH options for ssh-spawner") +set(GASNET_WITH_SSH_OUT_DEGREE "" CACHE STRING "SSH out-degree for ssh-spawner") + +#--------------------------------------------------------------------- +# Tests +#--------------------------------------------------------------------- +option(GASNET_ENABLE_TESTS "Build and enable tests" ON) + +#--------------------------------------------------------------------- +# Force options for atomic operations +#--------------------------------------------------------------------- +option(GASNET_FORCE_GENERIC_ATOMICOPS "Force generic (mutex-based) atomic operations" OFF) +option(GASNET_FORCE_OS_ATOMICOPS "Force OS-based atomic operations" OFF) +option(GASNET_FORCE_COMPILER_ATOMICOPS "Force compiler-based atomic operations" OFF) + +#--------------------------------------------------------------------- +# Memory barrier force options +#--------------------------------------------------------------------- +option(GASNET_FORCE_YIELD_MEMBARS "Force yield-based memory barriers" OFF) +option(GASNET_FORCE_SLOW_MEMBARS "Force slow memory barriers" OFF) + +#--------------------------------------------------------------------- +# Timer force options +#--------------------------------------------------------------------- +option(GASNET_FORCE_GETTIMEOFDAY "Force use of gettimeofday for timers" OFF) +option(GASNET_FORCE_POSIX_REALTIME "Force use of POSIX realtime clock for timers" OFF) diff --git a/cmake/GasNetPSHM.cmake b/cmake/GasNetPSHM.cmake new file mode 100644 index 000000000..55480ce76 --- /dev/null +++ b/cmake/GasNetPSHM.cmake @@ -0,0 +1,54 @@ +#============================================================================= +# GasNetPSHM.cmake - Inter-Process Shared Memory configuration +#============================================================================= + +include(CheckCSourceCompiles) +include(CheckFunctionExists) +include(CheckIncludeFile) + +if(GASNET_ENABLE_PSHM) + # POSIX shared memory (shm_open) + if(GASNET_ENABLE_PSHM_POSIX) + check_function_exists("shm_open" HAVE_SHM_OPEN) + check_function_exists("shm_unlink" HAVE_SHM_UNLINK) + if(HAVE_SHM_OPEN AND HAVE_SHM_UNLINK) + set(GASNET_PSHM_POSIX_ENABLED TRUE) + endif() + endif() + + # SysV shared memory (shmat/shmget) + if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND NOT GASNET_PSHM_POSIX_ENABLED) + check_function_exists("shmat" HAVE_SHMAT) + if(HAVE_SHMAT) + set(GASNET_PSHM_SYSV_ENABLED TRUE) + endif() + endif() + + # hugetlbfs + if(GASNET_ENABLE_PSHM_HUGETLBFS OR CMAKE_SYSTEM_NAME MATCHES "Cray") + find_library(HUGETLBFS_LIB hugetlbfs) + if(HUGETLBFS_LIB) + set(GASNET_PSHM_HUGETLBFS_ENABLED TRUE) + endif() + endif() + + # XPMEM + if(GASNET_ENABLE_PSHM_XPMEM) + check_include_file("xpmem.h" HAVE_XPMEM_H) + check_function_exists("xpmem_make" HAVE_XPMEM) + if(HAVE_XPMEM_H AND HAVE_XPMEM) + set(GASNET_PSHM_XPMEM_ENABLED TRUE) + endif() + endif() + + if(GASNET_PSHM_POSIX_ENABLED OR GASNET_PSHM_SYSV_ENABLED OR + GASNET_PSHM_HUGETLBFS_ENABLED OR GASNET_PSHM_XPMEM_ENABLED) + set(GASNET_PSHM_ENABLED TRUE) + else() + set(GASNET_PSHM_ENABLED FALSE) + message(STATUS "No PSHM mechanism available; disabling PSHM") + endif() + + # Detect socketpair for PSHM bootstrap + check_function_exists("socketpair" HAVE_SOCKETPAIR) +endif() diff --git a/cmake/GasNetPlatform.cmake b/cmake/GasNetPlatform.cmake new file mode 100644 index 000000000..ace1a118f --- /dev/null +++ b/cmake/GasNetPlatform.cmake @@ -0,0 +1,166 @@ +#============================================================================= +# GasNetPlatform.cmake - Platform and OS detection +#============================================================================= + +#--------------------------------------------------------------------- +# Canonical system identification +#--------------------------------------------------------------------- +# These are used to set GASNETI_PLATFORM_COMPILER_* defines that +# gasnet_portable_platform.h uses for compiler identity verification. + +include(CheckTypeSize) + +check_type_size("void *" SIZEOF_VOID_P BUILTIN_TYPES_ONLY) +check_type_size("size_t" SIZEOF_SIZE_T BUILTIN_TYPES_ONLY) +if(NOT DEFINED SIZEOF_VOID_P) + set(SIZEOF_VOID_P 8) +endif() +if(NOT DEFINED SIZEOF_SIZE_T) + set(SIZEOF_SIZE_T 8) +endif() + +#--------------------------------------------------------------------- +# Detect endianness +#--------------------------------------------------------------------- +include(TestBigEndian) +test_big_endian(WORDS_BIGENDIAN) + +#--------------------------------------------------------------------- +# Detect OS for platform identification +#--------------------------------------------------------------------- +if(APPLE) + set(GASNET_PLATFORM_OS "DARWIN") + set(GASNETI_ARCH_DARWIN 1) +elseif(UNIX) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(GASNET_PLATFORM_OS "LINUX") + set(GASNETI_ARCH_LINUX 1) + elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(GASNET_PLATFORM_OS "FREEBSD") + elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + set(GASNET_PLATFORM_OS "SOLARIS") + elseif(CMAKE_SYSTEM_NAME STREQUAL "CYGWIN_NT") + set(GASNET_PLATFORM_OS "CYGWIN") + set(GASNETI_ARCH_CYGWIN 1) + endif() +elseif(MSVC) + set(GASNET_PLATFORM_OS "MSWINDOWS") +endif() + +#--------------------------------------------------------------------- +# Detect CPU architecture +#--------------------------------------------------------------------- +set(GASNET_PLATFORM_ARCH "") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64") + set(GASNET_PLATFORM_ARCH "X86_64") + set(GASNETI_ARCH_X86_64 1) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i[3-6]86") + set(GASNET_PLATFORM_ARCH "X86") + set(GASNETI_ARCH_X86 1) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64") + set(GASNET_PLATFORM_ARCH "AARCH64") + set(GASNETI_ARCH_AARCH64 1) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") + set(GASNET_PLATFORM_ARCH "ARM") + set(GASNETI_ARCH_ARM 1) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64|powerpc64") + set(GASNET_PLATFORM_ARCH "PPC64") + set(GASNETI_ARCH_PPC64 1) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc|powerpc") + set(GASNET_PLATFORM_ARCH "POWERPC") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips") + set(GASNET_PLATFORM_ARCH "MIPS") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc") + set(GASNET_PLATFORM_ARCH "SPARC") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv") + set(GASNET_PLATFORM_ARCH "RISCV") +endif() + +#--------------------------------------------------------------------- +# Detect common platform features +#--------------------------------------------------------------------- +include(CheckIncludeFile) +include(CheckFunctionExists) +include(CheckSymbolExists) + +check_include_file("features.h" HAVE_FEATURES_H) +check_include_file("inttypes.h" HAVE_INTTYPES_H) +check_include_file("stdint.h" HAVE_STDINT_H) +check_include_file("sys/types.h" HAVE_SYS_TYPES_H) +check_include_file("execinfo.h" HAVE_EXECINFO_H) + +#--------------------------------------------------------------------- +# Detect mmap support +#--------------------------------------------------------------------- +check_function_exists("mmap" HAVE_MMAP) +check_include_file("sys/mman.h" HAVE_SYS_MMAN_H) +if(HAVE_SYS_MMAN_H) + check_symbol_exists("MAP_ANON" "sys/mman.h" HAVE_MAP_ANON) + check_symbol_exists("MAP_ANONYMOUS" "sys/mman.h" HAVE_MAP_ANONYMOUS) + check_symbol_exists("MAP_NORESERVE" "sys/mman.h" HAVE_MAP_NORESERVE) +endif() + +#--------------------------------------------------------------------- +# POSIX functions +#--------------------------------------------------------------------- +check_function_exists("posix_memalign" HAVE_POSIX_MEMALIGN) +check_function_exists("clock_gettime" HAVE_CLOCK_GETTIME) +check_function_exists("sched_yield" HAVE_SCHED_YIELD) +check_function_exists("usleep" HAVE_USLEEP) +check_function_exists("nanosleep" HAVE_NANOSLEEP) + +check_symbol_exists("snprintf" "stdio.h" HAVE_SNPRINTF_DECL) +check_symbol_exists("vsnprintf" "stdio.h" HAVE_VSNPRINTF_DECL) +check_symbol_exists("isblank" "ctype.h" HAVE_ISBLANK_DECL) + +#--------------------------------------------------------------------- +# Signal handling +#--------------------------------------------------------------------- +check_function_exists("sigaction" HAVE_SIGACTION) +if(HAVE_SIGACTION) + check_symbol_exists("SA_RESTART" "signal.h" GASNETI_HAVE_SA_RESTART) +endif() + +#--------------------------------------------------------------------- +# Backtrace support +#--------------------------------------------------------------------- +check_function_exists("backtrace" HAVE_BACKTRACE) +check_function_exists("backtrace_symbols" HAVE_BACKTRACE_SYMBOLS) + +#--------------------------------------------------------------------- +# prctl support (Linux) +#--------------------------------------------------------------------- +check_symbol_exists("PR_SET_PDEATHSIG" "sys/prctl.h" HAVE_PR_SET_PDEATHSIG) +check_symbol_exists("PR_SET_PTRACER" "sys/prctl.h" HAVE_PR_SET_PTRACER) + +#--------------------------------------------------------------------- +# Page size detection +#--------------------------------------------------------------------- +include(CheckCSourceRuns) +check_c_source_runs(" +#include +int main() { long sz = sysconf(_SC_PAGESIZE); return (sz > 0) ? 0 : 1; } +" GASNET_PAGESIZE_RUNNABLE) + +if(GASNET_PAGESIZE_RUNNABLE) + # Will be determined at runtime via sysconf + set(GASNETI_PAGESIZE 0) + set(GASNETI_PAGESHIFT 0) +else() + set(GASNETI_PAGESIZE 4096) + set(GASNETI_PAGESHIFT 12) +endif() + +#--------------------------------------------------------------------- +# Cache line size detection +#--------------------------------------------------------------------- +set(GASNETI_CACHE_LINE_BYTES 64 CACHE STRING "Cache line size in bytes") +if(GASNETI_CACHE_LINE_BYTES EQUAL 128) + set(GASNETI_CACHE_LINE_SHIFT 7) +elseif(GASNETI_CACHE_LINE_BYTES EQUAL 64) + set(GASNETI_CACHE_LINE_SHIFT 6) +elseif(GASNETI_CACHE_LINE_BYTES EQUAL 32) + set(GASNETI_CACHE_LINE_SHIFT 5) +else() + set(GASNETI_CACHE_LINE_SHIFT 0) +endif() diff --git a/cmake/GasNetPthreads.cmake b/cmake/GasNetPthreads.cmake new file mode 100644 index 000000000..204122f27 --- /dev/null +++ b/cmake/GasNetPthreads.cmake @@ -0,0 +1,68 @@ +#============================================================================= +# GasNetPthreads.cmake - Pthreads detection +#============================================================================= + +if(GASNET_PTHREADS_MODE STREQUAL "OFF") + set(GASNET_HAVE_PTHREADS OFF) + return() +endif() + +find_package(Threads QUIET) + +if(NOT Threads_FOUND AND GASNET_PTHREADS_MODE STREQUAL "ON") + message(FATAL_ERROR "Pthreads requested but not found. Try setting GASNET_PTHREADS_MODE=AUTO or install pthreads.") +endif() + +if(Threads_FOUND) + set(GASNET_HAVE_PTHREADS ON) + set(GASNET_THREAD_DEFINES "${CMAKE_THREAD_LIBS_INIT}") + set(GASNET_THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}") + + # Set thread defines based on platform + if(APPLE) + set(GASNET_THREAD_DEFINES "") + elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(GASNET_THREAD_DEFINES "-D_THREAD_SAFE") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(GASNET_THREAD_DEFINES "-D_REENTRANT") + endif() + + # Detect pthread features + include(CheckFunctionExists) + include(CheckCSourceCompiles) + + check_function_exists("pthread_setconcurrency" HAVE_PTHREAD_SETCONCURRENCY) + check_function_exists("pthread_kill" HAVE_PTHREAD_KILL) + check_function_exists("pthread_sigmask" HAVE_PTHREAD_SIGMASK) + + # Check for pthread_rwlock_t + check_c_source_compiles(" + #include + int main(void) { pthread_rwlock_t rwlock; return 0; } + " GASNETI_HAVE_PTHREAD_RWLOCK) + + # Thread info optimization + if(NOT DEFINED GASNETI_THREADINFO_OPT_CONFIGURE) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") + set(GASNETI_THREADINFO_OPT_CONFIGURE 1) + else() + set(GASNETI_THREADINFO_OPT_CONFIGURE 0) + endif() + endif() + +else() + set(GASNET_HAVE_PTHREADS OFF) + set(GASNET_THREAD_DEFINES "") + set(GASNET_THREAD_LIBS "") +endif() + +# Threading library build flags +if(GASNET_BUILD_PAR AND NOT GASNET_HAVE_PTHREADS) + message(WARNING "PAR libraries require pthreads; disabling PAR and PARSYNC builds") + set(GASNET_BUILD_PAR OFF) + set(GASNET_BUILD_PARSYNC OFF) +endif() + +if(GASNET_BUILD_PARSYNC AND NOT GASNET_HAVE_PTHREADS) + set(GASNET_BUILD_PARSYNC OFF) +endif() diff --git a/cmake/GasNetTimer.cmake b/cmake/GasNetTimer.cmake new file mode 100644 index 000000000..61b9edc5b --- /dev/null +++ b/cmake/GasNetTimer.cmake @@ -0,0 +1,56 @@ +#============================================================================= +# GasNetTimer.cmake - High-performance timer detection +# +# GASNet uses platform-native timers with fallback to POSIX. +# Priority: RDTSC > mach_absolute_time > clock_gettime > gettimeofday +#============================================================================= + +# Force options override +if(GASNET_FORCE_GETTIMEOFDAY) + set(GASNETI_TIMER_IMPL "GETTIMEOFDAY") + return() +endif() + +if(GASNET_FORCE_POSIX_REALTIME AND HAVE_CLOCK_GETTIME) + set(GASNETI_TIMER_IMPL "POSIX_REALTIME") + return() +endif() + +# Detect sleep functions +include(CheckFunctionExists) +check_function_exists("clock_nanosleep" HAVE_CLOCK_NANOSLEEP) +check_function_exists("nsleep" HAVE_NSLEEP) + +# On Linux with x86/x86_64, use RDTSC +if(GASNET_PLATFORM_OS STREQUAL "LINUX" AND GASNETI_HAVE_CC_GCC_ASM) + if(GASNET_PLATFORM_ARCH STREQUAL "X86_64" OR GASNET_PLATFORM_ARCH STREQUAL "X86") + set(GASNETI_TIMER_IMPL "RDTSC") + endif() +endif() + +# On macOS, use mach_absolute_time +if(NOT GASNETI_TIMER_IMPL AND APPLE) + set(GASNETI_TIMER_IMPL "MACH") +endif() + +# On AARCH64 with GCC asm, use CNTVCT_EL0 +if(NOT GASNETI_TIMER_IMPL AND GASNETI_HAVE_CC_GCC_ASM AND GASNETI_HAVE_AARCH64_CNTVCT_EL0) + set(GASNETI_TIMER_IMPL "AARCH64") +endif() + +# On Cygwin, use QueryPerformanceCounter +if(NOT GASNETI_TIMER_IMPL AND CYGWIN) + set(GASNETI_TIMER_IMPL "QPC") +endif() + +# Fall back to clock_gettime if available +if(NOT GASNETI_TIMER_IMPL AND HAVE_CLOCK_GETTIME) + set(GASNETI_TIMER_IMPL "POSIX_REALTIME") +endif() + +# Ultimate fallback +if(NOT GASNETI_TIMER_IMPL) + set(GASNETI_TIMER_IMPL "GETTIMEOFDAY") +endif() + +message(STATUS "GASNet timer implementation: ${GASNETI_TIMER_IMPL}") diff --git a/cmake/gasnet_config.h.in b/cmake/gasnet_config.h.in new file mode 100644 index 000000000..8504ad9bb --- /dev/null +++ b/cmake/gasnet_config.h.in @@ -0,0 +1,184 @@ +/* gasnet_config.h - Generated by CMake for GASNet-EX */ +#ifndef GASNET_CONFIG_H +#define GASNET_CONFIG_H + +/* Version numbers */ +#define GASNET_RELEASE_VERSION_MAJOR @GASNET_RELEASE_VERSION_MAJOR@ +#define GASNET_RELEASE_VERSION_MINOR @GASNET_RELEASE_VERSION_MINOR@ +#define GASNET_RELEASE_VERSION_PATCH @GASNET_RELEASE_VERSION_PATCH@ +#define GASNETI_EX_SPEC_VERSION_MAJOR @GASNETEX_SPEC_VERSION_MAJOR@ +#define GASNETI_EX_SPEC_VERSION_MINOR @GASNETEX_SPEC_VERSION_MINOR@ +#define GASNETI_SPEC_VERSION_MAJOR @GASNET_SPEC_VERSION_MAJOR@ +#define GASNETI_SPEC_VERSION_MINOR @GASNET_SPEC_VERSION_MINOR@ +#define GASNETI_TOOLS_SPEC_VERSION_MAJOR @GASNETT_SPEC_VERSION_MAJOR@ +#define GASNETI_TOOLS_SPEC_VERSION_MINOR @GASNETT_SPEC_VERSION_MINOR@ +#define GASNETI_RELEASE_VERSION "@GASNET_RELEASE_VERSION@" + +/* Build configuration */ +@GASNET_DEBUG_DEFINE@ +@GASNET_NDEBUG_DEFINE@ +@GASNET_TRACE_DEFINE@ +@GASNET_STATS_DEFINE@ +@GASNET_SRCLINES_DEFINE@ +@GASNET_DEBUGMALLOC_DEFINE@ +@GASNET_DEBUG_VERBOSE_DEFINE@ +@GASNETI_VALGRIND_DEFINE@ + +/* Segment configuration */ +@GASNET_SEGMENT_DEFINE@ +@GASNETI_DISABLE_ALIGNED_SEGMENTS_DEFINE@ + +/* Platform / compiler identity (must match gasnet_portable_platform.h values) */ +#define GASNETI_PLATFORM_COMPILER_FAMILYID @GASNET_CC_FAMILYID@ +#define GASNETI_PLATFORM_COMPILER_ID @GASNET_CC_PLATFORM_ID@ +#define GASNETI_PLATFORM_COMPILER_VERSION @GASNET_CC_VERSION@ +#define GASNETI_PLATFORM_COMPILER_C_LANGLVL @GASNET_CC_LANGLVL@ +#define GASNETI_PLATFORM_CXX_FAMILYID @GASNET_CXX_FAMILYID@ +#define GASNETI_PLATFORM_CXX_ID @GASNET_CXX_PLATFORM_ID@ +#define GASNETI_PLATFORM_CXX_VERSION @GASNET_CXX_VERSION@ +#define GASNETI_PLATFORM_CXX_CXX_LANGLVL @GASNET_CXX_LANGLVL@ + +/* Compiler builtins */ +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_EXPECT +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_CONSTANT_P +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_PREFETCH +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_UNREACHABLE +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_BSWAP32 +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_BSWAP64 +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_CLZ +#cmakedefine01 GASNETI_HAVE_CC_BUILTIN_CTZ + +/* Inline assembly */ +#cmakedefine01 GASNETI_HAVE_CC_GCC_ASM +#cmakedefine01 GASNETI_HAVE_CXX_GCC_ASM + +/* __sync atomics */ +#cmakedefine01 GASNETI_HAVE_CC_SYNC_ATOMICS_32 +#cmakedefine01 GASNETI_HAVE_CC_SYNC_ATOMICS_64 +#cmakedefine01 GASNETI_HAVE_CC_SYNC_SYNCHRONIZE + +/* Architecture-specific */ +@WORDS_BIGENDIAN_VAL@ +#define SIZEOF_VOID_P @SIZEOF_VOID_P@ +#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@ +#cmakedefine01 GASNETI_HAVE_X86_CMPXCHG16B +#cmakedefine01 GASNETI_HAVE_AARCH64_CNTVCT_EL0 +#cmakedefine01 GASNETI_CONFIGURED_PIC + +/* Atomics */ +#define GASNETI_ATOMIC_IMPL_CONFIGURE @GASNETI_ATOMIC_IMPL_CONFIGURE@ +#define GASNETI_ATOMIC32_IMPL_CONFIGURE @GASNETI_ATOMIC32_IMPL_CONFIGURE@ +#define GASNETI_ATOMIC64_IMPL_CONFIGURE @GASNETI_ATOMIC64_IMPL_CONFIGURE@ + +/* Threading */ +#cmakedefine01 HAVE_PTHREAD_H +#cmakedefine01 GASNETI_HAVE_PTHREAD_RWLOCK +#cmakedefine01 GASNETI_HAVE_TLS_SUPPORT +#cmakedefine01 GASNETI_THREADINFO_OPT_CONFIGURE + +/* PSHM */ +@GASNETI_PSHM_ENABLED_VAL@ + +/* Page/cache sizes */ +#define GASNETI_PAGESIZE @GASNETI_PAGESIZE@ +#define GASNETI_PAGESHIFT @GASNETI_PAGESHIFT@ +#define GASNETI_CACHE_LINE_BYTES @GASNETI_CACHE_LINE_BYTES@ +#define GASNETI_CACHE_LINE_SHIFT @GASNETI_CACHE_LINE_SHIFT@ + +/* System headers */ +#cmakedefine01 HAVE_FEATURES_H +#cmakedefine01 HAVE_INTTYPES_H +#cmakedefine01 HAVE_STDINT_H +#cmakedefine01 HAVE_SYS_TYPES_H +#cmakedefine01 HAVE_EXECINFO_H + +/* System functions */ +#cmakedefine01 HAVE_MMAP +#cmakedefine01 HAVE_MAP_ANON +#cmakedefine01 HAVE_MAP_ANONYMOUS +#cmakedefine01 HAVE_MAP_NORESERVE +#cmakedefine01 HAVE_POSIX_MEMALIGN +#cmakedefine01 HAVE_CLOCK_GETTIME +#cmakedefine01 HAVE_SCHED_YIELD +#cmakedefine01 HAVE_USLEEP +#cmakedefine01 HAVE_NANOSLEEP +#cmakedefine01 HAVE_CLOCK_NANOSLEEP +#cmakedefine01 HAVE_NSLEEP +#cmakedefine01 HAVE_SNPRINTF_DECL +#cmakedefine01 HAVE_VSNPRINTF_DECL +#cmakedefine01 HAVE_ISBLANK_DECL +#cmakedefine01 HAVE_SIGACTION +#cmakedefine01 GASNETI_HAVE_SA_RESTART +#cmakedefine01 HAVE_BACKTRACE +#cmakedefine01 HAVE_BACKTRACE_SYMBOLS +@HAVE_PR_SET_PDEATHSIG_VAL@ +@HAVE_PR_SET_PTRACER_VAL@ +#cmakedefine01 HAVE_PTMALLOC + +/* Misc */ +#define HAVE_C99_FORMAT_SPECIFIERS @HAVE_C99_FORMAT_SPECIFIERS@ +#cmakedefine01 GASNETI_HAVE_PAUSE +#define GASNETI_PAUSE_INSTRUCTION @GASNETI_PAUSE_INSTRUCTION@ + +/* Memory kinds */ +#cmakedefine01 GASNETI_MK_CLASS_CUDA_UVA_ENABLED +#cmakedefine01 GASNETI_MK_CLASS_HIP_ENABLED +#cmakedefine01 GASNETI_MK_CLASS_ZE_ENABLED + +/* Force options */ +@GASNETI_FORCE_GENERIC_ATOMICOPS_DEFINE@ +@GASNETI_FORCE_OS_ATOMICOPS_DEFINE@ +@GASNETI_FORCE_COMPILER_ATOMICOPS_DEFINE@ +@GASNETI_FORCE_YIELD_MEMBARS_DEFINE@ +@GASNETI_FORCE_SLOW_MEMBARS_DEFINE@ +@GASNETI_FORCE_GETTIMEOFDAY_DEFINE@ +@GASNETI_FORCE_POSIX_REALTIME_DEFINE@ +@GASNETI_BUG1389_WORKAROUND_DEFINE@ + +/* PSHM subtypes */ +@GASNETI_PSHM_POSIX_VAL@ +@GASNETI_PSHM_SYSV_VAL@ +@GASNETI_PSHM_XPMEM_VAL@ +@GASNETI_PSHM_HUGETLBFS_VAL@ +@GASNETI_PSHM_FILE_VAL@ +#cmakedefine01 GASNETC_HAVE_O_ASYNC +#cmakedefine01 GASNETC_USE_SOCKETPAIR +#cmakedefine01 HAVE_SOCKETPAIR + +/* Cross-compiling */ +#cmakedefine01 GASNETI_CROSS_COMPILING + +/* Enabled conduits */ +#define GASNETI_CONDUITS @GASNETI_CONDUITS@ + +/* Conduit spawner configs */ +#define GASNETC_SMP_SPAWNER_CONF @GASNETC_SMP_SPAWNER_CONF@ + +/* Thread model alignment */ +#define GASNETI_TM0_ALIGN @GASNETI_TM0_ALIGN@ + +/* System identification */ +#define GASNETI_SYSTEM_TUPLE @GASNETI_SYSTEM_TUPLE@ +#define GASNETI_SYSTEM_NAME @GASNETI_SYSTEM_NAME@ +#define GASNETI_BUILD_ID @GASNETI_BUILD_ID@ +#define GASNETI_CONFIGURE_ARGS @GASNETI_CONFIGURE_ARGS@ + +/* Common symbol attribute for tentative definitions */ +@GASNETI_COMMON_VAL@ + +/* Default max segment size */ +#define GASNETI_MAX_SEGSIZE_CONFIGURE @GASNETI_MAX_SEGSIZE_CONFIGURE@ + +/* GCC subfamily */ +#cmakedefine01 GASNETI_GCC_GCCFSS +#cmakedefine01 GASNETI_GCC_APPLE + +/* Inline modifier (per compiler) */ +#define GASNETI_CC_INLINE_MODIFIER @GASNETI_CC_INLINE_MODIFIER@ +#define GASNETI_CXX_INLINE_MODIFIER @GASNETI_CXX_INLINE_MODIFIER@ + +/* Restrict keyword */ +#define GASNETI_CC_RESTRICT @GASNETI_CC_RESTRICT@ +#define GASNETI_CXX_RESTRICT @GASNETI_CXX_RESTRICT@ + +#endif /* GASNET_CONFIG_H */ diff --git a/conduits/CMakeLists.txt b/conduits/CMakeLists.txt new file mode 100644 index 000000000..068f27b26 --- /dev/null +++ b/conduits/CMakeLists.txt @@ -0,0 +1,56 @@ +#============================================================================= +# conduits/CMakeLists.txt - Build all enabled conduits +#============================================================================= + +include(GasNetConduit) + +# SMP conduit (always available -- shared memory loopback) +if(GASNET_ENABLE_SMP) + message(STATUS "Configuring smp-conduit") + add_subdirectory(smp) +endif() + +# UDP conduit (requires C++ for amudp; optional) +if(GASNET_ENABLE_UDP) + message(STATUS "Configuring udp-conduit") + add_subdirectory(udp) +endif() + +# MPI conduit (requires MPI) +if(GASNET_ENABLE_MPI) + message(STATUS "Configuring mpi-conduit") + add_subdirectory(mpi) +endif() + +# IB Verbs conduit (requires libibverbs) +if(GASNET_ENABLE_IBV) + find_package(IBVerbs QUIET) + if(IBVerbs_FOUND) + message(STATUS "Configuring ibv-conduit") + add_subdirectory(ibv) + else() + message(STATUS "libibverbs not found; skipping ibv-conduit") + endif() +endif() + +# OFI conduit (requires libfabric) +if(GASNET_ENABLE_OFI) + find_package(Libfabric QUIET) + if(Libfabric_FOUND) + message(STATUS "Configuring ofi-conduit") + add_subdirectory(ofi) + else() + message(STATUS "libfabric not found; skipping ofi-conduit") + endif() +endif() + +# UCX conduit (requires libucp) +if(GASNET_ENABLE_UCX) + find_package(UCX QUIET) + if(UCX_FOUND) + message(STATUS "Configuring ucx-conduit") + add_subdirectory(ucx) + else() + message(STATUS "UCX not found; skipping ucx-conduit") + endif() +endif() diff --git a/conduits/ibv/CMakeLists.txt b/conduits/ibv/CMakeLists.txt new file mode 100644 index 000000000..27ae59521 --- /dev/null +++ b/conduits/ibv/CMakeLists.txt @@ -0,0 +1,21 @@ +# ibv-conduit: Native InfiniBand Verbs conduit +find_package(IBVerbs REQUIRED) + +gasnet_conduit_setup(ibv + SRC_DIR "${PROJECT_SOURCE_DIR}/ibv-conduit" + SOURCES + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_core.c" + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_core_connect.c" + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_core_sndrcv.c" + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_core_thread.c" + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_extended.c" + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_firehose.c" + "${PROJECT_SOURCE_DIR}/ibv-conduit/gasnet_ratomic.c" + EXTRA_FLAGS + ${IBVERBS_CFLAGS} + LINK_LIBS + ${IBVERBS_LIBRARIES} + KINDS + cuda_uva hip + RUN_CMD "gasnetrun_ibv -np %N %P %A" +) diff --git a/conduits/mpi/CMakeLists.txt b/conduits/mpi/CMakeLists.txt new file mode 100644 index 000000000..f5e2231b4 --- /dev/null +++ b/conduits/mpi/CMakeLists.txt @@ -0,0 +1,16 @@ +# mpi-conduit: Portable MPI conduit +find_package(MPI REQUIRED COMPONENTS C) + +gasnet_conduit_setup(mpi + SRC_DIR "${PROJECT_SOURCE_DIR}/mpi-conduit" + SOURCES + "${PROJECT_SOURCE_DIR}/mpi-conduit/gasnet_core.c" + "${PROJECT_SOURCE_DIR}/extended-ref/gasnet_extended.c" + EXTRA_FLAGS + -I${PROJECT_SOURCE_DIR}/other/ammpi + -I${PROJECT_BINARY_DIR}/other/ammpi + ${MPI_C_COMPILE_FLAGS} + LINK_LIBS + ${MPI_C_LIBRARIES} + RUN_CMD "gasnetrun_mpi -np %N %P %A" +) diff --git a/conduits/ofi/CMakeLists.txt b/conduits/ofi/CMakeLists.txt new file mode 100644 index 000000000..cca978132 --- /dev/null +++ b/conduits/ofi/CMakeLists.txt @@ -0,0 +1,18 @@ +# ofi-conduit: Open Fabrics Interfaces conduit +find_package(Libfabric REQUIRED) + +gasnet_conduit_setup(ofi + SRC_DIR "${PROJECT_SOURCE_DIR}/ofi-conduit" + SOURCES + "${PROJECT_SOURCE_DIR}/ofi-conduit/gasnet_core.c" + "${PROJECT_SOURCE_DIR}/ofi-conduit/gasnet_extended.c" + "${PROJECT_SOURCE_DIR}/ofi-conduit/gasnet_ofi.c" + "${PROJECT_SOURCE_DIR}/ofi-conduit/gasnet_hwloc.c" + EXTRA_FLAGS + ${LIBFABRIC_CFLAGS} + LINK_LIBS + ${LIBFABRIC_LIBRARIES} + KINDS + cuda_uva hip ze + RUN_CMD "gasnetrun_ofi -np %N %P %A" +) diff --git a/conduits/smp/CMakeLists.txt b/conduits/smp/CMakeLists.txt new file mode 100644 index 000000000..af5afde18 --- /dev/null +++ b/conduits/smp/CMakeLists.txt @@ -0,0 +1,8 @@ +# smp-conduit: SMP shared-memory loopback +gasnet_conduit_setup(smp + SRC_DIR "${PROJECT_SOURCE_DIR}/smp-conduit" + SOURCES + "${PROJECT_SOURCE_DIR}/smp-conduit/gasnet_core.c" + "${PROJECT_SOURCE_DIR}/smp-conduit/gasnet_extended.c" + RUN_CMD "gasnetrun_smp -np %N %P %A" +) diff --git a/conduits/ucx/CMakeLists.txt b/conduits/ucx/CMakeLists.txt new file mode 100644 index 000000000..7a68bae25 --- /dev/null +++ b/conduits/ucx/CMakeLists.txt @@ -0,0 +1,18 @@ +# ucx-conduit: Unified Communication X conduit (experimental) +find_package(UCX REQUIRED) + +gasnet_conduit_setup(ucx + SRC_DIR "${PROJECT_SOURCE_DIR}/ucx-conduit" + SOURCES + "${PROJECT_SOURCE_DIR}/ucx-conduit/gasnet_core.c" + "${PROJECT_SOURCE_DIR}/ucx-conduit/gasnet_core_sndrcv.c" + "${PROJECT_SOURCE_DIR}/ucx-conduit/gasnet_extended.c" + "${PROJECT_SOURCE_DIR}/ucx-conduit/gasnet_ratomic.c" + EXTRA_FLAGS + ${UCX_CFLAGS} + LINK_LIBS + ${UCX_LIBRARIES} + KINDS + cuda_uva hip + RUN_CMD "gasnetrun_ucx -np %N %P %A" +) diff --git a/conduits/udp/CMakeLists.txt b/conduits/udp/CMakeLists.txt new file mode 100644 index 000000000..4e2c6a971 --- /dev/null +++ b/conduits/udp/CMakeLists.txt @@ -0,0 +1,11 @@ +# udp-conduit: Portable UDP/IP conduit +gasnet_conduit_setup(udp + SRC_DIR "${PROJECT_SOURCE_DIR}/udp-conduit" + SOURCES + "${PROJECT_SOURCE_DIR}/udp-conduit/gasnet_core.c" + "${PROJECT_SOURCE_DIR}/extended-ref/gasnet_extended.c" + EXTRA_FLAGS + -I${PROJECT_SOURCE_DIR}/other/amudp + -I${PROJECT_BINARY_DIR}/other/amudp + RUN_CMD "%P %N %A" +) diff --git a/extended-ref/CMakeLists.txt b/extended-ref/CMakeLists.txt new file mode 100644 index 000000000..47ae1d051 --- /dev/null +++ b/extended-ref/CMakeLists.txt @@ -0,0 +1,27 @@ +#============================================================================= +# extended-ref/CMakeLists.txt - Reference extended API implementation +# +# This directory contains sources for the reference implementation of the +# GASNet extended API. These sources are compiled directly into each conduit +# library (not as a separate library), so this file is a placeholder. +# The actual sources are listed in cmake/GasNetConduit.cmake. +#============================================================================= + +# Install extended-ref public headers alongside each conduit's headers +# These are included by conduit-specific install rules +set(EXTENDED_REF_HEADERS + "${CMAKE_CURRENT_SOURCE_DIR}/gasnet_extended.h" + "${CMAKE_CURRENT_SOURCE_DIR}/gasnet_extended_fwd.h" + "${CMAKE_CURRENT_SOURCE_DIR}/gasnet_extended_help.h" + "${CMAKE_CURRENT_SOURCE_DIR}/vis/gasnet_vis_fwd.h" + "${CMAKE_CURRENT_SOURCE_DIR}/ratomic/gasnet_ratomic_fwd.h" + "${CMAKE_CURRENT_SOURCE_DIR}/coll/gasnet_coll_fwd.h" +) + +# Install public API headers globally +install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/coll/gasnet_coll.h" + "${CMAKE_CURRENT_SOURCE_DIR}/ratomic/gasnet_ratomic.h" + "${CMAKE_CURRENT_SOURCE_DIR}/vis/gasnet_vis.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) diff --git a/other/CMakeLists.txt b/other/CMakeLists.txt new file mode 100644 index 000000000..2d6e112a5 --- /dev/null +++ b/other/CMakeLists.txt @@ -0,0 +1,127 @@ +#============================================================================= +# other/CMakeLists.txt - Build gasnet_tools library and supporting components +#============================================================================= + +#--------------------------------------------------------------------- +# gasnet_tools library - conduit-independent portability library +#--------------------------------------------------------------------- +set(TOOLS_SOURCES + "${PROJECT_SOURCE_DIR}/gasnet_tools.c" +) + +set(TOOLS_INCLUDES + "${PROJECT_SOURCE_DIR}" + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/other" +) + +# SEQ variant +if(GASNET_BUILD_SEQ) + add_library(gasnet_tools-seq STATIC ${TOOLS_SOURCES}) + target_include_directories(gasnet_tools-seq PRIVATE ${TOOLS_INCLUDES}) + target_compile_definitions(gasnet_tools-seq PRIVATE + -DGASNET_SEQ + -DGASNETT_THREAD_SINGLE + -DGASNETI_BUILDING_TOOLS + -D_GNU_SOURCE=1 + ) + set_target_properties(gasnet_tools-seq PROPERTIES + C_STANDARD 11 + POSITION_INDEPENDENT_CODE ON + ) + install(TARGETS gasnet_tools-seq ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") + message(STATUS " Created library: gasnet_tools-seq") +endif() + +# PAR variant (thread-safe) +if(GASNET_BUILD_PAR AND GASNET_HAVE_PTHREADS) + add_library(gasnet_tools-par STATIC ${TOOLS_SOURCES}) + target_include_directories(gasnet_tools-par PRIVATE ${TOOLS_INCLUDES}) + target_compile_definitions(gasnet_tools-par PRIVATE + -DGASNET_PAR + -DGASNETT_THREAD_SAFE + -DGASNETI_BUILDING_TOOLS + -D_GNU_SOURCE=1 + ${GASNET_THREAD_DEFINES} + ) + if(GASNET_THREAD_LIBS) + target_link_libraries(gasnet_tools-par PRIVATE ${GASNET_THREAD_LIBS}) + endif() + set_target_properties(gasnet_tools-par PROPERTIES + C_STANDARD 11 + POSITION_INDEPENDENT_CODE ON + ) + install(TARGETS gasnet_tools-par ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") + message(STATUS " Created library: gasnet_tools-par") +endif() + +#--------------------------------------------------------------------- +# Install other/ headers +#--------------------------------------------------------------------- +install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/gasnet_arch_arm.h" + "${CMAKE_CURRENT_SOURCE_DIR}/portable_inttypes.h" + "${CMAKE_CURRENT_SOURCE_DIR}/portable_platform.h" + "${CMAKE_CURRENT_SOURCE_DIR}/gasnet_portable_platform.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +#--------------------------------------------------------------------- +# Generate pkg-config files for tools library +#--------------------------------------------------------------------- +if(GASNET_BUILD_SEQ) + set(pc_file "${CMAKE_CURRENT_BINARY_DIR}/gasnet_tools-seq.pc") + file(WRITE "${pc_file}" "prefix=${CMAKE_INSTALL_PREFIX} +exec_prefix=\${prefix} +libdir=\${exec_prefix}/${CMAKE_INSTALL_LIBDIR} +includedir=\${prefix}/${CMAKE_INSTALL_INCLUDEDIR} + +Name: GASNet Tools (SEQ) +Description: GASNet-EX conduit-independent tools library (single-threaded) +Version: ${GASNET_RELEASE_VERSION} +URL: https://gasnet.lbl.gov + +Libs: -L\${libdir} -lgasnet_tools-seq +Cflags: -I\${includedir} +") + install(FILES "${pc_file}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif() + +if(GASNET_BUILD_PAR AND GASNET_HAVE_PTHREADS) + set(pc_file "${CMAKE_CURRENT_BINARY_DIR}/gasnet_tools-par.pc") + file(WRITE "${pc_file}" "prefix=${CMAKE_INSTALL_PREFIX} +exec_prefix=\${prefix} +libdir=\${exec_prefix}/${CMAKE_INSTALL_LIBDIR} +includedir=\${prefix}/${CMAKE_INSTALL_INCLUDEDIR} + +Name: GASNet Tools (PAR) +Description: GASNet-EX conduit-independent tools library (thread-safe) +Version: ${GASNET_RELEASE_VERSION} +URL: https://gasnet.lbl.gov + +Libs: -L\${libdir} -lgasnet_tools-par ${GASNET_THREAD_LIBS} +Cflags: -I\${includedir} +") + install(FILES "${pc_file}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif() + +#--------------------------------------------------------------------- +# Install documentation from other/spawner directories +#--------------------------------------------------------------------- +if(GASNET_ENABLE_SMP OR GASNET_ENABLE_IBV OR GASNET_ENABLE_OFI OR GASNET_ENABLE_UCX) + install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/ssh-spawner/README" + DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/GASNet" + RENAME "README-ssh-spawner" + ) + install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/mpi-spawner/README" + DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/GASNet" + RENAME "README-mpi-spawner" + ) + install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/pmi-spawner/README" + DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/GASNet" + RENAME "README-pmi-spawner" + ) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..80dc3bd3b --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,105 @@ +#============================================================================= +# tests/CMakeLists.txt - Build and run GASNet tests +#============================================================================= + +#--------------------------------------------------------------------- +# Test programs (GASNet API tests) +#--------------------------------------------------------------------- +set(GASNET_TESTS + testgasnet testlegacy testtools testinternal testenv testhsl + testsmall testlarge testval testam testmisc testcore1 testcore2 + testcore3 testcore4 testcore5 testslice testbarrier testbarrierconf + testbarrierlate testlogGP testalign testrand testexit testvis + testcoll testcollperf testteambarrier testteambcast testreduce + testteam testnbr testvisperf testqueue testratomic testfaddperf + testimm testsplit testacc testsegment testtmpair testreadonly + testalltoall testtoken testprogthr testmpi testcontend testlockcontend + testthreads testcxx testlegacycxx testtoolscxx +) + +set(TEST_INCLUDES + "${CMAKE_CURRENT_SOURCE_DIR}" + "${PROJECT_SOURCE_DIR}" + "${PROJECT_BINARY_DIR}" +) + +# Choose the first available conduit for test linking +set(TEST_CONDUIT "smp" CACHE STRING "Conduit to use for building tests") +set(TEST_THREAD_MODE "seq" CACHE STRING "Thread mode for tests: seq, par, or parsync") + +# Select the correct library based on conduit and thread mode +set(TEST_LIB "gasnet-${TEST_CONDUIT}-${TEST_THREAD_MODE}") + +# Only build tests if the requested library exists +if(TARGET ${TEST_LIB}) + foreach(test_name ${GASNET_TESTS}) + # Determine source file extension + set(test_ext "c") + if(test_name STREQUAL "testcxx" OR test_name STREQUAL "testlegacycxx") + set(test_ext "cc") + endif() + if(test_name STREQUAL "testtoolscxx") + set(test_ext "cc") + endif() + + set(test_src "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.${test_ext}") + + if(EXISTS "${test_src}") + add_executable(${test_name} "${test_src}") + target_include_directories(${test_name} PRIVATE ${TEST_INCLUDES}) + target_link_libraries(${test_name} PRIVATE ${TEST_LIB}) + + # Thread library for par/parsync tests + if(TEST_THREAD_MODE STREQUAL "par" OR TEST_THREAD_MODE STREQUAL "parsync") + if(GASNET_THREAD_LIBS) + target_link_libraries(${test_name} PRIVATE ${GASNET_THREAD_LIBS}) + endif() + endif() + + # Use MPI C++ linker for C++ tests if MPI is involved + if(test_name STREQUAL "testcxx" OR test_name STREQUAL "testlegacycxx") + set_source_files_properties("${test_src}" PROPERTIES LANGUAGE CXX) + endif() + + # Add test to CTest + add_test(NAME ${test_name} + COMMAND ${test_name} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + ) + endif() + endforeach() + + # delay.c is a special test utility compiled with -O0 + add_library(testdelay STATIC "${CMAKE_CURRENT_SOURCE_DIR}/delay.c") + target_include_directories(testdelay PRIVATE + ${TEST_INCLUDES} + "${PROJECT_SOURCE_DIR}/other" + ) + target_compile_definitions(testdelay PRIVATE -DGASNET_SEQ) + target_compile_options(testdelay PRIVATE "-O0") + if(TARGET testlogGP) + target_link_libraries(testlogGP PRIVATE testdelay) + endif() + if(TARGET testbarrierlate) + target_link_libraries(testbarrierlate PRIVATE testdelay) + endif() + + # GPU tests - conditionally built + if(GASNET_KIND_CUDA_UVA_ENABLED AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testcudauva.c") + add_executable(testcudauva "${CMAKE_CURRENT_SOURCE_DIR}/testcudauva.c") + target_include_directories(testcudauva PRIVATE ${TEST_INCLUDES}) + target_link_libraries(testcudauva PRIVATE ${TEST_LIB} ${CUDA_LIBRARIES}) + endif() + + if(GASNET_KIND_HIP_ENABLED AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testhip.c") + add_executable(testhip "${CMAKE_CURRENT_SOURCE_DIR}/testhip.c") + target_include_directories(testhip PRIVATE ${TEST_INCLUDES}) + target_link_libraries(testhip PRIVATE ${TEST_LIB}) + endif() + + if(GASNET_KIND_ZE_ENABLED AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/testze.c") + add_executable(testze "${CMAKE_CURRENT_SOURCE_DIR}/testze.c") + target_include_directories(testze PRIVATE ${TEST_INCLUDES}) + target_link_libraries(testze PRIVATE ${TEST_LIB}) + endif() +endif()