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

Fix return type for atomicAdd with unsigned long long operands #52

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

fwyzard
Copy link
Contributor

@fwyzard fwyzard commented Jan 1, 2024

Fix the return type for

atomicAdd(unsigned long long* address, unsigned long long val)

from std::uint64 to unsigned long long.

This overload is enabled only if std::uint64 and unsigned long long are different types, so the return type should be unsigned long long.

@fwyzard
Copy link
Contributor Author

fwyzard commented Jan 1, 2024

OTOH, is the template-based check really needed ?
If unsigned long long and std::uint64 are the same type, the second inline function would simply be an identical redefinition of the first one, which should not be an issue ?

inline
std::uint64_t atomicAdd(std::uint64_t* address, std::uint64_t val) noexcept
{
    return hip::detail::atomic_add(address, val);
}

inline
unsigned long long atomicAdd(unsigned long long* address, unsigned long long val) noexcept
{
    return hip::detail::atomic_add(address, val);
}

@fwyzard
Copy link
Contributor Author

fwyzard commented Jan 1, 2024

In fact, the latter seems a more robust solution, because it supports the cases where val is not an unsigned long long but can be converted to it - while the current code and version in the PR does not.

@AlexVlx
Copy link
Collaborator

AlexVlx commented Feb 16, 2024

This was discussed in the past, and the conclusion is that I made a mistake using the sized integer types here, because it introduces divergence versus the HIP / CUDA interfaces. Hence, we probably want to just remove uses of the sized integer typedefs and match the original HIP interface.

@AlexVlx
Copy link
Collaborator

AlexVlx commented Feb 16, 2024

This is the prior discussion on the topic: #50.

@fwyzard
Copy link
Contributor Author

fwyzard commented Feb 16, 2024

I see.

Do you prefer a PR that replaces all std::int.../std::uint... style types with the plain int/unsigned int etc. ones ?

@AlexVlx
Copy link
Collaborator

AlexVlx commented Feb 21, 2024

I see.

Do you prefer a PR that replaces all std::int.../std::uint... style types with the plain int/unsigned int etc. ones ?

As far as preferences go, that would be my choice, however it's more work for you. So if you're feeling particularly generous, it'd be welcome, if not we can just merge this as is and revisit/cleanup later:)

@fwyzard
Copy link
Contributor Author

fwyzard commented Feb 21, 2024

No problem - just one question:

The ROCm/HIP headers have, for example

int atomicAdd(int* address, int val);
unsigned int atomicAdd(unsigned int* address, unsigned int val);
unsigned long atomicAdd(unsigned long* address, unsigned long val);
unsigned long long atomicAdd(unsigned long long* address, unsigned long long val);
float atomicAdd(float* address, float val);
double atomicAdd(double* address, double val);

Should I put the unsigned long case as well ?

@fwyzard fwyzard force-pushed the fix_ull_atomicAdd_return_type branch from b83b838 to 201bb03 Compare February 22, 2024 00:22
@fwyzard
Copy link
Contributor Author

fwyzard commented Feb 22, 2024

I've tried to implement:

  • all cases that were there before (e.g. atomicCAS with short)
  • all cases supported by HIP/ROCm, except for some floating point ones (e.g. atomicCAS with float or double arguments is not implemented)
  • all cases supported by CUDA, even if they are not in HIP/ROCm (e.g. atomicAnd with long long arguments)

Differences with respect to HIP/ROCm are marked with a FIXME.

@AlexVlx
Copy link
Collaborator

AlexVlx commented Mar 15, 2024

@fwyzard apologies for taking a bit long on this one. The change looks good in principle but the CI is showing that it's tickling Windows in the wrong way, let me figure out why so that we can fix it.

@fwyzard
Copy link
Contributor Author

fwyzard commented Mar 15, 2024

OK, sure.
Unfortunately I cannot help with that, as I don't have a Windows machine.

@AlexVlx AlexVlx merged commit 50954af into ROCm:master Mar 19, 2024
1 of 3 checks passed
@fwyzard fwyzard deleted the fix_ull_atomicAdd_return_type branch March 19, 2024 16:51
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.

None yet

2 participants