Updated passing of arguments from python to cuda

This commit is contained in:
André R. Brodtkorb 2018-08-13 09:02:44 +02:00
parent 8ccc0d57a0
commit 8614ba96cd
8 changed files with 28 additions and 17 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -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)"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"