Skip to content

Commit

Permalink
Expunge COFFEE (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward authored May 10, 2023
1 parent 06697a3 commit edae288
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 309 deletions.
1 change: 0 additions & 1 deletion pyop2/codegen/loopycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def _match_caller_callee_argument_dimension_(program, callee_function_name):
invocations would demand complex renaming logic which is not
implemented yet.
"""

assert isinstance(program, TranslationUnit)
assert isinstance(callee_function_name, str)
assert callee_function_name not in program.entrypoints
Expand Down
16 changes: 5 additions & 11 deletions pyop2/codegen/rep2loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,22 +552,16 @@ def renamer(expr):
headers = headers | set(["#include <petsclog.h>"])
preamble = "\n".join(sorted(headers))

from coffee.base import Node
from loopy.kernel.function_interface import CallableKernel

if isinstance(kernel.code, loopy.TranslationUnit):
knl = kernel.code
wrapper = loopy.merge([wrapper, knl])
names = knl.callables_table
for name in names:
if isinstance(wrapper.callables_table[name], CallableKernel):
wrapper = _match_caller_callee_argument_dimension_(wrapper, name)
# remove the local kernel from the available entrypoints
wrapper = wrapper.copy(entrypoints=wrapper.entrypoints-{kernel.name})
wrapper = _match_caller_callee_argument_dimension_(wrapper, kernel.name)
else:
# kernel is a string, add it to preamble
if isinstance(kernel.code, Node):
code = kernel.code.gencode()
else:
code = kernel.code
assert isinstance(kernel.code, str)
code = kernel.code
wrapper = loopy.register_callable(
wrapper,
kernel.name,
Expand Down
33 changes: 4 additions & 29 deletions pyop2/local_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import hashlib
from typing import Union

import coffee
import loopy as lp
from loopy.tools import LoopyKeyBuilder
import numpy as np
Expand Down Expand Up @@ -36,8 +35,6 @@ def Kernel(code, name, **kwargs):
"""
if isinstance(code, str):
return CStringLocalKernel(code, name, **kwargs)
elif isinstance(code, coffee.base.Node):
return CoffeeLocalKernel(code, name, **kwargs)
elif isinstance(code, (lp.LoopKernel, lp.TranslationUnit)):
return LoopyLocalKernel(code, name, **kwargs)
else:
Expand Down Expand Up @@ -120,9 +117,7 @@ def cache_key(self):
@cached_property
def _immutable_cache_key(self):
# We need this function because self.accesses is mutable due to legacy support
if isinstance(self.code, coffee.base.Node):
code = self.code.gencode()
elif isinstance(self.code, lp.TranslationUnit):
if isinstance(self.code, lp.TranslationUnit):
key_hash = hashlib.sha256()
self.code.update_persistent_hash(key_hash, LoopyKeyBuilder())
code = key_hash.hexdigest()
Expand Down Expand Up @@ -160,10 +155,7 @@ def num_flops(self):
if not configuration["compute_kernel_flops"]:
return 0

if isinstance(self.code, coffee.base.Node):
v = coffee.visitors.EstimateFlops()
return v.visit(self.code)
elif isinstance(self.code, lp.TranslationUnit):
if isinstance(self.code, lp.TranslationUnit):
op_map = lp.get_op_map(
self.code.copy(options=lp.Options(ignore_boostable_into=True),
silenced_warnings=['insn_count_subgroups_upper_bound',
Expand Down Expand Up @@ -195,8 +187,8 @@ class CStringLocalKernel(LocalKernel):
""":class:`LocalKernel` class where `code` is a string of C code.
:kwarg dtypes: Iterable of datatypes (either `np.dtype` or `str`) for
each kernel argument. This is not required for :class:`CoffeeLocalKernel`
or :class:`LoopyLocalKernel` because it can be inferred.
each kernel argument. This is not required for :class:`LoopyLocalKernel`
because it can be inferred.
All other `__init__` parameters are the same.
"""
Expand All @@ -215,23 +207,6 @@ def dtypes(self, dtypes):
self._dtypes = dtypes


class CoffeeLocalKernel(LocalKernel):
""":class:`LocalKernel` class where `code` has type :class:`coffee.base.Node`."""

@validate_type(("code", coffee.base.Node, TypeError))
def __init__(self, code, name, accesses=None, dtypes=None, **kwargs):
super().__init__(code, name, accesses, **kwargs)
self._dtypes = dtypes

@property
def dtypes(self):
return self._dtypes

@dtypes.setter
def dtypes(self, dtypes):
self._dtypes = dtypes


class LoopyLocalKernel(LocalKernel):
""":class:`LocalKernel` class where `code` has type :class:`loopy.LoopKernel`
or :class:`loopy.TranslationUnit`.
Expand Down
2 changes: 1 addition & 1 deletion pyop2/op2.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from pyop2.types import (READ, WRITE, RW, INC, MIN, MAX,
ON_BOTTOM, ON_TOP, ON_INTERIOR_FACETS, ALL)

from pyop2.local_kernel import CStringLocalKernel, LoopyLocalKernel, CoffeeLocalKernel, Kernel # noqa: F401
from pyop2.local_kernel import CStringLocalKernel, LoopyLocalKernel, Kernel # noqa: F401
from pyop2.global_kernel import (GlobalKernelArg, DatKernelArg, MixedDatKernelArg, # noqa: F401
MatKernelArg, MixedMatKernelArg, MapKernelArg, GlobalKernel)
from pyop2.parloop import (GlobalParloopArg, DatParloopArg, MixedDatParloopArg, # noqa: F401
Expand Down
4 changes: 2 additions & 2 deletions pyop2/parloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pyop2.exceptions import KernelTypeError, MapValueError, SetTypeError
from pyop2.global_kernel import (GlobalKernelArg, DatKernelArg, MixedDatKernelArg,
MatKernelArg, MixedMatKernelArg, GlobalKernel)
from pyop2.local_kernel import LocalKernel, CStringLocalKernel, CoffeeLocalKernel, LoopyLocalKernel
from pyop2.local_kernel import LocalKernel, CStringLocalKernel, LoopyLocalKernel
from pyop2.types import (Access, Global, AbstractDat, Dat, DatView, MixedDat, Mat, Set,
MixedSet, ExtrudedSet, Subset, Map, ComposedMap, MixedMap)
from pyop2.utils import cached_property
Expand Down Expand Up @@ -624,7 +624,7 @@ def LegacyParloop(local_knl, iterset, *args, **kwargs):

# finish building the local kernel
local_knl.accesses = tuple(a.access for a in args)
if isinstance(local_knl, (CStringLocalKernel, CoffeeLocalKernel)):
if isinstance(local_knl, CStringLocalKernel):
local_knl.dtypes = tuple(a.data.dtype for a in args)

global_knl_args = tuple(a.global_kernel_arg for a in args)
Expand Down
1 change: 0 additions & 1 deletion requirements-git.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
git+https://github.com/coneoproject/COFFEE.git#egg=coffee
git+https://github.com/firedrakeproject/loopy.git@main#egg=loopy
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ def get_petsc_dir():
'decorator',
'mpi4py',
'numpy>=1.6',
'COFFEE',
]

dep_links = ['git+https://github.com/coneoproject/COFFEE#egg=COFFEE-dev']

version = sys.version_info[:2]

if version < (3, 6):
Expand Down Expand Up @@ -141,7 +138,6 @@ def run(self):
'Programming Language :: Python :: 3.6',
],
install_requires=install_requires + test_requires,
dependency_links=dep_links,
packages=['pyop2', 'pyop2.codegen', 'pyop2.types'],
package_data={
'pyop2': ['assets/*', '*.h', '*.pxd', '*.pyx', 'codegen/c/*.c']},
Expand Down
8 changes: 1 addition & 7 deletions test/unit/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
from pyop2 import op2, mpi
from pyop2.caching import disk_cached

from coffee.base import *


def _seed():
return 0.02041724
Expand Down Expand Up @@ -419,11 +417,7 @@ def test_vector_map(self, iterset, x2, iter2ind2):
def test_same_iteration_space_works(self, iterset, x2, iter2ind2):
self.cache.clear()
assert len(self.cache) == 0
kernel_code = FunDecl("void", "k",
[Decl("int*", c_sym("x"), qualifiers=["unsigned"])],
c_for("i", 1, ""),
pred=["static"])
k = op2.Kernel(kernel_code.gencode(), 'k')
k = op2.Kernel("""static void k(void *x) {}""", 'k')

op2.par_loop(k, iterset,
x2(op2.INC, iter2ind2))
Expand Down
43 changes: 1 addition & 42 deletions test/unit/test_extrusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def compute_ind_extr(nums,
return ind


from coffee.base import *

# Data type
valuetype = numpy.float64

Expand Down Expand Up @@ -333,45 +331,6 @@ def extrusion_kernel():
return op2.Kernel(kernel_code, "extrusion")


@pytest.fixture
def vol_comp():
init = FlatBlock("""
double area = x[0][0]*(x[2][1]-x[4][1]) + x[2][0]*(x[4][1]-x[0][1])
+ x[4][0]*(x[0][1]-x[2][1]);
if (area < 0)
area = area * (-1.0);
""")
assembly = Incr(Symbol("A", ("i0", "i1")),
FlatBlock("0.5 * area * (x[1][2] - x[0][2])"))
assembly = c_for("i0", 6, c_for("i1", 6, assembly))
kernel_code = FunDecl("void", "vol_comp",
[Decl("double", Symbol("A", (6, 6))),
Decl("double", Symbol("x", (6, 3)))],
Block([init, assembly], open_scope=False),
pred=["static"])
return op2.Kernel(kernel_code.gencode(), "vol_comp")


@pytest.fixture
def vol_comp_rhs():
init = FlatBlock("""
double area = x[0][0]*(x[2][1]-x[4][1]) + x[2][0]*(x[4][1]-x[0][1])
+ x[4][0]*(x[0][1]-x[2][1]);
if (area < 0)
area = area * (-1.0);
""")
assembly = Incr(Symbol("A", ("i0",)),
FlatBlock("0.5 * area * (x[1][2] - x[0][2]) * y[0]"))
assembly = c_for("i0", 6, assembly)
kernel_code = FunDecl("void", "vol_comp_rhs",
[Decl("double", Symbol("A", (6,))),
Decl("double", Symbol("x", (6, 3))),
Decl("int", Symbol("y", (1,)))],
Block([init, assembly], open_scope=False),
pred=["static"])
return op2.Kernel(kernel_code.gencode(), "vol_comp_rhs")


class TestExtrusion:

"""
Expand Down Expand Up @@ -423,7 +382,7 @@ def test_extruded_layer_arg(self, elements, field_map, dat_f):
pass_layer_arg=True)
end = layers - 1
start = 0
ref = np.arange(start, end)
ref = numpy.arange(start, end)
assert [dat_f.data[end*n:end*(n+1)] == ref
for n in range(int(len(dat_f.data)/end) - 1)]

Expand Down
15 changes: 5 additions & 10 deletions test/unit/test_indirect_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from pyop2 import op2
from pyop2.exceptions import MapValueError

from coffee.base import *


nelems = 4096

Expand Down Expand Up @@ -265,14 +263,11 @@ def test_mixed_non_mixed_dat(self, mdat, mmap, iterset):
def test_mixed_non_mixed_dat_itspace(self, mdat, mmap, iterset):
"""Increment into a MixedDat from a Dat using iteration spaces."""
d = op2.Dat(iterset, np.ones(iterset.size))
assembly = Incr(Symbol("d", ("j",)), Symbol("x", (0,)))
assembly = c_for("j", 2, assembly)
kernel_code = FunDecl("void", "inc",
[Decl("double", c_sym("*d")),
Decl("double", c_sym("*x"))],
Block([assembly], open_scope=False),
pred=["static"])
op2.par_loop(op2.Kernel(kernel_code.gencode(), "inc"), iterset,
kernel_inc = """static void inc(double *d, double *x) {
for (int i=0; i<2; ++i)
d[i] += x[0];
}"""
op2.par_loop(op2.Kernel(kernel_inc, "inc"), iterset,
mdat(op2.INC, mmap),
d(op2.READ))
assert all(mdat[0].data == 1.0) and mdat[1].data == 4096.0
Expand Down
Loading

0 comments on commit edae288

Please sign in to comment.