mirror of
https://github.com/smyalygames/FiniteVolumeGPU.git
synced 2025-07-13 02:30:59 +02:00
Updated passing of arguments from python to cuda
This commit is contained in:
parent
8ccc0d57a0
commit
8614ba96cd
@ -194,8 +194,8 @@ class CudaContext(object):
|
|||||||
"""
|
"""
|
||||||
def get_prepared_kernel(self, kernel_filename, kernel_function_name, \
|
def get_prepared_kernel(self, kernel_filename, kernel_function_name, \
|
||||||
prepared_call_args, \
|
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
|
Helper function to print compilation output
|
||||||
"""
|
"""
|
||||||
@ -213,11 +213,11 @@ class CudaContext(object):
|
|||||||
# Create a hash of the kernel (and its includes)
|
# Create a hash of the kernel (and its includes)
|
||||||
root, ext = os.path.splitext(kernel_filename)
|
root, ext = os.path.splitext(kernel_filename)
|
||||||
kernel_hash = root \
|
kernel_hash = root \
|
||||||
+ "_" + str(block_width) + "x" + str(block_height) \
|
|
||||||
+ "_" + CudaContext.hash_kernel( \
|
+ "_" + CudaContext.hash_kernel( \
|
||||||
os.path.join(self.module_path, kernel_filename), \
|
os.path.join(self.module_path, kernel_filename), \
|
||||||
include_dirs=[self.module_path] + include_dirs, \
|
include_dirs=[self.module_path] + include_dirs, \
|
||||||
verbose=verbose) \
|
verbose=verbose) \
|
||||||
|
+ "_" + str(hash(str(kwargs))) \
|
||||||
+ ext
|
+ ext
|
||||||
cached_kernel_filename = os.path.join(self.cache_path, kernel_hash)
|
cached_kernel_filename = os.path.join(self.cache_path, kernel_hash)
|
||||||
|
|
||||||
@ -246,11 +246,15 @@ class CudaContext(object):
|
|||||||
if (verbose):
|
if (verbose):
|
||||||
print("`-> Compiling " + kernel_filename)
|
print("`-> Compiling " + kernel_filename)
|
||||||
|
|
||||||
#Create define string
|
#Create kernel string
|
||||||
define_string = "#define BLOCK_WIDTH " + str(block_width) + "\n"
|
kernel_string = ""
|
||||||
define_string += "#define BLOCK_HEIGHT " + str(block_height) + "\n\n"
|
for key, value in kwargs.items():
|
||||||
|
kernel_string += "#define {:s} {:s}\n".format(str(key), str(value))
|
||||||
kernel_string = define_string + '#include "' + os.path.join(self.module_path, kernel_filename) + '"'
|
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:
|
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)
|
cubin = cuda_compiler.compile(kernel_string, include_dirs=include_dirs, no_extern_c=no_extern_c, cache_dir=False)
|
||||||
|
@ -70,7 +70,8 @@ class FORCE (Simulator.BaseSimulator):
|
|||||||
#Get kernels
|
#Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("FORCE_kernel.cu", "FORCEKernel", \
|
self.kernel = context.get_prepared_kernel("FORCE_kernel.cu", "FORCEKernel", \
|
||||||
"iiffffPiPiPiPiPiPi", \
|
"iiffffPiPiPiPiPiPi", \
|
||||||
block_width, block_height)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "First order centered"
|
return "First order centered"
|
||||||
|
@ -64,8 +64,9 @@ class HLL (Simulator.BaseSimulator):
|
|||||||
|
|
||||||
#Get kernels
|
#Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("HLL_kernel.cu", "HLLKernel", \
|
self.kernel = context.get_prepared_kernel("HLL_kernel.cu", "HLLKernel", \
|
||||||
"iiffffPiPiPiPiPiPi", \
|
"iiffffPiPiPiPiPiPi", \
|
||||||
block_width, block_height)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Harten-Lax-van Leer"
|
return "Harten-Lax-van Leer"
|
||||||
|
@ -71,7 +71,8 @@ class HLL2 (Simulator.BaseSimulator):
|
|||||||
#Get kernels
|
#Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("HLL2_kernel.cu", "HLL2Kernel", \
|
self.kernel = context.get_prepared_kernel("HLL2_kernel.cu", "HLL2Kernel", \
|
||||||
"iifffffiPiPiPiPiPiPi", \
|
"iifffffiPiPiPiPiPiPi", \
|
||||||
block_width, block_height)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Harten-Lax-van Leer (2nd order)"
|
return "Harten-Lax-van Leer (2nd order)"
|
||||||
|
@ -74,7 +74,8 @@ class KP07 (Simulator.BaseSimulator):
|
|||||||
#Get kernels
|
#Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("KP07_kernel.cu", "KP07Kernel", \
|
self.kernel = context.get_prepared_kernel("KP07_kernel.cu", "KP07Kernel", \
|
||||||
"iiffffffiPiPiPiPiPiPi", \
|
"iiffffffiPiPiPiPiPiPi", \
|
||||||
block_width, block_height)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Kurganov-Petrova 2007"
|
return "Kurganov-Petrova 2007"
|
||||||
|
@ -72,7 +72,8 @@ class KP07_dimsplit (Simulator.BaseSimulator):
|
|||||||
#Get kernels
|
#Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("KP07_dimsplit_kernel.cu", "KP07DimsplitKernel", \
|
self.kernel = context.get_prepared_kernel("KP07_dimsplit_kernel.cu", "KP07DimsplitKernel", \
|
||||||
"iifffffiPiPiPiPiPiPi", \
|
"iifffffiPiPiPiPiPiPi", \
|
||||||
block_width, block_height)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Kurganov-Petrova 2007 dimensionally split"
|
return "Kurganov-Petrova 2007 dimensionally split"
|
||||||
|
@ -66,8 +66,9 @@ class LxF (Simulator.BaseSimulator):
|
|||||||
# Get kernels
|
# Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("LxF_kernel.cu", "LxFKernel", \
|
self.kernel = context.get_prepared_kernel("LxF_kernel.cu", "LxFKernel", \
|
||||||
"iiffffPiPiPiPiPiPi", \
|
"iiffffPiPiPiPiPiPi", \
|
||||||
block_width, block_height, \
|
no_extern_c=True, \
|
||||||
no_extern_c=True)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Lax Friedrichs"
|
return "Lax Friedrichs"
|
||||||
|
@ -65,7 +65,8 @@ class WAF (Simulator.BaseSimulator):
|
|||||||
#Get kernels
|
#Get kernels
|
||||||
self.kernel = context.get_prepared_kernel("WAF_kernel.cu", "WAFKernel", \
|
self.kernel = context.get_prepared_kernel("WAF_kernel.cu", "WAFKernel", \
|
||||||
"iiffffiPiPiPiPiPiPi", \
|
"iiffffiPiPiPiPiPiPi", \
|
||||||
block_width, block_height)
|
BLOCK_WIDTH=block_width, \
|
||||||
|
BLOCK_HEIGHT=block_height)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Weighted average flux"
|
return "Weighted average flux"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user