Skip to content

Masses/couplings as compile time constants instead of constant memory #39

Open

Description

@valassi

Hi @oliviermattelaer, this is a followup of our chat this afternoon and a spinoff of issue #23.

We should check again the effect of having masses/couplings in constant memory instead of compile time constants. This commit saves 4 registers (down from 178 to 174)
6679569

Is this because some values are hardcoded to 0? Or is this irrelevant?

If it is because they are 0, then maybe we could move the others to constant memory, but still keep in mind that couplings are only purely real or purely imaginary (is this true?), and thus save the registers, while still allowing variable couplings (in constant memory) that are not hardcoded at compile time.

Thanks, Andrea

Originally posted by @valassi in #23 (comment)

Activity

  1. valassi commented on Oct 18, 2021

    @valassi
    MemberAuthor

    A brief followup on this issue, see #263.

    I thought that in the latest eemumu/epoch1 I was using parameters read from file (and set via cudamemcptosymbol into cuda constant memory), but actually I was using hardcoded compile time constants. The confusion comes from the fact that nvcc does not give me a warning (see #263, #264).

    Now, I have gone back to reading from files the user-defined values. It is clear that this does affect cuda performance. Certainly, it increases registers from 122 to 128. In addition, the throughput seems a tiny bit slower, say 1-2% slower.

    So, all in all, one could eventually think of hardcoding parameters in the code. To allow user-defined parameters, maybe one could simply code-generate some header files instead of card files, where all parameteres are defined as human-readabale constexpr lines. This would allow users to still modify these values (but they would need to do it before building the code, rather than at runtime). I keep this issue open as one idea.

    But for the moment I will move the defaults back to reading parameters from file, even if this comes with a tiny performance loss.

  2. changed the title [-]Investigate masses/couplings in constant memory instead of compile time constants[/-] [+]Masses/couplings as compile time constants instead of constant memory[/+] on Dec 9, 2021
  3. valassi commented on Dec 9, 2021

    @valassi
    MemberAuthor

    I have just opened PR #306. I copy the relevant text here

    This is a followup to #23 and #39

    Yesterday while working on unrelated things (older WIP in klas3/klas3base in eemumu epoch1) I realised there was a performance regression of around 20% in cuda for eemumu between epoch1 and epochX, because epoch1 was using hardcoded parameters while epoch1 was using parameters read from file and then set in constant memory.

    I moved also epoch1 to the (slower, but more default) reading f parameters from files. However, I also added the option to use hardcoded physics parameters, bth in c++ and cuda, if an ifdef switches them on. This PR is the result of that.

    The implementation is fully functional, but it includes a few hacks which should be improved. The complication comes from the fact that one should use constexpr in the calculation of derived parameters, and there are two issues:

    • first, sqrt is not constexpr: I worked around this by using a nice solution based on Netwon Raphson that I found on SO, and this is code that can remain
    • second, a lot of complex arithmetics is also not constexpr, and something as simple as multiplying two complex numbers is not constexpr; I worked around this by massaging manually a few formulas, and only including all constants that are relevant to eemumu, ggtt and ggttgg

    Eventually, the hack of the second issue above should be removed

    • the easiest would be to use a custom complex implementation (Simple custom complex class (cxsmpl) #307), which is something that I had in mind anyway to go beyond std, thrust and all others (we really only need basic + - * /)
    • once that is fixed, it is possible to derive automatically generated code, so one would have to backport in python (essentially a third set of methods, merging the two presently used for the declaration in .h and assignment in .cc)

    This PR in any case is now fully functional (not WIP) and can be merged

  4. valassi commented on May 22, 2023

    @valassi
    MemberAuthor

    The option to use compile time constants for physics parameters is now fully functional (HRDCOD=1), for instance thorugh MR #306. I would close the older issue #23 where the initial studies were done, for issue cleanup, but I would keep #39 still open for further studies. It is still not completely clear to me when/if one option is sfatsre than the other. In reweighting in any case we need HRDCOD=0, rather than HRDCOD=1. Closing #23 and leaving #39 open.

  5. self-assigned this
    on May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions