Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 67 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,56 @@ if(NOT DEFINED BUILD_EXAMPLES)
endif()
option(openPMD_BUILD_CLI_TOOLS "Build the command line tools" ${BUILD_CLI_TOOLS})
option(openPMD_BUILD_EXAMPLES "Build the examples" ${BUILD_EXAMPLES})
openpmd_option(CUDA_EXAMPLES "Use CUDA in examples" OFF)
# Remember whether the options were set explicitly (e.g. on the command line)
# before creating the cache entries. CMake marks command-line cache entries as
# UNINITIALIZED until the option() call assigns them a type.
if(DEFINED openPMD_USE_CUDA)
set(openPMD_USE_CUDA_explicit TRUE)
get_property(_openPMD_USE_CUDA_type CACHE openPMD_USE_CUDA PROPERTY TYPE)
if(_openPMD_USE_CUDA_type STREQUAL "UNINITIALIZED")
set(openPMD_USE_CUDA_user_specified TRUE)
else()
set(openPMD_USE_CUDA_user_specified FALSE)
endif()
else()
set(openPMD_USE_CUDA_explicit FALSE)
set(openPMD_USE_CUDA_user_specified FALSE)
endif()
if(DEFINED openPMD_USE_CUDA_EXAMPLES)
get_property(_openPMD_USE_CUDA_EXAMPLES_type CACHE
openPMD_USE_CUDA_EXAMPLES PROPERTY TYPE)
if(_openPMD_USE_CUDA_EXAMPLES_type STREQUAL "UNINITIALIZED")
set(openPMD_USE_CUDA_EXAMPLES_user_specified TRUE)
else()
set(openPMD_USE_CUDA_EXAMPLES_user_specified FALSE)
endif()
else()
set(openPMD_USE_CUDA_EXAMPLES_user_specified FALSE)
endif()
openpmd_option(CUDA "Use CUDA in tests and examples" OFF)

# deprecated: backwards compatibility to the CUDA_EXAMPLES option
openpmd_option(CUDA_EXAMPLES "Deprecated: use openPMD_USE_CUDA" OFF)
mark_as_advanced(openPMD_USE_CUDA_EXAMPLES)
if(openPMD_USE_CUDA_user_specified
AND openPMD_USE_CUDA_EXAMPLES_user_specified)
message(WARNING
"Both openPMD_USE_CUDA and the deprecated openPMD_USE_CUDA_EXAMPLES "
"were specified; openPMD_USE_CUDA takes precedence.")
endif()
if(NOT openPMD_USE_CUDA_EXAMPLES STREQUAL "OFF")
message(DEPRECATION
"openPMD_USE_CUDA_EXAMPLES is deprecated; use openPMD_USE_CUDA")
if(NOT openPMD_USE_CUDA_explicit)
set(openPMD_USE_CUDA "${openPMD_USE_CUDA_EXAMPLES}" CACHE STRING
"Use CUDA in tests and examples" FORCE)
endif()
endif()
unset(openPMD_USE_CUDA_explicit)
unset(openPMD_USE_CUDA_user_specified)
unset(openPMD_USE_CUDA_EXAMPLES_user_specified)
unset(_openPMD_USE_CUDA_type)
unset(_openPMD_USE_CUDA_EXAMPLES_type)


# Helper Functions ############################################################
Expand Down Expand Up @@ -272,14 +321,19 @@ target_link_libraries(openPMD::thirdparty::toml11
INTERFACE toml11::toml11)

# external: CUDA (optional)
if(openPMD_BUILD_EXAMPLES) # currently only used in examples
if(openPMD_USE_CUDA_EXAMPLES STREQUAL AUTO)
find_package(CUDAToolkit)
elseif(openPMD_USE_CUDA_EXAMPLES)
find_package(CUDAToolkit REQUIRED)
endif()
if(openPMD_USE_CUDA STREQUAL AUTO)
find_package(CUDAToolkit QUIET)
set(openPMD_HAVE_CUDA ${CUDAToolkit_FOUND})
elseif(openPMD_USE_CUDA)
find_package(CUDAToolkit REQUIRED)
set(openPMD_HAVE_CUDA TRUE)
else()
set(openPMD_HAVE_CUDA FALSE)
endif()
if(CUDAToolkit_FOUND)

