Skip to content

Commit

Permalink
Merge pull request #3 from ecmwf-ifs/naml-accord-rebased
Browse files Browse the repository at this point in the history
Most recent "accord" version, with ECMWF-compatible copyright headers
  • Loading branch information
mlange05 authored Nov 3, 2023
2 parents 47996c1 + 456e7f6 commit b268566
Show file tree
Hide file tree
Showing 35 changed files with 1,071 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: CMake
name: FieldAPI_Tests

on: [push, pull_request]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
BUILD_TYPE: RelWithDebInfo

jobs:
build:
Expand All @@ -21,18 +21,30 @@ jobs:
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- run: pip install fypp

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Install fiat
run: |
git clone https://github.com/ecmwf/ecbuild.git
export PATH=${{github.workspace}}/ecbuild/bin:$PATH
git clone https://github.com/ecmwf-ifs/fiat.git
cd fiat
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/fiat/install
make -j
make install
cp ${{github.workspace}}/fiat/install/module/parkind_dp/* ${{github.workspace}}/fiat/install/module/fiat/
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build field api
run: |
export fiat_DIR=${{github.workspace}}/fiat/install
mkdir build
cd build
cmake ..
make -j
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
run: |
cd build
export DEV_ALLOC_SIZE=1000000
ctest
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (USE_OPENACC)
if (CMAKE_Fortran_COMPILER_ID STREQUAL "PGI"
OR CMAKE_Fortran_COMPILER_ID STREQUAL "NVIDIA"
OR CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
set (CMAKE_Fortran_FLAGS "-acc=gpu -Mlarge_arrays -gopt -gpu=cc70 -Minfo=accel,all,intensity,ccff")
set (CMAKE_Fortran_FLAGS "-acc=gpu -Mlarge_arrays -gopt -gpu=cc70 -Minfo=accel,all,ccff")
endif ()

endif ()
Expand All @@ -39,7 +39,6 @@ endif ()
find_package (fiat REQUIRED)

set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -I${fiat_BASE_DIR}/module/fiat -I${fiat_BASE_DIR}/include/fiat")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -L${fiat_BASE_DIR}/lib64 -lfiat -Wl,-rpath,${fiat_BASE_DIR}/lib64")

if (fiat_HAVE_DOUBLE_PRECISION)
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -I${fiat_BASE_DIR}/module/parkind_dp")
Expand All @@ -56,12 +55,12 @@ if (NOT FYPP_PATH)
endif()
message (STATUS "fypp is ${FYPP_PATH}")

set (SOURCES field_basic_module.F90 dev_alloc.c)
set (SOURCES field_basic_module.F90 field_init_debug_value_module.F90 dev_alloc.c)

foreach (SUFF IN ITEMS IM RM RB RD LM)
string (TOLOWER ${SUFF} suff)
foreach (RANK RANGE 2 5)
foreach (FUNC IN ITEMS "" _gathscat _access _util)
foreach (FUNC IN ITEMS "" _gathscat _access _util _array_util)
add_custom_command (OUTPUT field_${RANK}${suff}${FUNC}_module.F90
COMMAND ${FYPP_PATH} -DRANK=${RANK} -DSUFF='${SUFF}' -m os -M ${CMAKE_CURRENT_SOURCE_DIR} -m fieldType
${CMAKE_CURRENT_SOURCE_DIR}/field_RANKSUFF${FUNC}_module.fypp > field_${RANK}${suff}${FUNC}_module.F90
Expand All @@ -73,7 +72,7 @@ foreach (SUFF IN ITEMS IM RM RB RD LM)
endforeach ()

foreach (SRC IN ITEMS dev_alloc_module field_factory_module field_access_module
field_array_module field_module field_gathscat_module field_util_module)
field_array_module field_module field_gathscat_module field_util_module field_array_util_module)
add_custom_command (OUTPUT ${SRC}.F90
COMMAND ${FYPP_PATH} -m os -M ${CMAKE_CURRENT_SOURCE_DIR} -m fieldType ${CMAKE_CURRENT_SOURCE_DIR}/${SRC}.fypp > ${SRC}.F90
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC}.fypp
Expand All @@ -93,10 +92,9 @@ if (OpenACC_Fortran_FOUND AND USE_OPENACC)
endif ()

add_executable (main.x main.F90)
target_link_libraries (main.x PUBLIC ${LIBNAME})
target_link_libraries (main.x PUBLIC ${LIBNAME} -L${fiat_BASE_DIR}/lib64 -L${fiat_BASE_DIR}/lib -lfiat -Wl,-rpath,${fiat_BASE_DIR}/lib64 -Wl,-rpath,${fiat_BASE_DIR}/lib)
enable_testing ()
add_subdirectory (tests)

install(TARGETS ${LIBNAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX})

42 changes: 39 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ codebase. To compile it you need:
```
mkdir build
cd build
cmake ..
cmake .. -Dfiat_HAVE_DOUBLE_PRECISION=1 -DUSE_OPENACC=1
make
ctest #Optional, will run the tests
```

The library has been tested with the nvhpc toolkit from Nvidia, version 23.3
and is continually tested with newer releases.
The library has been tested with the nvhpc toolkit from Nvidia, version 23.9
and is continually tested with newer releases. It has also been tested on CPU
(-DUSE_OPENACC=0) with GCC 12 and Intel 2018.

# Field API types

Expand Down Expand Up @@ -146,6 +147,30 @@ CALL FIELD_DELETE(FO)
!The data will be freed if MYTEST was true, otherwise there are no data to deallocate
```

### Initialisation

In the case of field owner it is possible to initiliase it with a specific
value at creation time by adding the INIT\_VALUE optional argument.

```
CLASS(FIELD_2IM), POINTER :: O => NULL()
!This field owner will be initialised to 3
CALL FIELD_NEW(O, LBOUNDS=[1,1], UBOUNDS=[10,10], INIT_VALUE=3_JPIM)
```

It is also possible to activate a debug value to initialise all non-initialised
owner. To do so it is necessary to import the module *field_init_debug_module*
and set *use_init_debug_value* to true. Then one can *set
init_debug_value_jpim* to a custom value.

```
USE FIELD_INIT_DEBUG_VALUE_MODULE
USE_INIT_DEBUG_VALUE = .TRUE.
INIT_DEBUG_VALUE_JPIM = -7
!This field owner will be initialised to -7
CALL FIELD_NEW(O, LBOUNDS=[1,1], UBOUNDS=[10,10])
```

## Asynchronism

This functionnality is still being tested.
Expand Down Expand Up @@ -202,6 +227,13 @@ write(*,*)"Total/Avg Time spend on transfer CPU->GPU", NUM_CPU_GPU_TR, "/" AVG,
...
```

## Note on GET\_VIEW

GET\_VIEW must only be called in sections of code running on the host. The
field's data must be present on the host. It will not work if the data are on
the device or if the field has not been allocated yet (when using the DELAY
option).

# Public API

For field api type:
Expand Down Expand Up @@ -237,5 +269,9 @@ REAL :: TOTAL_TIME_TRANSFER_CPU_TO_GPU
REAL :: TOTAL_TIME_TRANSFER_GPU_TO_CPU
```

# License

The field API library is licenced under the Apache licence, version 2.0.

[buddy_alloc](https://github.com/spaskalev/buddy_alloc) is property of Stanislav Paskalev and licensed under the BSD Zero Clause License

112 changes: 112 additions & 0 deletions field_RANKSUFF_array_util_module.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
!COPYRIGHT Meteo-France 2023
MODULE FIELD_${RANK}$${SUFF}$_ARRAY_UTIL_MODULE

#:set fieldTypeList = fieldType.getFieldTypeList (ranks=[RANK], kinds=['JP' + SUFF])

USE FIELD_ARRAY_MODULE
${fieldType.useParkind1 ()}$

IMPLICIT NONE

#:for method in ['LOAD', 'SAVE', 'COPY', 'WIPE', 'HOST']
INTERFACE ${method}$
#:for ft in fieldTypeList
MODULE PROCEDURE ${method}$_${ft.name}$_ARRAY
#:endfor
END INTERFACE

#:endfor

CONTAINS

#:for ft in fieldTypeList
SUBROUTINE LOAD_${ft.name}$_ARRAY (KLUN, YD)

USE FIELD_UTIL_MODULE, ONLY : LOAD

INTEGER (KIND=JPIM), INTENT (IN) :: KLUN
TYPE (${ft.name}$_ARRAY) :: YD

IF (ASSOCIATED (YD%F_P)) THEN
CALL LOAD (KLUN, YD%F_P)
ENDIF

END SUBROUTINE

SUBROUTINE SAVE_${ft.name}$_ARRAY (KLUN, YD)

USE FIELD_UTIL_MODULE, ONLY : SAVE

INTEGER (KIND=JPIM), INTENT (IN) :: KLUN
TYPE (${ft.name}$_ARRAY) :: YD
END SUBROUTINE

SUBROUTINE COPY_${ft.name}$_ARRAY (SELF, LDCREATED, LDFIELDAPI)

USE FIELD_UTIL_MODULE, ONLY : COPY

TYPE (${ft.name}$_ARRAY) :: SELF
LOGICAL, INTENT (IN), OPTIONAL :: LDCREATED, LDFIELDAPI
LOGICAL :: LLFIELDAPI, LLCREATED

LLFIELDAPI = .FALSE.
IF (PRESENT (LDFIELDAPI)) LLFIELDAPI = LDFIELDAPI

LLCREATED = .FALSE.
IF (PRESENT (LDCREATED)) LLCREATED = LDCREATED

IF (.NOT. LLCREATED) THEN
!$acc enter data create (SELF)
!$acc update device (SELF)
ENDIF

!$acc serial present (SELF)
NULLIFY (SELF%P)
NULLIFY (SELF%F_P)
!$acc end serial

IF (LLFIELDAPI .AND. ASSOCIATED (SELF%F_P)) THEN
CALL COPY (SELF%F_P, LDCREATED)
ENDIF

END SUBROUTINE

SUBROUTINE WIPE_${ft.name}$_ARRAY (SELF, LDDELETED, LDFIELDAPI)

USE FIELD_UTIL_MODULE, ONLY : WIPE

TYPE (${ft.name}$_ARRAY) :: SELF
LOGICAL, INTENT (IN), OPTIONAL :: LDDELETED, LDFIELDAPI
LOGICAL :: LLFIELDAPI, LLDELETED

LLFIELDAPI = .FALSE.
IF (PRESENT (LDFIELDAPI)) LLFIELDAPI = LDFIELDAPI

LLDELETED = .FALSE.
IF (PRESENT (LDDELETED)) LLDELETED = LDDELETED

IF (LLFIELDAPI .AND. ASSOCIATED (SELF%F_P)) THEN
CALL WIPE (SELF%F_P, LDDELETED)
ENDIF

IF (.NOT. LLDELETED) THEN
!$acc exit data delete (SELF)
ENDIF

END SUBROUTINE

SUBROUTINE HOST_${ft.name}$_ARRAY (SELF)

USE FIELD_UTIL_MODULE, ONLY : HOST

TYPE (${ft.name}$_ARRAY) :: SELF

IF (ASSOCIATED (SELF%F_P)) THEN
CALL HOST (SELF%F_P)
ENDIF

END SUBROUTINE

#:endfor

END MODULE
Loading

0 comments on commit b268566

Please sign in to comment.