Skip to content

Commit 9bfef04

Browse files
sv2518kaushikcfd
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 94572d7 commit 9bfef04

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
@@ -840,9 +840,14 @@ def get_function_declaration(
840840

841841
# subkernel launches occur only as part of entrypoint kernels for now
842842
from loopy.schedule.tools import get_subkernel_arg_info
843+
from loopy.kernel.tools import get_subkernels
843844
skai = get_subkernel_arg_info(kernel, subkernel_name)
845+
if (self.target.single_subkernel_is_entrypoint
846+
and len(get_subkernels(kernel)) > 1):
847+
raise LoopyError(f"Kernel '{kernel.name}' has more than one"
848+
f" subkernel, not allowed in {self.target}.")
844849
passed_names = (skai.passed_names
845-
if self.target.is_executable
850+
if not self.target.single_subkernel_is_entrypoint
846851
else [arg.name for arg in kernel.args])
847852
written_names = skai.written_names
848853
else:
@@ -1336,8 +1341,8 @@ def get_dtype_registry(self):
13361341
return DTypeRegistryWrapper(result)
13371342

13381343
@property
1339-
def is_executable(self) -> bool:
1340-
return False
1344+
def single_subkernel_is_entrypoint(self) -> bool:
1345+
return True
13411346

13421347

13431348
class CASTBuilder(CFamilyASTBuilder):
@@ -1383,8 +1388,8 @@ def get_host_ast_builder(self):
13831388
return CFamilyASTBuilder(self)
13841389

13851390
@property
1386-
def is_executable(self) -> bool:
1387-
return True
1391+
def single_subkernel_is_entrypoint(self) -> bool:
1392+
return False
13881393

13891394
# }}}
13901395

‎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
@@ -552,8 +552,8 @@ def with_device(self, device):
552552
return self
553553

554554
@property
555-
def is_executable(self) -> bool:
556-
return True
555+
def single_subkernel_is_entrypoint(self) -> bool:
556+
return False
557557

558558
# }}}
559559

0 commit comments

Comments
 (0)