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

Add math special functions: erf, erfcx, expint1, Bessel functions, Hankel functions #3920

Merged
merged 30 commits into from
Jul 12, 2021

Conversation

vqd8a
Copy link
Contributor

@vqd8a vqd8a commented Apr 7, 2021

This PR will add mathematical special functions needed by GEMMA's deep slot code.

@vqd8a vqd8a closed this Apr 7, 2021
@vqd8a vqd8a reopened this Apr 7, 2021
@vqd8a vqd8a marked this pull request as draft April 7, 2021 16:07
@vqd8a vqd8a added the [WIP] label Apr 7, 2021
@vqd8a vqd8a changed the title DRAFT: Add math special functions: erf, erfcx, expint, bessel functions, hankel functions DRAFT: Add math special functions: erf, erfcx, expint, Bessel functions, Hankel functions Apr 7, 2021
@vqd8a vqd8a changed the title DRAFT: Add math special functions: erf, erfcx, expint, Bessel functions, Hankel functions Add math special functions: erf, erfcx, expint, Bessel functions, Hankel functions May 18, 2021
@vqd8a
Copy link
Contributor Author

vqd8a commented May 18, 2021

I have added the implementations of these functions and their unit tests. All checks passed except HIP tests in jenkin-ci check, where all 0s are returned for the Bessel functions and Hankel functions.
I don't know what happened since these unit tests are going well on Caraway and Tulip.

@vqd8a vqd8a marked this pull request as ready for review May 18, 2021 20:11
@vqd8a vqd8a requested a review from dalg24 May 18, 2021 20:11
@vqd8a vqd8a removed the [WIP] label May 18, 2021
@Rombur
Copy link
Member

Rombur commented May 18, 2021

Which compiler are you using on caraway and tulip? There are know bugs in the compiler used for CI. Once we merged #4025, the CI should used a better compiler.

@vqd8a
Copy link
Contributor Author

vqd8a commented May 18, 2021

@Rombur rocm/4.1.0 was used on caraway and rocm/4.2.0 was used on tulip. Thanks for letting me know. I will wait for #4025 got merged.

e1 = -infinity<RealType>::value;
}
else if (x == 0.0) {
e1 = infinity<RealType>::value;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it return -infty for x=0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 I use the definition of E1(x) while std::expint uses the definition of Ei(x). So I changed the function name to expint1 to avoid confusion.

core/src/Kokkos_Core.hpp Outdated Show resolved Hide resolved

//! Compute exponential integral E1(x) (x > 0).
template <class RealType>
KOKKOS_INLINE_FUNCTION RealType expint(const RealType& x) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not taking argument by value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 I see in Kokkos_Complex.hpp, taking argument by reference is used. Please explain why we should take argument by value.

Copy link
Member

Choose a reason for hiding this comment

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

Because this overload is for floating point numbers.
https://en.cppreference.com/w/cpp/numeric/special_functions/expint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 I see. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 I have changed it to taking argument by value.


//! Compute error function erf(z) for z=cmplx(x,y).
template <class CmplxType>
KOKKOS_INLINE_FUNCTION CmplxType cerf(const CmplxType& z) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider constraining the overload set for complex numbers.

Suggested change
KOKKOS_INLINE_FUNCTION CmplxType cerf(const CmplxType& z) {
template <class T>
KOKKOS_INLINE_FUNCTION Kokkos::complex<T> cerf(const Kokkos::complex<T>& z) {

Copy link
Member

Choose a reason for hiding this comment

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

Why did you prefix the name with "c"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 The names are now erf and erfcx.

//! Compute scaled complementary error function erfcx(z)=exp(z^2)*erfc(z)
//! for z=cmplx(x,y).
template <class CmplxType>
KOKKOS_INLINE_FUNCTION CmplxType cerfcx(const CmplxType& z) {
Copy link
Member

Choose a reason for hiding this comment

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

Ok to add erfcx but we need to provide an implementation for scalar types as well
erfcx(FloatingPoint)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 I have added an implementation for scalar type. For now, I do not use the std::erfc() for erfcx()=exp(x^2)*erfc(x) because it is going to overflow quickly (e.g. erfcx(35)=NaN). Instead, I use erfcx(Kokkos::complex<RealType>(x, 0.0)) for now. I will have an implementation of erfcx(real) in the future.

//! Compute Bessel function J0(z) of the first kind of order zero
//! for a complex argument
template <class CmplxType, class RealType, class IntType>
KOKKOS_INLINE_FUNCTION CmplxType cbesselj0(const CmplxType& z,
Copy link
Member

Choose a reason for hiding this comment

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

Implement cyl_bessel_j and error out if the order argument is not 0 (or 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 Since we decided to use cyl_bessel_j0 and cyl_bessel_j1 for order 0 and order 1, respectively, so I do not have cyl_bessel_j for now.

//! Compute Bessel function Y1(z) of the second kind of order one
//! for a complex argument
template <class CmplxType, class RealType, class IntType>
KOKKOS_INLINE_FUNCTION CmplxType cbessely1(const CmplxType& z,
Copy link
Member

Choose a reason for hiding this comment

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

Rename cyl_bessel_y1 for consistency with the C++ math functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalg24 I have changed all the Bessel function names accordingly.

@vqd8a
Copy link
Contributor Author

vqd8a commented Jun 29, 2021

@dalg24 I have addressed all your comments. Please let me know if you have additional comments. Thanks.

@vqd8a vqd8a changed the title Add math special functions: erf, erfcx, expint, Bessel functions, Hankel functions Add math special functions: erf, erfcx, expint1, Bessel functions, Hankel functions Jun 29, 2021
@vqd8a vqd8a requested a review from crtrott June 30, 2021 18:29
Copy link
Member

@crtrott crtrott left a comment

Choose a reason for hiding this comment

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

I'd love for Damien to approve but not sure he got access right now.

@vqd8a
Copy link
Contributor Author

vqd8a commented Jul 8, 2021

@crtrott Thanks, Christian. Should we wait for Damien to merge it?

@crtrott
Copy link
Member

crtrott commented Jul 8, 2021

I will check if he is able to review if not i will go ahead

@dalg24 dalg24 merged commit 7c5ee65 into kokkos:develop Jul 12, 2021
@vqd8a vqd8a added InDevelop Enhancement, fix, etc. has been merged into the develop branch; Feature Request Create new capability; will potentially require voting labels Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Create new capability; will potentially require voting InDevelop Enhancement, fix, etc. has been merged into the develop branch;
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants