Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,5 @@ jobs:
dependency_branch: develop
dependency_cmake_options: |
ecmwf-ifs/fiat: "-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -G Ninja -DENABLE_TESTS=OFF ${{ matrix.cmake_options}}"
cmake_options: "-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ${{ matrix.cmake_options }} -G Ninja -DENABLE_ACC=OFF -DENABLE_MPI=ON -DENABLE_IO_PARALLEL=ON -DENABLE_GET_VIEW_ABORT=${{ matrix.get_view_abort }} -DENABLE_DELAYED=${{ matrix.delayed }} ${{matrix.cmake_options}}"
cmake_options: "-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ${{ matrix.cmake_options }} -G Ninja -DENABLE_ACC=OFF -DENABLE_MPI=ON -DENABLE_IO_PARALLEL=ON -DENABLE_GET_VIEW_ABORT=${{ matrix.get_view_abort }} -DENABLE_DELAYED=${{ matrix.delayed }} -DENABLE_GUARD_0_SIZE=${{ matrix.delayed }} ${{matrix.cmake_options}}"
ctest_options: "${{ matrix.ctest_options }}"
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ ecbuild_add_option( FEATURE DELAYED
DEFAULT OFF
)

##Guard 0 sized allocations
ecbuild_add_option( FEATURE GUARD_0_SIZE
DESCRIPTION "Enable this option to guard 0 sized arrays in FIELD_ACCESS module"
DEFAULT ON
)

## fypp preprocessor flags
if(HAVE_CUDA OR HAVE_HIPFORT)
Expand All @@ -104,6 +109,9 @@ endif()
if(fiat_FOUND)
list( APPEND fypp_defines "-DWITH_FIAT")
endif()
if(HAVE_GUARD_0_SIZE)
list( APPEND fypp_defines "-DWITH_GUARD_0_SIZE")
endif()

## build precision independent srcs
add_subdirectory(src)
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Features of FIELD_API can be toggled by passing the following argument to the CM
| HIPFORT | OFF | Enable the use of advanced functionality via the hipfort runtime API e.g. host memory pinning, fast strided copies, asynchronous data transfers, etc.|
| GET_VIEW_ABORT | ON | If activated, get_view will abort when the data are not present on CPU. |
| DELAYED | OFF | If activated, field owners will be delayed by default. |
| GUARD_0_SIZE | ON | If activated, the module-level `GET_HOST_DATA_*`/`GET_DEVICE_DATA_*` accessors in `FIELD_ACCESS_MODULE` return a size-1 dummy pointer for 0-sized fields instead of the underlying 0-sized array. |
| IO_SERIAL | OFF | Use serial HDF5 to read and write FieldAPI variables. |
| IO_PARALLEL | OFF | Use HDF5 (rank defined by MPI) to read and write FieldAPI variables. |

Expand Down
4 changes: 4 additions & 0 deletions src/util/field_RANKSUFF_access_module.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ CONTAINS
#:for rank in range(ft.rank)
ISIZE = ISIZE * (IUBOUNDS(${rank + 1}$) - ILBOUNDS(${rank + 1}$) + 1)
#:endfor
#:if defined('WITH_GUARD_0_SIZE')
IF (ISIZE > 0) LEXISTS = .TRUE.
#:else
LEXISTS = .TRUE.
#:endif
ENDIF
IF (LEXISTS) THEN
CALL FIELD_PTR%GET_${what}$_DATA_${mode}$ (PTR)
Expand Down
5 changes: 3 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ foreach(TEST_FILE ${TEST_FILES})
target_compile_definitions( ${TEST_NAME}.x PRIVATE
$<$<BOOL:${HAVE_IO}>:HDF5::HDF5>
$<${HAVE_OMP_OFFLOAD}:OMPGPU>
$<${HAVE_CUDA}:_CUDA>
$<${HAVE_HIPFORT}:_HIP> )
$<${HAVE_CUDA}:_CUDA>
$<${HAVE_HIPFORT}:_HIP>
$<${HAVE_GUARD_0_SIZE}:WITH_GUARD_0_SIZE> )

if( DEFAULT_PRECISION MATCHES sp )
target_compile_definitions( ${TEST_NAME}.x PRIVATE PARKIND1_SINGLE )
Expand Down
6 changes: 6 additions & 0 deletions tests/test_0_sized_transfer.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ PROGRAM TEST_0_SIZED_TRANSFER
ENDIF

PTR => GET_HOST_DATA_RDONLY(O)
#ifdef WITH_GUARD_0_SIZE
IF( SIZE(PTR) /= 1 )THEN
CALL FIELD_ABORT("ALLOCATION SHOULD BE OF SIZE==1")
ENDIF
#else
IF( SIZE(PTR) /= 0 )THEN
CALL FIELD_ABORT("ALLOCATION SHOULD BE OF SIZE==0")
ENDIF
#endif

!...Ensure data can be copied to device and back safely
CALL O%SYNC_DEVICE_RDWR()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_0_sized_transfer_wrap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ PROGRAM TEST_0_SIZED_TRANSFER
ENDIF

PTR => GET_HOST_DATA_RDONLY(W)
#ifdef WITH_GUARD_0_SIZE
IF( SIZE(PTR) /= 1 )THEN
CALL FIELD_ABORT("ALLOCATION SHOULD BE OF SIZE==1")
ENDIF
#else
IF( SIZE(PTR) /= 0 )THEN
CALL FIELD_ABORT("ALLOCATION SHOULD BE OF SIZE==0")
ENDIF
#endif

!...Ensure data can be copied to device and back safely
CALL W%SYNC_DEVICE_RDWR()
Expand Down
Loading