Skip to content

Commit d1c8df5

Browse files
committed
feat: update InKernelCallable.emit_call types and docs
1 parent 4cd9833 commit d1c8df5

2 files changed

Lines changed: 34 additions & 37 deletions

File tree

loopy/kernel/function_interface.py

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from collections.abc import Iterator, Mapping, Sequence, Set
4343

4444
import islpy as isl
45-
from pymbolic.typing import Expression
45+
from pymbolic.typing import ArithmeticExpression, Expression
4646

4747
from loopy.kernel import LoopKernel
4848
from loopy.kernel.instruction import CallInstruction
@@ -543,31 +543,48 @@ def generate_preambles(self, target: TargetBase) -> Iterator[str]:
543543
"""
544544
raise NotImplementedError()
545545

546-
# FIXME(pyright): these return types are not correct: see IndexOfCallable.emit_call
547546
@abstractmethod
548547
def emit_call(self,
549548
expression_to_code_mapper: AbstractExpressionToCodeMapper,
550549
expression: p.Call,
551-
target: TargetBase) -> p.Call | p.CallWithKwargs:
552-
...
550+
target: TargetBase) -> ArithmeticExpression:
551+
"""Generate a target-specific call expression by mapping its arguments
552+
to the appropriate data types.
553+
554+
:arg expression_to_code_mapper: an instance of
555+
``loopy.symbolic.IdentityMapper``
556+
responsible mapping the arguments (see
557+
:meth:`~loopy.target.c.codegen.expression.ExpressionToCExpressionMapper`).
558+
"""
553559

554560
@abstractmethod
555561
def emit_call_insn(self,
556562
insn: CallInstruction,
557563
target: TargetBase,
558564
expression_to_code_mapper: AbstractExpressionToCodeMapper,
559-
) -> tuple[p.Call | p.CallWithKwargs, bool]:
565+
) -> tuple[ArithmeticExpression, bool]:
560566
"""
561567
Returns a tuple of ``(call, assignee_is_returned)`` which is the target
562568
facing function call that would be seen in the generated code. ``call``
563-
is an instance of ``pymbolic.primitives.Call`` and ``assignee_is_returned``
564-
is a boolean flag used to indicate if the assignee is returned
565-
by value of C-type targets.
566-
567-
*Example*: If ``assignee_is_returned=True``, then ``a, b = f(c, d)`` is
568-
interpreted in the target as ``a = f(c, d, &b)``. If
569-
``assignee_is_returned=False``, then ``a, b = f(c, d)`` is interpreted
570-
in the target as the statement ``f(c, d, &a, &b)``.
569+
is (usually) an instance of :class:`pymbolic.primitives.Call` and
570+
``assignee_is_returned`` is a boolean flag used to indicate if the
571+
assignee is returned by value of C-type targets.
572+
573+
.. note::
574+
575+
*Example*: If ``assignee_is_returned=True``, then ``a, b = f(c,
576+
d)`` is interpreted in the target as ``a = f(c, d, &b)``. If
577+
``assignee_is_returned=False``, then ``a, b = f(c, d)`` is
578+
interpreted in the target as the statement ``f(c, d, &a, &b)``.
579+
580+
:arg expression_to_code_mapper: an instance of
581+
``loopy.symbolic.IdentityMapper`` responsible for code mapping
582+
from :mod:`loopy` syntax to the *target syntax* (see
583+
:meth:`~loopy.target.c.codegen.expression.ExpressionToCExpressionMapper`).
584+
585+
:returns: a tuple of the call to be generated and an instance of
586+
:class:`bool` whether the first assignee is a part of the LHS in
587+
the assignment instruction
571588
"""
572589

573590
@abstractmethod
@@ -690,7 +707,7 @@ def is_ready_for_codegen(self) -> bool:
690707
def emit_call(self,
691708
expression_to_code_mapper: AbstractExpressionToCodeMapper,
692709
expression: p.Call,
693-
target: TargetBase) -> p.Call | p.CallWithKwargs:
710+
target: TargetBase) -> ArithmeticExpression:
694711
assert self.is_ready_for_codegen()
695712
assert self.arg_id_to_dtype is not None
696713

@@ -718,27 +735,7 @@ def emit_call_insn(self,
718735
insn: CallInstruction,
719736
target: TargetBase,
720737
expression_to_code_mapper: AbstractExpressionToCodeMapper,
721-
) -> tuple[p.Call | p.CallWithKwargs, bool]:
722-
"""
723-
:arg insn: An instance of :class:`loopy.kernel.instructions.CallInstruction`.
724-
:arg target: An instance of :class:`loopy.target.TargetBase`.
725-
:arg expression_to_code_mapper: An instance of :class:`IdentityMapper`
726-
responsible for code mapping from :mod:`loopy` syntax to the
727-
**target syntax**.
728-
729-
:returns: A tuple of the call to be generated and an instance of
730-
:class:`bool` whether the first assignee is a part of the LHS in
731-
the assignment instruction.
732-
733-
.. note::
734-
735-
The default implementation returns the first assignees and the
736-
references of the rest of the assignees are appended to the
737-
arguments of the call.
738-
739-
*Example:* ``c, d = f(a, b)`` is returned as ``c = f(a, b, &d)``
740-
"""
741-
738+
) -> tuple[ArithmeticExpression, bool]:
742739
from loopy.target.c import CFamilyTarget
743740
if not isinstance(target, CFamilyTarget):
744741
raise NotImplementedError(

loopy/library/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def get_loopy_callables() -> CallablesTable:
129129
category are --
130130
131131
- reductions leading to function calls like ``argmin``, ``argmax``.
132-
- callables that have a predefined meaning in :mod:`loo.py` like
133-
``make_tuple``, ``index_of``, ``indexof_vec``.
132+
- callables that have a predefined meaning in :mod:`loopy` like
133+
``make_tuple``, ``indexof``, ``indexof_vec``.
134134
"""
135135
return constantdict({
136136
"make_tuple": MakeTupleCallable(name="make_tuple"),

0 commit comments

Comments
 (0)