Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most recent "accord" version, with ECMWF-compatible copyright headers #3

Merged
merged 40 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a390143
Don't transfer data of field owner if it hasn't been initialised yet
dareg Jul 5, 2023
923a1ab
add test-case for field_gathscat
dareg Jul 6, 2023
61b9e4d
remove unused bit in UNINITIALIZED constant
dareg Jul 6, 2023
eec28ab
can now init field to a specific value
dareg Jul 6, 2023
e9720a3
can now choose to activate or not default debug value through cmake
dareg Jul 6, 2023
05f812f
only owner needs to be initiliased with default debug values
dareg Jul 6, 2023
7bab25b
fix test case for init debug value
dareg Jul 7, 2023
cdb3445
user can now choose debug value freely
dareg Jul 10, 2023
35b06e9
bugfix
dareg Jul 21, 2023
0c6dc0c
add more testing
dareg Jul 25, 2023
3d30696
bugfix
dareg Jul 27, 2023
618432b
bugfix:a test was using the old way of setting debug value
dareg Aug 3, 2023
3b40b46
make sure first call of get_device_data works with init_value and del…
dareg Aug 4, 2023
0159049
remove unnecessary PRESENT tests
dareg Aug 4, 2023
9bb793d
get_view was not notifying it might change the data
dareg Aug 21, 2023
1fce32a
fix test-case
dareg Aug 21, 2023
39749e1
cleaning
dareg Aug 21, 2023
3fb27d2
improve doc
dareg Aug 21, 2023
2475036
remove init_value for wrapper as it was unnecessary
dareg Aug 25, 2023
6570764
Compile with gcc 13
pmarguinaud Aug 21, 2023
daec7d7
Control export of symbols to avoid compiler crash
pmarguinaud Aug 22, 2023
bba5ac6
Control export of symbols to avoid compiler crash (gfortran)
pmarguinaud Aug 22, 2023
7336022
Move include abor1.intfb.h in subroutine bodies
pmarguinaud Aug 22, 2023
ab1fcb7
prevent use of get_view is data are not nhstfresh
dareg Aug 25, 2023
5d4c1e9
Change linker flags
pmarguinaud Aug 23, 2023
03696f3
Change linker flags
dareg Aug 25, 2023
3ba607a
fix get view
dareg Aug 29, 2023
23e4b0e
only unset ndevfresh bit in get_view
dareg Aug 29, 2023
ab960fb
Use .eqv. instead == for testing logical
dareg Aug 29, 2023
d5aa040
fix a test-case
dareg Aug 29, 2023
370a9bf
We want HAS_INIT_VALUE to be false by default
dareg Aug 29, 2023
51208b8
fix github's automatic testing
dareg Aug 29, 2023
bfa66d5
Change ERROR STOP into ABOR1 (get a backtrace) + update status in GET…
pmarguinaud Sep 12, 2023
8b88cc9
Add field_RANKSUFF_array_util_module.fypp
pmarguinaud Sep 12, 2023
2787dd8
Add CRC64 utility
pmarguinaud Sep 19, 2023
6482e22
Fix tests that we know will call abor1
dareg Sep 21, 2023
1d60145
condition must be a logical not integer
dareg Sep 21, 2023
f79fee5
improve doc
dareg Oct 23, 2023
27072cc
remove now unsupported option
dareg Oct 23, 2023
456e7f6
Readme: Add acknowledgement of the buddy alloc lib
mlange05 Nov 3, 2023
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
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