From 75d4f12a1ffaae351b16ab4f38b597917308202c Mon Sep 17 00:00:00 2001 From: bevilacqc Date: Wed, 15 Oct 2025 17:14:12 +0200 Subject: [PATCH 1/2] Add CUDA path to the search path when loading Gpufit.dll --- Gpufit/python/pygpufit/gpufit.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Gpufit/python/pygpufit/gpufit.py b/Gpufit/python/pygpufit/gpufit.py index 3e60278..d511685 100644 --- a/Gpufit/python/pygpufit/gpufit.py +++ b/Gpufit/python/pygpufit/gpufit.py @@ -21,7 +21,17 @@ else: raise RuntimeError('OS {} not supported by pyGpufit.'.format(os.name)) +cuda_path = None +# add CUDA_PATH to the dll search path +if os.name == 'nt' and hasattr(os, 'add_dll_directory') and 'CUDA_PATH' in os.environ: + cuda_path = os.add_dll_directory( + os.path.join(os.environ['CUDA_PATH'], 'bin')) +# load the GpuFit library lib = cdll.LoadLibrary(lib_path) +# remove CUDA_PATH from the dll search path +if cuda_path is not None: + cuda_path.close() +del cuda_path # gpufit_constrained function in the dll gpufit_func = lib.gpufit_constrained From f48f9d8b69e663a7076a38f1b901592e0f69ecce Mon Sep 17 00:00:00 2001 From: Carlo Bevilacqua Date: Tue, 21 Oct 2025 17:00:21 +0200 Subject: [PATCH 2/2] Added the bix/x64 path --- Gpufit/python/pygpufit/gpufit.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Gpufit/python/pygpufit/gpufit.py b/Gpufit/python/pygpufit/gpufit.py index d511685..b57d740 100644 --- a/Gpufit/python/pygpufit/gpufit.py +++ b/Gpufit/python/pygpufit/gpufit.py @@ -6,6 +6,7 @@ See https://docs.python.org/3.5/library/ctypes.html, http://www.scipy-lectures.org/advanced/interfacing_with_c/interfacing_with_c.html """ +from genericpath import isdir import os import time from ctypes import cdll, POINTER, byref, c_int, c_float, c_char, c_char_p, c_size_t @@ -21,17 +22,21 @@ else: raise RuntimeError('OS {} not supported by pyGpufit.'.format(os.name)) -cuda_path = None +cuda_paths = [] # add CUDA_PATH to the dll search path if os.name == 'nt' and hasattr(os, 'add_dll_directory') and 'CUDA_PATH' in os.environ: - cuda_path = os.add_dll_directory( + cuda_paths.append ( os.add_dll_directory( os.path.join(os.environ['CUDA_PATH'], 'bin')) + ) + cuda_bix_x64 = os.path.join(os.environ['CUDA_PATH'], 'bin/x64') + if os.path.isdir(cuda_bix_x64): + cuda_paths.append( os.add_dll_directory(cuda_bix_x64) ) # load the GpuFit library lib = cdll.LoadLibrary(lib_path) # remove CUDA_PATH from the dll search path -if cuda_path is not None: +for cuda_path in cuda_paths: cuda_path.close() -del cuda_path +del cuda_paths # gpufit_constrained function in the dll gpufit_func = lib.gpufit_constrained