From 67721b8914c83e6f5f0714d0a29f7403a07c1d2d Mon Sep 17 00:00:00 2001 From: sfilippone Date: Tue, 27 Jan 2026 12:18:05 +0100 Subject: [PATCH] Define check_addr --- cuda/cvectordev.c | 8 ++++++++ cuda/cvectordev.h | 1 + cuda/dvectordev.c | 8 ++++++++ cuda/dvectordev.h | 1 + cuda/psb_c_cuda_vect_mod.F90 | 12 ++++++++++++ cuda/psb_c_vectordev_mod.F90 | 9 +++++++++ cuda/psb_d_cuda_vect_mod.F90 | 12 ++++++++++++ cuda/psb_d_vectordev_mod.F90 | 9 +++++++++ cuda/psb_i_cuda_vect_mod.F90 | 5 ++--- cuda/psb_i_vectordev_mod.F90 | 18 +++++++++--------- cuda/psb_s_cuda_vect_mod.F90 | 12 ++++++++++++ cuda/psb_s_vectordev_mod.F90 | 9 +++++++++ cuda/psb_z_cuda_vect_mod.F90 | 12 ++++++++++++ cuda/psb_z_vectordev_mod.F90 | 9 +++++++++ cuda/svectordev.c | 8 ++++++++ cuda/svectordev.h | 1 + cuda/zvectordev.c | 8 ++++++++ cuda/zvectordev.h | 1 + 18 files changed, 131 insertions(+), 12 deletions(-) diff --git a/cuda/cvectordev.c b/cuda/cvectordev.c index 0eaacbdb..ea09f80e 100644 --- a/cuda/cvectordev.c +++ b/cuda/cvectordev.c @@ -42,6 +42,14 @@ int registerMappedFloatComplex(void *buff, void **d_p, int n, cuFloatComplex du return registerMappedMemory(buff,d_p,((size_t) n)*sizeof(cuFloatComplex)); } +int checkMultiVecDeviceFloatComplex(void* deviceMultiVec) +{ + struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceMultiVec; + fprintf(stderr,"checkMultiVecDeviceInt Size: %d Pointer %p\n", + devVec->size_,devVec->v_); + return(0); +} + int writeMultiVecDeviceFloatComplex(void* deviceVec, cuFloatComplex* hostVec) { int i; struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceVec; diff --git a/cuda/cvectordev.h b/cuda/cvectordev.h index 423da33e..be095ff5 100644 --- a/cuda/cvectordev.h +++ b/cuda/cvectordev.h @@ -40,6 +40,7 @@ #include "vector.h" int registerMappedFloatComplex(void *, void **, int, cuFloatComplex); +int checkMultiVecDeviceFloatComplex(void* deviceMultiVec); int writeMultiVecDeviceFloatComplex(void* deviceMultiVec, cuFloatComplex* hostMultiVec); int writeMultiVecDeviceFloatComplexR2(void* deviceMultiVec, cuFloatComplex* hostMultiVec, int ld); int readMultiVecDeviceFloatComplex(void* deviceMultiVec, cuFloatComplex* hostMultiVec); diff --git a/cuda/dvectordev.c b/cuda/dvectordev.c index 10bbc326..336aee52 100644 --- a/cuda/dvectordev.c +++ b/cuda/dvectordev.c @@ -42,6 +42,14 @@ int registerMappedDouble(void *buff, void **d_p, int n, double dummy) return registerMappedMemory(buff,d_p,((size_t) n)*sizeof(double)); } +int checkMultiVecDeviceDouble(void* deviceMultiVec) +{ + struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceMultiVec; + fprintf(stderr,"checkMultiVecDeviceInt Size: %d Pointer %p\n", + devVec->size_,devVec->v_); + return(0); +} + int writeMultiVecDeviceDouble(void* deviceVec, double* hostVec) { int i; struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceVec; diff --git a/cuda/dvectordev.h b/cuda/dvectordev.h index 0d2d2ab3..85699ffd 100644 --- a/cuda/dvectordev.h +++ b/cuda/dvectordev.h @@ -38,6 +38,7 @@ #include "vector.h" int registerMappedDouble(void *, void **, int, double); +int checkMultiVecDeviceDouble(void* deviceMultiVec); int writeMultiVecDeviceDouble(void* deviceMultiVec, double* hostMultiVec); int writeMultiVecDeviceDoubleR2(void* deviceMultiVec, double* hostMultiVec, int ld); int readMultiVecDeviceDouble(void* deviceMultiVec, double* hostMultiVec); diff --git a/cuda/psb_c_cuda_vect_mod.F90 b/cuda/psb_c_cuda_vect_mod.F90 index 711ec885..4513b2f5 100644 --- a/cuda/psb_c_cuda_vect_mod.F90 +++ b/cuda/psb_c_cuda_vect_mod.F90 @@ -86,6 +86,7 @@ module psb_c_cuda_vect_mod procedure, nopass :: device_wait => c_cuda_device_wait procedure, pass(x) :: free_buffer => c_cuda_free_buffer procedure, pass(x) :: maybe_free_buffer => c_cuda_maybe_free_buffer + procedure, pass(x) :: check_addr => c_cuda_check_addr procedure, pass(x) :: dot_v => c_cuda_dot_v procedure, pass(x) :: dot_a => c_cuda_dot_a procedure, pass(y) :: axpby_v => c_cuda_axpby_v @@ -219,6 +220,17 @@ contains end subroutine c_cuda_free_buffer + subroutine c_cuda_check_addr(x) + class(psb_c_vect_cuda), intent(inout) :: x + integer(psb_ipk_) info; + select type(ii=> x) + class is (psb_c_vect_cuda) + info = checkMultiVecDeviceFloatComplex(x%deviceVect) + class default + write(0,*) 'Check addr: cuda version, why am I here? ' + end select + end subroutine c_cuda_check_addr + subroutine c_cuda_gthzv_x(i,n,idx,x,y) use psb_cuda_env_mod use psi_serial_mod diff --git a/cuda/psb_c_vectordev_mod.F90 b/cuda/psb_c_vectordev_mod.F90 index 56531c4d..ea94f435 100644 --- a/cuda/psb_c_vectordev_mod.F90 +++ b/cuda/psb_c_vectordev_mod.F90 @@ -44,6 +44,15 @@ module psb_c_vectordev_mod end function registerMappedFloatComplex end interface + interface + function checkMultiVecDeviceFloatComplex(deviceVec) & + & result(res) bind(c,name='checkMultiVecDeviceFloatComplex') + use iso_c_binding + integer(c_int) :: res + type(c_ptr), value :: deviceVec + end function checkMultiVecDeviceFloatComplex + end interface + interface writeMultiVecDevice function writeMultiVecDeviceFloatComplex(deviceVec,hostVec) & & result(res) bind(c,name='writeMultiVecDeviceFloatComplex') diff --git a/cuda/psb_d_cuda_vect_mod.F90 b/cuda/psb_d_cuda_vect_mod.F90 index 036d2f01..b6e38ed6 100644 --- a/cuda/psb_d_cuda_vect_mod.F90 +++ b/cuda/psb_d_cuda_vect_mod.F90 @@ -86,6 +86,7 @@ module psb_d_cuda_vect_mod procedure, nopass :: device_wait => d_cuda_device_wait procedure, pass(x) :: free_buffer => d_cuda_free_buffer procedure, pass(x) :: maybe_free_buffer => d_cuda_maybe_free_buffer + procedure, pass(x) :: check_addr => d_cuda_check_addr procedure, pass(x) :: dot_v => d_cuda_dot_v procedure, pass(x) :: dot_a => d_cuda_dot_a procedure, pass(y) :: axpby_v => d_cuda_axpby_v @@ -219,6 +220,17 @@ contains end subroutine d_cuda_free_buffer + subroutine d_cuda_check_addr(x) + class(psb_d_vect_cuda), intent(inout) :: x + integer(psb_ipk_) info; + select type(ii=> x) + class is (psb_d_vect_cuda) + info = checkMultiVecDeviceDouble(x%deviceVect) + class default + write(0,*) 'Check addr: cuda version, why am I here? ' + end select + end subroutine d_cuda_check_addr + subroutine d_cuda_gthzv_x(i,n,idx,x,y) use psb_cuda_env_mod use psi_serial_mod diff --git a/cuda/psb_d_vectordev_mod.F90 b/cuda/psb_d_vectordev_mod.F90 index f5ec640e..368eda34 100644 --- a/cuda/psb_d_vectordev_mod.F90 +++ b/cuda/psb_d_vectordev_mod.F90 @@ -44,6 +44,15 @@ module psb_d_vectordev_mod end function registerMappedDouble end interface + interface + function checkMultiVecDeviceDouble(deviceVec) & + & result(res) bind(c,name='checkMultiVecDeviceDouble') + use iso_c_binding + integer(c_int) :: res + type(c_ptr), value :: deviceVec + end function checkMultiVecDeviceDouble + end interface + interface writeMultiVecDevice function writeMultiVecDeviceDouble(deviceVec,hostVec) & & result(res) bind(c,name='writeMultiVecDeviceDouble') diff --git a/cuda/psb_i_cuda_vect_mod.F90 b/cuda/psb_i_cuda_vect_mod.F90 index aba8fd52..3274a85e 100644 --- a/cuda/psb_i_cuda_vect_mod.F90 +++ b/cuda/psb_i_cuda_vect_mod.F90 @@ -83,8 +83,8 @@ module psb_i_cuda_vect_mod procedure, nopass :: device_wait => i_cuda_device_wait procedure, pass(x) :: free_buffer => i_cuda_free_buffer procedure, pass(x) :: maybe_free_buffer => i_cuda_maybe_free_buffer - procedure, pass(x) :: check_addr => i_cuda_check_addr + final :: i_cuda_vect_finalize end type psb_i_vect_cuda @@ -213,7 +213,6 @@ contains end select end subroutine i_cuda_check_addr - subroutine i_cuda_gthzv_x(i,n,idx,x,y) use psb_cuda_env_mod use psi_serial_mod @@ -811,12 +810,12 @@ contains integer(psb_ipk_), intent(out) :: info info = 0 + if (allocated(x%v)) deallocate(x%v, stat=info) if (c_associated(x%deviceVect)) then !!$ write(0,*)'d_cuda_free Calling freeMultiVecDevice' call freeMultiVecDevice(x%deviceVect) x%deviceVect=c_null_ptr end if - if (allocated(x%v)) deallocate(x%v, stat=info) call x%free_buffer(info) call x%set_sync() end subroutine i_cuda_free diff --git a/cuda/psb_i_vectordev_mod.F90 b/cuda/psb_i_vectordev_mod.F90 index 0134ffc3..ad9d6cef 100644 --- a/cuda/psb_i_vectordev_mod.F90 +++ b/cuda/psb_i_vectordev_mod.F90 @@ -44,6 +44,15 @@ module psb_i_vectordev_mod end function registerMappedInt end interface + interface + function checkMultiVecDeviceInt(deviceVec) & + & result(res) bind(c,name='checkMultiVecDeviceInt') + use iso_c_binding + integer(c_int) :: res + type(c_ptr), value :: deviceVec + end function checkMultiVecDeviceInt + end interface + interface writeMultiVecDevice function writeMultiVecDeviceInt(deviceVec,hostVec) & & result(res) bind(c,name='writeMultiVecDeviceInt') @@ -122,15 +131,6 @@ module psb_i_vectordev_mod integer(c_int) :: hidx(m,*) integer(c_int),value :: m,n end function writeMultiInt - end interface writeInt - - interface - function checkMultiVecDeviceInt(deviceVec) & - & result(res) bind(c,name='checkMultiVecDeviceInt') - use iso_c_binding - integer(c_int) :: res - type(c_ptr), value :: deviceVec - end function checkMultiVecDeviceInt end interface interface readInt diff --git a/cuda/psb_s_cuda_vect_mod.F90 b/cuda/psb_s_cuda_vect_mod.F90 index 973ac78c..87fd1254 100644 --- a/cuda/psb_s_cuda_vect_mod.F90 +++ b/cuda/psb_s_cuda_vect_mod.F90 @@ -86,6 +86,7 @@ module psb_s_cuda_vect_mod procedure, nopass :: device_wait => s_cuda_device_wait procedure, pass(x) :: free_buffer => s_cuda_free_buffer procedure, pass(x) :: maybe_free_buffer => s_cuda_maybe_free_buffer + procedure, pass(x) :: check_addr => s_cuda_check_addr procedure, pass(x) :: dot_v => s_cuda_dot_v procedure, pass(x) :: dot_a => s_cuda_dot_a procedure, pass(y) :: axpby_v => s_cuda_axpby_v @@ -219,6 +220,17 @@ contains end subroutine s_cuda_free_buffer + subroutine s_cuda_check_addr(x) + class(psb_s_vect_cuda), intent(inout) :: x + integer(psb_ipk_) info; + select type(ii=> x) + class is (psb_s_vect_cuda) + info = checkMultiVecDeviceFloat(x%deviceVect) + class default + write(0,*) 'Check addr: cuda version, why am I here? ' + end select + end subroutine s_cuda_check_addr + subroutine s_cuda_gthzv_x(i,n,idx,x,y) use psb_cuda_env_mod use psi_serial_mod diff --git a/cuda/psb_s_vectordev_mod.F90 b/cuda/psb_s_vectordev_mod.F90 index 38052ca5..28dd1460 100644 --- a/cuda/psb_s_vectordev_mod.F90 +++ b/cuda/psb_s_vectordev_mod.F90 @@ -44,6 +44,15 @@ module psb_s_vectordev_mod end function registerMappedFloat end interface + interface + function checkMultiVecDeviceFloat(deviceVec) & + & result(res) bind(c,name='checkMultiVecDeviceFloat') + use iso_c_binding + integer(c_int) :: res + type(c_ptr), value :: deviceVec + end function checkMultiVecDeviceFloat + end interface + interface writeMultiVecDevice function writeMultiVecDeviceFloat(deviceVec,hostVec) & & result(res) bind(c,name='writeMultiVecDeviceFloat') diff --git a/cuda/psb_z_cuda_vect_mod.F90 b/cuda/psb_z_cuda_vect_mod.F90 index 88c74936..b30488e6 100644 --- a/cuda/psb_z_cuda_vect_mod.F90 +++ b/cuda/psb_z_cuda_vect_mod.F90 @@ -86,6 +86,7 @@ module psb_z_cuda_vect_mod procedure, nopass :: device_wait => z_cuda_device_wait procedure, pass(x) :: free_buffer => z_cuda_free_buffer procedure, pass(x) :: maybe_free_buffer => z_cuda_maybe_free_buffer + procedure, pass(x) :: check_addr => z_cuda_check_addr procedure, pass(x) :: dot_v => z_cuda_dot_v procedure, pass(x) :: dot_a => z_cuda_dot_a procedure, pass(y) :: axpby_v => z_cuda_axpby_v @@ -219,6 +220,17 @@ contains end subroutine z_cuda_free_buffer + subroutine z_cuda_check_addr(x) + class(psb_z_vect_cuda), intent(inout) :: x + integer(psb_ipk_) info; + select type(ii=> x) + class is (psb_z_vect_cuda) + info = checkMultiVecDeviceDoubleComplex(x%deviceVect) + class default + write(0,*) 'Check addr: cuda version, why am I here? ' + end select + end subroutine z_cuda_check_addr + subroutine z_cuda_gthzv_x(i,n,idx,x,y) use psb_cuda_env_mod use psi_serial_mod diff --git a/cuda/psb_z_vectordev_mod.F90 b/cuda/psb_z_vectordev_mod.F90 index b893fbdc..90f30ce6 100644 --- a/cuda/psb_z_vectordev_mod.F90 +++ b/cuda/psb_z_vectordev_mod.F90 @@ -44,6 +44,15 @@ module psb_z_vectordev_mod end function registerMappedDoubleComplex end interface + interface + function checkMultiVecDeviceDoubleComplex(deviceVec) & + & result(res) bind(c,name='checkMultiVecDeviceDoubleComplex') + use iso_c_binding + integer(c_int) :: res + type(c_ptr), value :: deviceVec + end function checkMultiVecDeviceDoubleComplex + end interface + interface writeMultiVecDevice function writeMultiVecDeviceDoubleComplex(deviceVec,hostVec) & & result(res) bind(c,name='writeMultiVecDeviceDoubleComplex') diff --git a/cuda/svectordev.c b/cuda/svectordev.c index e1c43b5e..3bf32665 100644 --- a/cuda/svectordev.c +++ b/cuda/svectordev.c @@ -42,6 +42,14 @@ int registerMappedFloat(void *buff, void **d_p, int n, float dummy) return registerMappedMemory(buff,d_p,((size_t) n)*sizeof(float)); } +int checkMultiVecDeviceFloat(void* deviceMultiVec) +{ + struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceMultiVec; + fprintf(stderr,"checkMultiVecDeviceInt Size: %d Pointer %p\n", + devVec->size_,devVec->v_); + return(0); +} + int writeMultiVecDeviceFloat(void* deviceVec, float* hostVec) { int i; struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceVec; diff --git a/cuda/svectordev.h b/cuda/svectordev.h index 887a7755..2077c1d3 100644 --- a/cuda/svectordev.h +++ b/cuda/svectordev.h @@ -38,6 +38,7 @@ #include "vector.h" int registerMappedFloat(void *, void **, int, float); +int checkMultiVecDeviceFloat(void* deviceMultiVec); int writeMultiVecDeviceFloat(void* deviceMultiVec, float* hostMultiVec); int writeMultiVecDeviceFloatR2(void* deviceMultiVec, float* hostMultiVec, int ld); int readMultiVecDeviceFloat(void* deviceMultiVec, float* hostMultiVec); diff --git a/cuda/zvectordev.c b/cuda/zvectordev.c index 102ba0d2..ce045873 100644 --- a/cuda/zvectordev.c +++ b/cuda/zvectordev.c @@ -42,6 +42,14 @@ int registerMappedDoubleComplex(void *buff, void **d_p, int n, cuDoubleComplex return registerMappedMemory(buff,d_p,((size_t) n)*sizeof(cuDoubleComplex)); } +int checkMultiVecDeviceDoubleComplex(void* deviceMultiVec) +{ + struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceMultiVec; + fprintf(stderr,"checkMultiVecDeviceInt Size: %d Pointer %p\n", + devVec->size_,devVec->v_); + return(0); +} + int writeMultiVecDeviceDoubleComplex(void* deviceVec, cuDoubleComplex* hostVec) { int i; struct MultiVectDevice *devVec = (struct MultiVectDevice *) deviceVec; diff --git a/cuda/zvectordev.h b/cuda/zvectordev.h index 023c7f13..3f08da83 100644 --- a/cuda/zvectordev.h +++ b/cuda/zvectordev.h @@ -40,6 +40,7 @@ #include "vector.h" int registerMappedDoubleComplex(void *, void **, int, cuDoubleComplex); +int checkMultiVecDeviceDoubleComplex(void* deviceMultiVec); int writeMultiVecDeviceDoubleComplex(void* deviceMultiVec, cuDoubleComplex* hostMultiVec); int writeMultiVecDeviceDoubleComplexR2(void* deviceMultiVec, cuDoubleComplex* hostMultiVec, int ld);