Skip to content

Commit f97e873

Browse files
sv2518isuruf
authored andcommitted
Change naming of is_exectubale on Target class to single_subkernel_is_entrypoint, add docs and error when there is more than one subkernel.
Update how a subkernel is detected.
1 parent 8dd1c91 commit f97e873

6 files changed

Lines changed: 29 additions & 19 deletions

File tree

loopy/target/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,14 @@ def get_kernel_executor(self, kernel, *args, **kwargs):
161161
raise NotImplementedError()
162162

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

170174

loopy/target/c/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,14 @@ def get_function_declaration(
849849

850850
# subkernel launches occur only as part of entrypoint kernels for now
851851
from loopy.schedule.tools import get_subkernel_arg_info
852+
from loopy.kernel.tools import get_subkernels
852853
skai = get_subkernel_arg_info(kernel, subkernel_name)
854+
if (self.target.single_subkernel_is_entrypoint
855+
and len(get_subkernels(kernel)) > 1):
856+
raise LoopyError(f"Kernel '{kernel.name}' has more than one"
857+
f" subkernel, not allowed in {self.target}.")
853858
passed_names = (skai.passed_names
854-
if self.target.is_executable
859+
if not self.target.single_subkernel_is_entrypoint
855860
else [arg.name for arg in kernel.args])
856861
written_names = skai.written_names
857862
else:
@@ -1345,8 +1350,8 @@ def get_dtype_registry(self):
13451350
return DTypeRegistryWrapper(result)
13461351

13471352
@property
1348-
def is_executable(self) -> bool:
1349-
return False
1353+
def single_subkernel_is_entrypoint(self) -> bool:
1354+
return True
13501355

13511356

13521357
class CASTBuilder(CFamilyASTBuilder):
@@ -1392,8 +1397,8 @@ def get_host_ast_builder(self):
13921397
return CFamilyASTBuilder(self)
13931398

13941399
@property
1395-
def is_executable(self) -> bool:
1396-
return True
1400+
def single_subkernel_is_entrypoint(self) -> bool:
1401+
return False
13971402

13981403
# }}}
13991404

loopy/target/cuda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def vector_dtype(self, base, count):
256256
# }}}
257257

258258
@property
259-
def is_executable(self) -> bool:
259+
def single_subkernel_is_entrypoint(self) -> bool:
260260
return False
261261

262262
# }}}

loopy/target/ispc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ def get_dtype_registry(self):
199199
# }}}
200200

201201
@property
202-
def is_executable(self) -> bool:
203-
return False
202+
def single_subkernel_is_entrypoint(self) -> bool:
203+
return True
204204

205205

206206
class ISPCASTBuilder(CFamilyASTBuilder):
@@ -226,9 +226,9 @@ def get_function_declaration(
226226
# subkernel launches occur only as part of entrypoint kernels for now
227227
from loopy.schedule.tools import get_subkernel_arg_info
228228
skai = get_subkernel_arg_info(codegen_state.kernel, subkernel_name)
229-
passed_names = (skai.passed_names
230-
if self.target.is_executable
231-
else [arg.name for arg in kernel.args])
229+
passed_names = ([arg.name for arg in kernel.args]
230+
if self.target.single_subkernel_is_entrypoint
231+
else skai.passed_names)
232232
written_names = skai.written_names
233233
else:
234234
passed_names = [arg.name for arg in kernel.args]
@@ -269,7 +269,8 @@ def get_kernel_call(self, codegen_state: CodeGenerationState,
269269
"assert(programCount == (%s))"
270270
% ecm(lsize[0], PREC_NONE)))
271271

272-
if codegen_state.is_entrypoint and self.target.is_executable:
272+
if (codegen_state.is_entrypoint and
273+
self.target.single_subkernel_is_entrypoint):
273274
# subkernel launches occur only as part of entrypoint kernels for now
274275
from loopy.schedule.tools import get_subkernel_arg_info
275276
skai = get_subkernel_arg_info(codegen_state.kernel, subkernel_name)

loopy/target/opencl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def vector_dtype(self, base, count):
599599
return NumpyType(vec.types[base.numpy_dtype, count])
600600

601601
@property
602-
def is_executable(self) -> bool:
602+
def single_subkernel_is_entrypoint(self) -> bool:
603603
return False
604604

605605
# }}}

loopy/target/pyopencl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ def with_device(self, device):
646646
return self
647647

648648
@property
649-
def is_executable(self) -> bool:
650-
return True
649+
def single_subkernel_is_entrypoint(self) -> bool:
650+
return False
651651

652652
# }}}
653653

0 commit comments

Comments
 (0)