Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
791dfd3
Initial work towards using array contexts
inducer May 13, 2022
2da9092
update tests to pass actx
alexfikl Sep 3, 2022
3123ec7
sumpy.array_context additions
alexfikl Sep 3, 2022
ecc9d7f
port p2p to arraycontext
alexfikl Sep 3, 2022
2285243
port p2e to arraycontext
alexfikl Sep 3, 2022
c87c528
port e2p to arraycontext
alexfikl Sep 3, 2022
2aa656b
port e2e to arraycontext
alexfikl Sep 3, 2022
57971a5
port tools and toys to arraycontext
alexfikl Sep 3, 2022
1abff07
port test_tools to arraycontext
alexfikl Sep 3, 2022
5d95944
port test_misc to arraycontext
alexfikl Sep 3, 2022
9b4fbde
bump requirements
alexfikl Sep 4, 2022
71e6c65
start porting test_kernels to arraycontext
alexfikl Sep 4, 2022
7086997
more porting in test_kernels
alexfikl Sep 5, 2022
4523020
add arraycontext to docs
alexfikl Sep 5, 2022
aa5a50b
add some annotations to make_loopy_program
alexfikl Sep 5, 2022
bfce329
finish porting in test_kernels
alexfikl Sep 5, 2022
80b1045
port qbx to arraycontext
alexfikl Sep 5, 2022
81b92bd
port curve-pot to arraycontext
alexfikl Sep 5, 2022
5cc1919
add pytools to intersphinx
alexfikl Sep 5, 2022
04bb78a
add assumptions at kernel creation
alexfikl Sep 5, 2022
dd9e7d9
port expansion-toys to arraycontext
alexfikl Sep 5, 2022
5bba7e2
move get_kernel calls to separate line for debugging
alexfikl Sep 6, 2022
2332fd5
add fixed_parameters to make_loopy_program
alexfikl Sep 6, 2022
6da8704
port test_qbx to arraycontext
alexfikl Sep 6, 2022
4aca058
port test_matrixgen to arraycontext
alexfikl Sep 6, 2022
711f938
continue porting fmm to arraycontext
alexfikl Sep 6, 2022
276b42a
update drive_fmm from boxtree
alexfikl Sep 8, 2022
3f8b2b8
Merge branch 'main' into towards-array-context
alexfikl Sep 17, 2022
4c1985d
more work towards getting the fmm working
alexfikl Sep 17, 2022
2c93c4e
fix up fmm tests
alexfikl Sep 17, 2022
ddaa4ad
port distributed to arraycontext
alexfikl Sep 17, 2022
be9c909
add missing actx
alexfikl Sep 18, 2022
fd7e61f
fix kernel return values
alexfikl Sep 21, 2022
c3e35a5
actually loop over all results
alexfikl Sep 21, 2022
f6d6e9d
back up some more dictionary kernel accesses
alexfikl Sep 21, 2022
0fa102f
fix matrix generation
alexfikl Sep 21, 2022
a7bb63a
rip out timing collection
alexfikl Sep 25, 2022
15a15f2
Merge branch 'main' into towards-array-context
alexfikl Sep 25, 2022
567b947
remove unused imports (flake8)
alexfikl Sep 25, 2022
ea7656d
fix return value for form_locals
alexfikl Sep 25, 2022
2fd594d
Merge branch 'main' into towards-array-context
alexfikl Sep 26, 2022
bd5f578
remove ctx arg in KernelComputation
alexfikl Sep 26, 2022
4c3d838
back out some unneeded changes
alexfikl Sep 29, 2022
60e194d
point ci to updated pytential
alexfikl Sep 29, 2022
45a023e
fix kwargs name
alexfikl Sep 29, 2022
39d0757
Merge branch 'main' into towards-array-context
alexfikl Oct 17, 2022
5cbce16
Merge branch 'main' into towards-array-context
alexfikl Oct 30, 2022
e28d295
fix merge
alexfikl Oct 30, 2022
f1efc3a
Merge branch 'main' into towards-array-context
alexfikl Nov 6, 2022
447335d
Merge branch 'main' into towards-array-context
alexfikl Nov 28, 2022
b7df3ce
Merge branch 'main' into towards-array-context
alexfikl Jan 11, 2023
8397a93
Merge branch 'main' into towards-array-context
alexfikl Jan 31, 2023
237dad4
Merge branch 'main' into towards-array-context
alexfikl Apr 4, 2023
6f65431
Merge branch 'main' into towards-array-context
alexfikl Apr 26, 2023
53933e7
docs: add pytools to intersphinx
alexfikl Apr 28, 2023
b6b3e2e
Merge branch 'main' into towards-array-context
alexfikl Jun 16, 2023
b7203e2
fix device handling in p2p
alexfikl Jun 16, 2023
43148e1
Merge branch 'main' into towards-array-context
alexfikl Aug 2, 2023
a791aaf
Merge branch 'main' into towards-array-context
alexfikl Aug 5, 2023
51ac5f5
fix bad merge
alexfikl Aug 5, 2023
d88b9f4
Merge branch 'main' into towards-array-context
alexfikl Oct 17, 2023
4fe4f01
fix bad merge
alexfikl Oct 17, 2023
639c861
Merge branch 'main' into towards-array-context
alexfikl Feb 24, 2025
32173e0
fix some type annotations
alexfikl Feb 24, 2025
28cf7cd
fix some pylint errors
alexfikl Feb 24, 2025
de738c4
Drop register_optimization_preambles, handle FP contract in actx
inducer Dec 4, 2025
494220f
Fix some make_obj_array stragglers
inducer Dec 4, 2025
57dc042
get_cached_kernel_executor -> get_cached_kernel
inducer Dec 4, 2025
a57eb87
Fix toys
inducer Dec 9, 2025
53b6fc3
Fix jump and target derivative tests
inducer Dec 9, 2025
43af511
Fix test_unified_single_and_double
inducer Dec 10, 2025
ee19cf8
Address pocl 7.x pyvkfft miscompilation
inducer Dec 10, 2025
680aef7
Fix docs
inducer Dec 10, 2025
039119e
Use ArrayContext+assert instead of PyOpenCLActx in annotations
inducer Dec 10, 2025
22b9b8f
Fix some type annotations in P2P
inducer Dec 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ jobs:
run: |
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
if [[ "$DOWNSTREAM_PROJECT" == "pytential" && "$GITHUB_HEAD_REF" == "e2p" ]]; then
DOWNSTREAM_PROJECT=https://github.com/isuruf/pytential.git@e2p
if [[ "$DOWNSTREAM_PROJECT" == "pytential" && "$GITHUB_HEAD_REF" == "towards-array-context" ]]; then
DOWNSTREAM_PROJECT=https://github.com/alexfikl/pytential.git@towards-array-context
fi
test_downstream "$DOWNSTREAM_PROJECT"

