Skip to content

Commit

Permalink
Merge branch 'develop' into feature/array_view_variant
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck authored Sep 19, 2024
2 parents ed15c84 + 59efc06 commit 529d362
Show file tree
Hide file tree
Showing 35 changed files with 473 additions and 97 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

## [Unreleased]

## [0.39.0] - 2024-09-18

### Added
- Add HIC abstraction layer for HIP and CUDA by @wdeconinck in https://github.com/ecmwf/atlas/pull/219
- Support for HIP via HIC
- Add regional interpolation by @benjaminmenetrier in https://github.com/ecmwf/atlas/pull/215
- Pack vector components into higher-rank vector fields. by @odlomax in https://github.com/ecmwf/atlas/pull/218

### Fixed
- Fix missing header in FieldImpl.h by @tehrengruber in https://github.com/ecmwf/atlas/pull/214
- Bug fixes to vector interpolation with StructuredColumns and spherical vector interpolation by @MarekWlasak in https://github.com/ecmwf/atlas/pull/222


## [0.38.1] - 2024-07-15

### Fixed
Expand Down Expand Up @@ -551,6 +564,7 @@ Fix StructuredInterpolation2D with retry for failed stencils
## 0.13.0 - 2018-02-16

[Unreleased]: https://github.com/ecmwf/atlas/compare/master...develop
[0.39.0]: https://github.com/ecmwf/atlas/compare/0.38.1...0.39.0
[0.38.1]: https://github.com/ecmwf/atlas/compare/0.38.0...0.38.1
[0.38.0]: https://github.com/ecmwf/atlas/compare/0.37.0...0.38.0
[0.37.0]: https://github.com/ecmwf/atlas/compare/0.36.0...0.37.0
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ ecbuild_add_option( FEATURE ECKIT_DEVELOP
DESCRIPTION "Used to enable new features or API depending on eckit develop branch, not yet in a tagged release"
DEFAULT OFF )

add_subdirectory( hic )
find_package(hic)


include( features/BOUNDSCHECKING )
include( features/FORTRAN )
Expand All @@ -84,9 +87,6 @@ include( features/INIT_SNAN )
include( features/DOCS )
include( features/ATLAS_RUN )

add_subdirectory( hic )
find_package(hic)

################################################################################
# sources

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.38.1
0.39.0
5 changes: 3 additions & 2 deletions cmake/atlas_compile_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

if( CMAKE_CXX_COMPILER_ID MATCHES Cray )


ecbuild_add_cxx_flags("-hnomessage=3140" NAME atlas_cxx_disable_warnings ) # colon separated numbers
if( NOT CMAKE_CXX_COMPILER_ID MATCHES CrayClang )
ecbuild_add_cxx_flags("-hnomessage=3140" NAME atlas_cxx_disable_warnings ) # colon separated numbers
endif()
ecbuild_add_fortran_flags("-hnomessage=3140" NAME atlas_fortran_disable_warnings ) # colon separated numbers

# CC-3140 crayc++: WARNING File = atlas/functionspace/NodeColumns.cc, Line = 1, Column = 1
Expand Down
2 changes: 1 addition & 1 deletion cmake/atlas_host_device.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function( atlas_host_device srclist )
set( multi_value_args SOURCES )
cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${ARGN} )

if( HAVE_CUDA OR HAVE_HIP )
if( HAVE_GPU )
set( use_hic_srclist ${_PAR_SOURCES} )

foreach( src ${use_hic_srclist} )
Expand Down
10 changes: 9 additions & 1 deletion cmake/features/ACC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
if( atlas_HAVE_ATLAS_FIELD )

set( ATLAS_ACC_CAPABLE FALSE )
if( HAVE_CUDA )
if( HAVE_GPU )
if( CMAKE_Fortran_COMPILER_ID MATCHES "PGI|NVHPC" )
set( ATLAS_ACC_CAPABLE TRUE )
else()
find_package(OpenACC COMPONENTS C Fortran)
if(OpenACC_Fortran_FOUND AND OpenACC_C_FOUND)
set( ATLAS_ACC_CAPABLE TRUE )
endif()
endif()
endif()

Expand All @@ -22,6 +27,9 @@ if( atlas_HAVE_ACC )
if( NOT ACC_C_COMPILER )
ecbuild_error( "Could not find OpenACC capable C compiler" )
endif()
else()
set( ACC_Fortran_FLAGS ${OpenACC_Fortran_FLAGS} )
set( ACC_C_FLAGS ${OpenACC_C_FLAGS} )
endif()
endif()

