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

Replace GCC __ATOMIC* built-ins with std::atomic for interpreter.cc #4976

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anmyachev
Copy link
Contributor

@anmyachev anmyachev commented Oct 23, 2024

#include <atomic> is already used in other triton files, so I believe it's not a cardinally change.

Changes come from #4045

@Jokeren
Copy link
Contributor

Jokeren commented Oct 23, 2024

I think reinterpret_cast is not going to be a good solution.

For example, std::atomic<uint16_t> could be using full words on some platforms? while uint16_t is strictly 2 bytes

@Jokeren
Copy link
Contributor

Jokeren commented Oct 23, 2024

We have discussed it a while ago but was not able to find a stable solution. I think the bottom line is probably that we cannot directly replace it with std::atomic. Need to find ways to work around

@Jokeren
Copy link
Contributor

Jokeren commented Oct 23, 2024

See: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4013.html

@@ -95,13 +88,15 @@ template <typename DType> class AtomicRMWOpBase : public AtomicOp {
protected:
void applyAt(void *loc, size_t i) override final {
if (mask[i]) {
std::atomic<DType> *atomic_ptr = static_cast<std::atomic<DType> *>(loc);
Copy link
Contributor

Choose a reason for hiding this comment

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

While this usually works in practice, it's also undefined behavior which isn't great. C++20 has std::atomic_ref which would fix this issue but we don't compile with C++20 yet.

@anmyachev
Copy link
Contributor Author

@Jokeren @peterbell10 thanks for the review! I will try to address the comments.

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

Successfully merging this pull request may close these issues.

3 participants