diff --git a/bindings/Fortran/f2c/adios2_f2c_variable.cpp b/bindings/Fortran/f2c/adios2_f2c_variable.cpp index e0217e3dff..0250d829de 100644 --- a/bindings/Fortran/f2c/adios2_f2c_variable.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_variable.cpp @@ -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(adios2_set_memory_space(*variable, static_cast(*mem)); + *ierr = static_cast(adios2_set_memory_space(*variable, static_cast(*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(adios2_get_memory_space(&Cmem, *variable)); + if (*ierr == static_cast(adios2_error_none)) + { + *mem = static_cast(Cmem); + } } void FC_GLOBAL(adios2_set_shape_f2c, ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable, diff --git a/bindings/Fortran/modules/adios2_parameters_mod.f90 b/bindings/Fortran/modules/adios2_parameters_mod.f90 index 191a7c18d1..a96fd8549a 100644 --- a/bindings/Fortran/modules/adios2_parameters_mod.f90 +++ b/bindings/Fortran/modules/adios2_parameters_mod.f90 @@ -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 diff --git a/bindings/Fortran/modules/adios2_variable_mod.f90 b/bindings/Fortran/modules/adios2_variable_mod.f90 index b10545a409..0b15b1b3c5 100644 --- a/bindings/Fortran/modules/adios2_variable_mod.f90 +++ b/bindings/Fortran/modules/adios2_variable_mod.f90 @@ -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) diff --git a/testing/adios2/bindings/fortran/CMakeLists.txt b/testing/adios2/bindings/fortran/CMakeLists.txt index 341fc362f4..c026628343 100644 --- a/testing/adios2/bindings/fortran/CMakeLists.txt +++ b/testing/adios2/bindings/fortran/CMakeLists.txt @@ -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) diff --git a/testing/adios2/bindings/fortran/TestBPMemorySpace.F90 b/testing/adios2/bindings/fortran/TestBPMemorySpace.F90 new file mode 100644 index 0000000000..e22cb67438 --- /dev/null +++ b/testing/adios2/bindings/fortran/TestBPMemorySpace.F90 @@ -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 diff --git a/testing/adios2/bindings/fortran/TestBPMemorySpaceGPU.F90 b/testing/adios2/bindings/fortran/TestBPMemorySpaceGPU.F90 new file mode 100644 index 0000000000..64fb26755f --- /dev/null +++ b/testing/adios2/bindings/fortran/TestBPMemorySpaceGPU.F90 @@ -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