Expand Down
42 changes: 32 additions & 10 deletions cmake/features/CUDA.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@

ecbuild_add_option( FEATURE CUDA
DESCRIPTION "Enable CUDA support"
DEFAULT OFF
)
# ecbuild_add_option( FEATURE CUDA
# DESCRIPTION "Enable CUDA support"
# DEFAULT OFF
# )
# ecbuild_add_option( FEATURE HIP
# DESCRIPTION "Enable CUDA support"
# DEFAULT OFF
# )

if( HAVE_CUDA )

enable_language( CUDA )
ecbuild_info( "CUDA language enabled" )

find_package( CUDAToolkit REQUIRED )
set( atlas_HAVE_CUDA 0 )
set( atlas_HAVE_HIP 0 )
set( atlas_HAVE_GPU 0 )

if( hic_HAVE_CUDA )
enable_language( CUDA )
ecbuild_info( "CUDA language enabled" )
find_package(CUDAToolkit REQUIRED)
set( atlas_HAVE_CUDA 1 )
set( atlas_HAVE_GPU 1 )
elseif( hic_HAVE_HIP )
enable_language( HIP )
ecbuild_info( "HIP language enabled" )
find_package(hip CONFIG REQUIRED)
set( atlas_HAVE_HIP 1 )
set( atlas_HAVE_GPU 1 )
endif()

set( HAVE_CUDA ${atlas_HAVE_CUDA} )
set( HAVE_HIP ${atlas_HAVE_HIP} )
set( HAVE_GPU ${atlas_HAVE_GPU} )

if( HAVE_GPU )
ecbuild_info("GPU support enabled")
else()
ecbuild_info("GPU support not enabled")
endif()
4 changes: 2 additions & 2 deletions cmake/project_summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ if( atlas_HAVE_GRIDTOOLS_STORAGE )

else()

if( NOT atlas_HAVE_CUDA )
if( NOT atlas_HAVE_GPU )
ecbuild_info( "Array storage backend: Native [HOST]" )
else()
ecbuild_info( "Array storage backend: Native [CUDA]" )
ecbuild_info( "Array storage backend: Native [GPU]" )
endif()

endif()
Expand Down
5 changes: 4 additions & 1 deletion hic/src/hic/hic.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
#endif

