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

Develop #25

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open

Develop #25

wants to merge 16 commits into from

Conversation

JuanBSLeite
Copy link

No description provided.

@AAAlvesJr
Copy link
Contributor

Olá Juan, thanks for this PR.

I see a lot of files in your request. Could you reconfigure the PR and push only your contribution?
The file implementing the Flatté. Ideally, please, implement the line-shape in a header file ".h" (as you already did) and add some documentation citing also a reference from where you got the formulae. Then provide one or two examples placed in the folder "examples/phys" and add the target(s) to "examples/phys/CMakeList.txt". Creating the examples/NIPS_HYDRA is not necessary. There are some .xml files, and a .idea subdirectory, I suppose from your IDE (CLION ?). Please exclude then. Change fDaughter3Mass and the corresponding getter/setter members to fBachelorMass. I discovered recently that it keep as fDaughter3Mass can be painfully misleading...

Cheers
A.A.
.

@JuanBSLeite
Copy link
Author

JuanBSLeite commented Mar 10, 2018 via email

@JuanBSLeite
Copy link
Author

Hi Augusto,

I did the changes you said and updated my fork. I'll do the new PR now.

@henryiii
Copy link
Contributor

The PR gets updated automatically based on your branch (including master); on Monday I can show you how to squash and clean your commit history if you'd like.

@AAAlvesJr
Copy link
Contributor

Hi Juan, thanks.
Tell me one thing, how does this implementation compares to the original code you used as inspiration? Did you tested if they return the same values?
Other point: did you compared your implementation to the formulas here described in
CERN-EP-PHYS-76-8 ?

CMakeLists.txt Outdated

if(Minuit2_FOUND)
add_subdirectory(examples/phys)
Copy link
Contributor

Choose a reason for hiding this comment

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

All examples in the directory '''phys''' depends on Minuit2.
You need to put it inside the guards ''' if(Minuit2_FOUND) ... endif(Minuit2_FOUND)'''

@@ -350,7 +350,7 @@ int main(int argv, char** argc)

double f0_MASS = 0.965;
double f0_MAG = 12.341;
double f0_Phase = -62.852*(M_PI / 180) ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Document the numerical values, please.

@@ -350,7 +350,7 @@ int main(int argv, char** argc)

double f0_MASS = 0.965;
double f0_MAG = 12.341;
double f0_Phase = -62.852*(M_PI / 180) ;
double f0_Phase = -62.852*(M_PI / 180) +M_PI;
Copy link
Contributor

Choose a reason for hiding this comment

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

The primary documentation of code, is the code itself. So, please enforce double precision syntax where you are using it. For example '''180''' -> '''180.0'''


auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001);
auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001);
auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-100,100);
Copy link
Contributor

Choose a reason for hiding this comment

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

Define the limits in the parameters in terms of the nominal values in the parameters.

@@ -218,9 +218,9 @@ namespace hydra {


if(s >= twopimasssq)
rhopipi_real = (2. / 3) * TMath::Sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold
rhopipi_real = (2. / 3) * ::sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold
Copy link
Contributor

@AAAlvesJr AAAlvesJr Mar 19, 2018

Choose a reason for hiding this comment

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

This whole piece of code could generate branching and does unnecessary variable redefinition, which makes execution slow down on gpus. I consider a defect of C++ that variables are not default const, like in Rust, but this is another discussion. The code is also confusing. So deploy Boolean arithmetic here. Example:

instead to write

 if(condition) x = a+b;
else x=a-b;

write (1 line !)

x = a + (condition==true) *(b) - (condition!=true) *(b) 

and so on...
Please, reflect about this.

else
rhopipi_imag = (2. / 3) * TMath::Sqrt(-1 + twopimasssq / s);
rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s);
Copy link
Contributor

Choose a reason for hiding this comment

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

idem...

@AAAlvesJr
Copy link
Contributor

Hi Juan, thanks.
There are still some minor issues. I commented them inline. please address them and let me know. Thanks.

