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

[LLVM][GPU][+refactoring] Replacement of math intrinsics with library calls #835

Merged
merged 7 commits into from
Apr 8, 2022

Conversation

georgemitenkov
Copy link
Collaborator

@georgemitenkov georgemitenkov commented Mar 30, 2022

This PR adds a LLVM pass that replaces math intrinsics
with calls to math library. In particular:

  • Functionality of replacement with SIMD functions is factored
    out into a separate file and LLVM version dependencies are
    dropped (we use LLVM 13 already anyway).

  • A pass to replace intrinsics with libdevice calls when targeting
    CUDA platforms has been added. So far only exp is supported
    (single and double precision)

  • Added a test to check the replacement

Note: factoring replacement functionality into a separate file
allows us to completely drop the dependency on target information
inside LLVMCodegenVisitor😊

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #44990 (:white_check_mark:) have been uploaded here!

Status and direct links:

Copy link
Contributor

@iomaganaris iomaganaris left a comment

Choose a reason for hiding this comment

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

LGTM
Just a few small suggestions

DISPATCH("llvm.pow.f64", "_ZGVeN8vv_pow", FIXED(8))
// clang-format on
};
#undef DISPATCH
Copy link
Contributor

Choose a reason for hiding this comment

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

FIXED should also be undefined?

Suggested change
#undef DISPATCH
#undef DISPATCH
#undef FIXED

Comment on lines 113 to 121
// Add vectorizable functions to the target library info.
switch (library->second) {
case VecLib::LIBMVEC_X86:
if (!triple.isX86() || !triple.isArch64Bit())
break;
default:
tli.addVectorizableFunctionsFromVecLib(library->second);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a personal opinion, not sure what should be the proper way to do it or what could be the benefit of the switch but I think it would be more understandable to write this like:

Suggested change
// Add vectorizable functions to the target library info.
switch (library->second) {
case VecLib::LIBMVEC_X86:
if (!triple.isX86() || !triple.isArch64Bit())
break;
default:
tli.addVectorizableFunctionsFromVecLib(library->second);
break;
}
if (library->second != VecLib::LIBMVEC_X86 || (triple.isX86() && triple.isArch64Bit())) {
tli.addVectorizableFunctionsFromVecLib(library->second);
}

Feel free to keep this as you prefer


// Map of supported replacements. For now it is only exp.
static const std::map<std::string, std::string> libdevice_name = {
{"llvm.exp.f32", "__nv_expf"},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be good to add also pow and maybe look for any other math function commonly used in the mod files and also add it to the x86 and aarch64 maps. I can look at this also the next days

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #47044 (:no_entry:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #47063 (:white_check_mark:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #47062 (:white_check_mark:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #47154 (:white_check_mark:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #47153 (:white_check_mark:) have been uploaded here!

Status and direct links:

@georgemitenkov georgemitenkov merged commit 6c3fe22 into llvm Apr 8, 2022
@georgemitenkov georgemitenkov deleted the georgemitenkov/llvm-math-library-replacement branch April 8, 2022 07:30
iomaganaris added a commit that referenced this pull request May 10, 2022
… calls (#835)

Added an LLVM pass that replaces math intrinsics
with calls to math library. In particular:

* Functionality of replacement with SIMD functions is factored
out into a separate file and LLVM version dependencies are
dropped (LLVM 13 is already used anyway).

* A pass to replace intrinsics with libdevice calls when targeting
CUDA platforms has been added. So far only `exp` and `pow` are
 supported (single and double precision).

* Added a test to check the replacement

Co-authored-by: Ioannis Magkanaris <iomagkanaris@gmail.com>
iomaganaris added a commit that referenced this pull request May 12, 2022
… calls (#835)

Added an LLVM pass that replaces math intrinsics
with calls to math library. In particular:

* Functionality of replacement with SIMD functions is factored
out into a separate file and LLVM version dependencies are
dropped (LLVM 13 is already used anyway).

* A pass to replace intrinsics with libdevice calls when targeting
CUDA platforms has been added. So far only `exp` and `pow` are
 supported (single and double precision).

* Added a test to check the replacement

Co-authored-by: Ioannis Magkanaris <iomagkanaris@gmail.com>
iomaganaris added a commit that referenced this pull request Sep 15, 2022
… calls (#835)

Added an LLVM pass that replaces math intrinsics
with calls to math library. In particular:

* Functionality of replacement with SIMD functions is factored
out into a separate file and LLVM version dependencies are
dropped (LLVM 13 is already used anyway).

* A pass to replace intrinsics with libdevice calls when targeting
CUDA platforms has been added. So far only `exp` and `pow` are
 supported (single and double precision).

* Added a test to check the replacement

Co-authored-by: Ioannis Magkanaris <iomagkanaris@gmail.com>
iomaganaris added a commit that referenced this pull request Sep 15, 2022
… calls (#835)

Added an LLVM pass that replaces math intrinsics
with calls to math library. In particular:

* Functionality of replacement with SIMD functions is factored
out into a separate file and LLVM version dependencies are
dropped (LLVM 13 is already used anyway).

* A pass to replace intrinsics with libdevice calls when targeting
CUDA platforms has been added. So far only `exp` and `pow` are
 supported (single and double precision).

* Added a test to check the replacement

Co-authored-by: Ioannis Magkanaris <iomagkanaris@gmail.com>
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.

3 participants