Skip to content

Commit

Permalink
require targets to provide whether they are executable
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikcfd committed Jul 14, 2022
1 parent 04fb703 commit cdef4c4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
8 changes: 8 additions & 0 deletions loopy/target/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

from typing import (Any, Tuple, Generic, TypeVar, Sequence, ClassVar, Optional,
TYPE_CHECKING)
import abc

if TYPE_CHECKING:
from loopy.typing import ExpressionT
Expand Down Expand Up @@ -159,6 +160,13 @@ 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__`.
"""


class ASTBuilderBase(Generic[ASTType]):
"""An interface for generating (host or device) ASTs.
Expand Down
12 changes: 11 additions & 1 deletion loopy/target/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ def get_function_declaration(self, codegen_state: CodeGenerationState,
# 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(kernel, subkernel_name)
passed_names = skai.passed_names
passed_names = (skai.passed_names
if self.target.is_executable
else [arg.name for arg in kernel.args])
written_names = skai.written_names
else:
name = Value("static void", name)
Expand Down Expand Up @@ -1352,6 +1354,10 @@ def get_dtype_registry(self):
fill_registry_with_c99_complex_types(result)
return DTypeRegistryWrapper(result)

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


class CASTBuilder(CFamilyASTBuilder):
def preamble_generators(self):
Expand Down Expand Up @@ -1388,6 +1394,10 @@ def get_host_ast_builder(self):
# enable host code generation
return CFamilyASTBuilder(self)

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

# }}}


Expand Down
4 changes: 4 additions & 0 deletions loopy/target/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def vector_dtype(self, base, count):

# }}}

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

# }}}


Expand Down
10 changes: 8 additions & 2 deletions loopy/target/ispc.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def get_dtype_registry(self):

# }}}

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


class ISPCASTBuilder(CFamilyASTBuilder):
# {{{ top-level codegen
Expand All @@ -220,7 +224,9 @@ def get_function_declaration(self, codegen_state: CodeGenerationState,
# 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
passed_names = (skai.passed_names
if self.target.is_executable
else [arg.name for arg in kernel.args])
written_names = skai.written_names
else:
passed_names = [arg.name for arg in kernel.args]
Expand Down Expand Up @@ -261,7 +267,7 @@ def get_kernel_call(self, codegen_state: CodeGenerationState,
"assert(programCount == (%s))"
% ecm(lsize[0], PREC_NONE)))

if codegen_state.is_entrypoint:
if codegen_state.is_entrypoint and self.is_executable:
# 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
4 changes: 4 additions & 0 deletions loopy/target/opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ def is_vector_dtype(self, dtype):
def vector_dtype(self, base, count):
return NumpyType(vec.types[base.numpy_dtype, count])

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

# }}}


Expand Down
4 changes: 4 additions & 0 deletions loopy/target/pyopencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ def with_device(self, device):
"stop working in 2022.", DeprecationWarning, stacklevel=2)
return self

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

# }}}


Expand Down

0 comments on commit cdef4c4

Please sign in to comment.