@@ -223,19 +223,19 @@ namespace hydra {
rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, try to eliminate the if/else instructions using boolean arithmetic. Avoid value., enforce value.0.

@AAAlvesJr
Copy link
Contributor

One more point, I forgot to comment previously. The getter and setters should reflect the names of the members they refer to. For example: double fMass -> void SetMass(double mass){...}

@@ -78,11 +79,13 @@ namespace hydra {
* @param daugther3_mass daughter particle 2 mass
* @param radi decay vertex radio.
*/
FlatteLineShape(hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the length of the vector std::vector<std::vector<double>> params and what does it holds?
I think can be a good idea to document the meaning of this parameter.
Also, are these parameters supposed to be optimized in a fit? Case yes, consider to use the correct interface to store and make them "trackable" by Minuit2 and copy constructors on device and host sides.
If the number of such parameters is not fixed, but still constant at compile time, please, add a template parameter to the class to implement then, and set the default value to the most common case (my guess is most of the time it is 2...) . After set them using this->SetParameter(param_index, param_value) in the body of the constructor.

double mother_mass,
double daugther1_mass, double daugther2_mass, double daugther3_mass,
double radi) :
BaseFunctor<FlatteLineShape<CHANNEL, ArgIndex>, hydra::complex<double>, 3>{mean, rho1, rho2},
BaseFunctor<FlatteLineShape<CHANNEL, ArgIndex>, hydra::complex<double>,1>{mean},
fParams(params),
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, this implementation does not fit the Hydra's requirements, since this class is not copyable on device side for CUDA backends. This happens because you are using a std::vector as a member. This will works on host and device CPU-based backends, but not in CUDA, because std::vector are not implemented there...

}

__hydra_host__ __hydra_device__ inline
void SetDaughter1Mass(std::vector<std::vector<double>> _params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems to me this member is setting the wrong class member... Should be fDaughterMass1 instead of fParams, right?

@@ -256,6 +238,7 @@ namespace hydra {
double fBachelorMass;
double fMotherMass;
double fRadi;
std::vector<std::vector<double>> fParams;
Copy link
Contributor

Choose a reason for hiding this comment

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

this member is not copyable on CUDA...

@AAAlvesJr
Copy link
Contributor

Hi Juan, thanks for this contribution. It looks much better now! Indeed, the EvtGen's implementation is much more reliable...
Please, find my comments inline.
Cheers
A,A,

@AAAlvesJr
Copy link
Contributor

Hi Juan, let me confess I am a bit intrigued... How does this functor can be running in CUDA, if the member std::array<...> fParams is not copyable in that back-end?

As I told you personally a pair of times, if the thresholds are always fixed parameters, it is not necessary to pass them to the hydra::BaseFunctor interface, only the parameters that need be tracked during a fit need be passed...

Look forward for your feedback...
A.A.

@JuanBSLeite
Copy link
Author

Hi Augusto, std::array is a container to simple C array, it allow use iterators and other things, that's why I think it is running .
params is not inside the base functor, there is only one parameter there, that is the mean.

BaseFunctor<FlatteLineShape<CHANNEL, ArgIndex>, hydra::complex<double>,1>{mean}

@@ -238,7 +240,7 @@ for(size_t i = 0; i < fParams.size() ; i++) {
double fBachelorMass;
double fMotherMass;
double fRadi;
std::vector<std::vector<double>> fParams;
std::array<std::array<double,3>,2> fParams;
Copy link
Contributor

Choose a reason for hiding this comment

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

This member, std::array<std::array<double,3>,2> fParams; is not copyable in CUDA. AFAIK, there is no implementation of std::array in CUDA. Please, use double fParams[6]

@@ -121,12 +121,12 @@ namespace hydra {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

L.110 : BaseFunctor<FlatteLineShape<CHANNEL, ArgIndex>, hydra::complex, 7>::operator=(other);**
This should be 1 -------------------------------------------------------------------------------------------^^^

This assignment operator can't compile either.

@AAAlvesJr
Copy link
Contributor

Please, look my last comments.

The CUDA9 Programing Guide, section F.3.8, states:

F.3.8. Standard Library
Standard libraries are only supported in host code, but not in device code, unless specified otherwise.

AFAIK, the only Standard Library class supported is std::initializer_list, which is explained in the section F.3.15.2. std::initializer_list.

I am still wondering how your code can run on CUDA...

@JuanBSLeite
Copy link
Author

Can you try to run it in your machine?

@henryiii
Copy link
Contributor

henryiii commented Apr 17, 2018

I think std::array works if you use --expt-relaxed-constexpr (which you do), since the key methods are constexpr. I'm pretty sure I've used it on device before. I could be wrong, though.

Edit: From looking at the descriptions of std::initializer_list and the CUDA source, I don't see why it would be supported, though...

PS: std::move and std::forward are also explicitly supported (though they are not classes).

@AAAlvesJr
Copy link
Contributor

AAAlvesJr commented Apr 17, 2018

The Standard is clear enough about std::array, as so is the CUDA Programing Guide... Lets not drag ahead this discussion.
In summary, the class is not copyable in CUDA. Please, exchange it by a C-style array.

@AAAlvesJr
Copy link
Contributor

BTW, about relying on --expt-relaxed-constexpr for certain things

Programming Guide - v9.1.85
F.3.15.4. Constexpr functions and function templates

By default, a constexpr function cannot be called from a function with incompatible execution space 14. The experimental nvcc flag --expt-relaxed-constexpr removes this restriction. When this flag is specified, host code can invoke a __device__ constexpr function and device code can invoke a __host__ constexpr function. nvcc will define the macro __CUDACC_RELAXED_CONSTEXPR__ when --expt-relaxed-constexpr has been specified. Note that a function template instantiation may not be a constexpr function even if the corresponding template is marked with the keyword constexpr (C++11 Standard Section [dcl.constexpr.p6]).

@AAAlvesJr
Copy link
Contributor

ping...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants