Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ksagiyam/tsfc refactor 1 #261

Merged
merged 17 commits into from
Feb 10, 2022
Merged

Ksagiyam/tsfc refactor 1 #261

merged 17 commits into from
Feb 10, 2022

Conversation

ksagiyam
Copy link
Contributor

@ksagiyam ksagiyam commented Sep 1, 2021

Breaking #234 into smaller pieces (Phase 1)

This PR attempts to refactor TSFC.

Firedrake PR firedrakeproject/firedrake#2200 must follow this.

@ksagiyam ksagiyam force-pushed the ksagiyam/tsfc_refactor_1 branch 7 times, most recently from 5cff887 to 4d2358d Compare September 4, 2021 14:38
@ksagiyam ksagiyam marked this pull request as ready for review September 6, 2021 09:38
@ksagiyam ksagiyam force-pushed the ksagiyam/tsfc_refactor_1 branch from 1280275 to 2395192 Compare October 20, 2021 15:22
tsfc/driver.py Outdated
self.domain_number = domain_number
self.coefficients = coefficients
self.coefficient_numbers = coefficient_numbers
super(TSFCIntegralDataInfo, self).__init__()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is an immutable object does it make sense for it just to be a NamedTuple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Fixed.

@@ -114,6 +116,20 @@ def register_requirements(self, ir):
class KernelBuilderMixin(object):
"""Mixin for KernelBuilder classes."""

@cached_property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn this into a function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -114,6 +116,20 @@ def register_requirements(self, ir):
class KernelBuilderMixin(object):
"""Mixin for KernelBuilder classes."""

@cached_property
def fem_config(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring please!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

dont_split=(), diagonal=False):
"""Initialise a kernel builder."""
integral_type = integral_data_info.integral_type
subdomain_id = integral_data_info.subdomain_id
domain_number = integral_data_info.domain_number
super(KernelBuilder, self).__init__(scalar_type, integral_type.startswith("interior_facet"))
self.fem_scalar_type = fem_scalar_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor so that parameters["scalar_type"] is the only thing that is passed in and the coffee builder constructs the C-name of the type internally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we don't need to pass two scalar types that are generally the same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed using coffee.base.as_cstr().

@ksagiyam ksagiyam force-pushed the ksagiyam/tsfc_refactor_1 branch from 2395192 to 4793fc4 Compare October 22, 2021 15:57
@@ -116,6 +117,31 @@ def register_requirements(self, ir):
class KernelBuilderMixin(object):
"""Mixin for KernelBuilder classes."""

def compile_ufl(self, integrand, params, ctx):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call this compile_integrand ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

"""Compile UFL integrand.

:arg integrand: UFL integrand.
:arg params: a dict of parameters containing quadrature info.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ctx need a docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Added.

@@ -149,6 +149,13 @@ def construct_integrals(self, expressions, params):
self.argument_multiindices,
params)

def stash_integrals(self, reps, params, ctx):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@@ -156,6 +159,40 @@ def stash_integrals(self, reps, params, ctx):
for var, rep in zip(self.return_variables, reps):
mode_irs[mode].setdefault(var, []).append(rep)

def compile_gem(self, ctx):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring please.

Can we also document (somewhere, maybe not here) the interface that ctx must offer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more texts under KernelBuilderMixin.create_context method.

:kwarg tabulations: The runtime tabulations this kernel requires
:kwarg needs_cell_sizes: Does the kernel require cell sizes.
:kwarg flop_count: Estimated total flops for this kernel.
"""
def __init__(self, ast=None, integral_type=None, oriented=False,
subdomain_id=None, domain_number=None, quadrature_rule=None,
subdomain_id=None, domain_number=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quadrature rule is used by themis: https://github.com/celdred/themis, maybe instead of dropping it replace this commit with a comment that that is what it is for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@celdred what is themis' status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what themis is expecting from quad_rule. quad_rule is a local variable in for integral in integral_data.integrals loop (https://github.com/firedrakeproject/tsfc/blob/master/tsfc/driver.py#L193), but the last value it happens to take is passed to builder.construct_kernel(...) (https://github.com/firedrakeproject/tsfc/blob/master/tsfc/driver.py#L266), which themis seems to require.

@ksagiyam ksagiyam force-pushed the ksagiyam/tsfc_refactor_1 branch from fc66951 to c260ac8 Compare February 4, 2022 17:42
@ksagiyam ksagiyam force-pushed the ksagiyam/tsfc_refactor_1 branch from c260ac8 to 4a1cd20 Compare February 4, 2022 17:43
@dham dham merged commit 8711da9 into master Feb 10, 2022
@dham dham deleted the ksagiyam/tsfc_refactor_1 branch February 10, 2022 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants