From a0e17df420ac0edf67368bc459275560d6470108 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Thu, 14 Jul 2022 11:32:26 -0500 Subject: [PATCH] require targets to provide whether they are executable --- loopy/target/__init__.py | 8 ++++++++ loopy/target/c/__init__.py | 12 +++++++++++- loopy/target/cuda.py | 4 ++++ loopy/target/ispc.py | 10 ++++++++-- loopy/target/opencl.py | 4 ++++ loopy/target/pyopencl.py | 4 ++++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/loopy/target/__init__.py b/loopy/target/__init__.py index 5bb1043b9..572c0e95f 100644 --- a/loopy/target/__init__.py +++ b/loopy/target/__init__.py @@ -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 @@ -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. diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index de6a32a68..7a3588373 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -841,7 +841,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(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) @@ -1333,6 +1335,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): @@ -1376,6 +1382,10 @@ def get_host_ast_builder(self): # enable host code generation return CFamilyASTBuilder(self) + @property + def is_executable(self) -> bool: + return True + # }}} diff --git a/loopy/target/cuda.py b/loopy/target/cuda.py index 4a311f887..5254b08dc 100644 --- a/loopy/target/cuda.py +++ b/loopy/target/cuda.py @@ -255,6 +255,10 @@ def vector_dtype(self, base, count): # }}} + @property + def is_executable(self) -> bool: + return False + # }}} diff --git a/loopy/target/ispc.py b/loopy/target/ispc.py index 2fbd6bcf8..385fcf9f8 100644 --- a/loopy/target/ispc.py +++ b/loopy/target/ispc.py @@ -198,6 +198,10 @@ def get_dtype_registry(self): # }}} + @property + def is_executable(self) -> bool: + return False + class ISPCASTBuilder(CFamilyASTBuilder): # {{{ top-level codegen @@ -222,7 +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 + 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] @@ -263,7 +269,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.target.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) diff --git a/loopy/target/opencl.py b/loopy/target/opencl.py index 6957d3f96..37bee3856 100644 --- a/loopy/target/opencl.py +++ b/loopy/target/opencl.py @@ -598,6 +598,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 + # }}} diff --git a/loopy/target/pyopencl.py b/loopy/target/pyopencl.py index cb78e571b..641a40bef 100644 --- a/loopy/target/pyopencl.py +++ b/loopy/target/pyopencl.py @@ -551,6 +551,10 @@ def with_device(self, device): "stop working in 2022.", DeprecationWarning, stacklevel=2) return self + @property + def is_executable(self) -> bool: + return True + # }}}