Skip to content

Commit

Permalink
Change naming of is_exectubale on Target class to single_subkernel_is…
Browse files Browse the repository at this point in the history
…_entrypoint, add docs and error when there is more than one subkernel.

Update how a subkernel is detected.
  • Loading branch information
sv2518 authored and kaushikcfd committed Nov 10, 2022
1 parent 94572d7 commit 9bfef04
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
12 changes: 8 additions & 4 deletions loopy/target/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,14 @@ def get_kernel_executor(self, kernel, *args, **kwargs):
raise NotImplementedError()

@abc.abstractproperty
def is_executable(self) -> bool:
"""
Returns *True* only if the target allows executing loopy
translation units through :attr:`loopy.TranslationUnit.__call__`.
def single_subkernel_is_entrypoint(self) -> bool:
r"""
Returns *True* if *self* does NOT support generating code for
linearized kernels with more than one
:class:`~loopy.schedule.CallKernel`\ s. This guarantees the
:class:`~loopy.schedule.CallKernel` for which we generate code is the
entrypoint kernel. This also allows the target to skip the invoker
level code.
"""


Expand Down
15 changes: 10 additions & 5 deletions loopy/target/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,14 @@ def get_function_declaration(

# subkernel launches occur only as part of entrypoint kernels for now
from loopy.schedule.tools import get_subkernel_arg_info
from loopy.kernel.tools import get_subkernels
skai = get_subkernel_arg_info(kernel, subkernel_name)
if (self.target.single_subkernel_is_entrypoint
and len(get_subkernels(kernel)) > 1):
raise LoopyError(f"Kernel '{kernel.name}' has more than one"
f" subkernel, not allowed in {self.target}.")
passed_names = (skai.passed_names
if self.target.is_executable
if not self.target.single_subkernel_is_entrypoint
else [arg.name for arg in kernel.args])
written_names = skai.written_names
else:
Expand Down Expand Up @@ -1336,8 +1341,8 @@ def get_dtype_registry(self):
return DTypeRegistryWrapper(result)

@property
def is_executable(self) -> bool:
return False
def single_subkernel_is_entrypoint(self) -> bool:
return True


class CASTBuilder(CFamilyASTBuilder):
Expand Down Expand Up @@ -1383,8 +1388,8 @@ def get_host_ast_builder(self):
return CFamilyASTBuilder(self)

@property
def is_executable(self) -> bool:
return True
def single_subkernel_is_entrypoint(self) -> bool:
return False

# }}}

Expand Down
2 changes: 1 addition & 1 deletion loopy/target/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def vector_dtype(self, base, count):
# }}}

@property
def is_executable(self) -> bool:
def single_subkernel_is_entrypoint(self) -> bool:
return False

# }}}
Expand Down
13 changes: 7 additions & 6 deletions loopy/target/ispc.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def get_dtype_registry(self):
# }}}

@property
def is_executable(self) -> bool:
return False
def single_subkernel_is_entrypoint(self) -> bool:
return True


class ISPCASTBuilder(CFamilyASTBuilder):
Expand All @@ -226,9 +226,9 @@ def get_function_declaration(
# subkernel launches occur only as part of entrypoint kernels for now
from loopy.schedule.tools import get_subkernel_arg_info
skai = get_subkernel_arg_info(codegen_state.kernel, subkernel_name)
passed_names = (skai.passed_names
if self.target.is_executable
else [arg.name for arg in kernel.args])
passed_names = ([arg.name for arg in kernel.args]
if self.target.single_subkernel_is_entrypoint
else skai.passed_names)
written_names = skai.written_names
else:
passed_names = [arg.name for arg in kernel.args]
Expand Down Expand Up @@ -269,7 +269,8 @@ def get_kernel_call(self, codegen_state: CodeGenerationState,
"assert(programCount == (%s))"
% ecm(lsize[0], PREC_NONE)))

if codegen_state.is_entrypoint and self.target.is_executable:
if (codegen_state.is_entrypoint and
self.target.single_subkernel_is_entrypoint):
# subkernel launches occur only as part of entrypoint kernels for now
from loopy.schedule.tools import get_subkernel_arg_info
skai = get_subkernel_arg_info(codegen_state.kernel, subkernel_name)
Expand Down
2 changes: 1 addition & 1 deletion loopy/target/opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def vector_dtype(self, base, count):
return NumpyType(vec.types[base.numpy_dtype, count])

@property
def is_executable(self) -> bool:
def single_subkernel_is_entrypoint(self) -> bool:
return False

# }}}
Expand Down
4 changes: 2 additions & 2 deletions loopy/target/pyopencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ def with_device(self, device):
return self

@property
def is_executable(self) -> bool:
return True
def single_subkernel_is_entrypoint(self) -> bool:
return False

# }}}

Expand Down

0 comments on commit 9bfef04

Please sign in to comment.