Skip to content

Commit 207ae14

Browse files
committed
require targets to provide whether they are executable
1 parent 04fb703 commit 207ae14

6 files changed

Lines changed: 39 additions & 3 deletions

File tree

loopy/target/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
from typing import (Any, Tuple, Generic, TypeVar, Sequence, ClassVar, Optional,
5151
TYPE_CHECKING)
52+
import abc
5253

5354
if TYPE_CHECKING:
5455
from loopy.typing import ExpressionT
@@ -159,6 +160,13 @@ def get_kernel_executor(self, kernel, *args, **kwargs):
159160
"""
160161
raise NotImplementedError()
161162

163+
@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__`.
168+
"""
169+
162170

163171
class ASTBuilderBase(Generic[ASTType]):
164172
"""An interface for generating (host or device) ASTs.

loopy/target/c/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,9 @@ def get_function_declaration(self, codegen_state: CodeGenerationState,
859859
# subkernel launches occur only as part of entrypoint kernels for now
860860
from loopy.schedule.tools import get_subkernel_arg_info
861861
skai = get_subkernel_arg_info(kernel, subkernel_name)
862-
passed_names = skai.passed_names
862+
passed_names = (skai.passed_names
863+
if self.target.is_executable
864+
else [arg.name for arg in kernel.args])
863865
written_names = skai.written_names
864866
else:
865867
name = Value("static void", name)
@@ -1352,6 +1354,10 @@ def get_dtype_registry(self):
13521354
fill_registry_with_c99_complex_types(result)
13531355
return DTypeRegistryWrapper(result)
13541356

1357+
@property
1358+
def is_executable(self) -> bool:
1359+
return False
1360+
13551361

13561362
class CASTBuilder(CFamilyASTBuilder):
13571363
def preamble_generators(self):
@@ -1388,6 +1394,10 @@ def get_host_ast_builder(self):
13881394
# enable host code generation
13891395
return CFamilyASTBuilder(self)
13901396

1397+
@property
1398+
def is_executable(self) -> bool:
1399+
return True
1400+
13911401
# }}}
13921402

13931403

loopy/target/cuda.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ def vector_dtype(self, base, count):
264264

265265
# }}}
266266

267+
@property
268+
def is_executable(self) -> bool:
269+
return False
270+
267271
# }}}
268272

269273

loopy/target/ispc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ def get_dtype_registry(self):
198198

199199
# }}}
200200

201+
@property
202+
def is_executable(self) -> bool:
203+
return False
204+
201205

202206
class ISPCASTBuilder(CFamilyASTBuilder):
203207
# {{{ top-level codegen
@@ -220,7 +224,9 @@ def get_function_declaration(self, codegen_state: CodeGenerationState,
220224
# subkernel launches occur only as part of entrypoint kernels for now
221225
from loopy.schedule.tools import get_subkernel_arg_info
222226
skai = get_subkernel_arg_info(codegen_state.kernel, subkernel_name)
223-
passed_names = skai.passed_names
227+
passed_names = (skai.passed_names
228+
if self.target.is_executable
229+
else [arg.name for arg in kernel.args])
224230
written_names = skai.written_names
225231
else:
226232
passed_names = [arg.name for arg in kernel.args]
@@ -261,7 +267,7 @@ def get_kernel_call(self, codegen_state: CodeGenerationState,
261267
"assert(programCount == (%s))"
262268
% ecm(lsize[0], PREC_NONE)))
263269

264-
if codegen_state.is_entrypoint:
270+
if codegen_state.is_entrypoint and self.target.is_executable:
265271
# subkernel launches occur only as part of entrypoint kernels for now
266272
from loopy.schedule.tools import get_subkernel_arg_info
267273
skai = get_subkernel_arg_info(codegen_state.kernel, subkernel_name)

loopy/target/opencl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ def is_vector_dtype(self, dtype):
594594
def vector_dtype(self, base, count):
595595
return NumpyType(vec.types[base.numpy_dtype, count])
596596

597+
@property
598+
def is_executable(self) -> bool:
599+
return False
600+
597601
# }}}
598602

599603

loopy/target/pyopencl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ def with_device(self, device):
526526
"stop working in 2022.", DeprecationWarning, stacklevel=2)
527527
return self
528528

529+
@property
530+
def is_executable(self) -> bool:
531+
return True
532+
529533
# }}}
530534

531535

0 commit comments

Comments
 (0)