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

Improve documentation for virtual functions #551

Merged
merged 20 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/source/ProgrammingGuide/Kokkos-and-Virtual-Functions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# 14. Kokkos and Virtual Functions

```{warning}
Using virtual functions in parallel regions is not a good idea in general. It often degrades performance, it requires specific code for a correct execution on GPU, and it is not portable on every backend. We recommend to use a different approach whenever possible.
```

Due to oddities of GPU programming, the use of virtual functions in Kokkos parallel regions can be complicated. This document describes the problems you're likely to face, where they come from, and how to work around them.

Please note that virtual functions can be executed on device for the following backends:

- Cuda; and
- HIP.

## The Problem

In GPU programming, you might have run into the bug of calling a host function from the device. A similar thing can happen for subtle reasons in code using virtual functions. Consider the following code (using Cuda instructions as an example)
Expand All @@ -12,8 +21,8 @@ class Derived : public Base {

public:
KOKKOS_FUNCTION virtual void Bar(){
// all of physics
}
// function body
}
};

Base* hostInstance = new Derived();
Expand Down
Loading