diff --git a/SWESimulators/Common.py b/SWESimulators/Common.py index 87d47f5..fddd958 100644 --- a/SWESimulators/Common.py +++ b/SWESimulators/Common.py @@ -194,8 +194,8 @@ class CudaContext(object): """ def get_prepared_kernel(self, kernel_filename, kernel_function_name, \ prepared_call_args, \ - block_width, block_height, \ - include_dirs=[], verbose=False, no_extern_c=False): + include_dirs=[], verbose=False, no_extern_c=False, + **kwargs): """ Helper function to print compilation output """ @@ -213,11 +213,11 @@ class CudaContext(object): # Create a hash of the kernel (and its includes) root, ext = os.path.splitext(kernel_filename) kernel_hash = root \ - + "_" + str(block_width) + "x" + str(block_height) \ + "_" + CudaContext.hash_kernel( \ os.path.join(self.module_path, kernel_filename), \ include_dirs=[self.module_path] + include_dirs, \ verbose=verbose) \ + + "_" + str(hash(str(kwargs))) \ + ext cached_kernel_filename = os.path.join(self.cache_path, kernel_hash) @@ -246,11 +246,15 @@ class CudaContext(object): if (verbose): print("`-> Compiling " + kernel_filename) - #Create define string - define_string = "#define BLOCK_WIDTH " + str(block_width) + "\n" - define_string += "#define BLOCK_HEIGHT " + str(block_height) + "\n\n" - - kernel_string = define_string + '#include "' + os.path.join(self.module_path, kernel_filename) + '"' + #Create kernel string + kernel_string = "" + for key, value in kwargs.items(): + kernel_string += "#define {:s} {:s}\n".format(str(key), str(value)) + kernel_string += '#include "' + os.path.join(self.module_path, kernel_filename) + '"' + if (self.use_cache): + with io.open(cached_kernel_filename + ".txt", "w") as file: + file.write(kernel_string) + with Timer("compiler", verbose=False) as timer: cubin = cuda_compiler.compile(kernel_string, include_dirs=include_dirs, no_extern_c=no_extern_c, cache_dir=False) diff --git a/SWESimulators/FORCE.py b/SWESimulators/FORCE.py index 1074d54..b51417a 100644 --- a/SWESimulators/FORCE.py +++ b/SWESimulators/FORCE.py @@ -70,7 +70,8 @@ class FORCE (Simulator.BaseSimulator): #Get kernels self.kernel = context.get_prepared_kernel("FORCE_kernel.cu", "FORCEKernel", \ "iiffffPiPiPiPiPiPi", \ - block_width, block_height) + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "First order centered" diff --git a/SWESimulators/HLL.py b/SWESimulators/HLL.py index cf53b3c..d092448 100644 --- a/SWESimulators/HLL.py +++ b/SWESimulators/HLL.py @@ -64,8 +64,9 @@ class HLL (Simulator.BaseSimulator): #Get kernels self.kernel = context.get_prepared_kernel("HLL_kernel.cu", "HLLKernel", \ - "iiffffPiPiPiPiPiPi", \ - block_width, block_height) + "iiffffPiPiPiPiPiPi", \ + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "Harten-Lax-van Leer" diff --git a/SWESimulators/HLL2.py b/SWESimulators/HLL2.py index 79777a1..fcc82af 100644 --- a/SWESimulators/HLL2.py +++ b/SWESimulators/HLL2.py @@ -71,7 +71,8 @@ class HLL2 (Simulator.BaseSimulator): #Get kernels self.kernel = context.get_prepared_kernel("HLL2_kernel.cu", "HLL2Kernel", \ "iifffffiPiPiPiPiPiPi", \ - block_width, block_height) + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "Harten-Lax-van Leer (2nd order)" diff --git a/SWESimulators/KP07.py b/SWESimulators/KP07.py index 8ec091e..829d282 100644 --- a/SWESimulators/KP07.py +++ b/SWESimulators/KP07.py @@ -74,7 +74,8 @@ class KP07 (Simulator.BaseSimulator): #Get kernels self.kernel = context.get_prepared_kernel("KP07_kernel.cu", "KP07Kernel", \ "iiffffffiPiPiPiPiPiPi", \ - block_width, block_height) + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "Kurganov-Petrova 2007" diff --git a/SWESimulators/KP07_dimsplit.py b/SWESimulators/KP07_dimsplit.py index 19a4d00..9bb418e 100644 --- a/SWESimulators/KP07_dimsplit.py +++ b/SWESimulators/KP07_dimsplit.py @@ -72,7 +72,8 @@ class KP07_dimsplit (Simulator.BaseSimulator): #Get kernels self.kernel = context.get_prepared_kernel("KP07_dimsplit_kernel.cu", "KP07DimsplitKernel", \ "iifffffiPiPiPiPiPiPi", \ - block_width, block_height) + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "Kurganov-Petrova 2007 dimensionally split" diff --git a/SWESimulators/LxF.py b/SWESimulators/LxF.py index 0030971..2a8b6ea 100644 --- a/SWESimulators/LxF.py +++ b/SWESimulators/LxF.py @@ -66,8 +66,9 @@ class LxF (Simulator.BaseSimulator): # Get kernels self.kernel = context.get_prepared_kernel("LxF_kernel.cu", "LxFKernel", \ "iiffffPiPiPiPiPiPi", \ - block_width, block_height, \ - no_extern_c=True) + no_extern_c=True, \ + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "Lax Friedrichs" diff --git a/SWESimulators/WAF.py b/SWESimulators/WAF.py index c78a34a..059e6d8 100644 --- a/SWESimulators/WAF.py +++ b/SWESimulators/WAF.py @@ -65,7 +65,8 @@ class WAF (Simulator.BaseSimulator): #Get kernels self.kernel = context.get_prepared_kernel("WAF_kernel.cu", "WAFKernel", \ "iiffffiPiPiPiPiPiPi", \ - block_width, block_height) + BLOCK_WIDTH=block_width, \ + BLOCK_HEIGHT=block_height) def __str__(self): return "Weighted average flux"