Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
anagainaru committed Mar 6, 2024
1 parent 096e9d6 commit 85cd22f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
14 changes: 13 additions & 1 deletion bindings/Fortran/f2c/adios2_f2c_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,19 @@ 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));
*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,
Expand Down
1 change: 1 addition & 0 deletions bindings/Fortran/modules/adios2_parameters_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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

Expand Down
10 changes: 6 additions & 4 deletions bindings/Fortran/modules/adios2_variable_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ subroutine adios2_variable_steps(steps, variable, ierr)

end subroutine

subroutine adios2_set_memory_space_host(variable, ierr)
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, adios2_memory_space_host, ierr)
call adios2_set_memory_space_f2c(variable%f2c, mem, ierr)
end subroutine

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

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

subroutine adios2_set_shape(variable, ndims, shape_dims, ierr)
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

0 comments on commit 85cd22f

Please sign in to comment.