# The CUDA language is only needed to compile the examples. Tests only use the
# CUDA runtime, which is linked via the CUDA::cudart imported target.
if(openPMD_HAVE_CUDA AND openPMD_BUILD_EXAMPLES)
enable_language(CUDA)
set(openPMD_HAVE_CUDA_EXAMPLES TRUE)
else()
Expand Down Expand Up @@ -858,6 +912,7 @@ if(openPMD_BUILD_TESTING)
test/Files_SerialIO/components_without_extent.cpp
test/Files_SerialIO/read_while_writing.cpp
test/Files_SerialIO/file_state_lifetime.cpp
test/Files_SerialIO/adios2_array_ordering.cpp
)
elseif(${test_name} STREQUAL "ParallelIO" AND openPMD_HAVE_MPI)
list(APPEND ${out_list}
Expand Down Expand Up @@ -910,6 +965,10 @@ if(openPMD_BUILD_TESTING)
target_compile_definitions(${testname}Tests PRIVATE openPMD_USE_INVASIVE_TESTS=1)
endif()
target_link_libraries(${testname}Tests PRIVATE openPMD)
if(${testname} STREQUAL SerialIO AND openPMD_HAVE_CUDA)
target_link_libraries(${testname}Tests PRIVATE CUDA::cudart)
target_compile_definitions(${testname}Tests PRIVATE openPMD_TEST_CUDA=1)
endif()
if(${testname} MATCHES "Parallel.+$")
# Parallel tests use CatchRunner (custom main with MPI)
target_link_libraries(${testname}Tests PRIVATE CatchRunner)
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Optional language bindings:
* mpi4py 2.1+ (optional, for MPI)
* pandas 1.0+ (optional, for dataframes)
* dask 2021+ (optional, for dask dataframes)
* CUDA C++ (optional, currently used only in tests)
* CUDA C++ (optional, used in tests and examples)

## Installation

Expand Down Expand Up @@ -284,7 +284,11 @@ In order to skip building those, pass ``OFF`` to these ``cmake`` options:
| `openPMD_BUILD_TESTING` | **ON**/OFF | Build tests |
| `openPMD_BUILD_EXAMPLES` | **ON**/OFF | Build examples |
| `openPMD_BUILD_CLI_TOOLS` | **ON**/OFF | Build command-line tools |
| `openPMD_USE_CUDA_EXAMPLES` | ON/**OFF** | Use CUDA in examples |
| `openPMD_USE_CUDA` | ON/AUTO/**OFF** | Use CUDA in tests and examples |

CUDA is never used unless requested. The deprecated
`openPMD_USE_CUDA_EXAMPLES` option is kept as an advanced alias for
`openPMD_USE_CUDA`.

## Linking to your project

Expand Down
1 change: 1 addition & 0 deletions docs/source/backends/adios2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ environment variable default description
``OPENPMD_ADIOS2_NUM_SUBSTREAMS`` ``0`` Number of files to be created, 0 indicates maximum number possible.
``OPENPMD_ADIOS2_ENGINE`` ``File`` `ADIOS2 engine <https://adios2.readthedocs.io/en/latest/engines/engines.html>`_
``OPENPMD_ADIOS2_PRETEND_ENGINE`` *empty* Pretend that an (unknown) ADIOS2 engine is in fact another one (also see the ``adios2.pretend_engine`` :ref:`parameter <backendconfig-adios2>`).
``OPENPMD_ADIOS2_ARRAY_ORDERING`` see below Array ordering passed to ADIOS2 (``adios2_default``, ``row_major`` or ``column_major``, see the ``adios2.dataset.array_ordering`` :ref:`parameter <backendconfig-adios2>`). Defaults to ``adios2_default``.
``OPENPMD2_ADIOS2_USE_GROUP_TABLE`` ``0`` Use group table (see below)
``OPENPMD_ADIOS2_STATS_LEVEL`` see below Whether to generate statistics for variables in ADIOS2. (``1``: yes, ``0``: no)
``OPENPMD_ADIOS2_ASYNC_WRITE`` ``0`` ADIOS2 BP5 engine: 1 means setting "AsyncWrite" in ADIOS2 to "on". Flushes will go to the buffer by default (see ``preferred_flush_target``).
Expand Down
1 change: 1 addition & 0 deletions docs/source/details/adios2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
},
"dataset": {
"array_ordering": "adios2_default",
"operators": [
{
"type": "blosc",
Expand Down
4 changes: 4 additions & 0 deletions docs/source/details/adios2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# however rank 0 should be the most common option here
attribute_writing_ranks = 0

[adios2.dataset]
# one of "adios2_default", "row_major" or "column_major"
array_ordering = "adios2_default"

[adios2.engine]
type = "sst"
preferred_flush_target = "disk"
Expand Down
7 changes: 7 additions & 0 deletions docs/source/details/backendconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ Explanation of the single keys:
Additionally, specifying ``"disk_override"``, ``"buffer_override"`` or ``"new_step_override"`` will take precedence over options specified without the ``_override`` suffix, allowing to invert the normal precedence order.
This way, a data producing code can hardcode the preferred flush target per ``flush()`` call, but users can e.g. still entirely deactivate flushing to disk in the ``Series`` constructor by specifying ``preferred_flush_target = buffer_override``.
This is useful when applying the asynchronous IO capabilities of the BP5 engine.
* ``adios2.dataset.array_ordering``: Forwards the array ordering to ``adios2::Variable::SetArrayLayout``.
Possible values are ``"adios2_default"`` (default, let ADIOS2 decide), ``"row_major"`` and ``"column_major"``.
This option is only effective with ADIOS2 2.10 or newer built with GPU support (CUDA or Kokkos), where it controls how ADIOS2 interprets buffers.
It does not change the row-major semantics of datasets in the openPMD-api itself.
In GPU-enabled ADIOS2 builds, specifying ``"row_major"`` prevents ADIOS2 from automatically switching GPU buffers to column-major ordering.
In other builds, configuring anything other than ``"adios2_default"`` emits a warning since it cannot take effect.
Can also be set via the environment variable ``OPENPMD_ADIOS2_ARRAY_ORDERING``; a JSON/TOML option takes precedence.
* ``adios2.dataset.operators``: This key contains either a single ADIOS2 `operator <https://adios2.readthedocs.io/en/latest/components/components.html#operator>`_ or a list of operators, used to enable compression or dataset transformations.
Each operator is an object with two keys:

Expand Down
11 changes: 10 additions & 1 deletion docs/source/dev/buildoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,14 @@ CMake Option Values Description
``openPMD_BUILD_TESTING`` **ON**/OFF Build tests
``openPMD_BUILD_EXAMPLES`` **ON**/OFF Build examples
``openPMD_BUILD_CLI_TOOLS`` **ON**/OFF Build command-line tools
``openPMD_USE_CUDA_EXAMPLES`` ON/**OFF** Use CUDA in examples
``openPMD_USE_CUDA`` ON/AUTO/**OFF** Use CUDA in tests and examples
=============================== =============== ==================================================

CUDA is never used unless requested. The deprecated
``openPMD_USE_CUDA_EXAMPLES`` option is kept as an advanced alias for
``openPMD_USE_CUDA``.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could alternatively drop openPMD_USE_CUDA_EXAMPLES entirely. It is irrelevant for install scripts, so it's a reasonable break to change the option name. I don't want to introduce openPMD_USE_CUDA_TESTS next to the examples option, the level of control would be more fine-grained than anyone would really care about.


To run the GPU-aware tests, configure with ``-DopenPMD_USE_CUDA=ON`` and an
ADIOS2 build with GPU support (ADIOS2 2.10 or newer). The CUDA-specific tests
are tagged with ``[cuda]`` and can be run with
``./build/bin/SerialIOTests "[cuda]"``.
65 changes: 63 additions & 2 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ class ADIOS2IOHandlerImpl

UseSpan m_useSpanBasedPutByDefault = UseSpan::Auto;

enum class ArrayOrdering : char
{
Adios2Default,
RowMajor,
ColumnMajor
};

ArrayOrdering m_arrayOrdering = ArrayOrdering::Adios2Default;

enum class ModifiableAttributes : char
{
Yes,
Expand Down Expand Up @@ -356,8 +365,19 @@ class ADIOS2IOHandlerImpl
// use m_config
std::optional<std::vector<ParameterizedOperator>> getOperators();

static ArrayOrdering parseArrayOrdering(
std::string const &value, std::vector<std::string> const &configPath);

std::optional<ArrayOrdering> getArrayOrdering(json::TracingJSON config);

struct DatasetConfiguration
{
std::vector<ParameterizedOperator> operators;
ArrayOrdering arrayOrdering;
};

template <typename Parameter>
std::vector<ParameterizedOperator> getDatasetOperators(
DatasetConfiguration getDatasetConfiguration(
Parameter const &, Writable *, std::string const &varName);

std::string fileSuffix(bool verbose = true) const;
Expand Down Expand Up @@ -491,6 +511,40 @@ class ADIOS2IOHandlerImpl
var.SetStepSelection({step_selection, 1});
}

template <typename T>
void
applyArrayOrdering(adios2::Variable<T> &var, ArrayOrdering arrayOrdering)
{
#if openPMD_HAS_ADIOS_2_10 && \
(defined(ADIOS2_HAVE_GPU_SUPPORT) || defined(ADIOS2_HAVE_KOKKOS))
switch (arrayOrdering)
{
case ArrayOrdering::Adios2Default:
// leave the layout up to ADIOS2
break;
case ArrayOrdering::RowMajor:
var.SetArrayLayout(adios2::ArrayOrdering::RowMajor);
break;
case ArrayOrdering::ColumnMajor:
var.SetArrayLayout(adios2::ArrayOrdering::ColumnMajor);
break;
}
#else
(void)var;
if (arrayOrdering != ArrayOrdering::Adios2Default &&
!printedWarningsAlready.arrayOrderingUnsupported)
{
std::cerr
<< "[ADIOS2] Warning: The configured array ordering will be "
"ignored because this ADIOS2 build does not support it. "
"The 'adios2.dataset.array_ordering' option requires "
"ADIOS2 >= 2.10 built with GPU support."
<< std::endl;
printedWarningsAlready.arrayOrderingUnsupported = true;
}
#endif
}

/*
* Prepare a variable that already exists for an IO
* operation, including:
Expand Down Expand Up @@ -623,6 +677,7 @@ class ADIOS2IOHandlerImpl
{
bool noGroupBased = false;
bool blosc2bp5 = false;
bool arrayOrderingUnsupported = false;
} printedWarningsAlready;
}; // ADIOS2IOHandlerImpl

Expand Down Expand Up @@ -685,6 +740,7 @@ namespace detail
std::optional<size_t> stepSelection,
std::vector<ADIOS2IOHandlerImpl::ParameterizedOperator> const
&operators,
ADIOS2IOHandlerImpl::ArrayOrdering arrayOrdering,
detail::AdiosVariables const &);

static constexpr char const *errorMsg = "ADIOS2: openDataset()";
Expand All @@ -695,6 +751,7 @@ namespace detail
/**
* @brief Define a Variable of type T within the passed IO.
*
* @param impl The ADIOS2 backend implementation.
* @param IO The adios2::IO object within which to define the
* variable. The variable can later be retrieved from
* the IO using the passed name.
Expand All @@ -706,17 +763,21 @@ namespace detail
* @param start As in adios2::IO::DefineVariable
* @param count As in adios2::IO::DefineVariable
* @param constantDims As in adios2::IO::DefineVariable
* @param arrayOrdering The array ordering to apply to the variable.
*/
template <typename T>
static void call(
ADIOS2IOHandlerImpl *impl,
adios2::IO &IO,
std::string const &name,
std::vector<ADIOS2IOHandlerImpl::ParameterizedOperator> const
&compressions,
adios2::Dims const &shape = adios2::Dims(),
adios2::Dims const &start = adios2::Dims(),
adios2::Dims const &count = adios2::Dims(),
bool const constantDims = false);
bool const constantDims = false,
ADIOS2IOHandlerImpl::ArrayOrdering arrayOrdering =
ADIOS2IOHandlerImpl::ArrayOrdering::Adios2Default);

static constexpr char const *errorMsg = "ADIOS2: defineVariable()";
};
Expand Down
Loading
Loading