Skip to content

Add optional allow_single_version Boolean arg to actx.compile #227

Open

Description

@inducer

Benefits:

  • Avoids unexpected repeated compilation
  • Avoid dispatch cost to select which implementation to use

Drawbacks:

  • Less flexible, of course :)

Naming of the flag is an open question.

cc @majosm @MTCam

Activity

  1. kaushikcfd commented on Apr 26, 2023

    @kaushikcfd
    Collaborator

    I don't think I understand this. Could you please elaborate? Does this have to do with sub-expressions having the same value but different metadata?
    Thanks!

  2. inducer commented on Apr 26, 2023

    @inducer
    OwnerAuthor

    Sorry, I didn't spend enough time explaining. Right now, we have reasonably elaborate dispatch logic between different versions of a compiled function, based on shapes, which arguments are supplied, etc. This flag would assert that only a single version should ever exist, and calling the compiled function a second time with mismatched arguments would be an error. Does that make sense?

  3. kaushikcfd commented on Apr 26, 2023

    @kaushikcfd
    Collaborator

    Yep, makes sense. Thanks! Essentially this flag should ensure that length of BaseLazilyCompilingFunctionCaller.program_cache should not exceed 1.

  4. inducer commented on Apr 26, 2023

    @inducer
    OwnerAuthor

    Yup, exactly.

  5. majosm commented on Apr 26, 2023

    @majosm
    Collaborator

    Question: Would the allow_single_version=True case check if the arguments are the same as when it was compiled? Or is it more of an "at your own risk" thing?

  6. kaushikcfd commented on Apr 26, 2023

    @kaushikcfd
    Collaborator

    Question: Would the allow_single_version=True case check if the arguments are the same as when it was compiled? Or is it more of an "at your own risk" thing?

    It should be an error at this point if len(self.program_cache) > 1.

  7. majosm commented on Apr 26, 2023

    @majosm
    Collaborator

    Question: Would the allow_single_version=True case check if the arguments are the same as when it was compiled? Or is it more of an "at your own risk" thing?

    It should be an error at this point if len(self.program_cache) > 1.

    Does it still incur the "dispatch cost to select which implementation to use" then?

  8. kaushikcfd commented on Apr 26, 2023

    @kaushikcfd
    Collaborator

    Aah fair. I missed that as a constraint. Though I am unsure how to avoid the dispatch cost since we would always need to compute the arg_id_to_descr.

  9. majosm commented on Apr 26, 2023

    @majosm
    Collaborator

    In any case, I can see the value in avoiding multiple compiles. On the user side, though, I'm not sure if it's always obvious enough when it's happening that one would know to intervene. Kind of makes me wonder if the single_version_only=True behavior should be the default? i.e., emit an error if it tries to compile multiple times, unless the caller explicitly says it's OK. Not sure how much stuff this would break, though.

  10. inducer commented on Apr 26, 2023

    @inducer
    OwnerAuthor

    At the very least, it would break the LSRK45 time stepper, which relies on having two different versions at the moment.

    https://github.com/inducer/grudge/blob/c9906c9a20bfb5c78733093ccba716d7ac036897/grudge/shortcuts.py#L44-L62

  11. matthiasdiener commented on Apr 26, 2023

    @matthiasdiener
    Collaborator

    How about just emitting a warning instead of an exception? This would even work without necessarily changing the API.

  12. inducer commented on Apr 26, 2023

    @inducer
    OwnerAuthor

    IMO, both multi-version and single-version are legitimate uses of the function, unless the user says otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions