From 5d48148353d0f2c492fddfc4faae6cc4584026a3 Mon Sep 17 00:00:00 2001 From: Daniel Peter Date: Tue, 16 Sep 2025 11:21:40 +0200 Subject: [PATCH 1/2] updates deviceOverlap handling --- src/gpu/initialize_gpu.c | 7 ++++++- utils/GPU_tools/check_cuda_device.cu | 5 +++++ ...Us_in_C_and_CUDA_with_fault_tolerance_library_nov2011.c | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gpu/initialize_gpu.c b/src/gpu/initialize_gpu.c index c627089d7..25d89967e 100644 --- a/src/gpu/initialize_gpu.c +++ b/src/gpu/initialize_gpu.c @@ -350,11 +350,16 @@ static void output_cuda_device_infos(int myrank){ }else{ fprintf(fp," canMapHostMemory: FALSE\n"); } - if (deviceProp.deviceOverlap) { +#if CUDA_VERSION < 13000 || (defined (__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ < 13)) + if (deviceProp.deviceOverlap){ fprintf(fp," deviceOverlap: TRUE\n"); }else{ fprintf(fp," deviceOverlap: FALSE\n"); } +#else + // CUDA version >= 13, deviceOverlap deprecated, replaced by asyncEngineCount + fprintf(fp," asyncEngineCount: %d\n", deviceProp.asyncEngineCount); +#endif if (deviceProp.concurrentKernels) { fprintf(fp," concurrentKernels: TRUE\n"); }else{ diff --git a/utils/GPU_tools/check_cuda_device.cu b/utils/GPU_tools/check_cuda_device.cu index 292797e40..9d54c92b7 100644 --- a/utils/GPU_tools/check_cuda_device.cu +++ b/utils/GPU_tools/check_cuda_device.cu @@ -282,11 +282,16 @@ e.g., on titan enable environment CRAY_CUDA_MPS=1 to use a single GPU with multi }else{ printf(" canMapHostMemory: FALSE\n"); } +#if CUDA_VERSION < 13000 || (defined (__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ < 13)) if(deviceProp.deviceOverlap){ printf(" deviceOverlap: TRUE\n"); }else{ printf(" deviceOverlap: FALSE\n"); } +#else + // CUDA version >= 13, deviceOverlap deprecated, replaced by asyncEngineCount + printf(" asyncEngineCount: %d\n", deviceProp.asyncEngineCount); +#endif fflush(stdout); diff --git a/utils/infos/fault_tolerance_FTI_Leonardo_Bautista_Gomez/specfem3D_globe_simple_demo_code_for_GPUs_in_C_and_CUDA_with_fault_tolerance_library_nov2011.c b/utils/infos/fault_tolerance_FTI_Leonardo_Bautista_Gomez/specfem3D_globe_simple_demo_code_for_GPUs_in_C_and_CUDA_with_fault_tolerance_library_nov2011.c index 224b956c7..5f9e53876 100644 --- a/utils/infos/fault_tolerance_FTI_Leonardo_Bautista_Gomez/specfem3D_globe_simple_demo_code_for_GPUs_in_C_and_CUDA_with_fault_tolerance_library_nov2011.c +++ b/utils/infos/fault_tolerance_FTI_Leonardo_Bautista_Gomez/specfem3D_globe_simple_demo_code_for_GPUs_in_C_and_CUDA_with_fault_tolerance_library_nov2011.c @@ -207,10 +207,16 @@ int main(int argc, char *argv[]) else { printf("canMapHostMemory: FALSE\n"); } +#if CUDA_VERSION < 13000 || (defined (__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ < 13)) if(deviceProp.deviceOverlap) { printf("deviceOverlap: TRUE\n"); } else { printf("deviceOverlap: FALSE\n"); } +#else + // CUDA version >= 13, deviceOverlap deprecated, replaced by asyncEngineCount + printf(" asyncEngineCount: %d\n", deviceProp.asyncEngineCount); +#endif + #endif // make sure that the device has compute capability >= 1.3 From b32c591423f9bdfdd3a24756a12317c66f721580 Mon Sep 17 00:00:00 2001 From: Daniel Peter Date: Wed, 17 Sep 2025 12:11:52 +0200 Subject: [PATCH 2/2] updates NaN check for EMC model --- src/meshfem3D/model_EMC.f90 | 63 ++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/meshfem3D/model_EMC.f90 b/src/meshfem3D/model_EMC.f90 index 6bc202701..0414086e7 100644 --- a/src/meshfem3D/model_EMC.f90 +++ b/src/meshfem3D/model_EMC.f90 @@ -716,6 +716,8 @@ end subroutine check_dimorder ! -------------------------------- subroutine check_variable_attributes(ncid, varid, unit, direction, missing_val) + use, intrinsic :: ieee_arithmetic + implicit none integer, intent(in) :: ncid integer, intent(in) :: varid @@ -724,14 +726,18 @@ subroutine check_variable_attributes(ncid, varid, unit, direction, missing_val) ! local parameters integer :: num_atts,i character(len=100) :: name,value - real(kind=CUSTOM_REAL) :: fill_val + real(kind=CUSTOM_REAL) :: fill_val,val_read logical :: has_fill_value,has_missing_value +! note: isNaN() function is a GNU extension, thus not all compilers might have it. +! using a simple val /= val check can already work. +! here, we double-check with the IEEE intrinsic function ieee_is_nan() which should be Fortran2003 standard. + ! initializes unit = 0 direction = 0 - missing_val = 9999.0_CUSTOM_REAL - fill_val = 9999.0_CUSTOM_REAL + missing_val = 99999.0_CUSTOM_REAL ! initializes to some ficticious value + fill_val = 99999.0_CUSTOM_REAL has_missing_value = .false. has_fill_value = .false. @@ -804,22 +810,47 @@ subroutine check_variable_attributes(ncid, varid, unit, direction, missing_val) endif else if (trim(name) == 'missing_value') then + ! initialize to avoid issues with netcdf function call + val_read = 0.0_CUSTOM_REAL ! assigns value for invalid entries - call check_status(nf90_get_att(ncid, varid, name, missing_val)) - if (VERBOSE) print *,' missing value: ',missing_val + call check_status(nf90_get_att(ncid, varid, name, val_read)) + if (VERBOSE) print *,' missing value: ',val_read + ! to avoid compiler running into floating-point invalid errors, we double-check if value is not-a-number has_missing_value = .true. + ! isNaN check + if (val_read /= val_read) then + ! NaN value + has_missing_value = .false. + else + has_missing_value = .true. + endif + ! double-check with ieee function + if (ieee_support_standard(val_read)) then + if (ieee_is_nan(val_read)) has_missing_value = .false. + endif + ! only assign if not NaN + if (has_missing_value) missing_val = val_read else if (trim(name) == '_FillValue' .or. trim(name) == 'FillValue') then + ! initialize to avoid issues with netcdf function call + val_read = 0.0_CUSTOM_REAL ! assigns value for invalid entries - call check_status(nf90_get_att(ncid, varid, name, fill_val)) - if (VERBOSE) print *,' fill value: ',fill_val + call check_status(nf90_get_att(ncid, varid, name, val_read)) + if (VERBOSE) print *,' fill value: ',val_read + ! to avoid compiler running into floating-point invalid errors, we double-check if value is not-a-number + has_fill_value = .true. ! isNaN check - if (fill_val /= fill_val) then + if (val_read /= val_read) then ! NaN value has_fill_value = .false. else has_fill_value = .true. endif + ! double-check with ieee function + if (ieee_support_standard(val_read)) then + if (ieee_is_nan(val_read)) has_fill_value = .false. + endif + if (has_fill_value) fill_val = val_read else if (trim(name) == 'long_name' .or. trim(name) == '_long_name') then ! assigns value for invalid entries @@ -2887,6 +2918,22 @@ subroutine read_emc_model() double precision, parameter :: RCMB_ = 3480000.d0 double precision, parameter :: R_EARTH_ = 6371000.d0 + ! initializes + dir_dep = 0 + dir = 0 + + missing_val_vp = 99999.0_CUSTOM_REAL ! initializes to some ficticious value + missing_val_vs = 99999.0_CUSTOM_REAL + missing_val_rho = 99999.0_CUSTOM_REAL + missing_val_dep = 99999.0_CUSTOM_REAL + + missing_val_vpv = 99999.0_CUSTOM_REAL + missing_val_vph = 99999.0_CUSTOM_REAL + missing_val_vsv = 99999.0_CUSTOM_REAL + missing_val_vsh = 99999.0_CUSTOM_REAL + missing_val_eta = 99999.0_CUSTOM_REAL + missing_val_qmu = 99999.0_CUSTOM_REAL + if (VERBOSE) print *,'reading EMC model:' ! Open netcdf file with write access