Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions sasmodels/kernelcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ def has_type(self, dtype):
"""
return self.context.get(dtype, None) is not None

def compile_program(self, name, source, dtype, fast, timestamp):
# type: (str, str, np.dtype, bool, float) -> cl.Program
def compile_program(self, name, source, dtype, fast, timestamp, kernel_names):
# type: (str, str, np.dtype, bool, float, list[str]) -> cl.Program
"""
Compile the program for the device in the given context.
"""
Expand All @@ -299,17 +299,18 @@ def compile_program(self, name, source, dtype, fast, timestamp):
tag = generate.tag_source(source)
key = "%s-%s-%s%s"%(name, dtype, tag, ("-fast" if fast else ""))
# Check timestamp on program.
program, program_timestamp = self.compiled.get(key, (None, np.inf))
if program_timestamp < timestamp:
program, compile_timestamp, kernels = self.compiled.get(key, (None, np.inf, []))
if compile_timestamp < timestamp:
del self.compiled[key]
if key not in self.compiled:
context = self.context[dtype]
logging.info("building %s for OpenCL %s", key,
context.devices[0].name.strip())
program = compile_model(self.context[dtype],
str(source), dtype, fast)
self.compiled[key] = (program, timestamp)
return program
kernels = [getattr(program, k) for k in kernel_names]
self.compiled[key] = (program, timestamp, kernels)
return kernels


def _create_some_context():
Expand Down Expand Up @@ -457,20 +458,18 @@ def get_function(self, name):
def _prepare_program(self):
# type: (str) -> None
env = environment()
variants = ['Iq', 'Iqxy', 'Imagnetic']
kernel_names = [generate.kernel_name(self.info, k) for k in variants]
timestamp = generate.ocl_timestamp(self.info)
program = env.compile_program(
kernels = env.compile_program(
self.info.name,
self.source['opencl'],
self.dtype,
self.fast,
timestamp)
variants = ['Iq', 'Iqxy', 'Imagnetic']
names = [generate.kernel_name(self.info, k) for k in variants]
functions = [getattr(program, k) for k in names]
self._kernels = {k: v for k, v in zip(variants, functions)}
# Keep a handle to program so GC doesn't collect.
self._program = program

timestamp,
kernel_names,
)
self._kernels = {k: v for k, v in zip(variants, kernels)}

# TODO: Check that we don't need a destructor for buffers which go out of scope.
class GpuInput:
Expand Down
27 changes: 13 additions & 14 deletions sasmodels/kernelcuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def has_type(self, dtype):
"""
return has_type(dtype)

def compile_program(self, name, source, dtype, fast, timestamp):
# type: (str, str, np.dtype, bool, float) -> SourceModule
def compile_program(self, name, source, dtype, fast, timestamp, kernel_names):
# type: (str, str, np.dtype, bool, float, list[str]) -> SourceModule
"""
Compile the program for the device in the given context.
"""
Expand All @@ -284,14 +284,15 @@ def compile_program(self, name, source, dtype, fast, timestamp):
tag = generate.tag_source(source)
key = "%s-%s-%s%s"%(name, dtype, tag, ("-fast" if fast else ""))
# Check timestamp on program.
program, program_timestamp = self.compiled.get(key, (None, np.inf))
if program_timestamp < timestamp:
program, compile_timestamp, kernels = self.compiled.get(key, (None, np.inf, []))
if compile_timestamp < timestamp:
del self.compiled[key]
if key not in self.compiled:
logging.info("building %s for CUDA", key)
program = compile_model(str(source), dtype, fast)
self.compiled[key] = (program, timestamp)
return program
kernels = [getattr(program, k) for k in kernel_names]
self.compiled[key] = (program, timestamp, kernels)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be failing with TypeError: unhashable type: 'list', and similarly in kernelcl.

return kernels


class GpuModel(KernelModel):
Expand Down Expand Up @@ -349,19 +350,17 @@ def get_function(self, name):
def _prepare_program(self):
# type: (str) -> None
env = environment()
variants = ['Iq', 'Iqxy', 'Imagnetic']
kernel_names = [generate.kernel_name(self.info, k) for k in variants]
timestamp = generate.ocl_timestamp(self.info)
program = env.compile_program(
kernels = env.compile_program(
self.info.name,
self.source['opencl'],
self.dtype,
self.fast,
timestamp)
variants = ['Iq', 'Iqxy', 'Imagnetic']
names = [generate.kernel_name(self.info, k) for k in variants]
functions = [program.get_function(k) for k in names]
self._kernels = {k: v for k, v in zip(variants, functions)}
# Keep a handle to program so GC doesn't collect.
self._program = program
timestamp,
kernel_names)
self._kernels = {k: v for k, v in zip(variants, kernels)}


# TODO: Check that we don't need a destructor for buffers which go out of scope.
Expand Down