-
Notifications
You must be signed in to change notification settings - Fork 69
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
Shared memory allocation without the use of an ID #81
Comments
The community does not really has a clue to solve the problem directly and I think there is no perfect way, but managing the shared memory directly is the most promising solution for me. Maybe alpaka could provide varying solutions to the problem (ID and self managed)? So we can leave the decision by the user. But what interface can we provide for this ? |
This should not get lost: We tried this some time ago by misusing a language shortcoming see #85. |
We would like to implement this for alpaka 0.7.0. Due to time constraints this is marked as an OPTIONAL feature for the next release. |
Just stumbled over a trick in C++20 we could try: https://youtu.be/z5AnYgyjQ-o?t=2567 template <auto Lambda = []{}>
auto declareSharedVar() {
static constexpr std::source_location loc = std::source_location::current();
static constexpr const void* counter = static_cast<const void*>(&loc);
return counter;
}
int main() {
std::cout << declareSharedVar() << "\n";
std::cout << declareSharedVar() << "\n";
for (int i = 0; i < 3; i++)
std::cout << declareSharedVar() << "\n";
} https://godbolt.org/z/nzr7vMcGc The value of |
I like it, the only problem will be the loop and if someone encapsulates the allocation within a helper, but if |
The loop is not the problem. The program I described prints: 0x402040
0x402038
0x402030
0x402030
0x402030 So the counter in the loop is the same for each loop iteration. The counter value changes for each source location. If you wrap the call to auto wrap() {
return declareSharedVar();
}
int main() {
std::cout << declareSharedVar() << "\n";
std::cout << declareSharedVar() << "\n";
for (int i = 0; i < 3; i++)
std::cout << declareSharedVar() << "\n";
std::cout << wrap() << "\n";
std::cout << wrap() << "\n"; // problem, prints the same as previous call to wrap()
} |
There is/was a bug in shared memory allocation when multiple shared variables/arrays with same size and type was defined. These variables/arrays pointed to the same memory.
this pull request here, solved the problem by introducing an ID for each shared memory call, which can be made unique by
__COUNTER__
macro.I opened this issue such that we do not forget that using this macro is not the most beautiful solution to this problem. I hope the stackoverflow community has some answer on this problem.
One solution is shown by the bulk project with
bulk::malloc
.The text was updated successfully, but these errors were encountered: