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

Fortran bindings for memory space related functions #4077

Merged
merged 3 commits into from
Mar 7, 2024
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
19 changes: 19 additions & 0 deletions bindings/Fortran/f2c/adios2_f2c_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ void FC_GLOBAL(adios2_variable_steps_f2c,
}
}

void FC_GLOBAL(adios2_set_memory_space_f2c, ADIOS2_SET_MEMORY_SPACE_F2C)(adios2_variable **variable,
const int *mem, int *ierr)
{
*ierr = static_cast<int>(
adios2_set_memory_space(*variable, static_cast<adios2_memory_space>(*mem)));
}

void FC_GLOBAL(adios2_get_memory_space_f2c,
ADIOS2_GET_MEMORY_SPACE_F2C)(int *mem, adios2_variable **variable, int *ierr)
{
*mem = 0;
adios2_memory_space Cmem;
*ierr = static_cast<int>(adios2_get_memory_space(&Cmem, *variable));
if (*ierr == static_cast<int>(adios2_error_none))
{
*mem = static_cast<int>(Cmem);
}
}

void FC_GLOBAL(adios2_set_shape_f2c, ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable,
const int *ndims, const int64_t *shape,
int *ierr)
Expand Down
4 changes: 4 additions & 0 deletions bindings/Fortran/modules/adios2_parameters_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module adios2_parameters_mod
integer, parameter :: adios2_mode_deferred = 4
integer, parameter :: adios2_mode_sync = 5

integer, parameter :: adios2_memory_space_detect = 0
integer, parameter :: adios2_memory_space_host = 1
integer, parameter :: adios2_memory_space_gpu = 2

! Step Mode
integer, parameter :: adios2_step_mode_append = 0
integer, parameter :: adios2_step_mode_update = 1
Expand Down
16 changes: 16 additions & 0 deletions bindings/Fortran/modules/adios2_variable_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ subroutine adios2_variable_steps(steps, variable, ierr)

end subroutine

subroutine adios2_set_memory_space(variable, mem, ierr)
type(adios2_variable), intent(in) :: variable
integer, intent(in) :: mem
integer, intent(out) :: ierr

call adios2_set_memory_space_f2c(variable%f2c, mem, ierr)
end subroutine

subroutine adios2_get_memory_space(mem, variable, ierr)
integer, intent(out) :: mem
type(adios2_variable), intent(in) :: variable
integer, intent(out) :: ierr

call adios2_get_memory_space_f2c(mem, variable%f2c, ierr)
end subroutine

subroutine adios2_set_shape(variable, ndims, shape_dims, ierr)
type(adios2_variable), intent(in) :: variable
integer, intent(in) :: ndims
Expand Down
4 changes: 4 additions & 0 deletions testing/adios2/bindings/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ fortran_add_test_helper(BPReadGlobalsByName MPI_ONLY)
fortran_add_test_helper(BPWriteMemorySelectionRead2D MPI_ONLY)
fortran_add_test_helper(BPWriteMemorySelectionRead3D MPI_ONLY)
fortran_add_test_helper(NullEngine MPI_ONLY)
fortran_add_test_helper(BPMemorySpace MPI_NONE)
if(ADIOS2_HAVE_GPU_Support)
fortran_add_test_helper(BPMemorySpaceGPU MPI_NONE)
endif()

if(ADIOS2_HAVE_MPI)
add_subdirectory(operation)
Expand Down
41 changes: 41 additions & 0 deletions testing/adios2/bindings/fortran/TestBPMemorySpace.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
program TestBPMemorySpace
use adios2
implicit none

integer(kind=8), dimension(1) :: shape_dims, start_dims, count_dims
integer(kind=4) :: ierr, mem

type(adios2_adios) :: adios
type(adios2_variable) :: variable
type(adios2_io) :: ioWrite

shape_dims(1) = 10
start_dims(1) = 0
count_dims(1) = 10

if( adios%valid .eqv. .true. ) stop 'Invalid adios default'
if( variable%valid .eqv. .true. ) stop 'Invalid variables default'

call adios2_init(adios, ierr)
if( adios%valid .eqv. .false. ) stop 'Invalid adios2_init'

call adios2_declare_io(ioWrite, adios, "ioWrite", ierr)
if( ioWrite%valid .eqv. .false. ) stop 'Invalid adios2_declare_io'

call adios2_set_engine(ioWrite, 'File', ierr)

call adios2_define_variable(variable, ioWrite, "var_I32", &
adios2_type_integer4, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)

! check that the default execution space is Detect
call adios2_get_memory_space(mem, variable, ierr)
if (mem /= adios2_memory_space_detect) stop 'Invalid adios2_memory_space'

! check that the execution space is updated to Host
call adios2_set_memory_space(variable, adios2_memory_space_host, ierr)
call adios2_get_memory_space(mem, variable, ierr)
if (mem /= adios2_memory_space_host) stop 'Invalid adios2_memory_space'

end program TestBPMemorySpace
41 changes: 41 additions & 0 deletions testing/adios2/bindings/fortran/TestBPMemorySpaceGPU.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
program TestBPMemorySpace
use adios2
implicit none

integer(kind=8), dimension(1) :: shape_dims, start_dims, count_dims
integer(kind=4) :: ierr, mem

type(adios2_adios) :: adios
type(adios2_variable) :: variable
type(adios2_io) :: ioWrite

shape_dims(1) = 10
start_dims(1) = 0
count_dims(1) = 10

if( adios%valid .eqv. .true. ) stop 'Invalid adios default'
if( variable%valid .eqv. .true. ) stop 'Invalid variables default'

call adios2_init(adios, ierr)
if( adios%valid .eqv. .false. ) stop 'Invalid adios2_init'

call adios2_declare_io(ioWrite, adios, "ioWrite", ierr)
if( ioWrite%valid .eqv. .false. ) stop 'Invalid adios2_declare_io'

call adios2_set_engine(ioWrite, 'File', ierr)

call adios2_define_variable(variable, ioWrite, "var_I32", &
adios2_type_integer4, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)

! check that the default execution space is Detect
call adios2_get_memory_space(mem, variable, ierr)
if (mem /= adios2_memory_space_detect) stop 'Invalid adios2_memory_space'

! check that the execution space is updated to GPU
call adios2_set_memory_space(variable, adios2_memory_space_gpu, ierr)
call adios2_get_memory_space(mem, variable, ierr)
if (mem /= adios2_memory_space_gpu) stop 'Invalid adios2_memory_space'

end program TestBPMemorySpace
Loading