inline void hic_assert(hicError_t err, const char* const func, const char* const file, const int line) {
if (err != hicSuccess) {
// Ignore errors when HIP/CUDA runtime is unloaded or deinitialized.
// This happens when calling HIP/CUDA after main has ended, e.g. in teardown of static variables calling `hicFree`
// --> ignore hicErrorDeinitialized (a.k.a. cudaErrorCudartUnloading / hipErrorDeinitialized)
if (err != hicSuccess && err != hicErrorDeinitialized) {
std::ostringstream msg;
msg << "HIC Runtime Error [code="<<err<<"] at: " << file << " + " << line << " : " << func << "\n";
msg << " Reason: " << hicGetErrorString(err);
Expand Down
24 changes: 24 additions & 0 deletions hic/src/hic/hic_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@
#include <cuda_runtime.h>
#elif HIC_BACKEND_HIP
#define HIC_BACKEND hip
#if defined(DEPRECATED)
#define DEFINED_OUTERSCOPE DEPRECATED
#undef DEPRECATED
#endif
#include <hip/hip_runtime.h>
#if defined(DEPRECATED)
#undef DEPRECATED
#endif
#if defined(DEFINED_OUTERSCOPE)
#define DEPRECATED DEFINED_OUTERSCOPE
#endif

#if HIP_VERSION_MAJOR < 6
enum hicMemoryType {
hicMemoryTypeUnregistered = 0 ,
hicMemoryTypeHost = 1 ,
Expand Down Expand Up @@ -68,6 +79,7 @@
attributes->hostPointer = attr_.hostPointer;
return err;
};
#endif

#elif HIC_BACKEND_DUMMY
#define HIC_BACKEND dummy
Expand Down Expand Up @@ -118,6 +130,8 @@ HIC_FUNCTION(MemPrefetchAsync)
HIC_FUNCTION(PeekAtLastError)
#if !HIC_BACKEND_HIP
HIC_FUNCTION(PointerGetAttributes)
#elif HIP_VERSION_MAJOR >= 6
HIC_FUNCTION(PointerGetAttributes)
#endif
HIC_FUNCTION(StreamCreate)
HIC_FUNCTION(StreamDestroy)
Expand All @@ -128,6 +142,8 @@ HIC_TYPE(Event_t)
HIC_TYPE(Stream_t)
#if !HIC_BACKEND_HIP
HIC_TYPE(PointerAttributes)
#elif HIP_VERSION_MAJOR >= 6
using HIC_SYMBOL(PointerAttributes) = HIC_BACKEND_SYMBOL(PointerAttribute_t);
#endif

HIC_VALUE(CpuDeviceId)
Expand All @@ -142,6 +158,14 @@ HIC_VALUE(MemcpyDeviceToHost)
HIC_VALUE(MemcpyHostToDevice)
HIC_VALUE(Success)

#if HIC_BACKEND_CUDA
constexpr hicError_t hicErrorDeinitialized = cudaErrorCudartUnloading;
#elif HIC_BACKEND_HIP
constexpr hicError_t hicErrorDeinitialized = hipErrorDeinitialized;
#else
constexpr hicError_t hicErrorDeinitialized = 4;
#endif

//------------------------------------------------
HIC_NAMESPACE_END
//------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/atlas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ library/detail/BlackMagic.h
library/detail/Debug.h


parallel/acc/acc.cc
parallel/acc/acc.h
parallel/mpi/mpi.cc
parallel/mpi/mpi.h
parallel/omp/omp.cc
Expand Down Expand Up @@ -929,7 +931,7 @@ list( APPEND source_list
)


if( atlas_HAVE_CUDA )
if( atlas_HAVE_GPU )
include( atlas_host_device )
list( APPEND source_list
parallel/HaloExchangeGPU.h
Expand Down Expand Up @@ -1001,4 +1003,12 @@ ecbuild_add_library( TARGET atlas

)

if( HAVE_ACC )
target_link_options( atlas INTERFACE
$<$<LINK_LANG_AND_ID:C,NVHPC>:SHELL:-acc=gpu>
$<$<LINK_LANG_AND_ID:CXX,NVHPC>:SHELL:-acc=gpu>
$<$<LINK_LANG_AND_ID:Fortran,NVHPC>:SHELL:-acc=gpu>
$<$<LINK_LANG_AND_ID:CUDA,NVIDIA>:SHELL:-acc=gpu> )
endif()

target_compile_features( atlas PUBLIC cxx_std_17 )
8 changes: 4 additions & 4 deletions src/atlas/array/SVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@ class SVector {

ATLAS_HOST_DEVICE
T& operator()(const idx_t idx) {
assert(data_ && idx < size_);
//assert(data_ && idx < size_);
return data_[idx];
}
ATLAS_HOST_DEVICE
T const& operator()(const idx_t idx) const {
assert(data_ && idx < size_);
//assert(data_ && idx < size_);
return data_[idx];
}

ATLAS_HOST_DEVICE
T& operator[](const idx_t idx) {
assert(data_ && idx < size_);
//assert(data_ && idx < size_);
return data_[idx];
}
ATLAS_HOST_DEVICE
T const& operator[](const idx_t idx) const {
assert(data_ && idx < size_);
//assert(data_ && idx < size_);
return data_[idx];
}

Expand Down
8 changes: 6 additions & 2 deletions src/atlas/array/native/NativeArrayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ class ArrayView {
ATLAS_HOST_DEVICE
void check_bounds(Ints... idx) const {
static_assert(sizeof...(idx) == Rank, "Expected number of indices is different from rank of array");
#if ATLAS_HOST_COMPILE
return check_bounds_part<0>(idx...);
#endif
}
#else
template <typename... Ints>
Expand All @@ -366,11 +368,13 @@ class ArrayView {
ATLAS_HOST_DEVICE
void check_bounds_force(Ints... idx) const {
static_assert(sizeof...(idx) == Rank, "Expected number of indices is different from rank of array");
#if ATLAS_HOST_COMPILE
return check_bounds_part<0>(idx...);
#endif
}

template <int Dim, typename Int, typename... Ints>
ATLAS_HOST_DEVICE
ATLAS_HOST
void check_bounds_part(Int idx, Ints... next_idx) const {
if (idx_t(idx) >= shape_[Dim]) {
throw_OutOfRange("ArrayView", array_dim<Dim>(), idx, shape_[Dim]);
Expand All @@ -379,7 +383,7 @@ class ArrayView {
}

template <int Dim, typename Int>
ATLAS_HOST_DEVICE
ATLAS_HOST
void check_bounds_part(Int last_idx) const {
if (idx_t(last_idx) >= shape_[Dim]) {
throw_OutOfRange("ArrayView", array_dim<Dim>(), last_idx, shape_[Dim]);
Expand Down
Loading

0 comments on commit 529d362

Please sign in to comment.