Expand Down
3 changes: 2 additions & 1 deletion .test-conda-env-py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ dependencies:
- numpy
- scipy
- sympy
- pocl
# https://github.com/pocl/pocl/issues/2069
- pocl<7
- pocl-cuda
- islpy
- pyopencl
Expand Down
3 changes: 3 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

nitpick_ignore_regex = [
["py:class", r"symengine\.(.+)"], # :cry:
["py:class", r"ToTagSetConvertible"], # :cry:
]

sphinxconfig_missing_reference_aliases = {
Expand All @@ -36,6 +37,7 @@
"np.complexfloating": "class:numpy.complexfloating",
"np.inexact": "class:numpy.inexact",
"np.dtype": "class:numpy.dtype",
"np.number": "class:numpy.number",
# pytools
"obj_array.ObjectArray1D": "obj:pytools.obj_array.ObjectArray1D",
# sympy
Expand All @@ -53,6 +55,7 @@
"CallInstruction": "class:loopy.kernel.instruction.CallInstruction",
# arraycontext
"Array": "obj:arraycontext.Array",
"ArrayContext": "class:arraycontext.ArrayContext",
# boxtree
"FMMTraversalInfo": "class:boxtree.traversal.FMMTraversalInfo",
# sumpy
Expand Down
13 changes: 8 additions & 5 deletions examples/curve-pot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def draw_pot_figure(aspect_ratio,
knl_kwargs = {}

vol_source_knl, vol_target_knl = process_kernel(knl, what_operator)
p2p = P2P(actx.context,
p2p = P2P(
source_kernels=(vol_source_knl,),
target_kernels=(vol_target_knl,),
exclude_self=False,
Expand All @@ -100,7 +100,7 @@ def draw_pot_figure(aspect_ratio,
lpot_source_knl, lpot_target_knl = process_kernel(knl, what_operator_lpot)

from sumpy.qbx import LayerPotential
lpot = LayerPotential(actx.context,
lpot = LayerPotential(
expansion=expn_class(knl, order=order),
source_kernels=(lpot_source_knl,),
target_kernels=(lpot_target_knl,),
Expand Down Expand Up @@ -184,7 +184,8 @@ def map_to_curve(t: NDArray[np.floating]):

def apply_lpot(x: NDArray[np.inexact]) -> NDArray[np.inexact]:
xovsmp = fim @ x
_evt, (y,) = lpot(actx.queue,
y, = lpot(
actx,
sources,
ovsmp_sources,
actx.from_numpy(centers),
Expand All @@ -209,7 +210,8 @@ def apply_lpot(x: NDArray[np.inexact]) -> NDArray[np.inexact]:
density = np.cos(mode_nr*2*np.pi*native_t).astype(np.complex128)
strength = actx.from_numpy(native_curve.speed * native_weights * density)

_evt, (vol_pot,) = p2p(actx.queue,
vol_pot, = p2p(
actx,
targets,
sources,
[strength], **volpot_kwargs)
Expand All @@ -219,7 +221,8 @@ def apply_lpot(x: NDArray[np.inexact]) -> NDArray[np.inexact]:
ovsmp_strength = actx.from_numpy(
ovsmp_curve.speed * ovsmp_weights * ovsmp_density)

_evt, (curve_pot,) = lpot(actx.queue,
curve_pot, = lpot(
actx,
sources,
ovsmp_sources,
actx.from_numpy(centers),
Expand Down
15 changes: 7 additions & 8 deletions examples/expansion-toys.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def main():
actx = PyOpenCLArrayContext(queue)

tctx = t.ToyContext(
actx.context,
# LaplaceKernel(2),
YukawaKernel(2), extra_kernel_kwargs={"lam": 5},
# HelmholtzKernel(2), extra_kernel_kwargs={"k": 0.3},
Expand All @@ -36,22 +35,22 @@ def main():
fp = FieldPlotter([3, 0], extent=8)

if USE_MATPLOTLIB:
t.logplot(fp, pt_src, cmap="jet")
t.logplot(actx, fp, pt_src, cmap="jet")
plt.colorbar()
plt.show()

mexp = t.multipole_expand(pt_src, [0, 0], 5)
mexp2 = t.multipole_expand(mexp, [0, 0.25]) # noqa: F841
lexp = t.local_expand(mexp, [3, 0])
lexp2 = t.local_expand(lexp, [3, 1], 3)
mexp = t.multipole_expand(actx, pt_src, [0, 0], order=5)
mexp2 = t.multipole_expand(actx, mexp, [0, 0.25]) # noqa: F841
lexp = t.local_expand(actx, mexp, [3, 0])
lexp2 = t.local_expand(actx, lexp, [3, 1], order=3)

# diff = mexp - pt_src
# diff = mexp2 - pt_src
diff = lexp2 - pt_src

print(t.l_inf(diff, 1.2, center=lexp2.center))
print(t.l_inf(actx, diff, 1.2, center=lexp2.center))
if USE_MATPLOTLIB:
t.logplot(fp, diff, cmap="jet", vmin=-3, vmax=0)
t.logplot(actx, fp, diff, cmap="jet", vmin=-3, vmax=0)
plt.colorbar()
plt.show()

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ git+https://github.com/inducer/pytools.git#egg=pytools
git+https://github.com/inducer/pymbolic.git#egg=pymbolic
git+https://github.com/inducer/islpy.git#egg=islpy
git+https://github.com/inducer/pyopencl.git#egg=pyopencl
git+https://github.com/inducer/boxtree.git#egg=boxtree
git+https://github.com/alexfikl/boxtree.git@towards-array-context#egg=boxtree
git+https://github.com/inducer/loopy.git#egg=loopy
git+https://github.com/inducer/arraycontext.git#egg=arraycontext
git+https://github.com/inducer/pyfmmlib.git#egg=pyfmmlib
6 changes: 2 additions & 4 deletions sumpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
]


code_cache: WriteOncePersistentDict[Hashable, lp.TranslationUnit] = \
WriteOncePersistentDict("sumpy-code-cache-v6-"+VERSION_TEXT, safe_sync=False)
code_cache: WriteOncePersistentDict[Hashable, lp.TranslationUnit] = (
WriteOncePersistentDict(f"sumpy-code-cache-v8-{VERSION_TEXT}", safe_sync=False))


# {{{ optimization control
Expand All @@ -87,8 +87,6 @@ def set_optimization_enabled(flag):

# {{{ cache control

CACHING_ENABLED = True

CACHING_ENABLED = (
"SUMPY_NO_CACHE" not in os.environ
and "CG_NO_CACHE" not in os.environ)
Expand Down
84 changes: 75 additions & 9 deletions sumpy/array_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,102 @@
THE SOFTWARE.
"""

from typing import TYPE_CHECKING, Any

from boxtree.array_context import PyOpenCLArrayContext as PyOpenCLArrayContextBase
from typing_extensions import override

import loopy as lp
from arraycontext.pytest import (
_PytestPyOpenCLArrayContextFactoryWithClass,
register_pytest_array_context_factory,
)


if TYPE_CHECKING:
from collections.abc import Iterator

from numpy.typing import DTypeLike

from arraycontext import ArrayContext
from loopy import TranslationUnit
from loopy.codegen import PreambleInfo
from pytools.tag import ToTagSetConvertible


__doc__ = """
Array Context
-------------

.. autofunction:: make_loopy_program
.. autoclass:: PyOpenCLArrayContext
"""


# {{{ PyOpenCLArrayContext

def make_loopy_program(
domains, statements,

Check warning on line 61 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Type annotation is missing for parameter "statements" (reportMissingParameterType)

Check warning on line 61 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Type of parameter "statements" is unknown (reportUnknownParameterType)

Check warning on line 61 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Type annotation is missing for parameter "domains" (reportMissingParameterType)

Check warning on line 61 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Type of parameter "domains" is unknown (reportUnknownParameterType)
kernel_data: list[Any] | None = None, *,
name: str = "sumpy_loopy_kernel",
silenced_warnings: list[str] | str | None = None,
assumptions: str = "",
fixed_parameters: dict[str, Any] | None = None,
index_dtype: DTypeLike = None,

Check failure on line 67 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Expression of type "None" cannot be assigned to parameter of type "DTypeLike"   Type "None" is not assignable to type "DTypeLike"     "None" is not assignable to "type[Any]"     "None" is not assignable to "dtype[Any]"     "None" is incompatible with protocol "_HasDType[dtype[Any]]"       "dtype" is not present     "None" is incompatible with protocol "_HasNumPyDType[dtype[Any]]"       "__numpy_dtype__" is not present     "None" is not assignable to "tuple[_DTypeLikeNested, _DTypeLikeNested]" ... (reportArgumentType)
tags: ToTagSetConvertible = None):
"""Return a :class:`loopy.LoopKernel` suitable for use with
:meth:`arraycontext.ArrayContext.call_loopy`.
"""
if kernel_data is None:
kernel_data = [...]

if silenced_warnings is None:
silenced_warnings = []

import loopy as lp
from arraycontext.loopy import _DEFAULT_LOOPY_OPTIONS

return lp.make_kernel(
domains,

Check warning on line 82 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument type is unknown   Argument corresponds to parameter "domains" in function "make_kernel" (reportUnknownArgumentType)
statements,

Check warning on line 83 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument type is unknown   Argument corresponds to parameter "instructions" in function "make_kernel" (reportUnknownArgumentType)
kernel_data=kernel_data,
options=_DEFAULT_LOOPY_OPTIONS,
default_offset=lp.auto,
name=name,
lang_version=lp.MOST_RECENT_LANGUAGE_VERSION,
assumptions=assumptions,
fixed_parameters=fixed_parameters,
silenced_warnings=silenced_warnings,
index_dtype=index_dtype,
tags=tags)


def _fp_contract_fast_preamble(
preamble_info: PreambleInfo

Check warning on line 97 in sumpy/array_context.py

View workflow job for this annotation

GitHub Actions / basedpyright

"preamble_info" is not accessed (reportUnusedParameter)
) -> Iterator[tuple[str, str]]:
yield ("fp_contract_fast_pocl", "#pragma clang fp contract(fast)")


class PyOpenCLArrayContext(PyOpenCLArrayContextBase):
def transform_loopy_program(self, t_unit):
default_ep = t_unit.default_entrypoint
options = default_ep.options
@override
def transform_loopy_program(self, t_unit: TranslationUnit):
import pyopencl as cl
device = self.queue.device
if (device.platform.name == "Portable Computing Language"
and (device.type & cl.device_type.GPU)):
t_unit = lp.register_preamble_generators(
t_unit,
[_fp_contract_fast_preamble])

return t_unit

if not (options.return_dict and options.no_numpy):
raise ValueError("Loopy kernel passed to call_loopy must "
"have return_dict and no_numpy options set. "
"Did you use arraycontext.make_loopy_program "
"to create this kernel?")

return super().transform_loopy_program(t_unit)
def is_cl_cpu(actx: ArrayContext) -> bool:
if not isinstance(actx, PyOpenCLArrayContext):
return False

import pyopencl as cl
return all(dev.type & cl.device_type.CPU for dev in actx.context.devices)

# }}}

Expand Down
22 changes: 0 additions & 22 deletions sumpy/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@

from numpy.typing import DTypeLike

import pyopencl as cl
from loopy.codegen import PreambleInfo
from loopy.target import TargetBase
from loopy.translation_unit import CallablesInferenceContext
from loopy.types import LoopyType
Expand Down Expand Up @@ -249,26 +247,6 @@

return loopy_knl


def _fp_contract_fast_preamble(
preamble_info: PreambleInfo
) -> Iterator[tuple[str, str]]:
yield ("fp_contract_fast_pocl", "#pragma clang fp contract(fast)")


def register_optimization_preambles(
loopy_knl: lp.TranslationUnit, device: cl.Device
) -> lp.TranslationUnit:
if isinstance(loopy_knl.target, lp.PyOpenCLTarget):
import pyopencl as cl
if (device.platform.name == "Portable Computing Language"
and (device.type & cl.device_type.GPU)):
loopy_knl = lp.register_preamble_generators(
loopy_knl,
[_fp_contract_fast_preamble])

return loopy_knl

# }}}


Expand Down Expand Up @@ -753,7 +731,7 @@
assignments: Iterable[tuple[str, sym.Expr]],
vector_names: Set[str] | None = None,
pymbolic_expr_maps: Sequence[Callable[[Expression], Expression]] = (),
complex_dtype: DTypeLike = None,

Check failure on line 734 in sumpy/codegen.py

View workflow job for this annotation

GitHub Actions / basedpyright

Expression of type "None" cannot be assigned to parameter of type "DTypeLike"   Type "None" is not assignable to type "DTypeLike"     "None" is not assignable to "type[Any]"     "None" is not assignable to "dtype[Any]"     "None" is incompatible with protocol "_HasDType[dtype[Any]]"       "dtype" is not present     "None" is incompatible with protocol "_HasNumPyDType[dtype[Any]]"       "__numpy_dtype__" is not present     "None" is not assignable to "tuple[_DTypeLikeNested, _DTypeLikeNested]" ... (reportArgumentType)
retain_names: Set[str] | None = None,
) -> Sequence[Assignment | CallInstruction]:
if vector_names is None:
Expand Down
Loading
Loading