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

[FEA] make raft sources compilable with clang #424

Merged
merged 11 commits into from
Feb 16, 2022

Conversation

MatthiasKohl
Copy link
Contributor

@MatthiasKohl MatthiasKohl commented Dec 14, 2021

This makes RAFT sources compilable with clang.
It fixes some fragile code (using static const instead of static constexpr or %laneid in PTX relying on quirks in nvcc which make this happen).

RAFT is still not compilable with clang entirely though due to the dependencies:

  1. cub has this issue before 1.14: Fix clang compile error NVIDIA/cub#335
  2. libcudacxx has issues with atomic, which should be fixed in >= 1.7.0-ea (wasn't able to verify this yet)
  3. libcudacxx has issues with variadic CUDA functions, which is apparently fixed by passing -Xclang -fcuda-allow-variadic-functions to clang (wasn't able to verify this yet)
  4. cooperative_groups from CUDA does not work with clang 11.0 / 11.1 but only with >= 13

EDIT: this is necessary to close #84

@MatthiasKohl MatthiasKohl requested review from a team as code owners December 14, 2021 22:42
@github-actions github-actions bot added the cpp label Dec 14, 2021
@MatthiasKohl MatthiasKohl added bug Something isn't working CMake feature request New feature or request non-breaking Non-breaking change labels Dec 14, 2021
@MatthiasKohl
Copy link
Contributor Author

question to reviewers: what would be the easiest way to bump up versions of tools and dependencies ?
In particular, to make this really happen, we would need thrust/cub >= 1.14, libcudacxx >= 1.7.0-ea and clang-tools >= 13.

With the Rapids cpm system, this seems prohibitively hard. Why?

@MatthiasKohl MatthiasKohl removed the bug Something isn't working label Dec 14, 2021
@MatthiasKohl MatthiasKohl changed the title [BUG] [FEA] make raft sources compilable with clang [FEA] make raft sources compilable with clang Dec 14, 2021
@cjnolet
Copy link
Member

cjnolet commented Dec 20, 2021

@MatthiasKohl, I know you've put this down in the meantime due to some issues w/ dependent versions in RAPIDS. I still see value in merging the c++ code changes and keeping the script in a PR until clang support is ready to go. What do you think?

@MatthiasKohl
Copy link
Contributor Author

Yes I think it makes sense to add these changes to RAFT. But it's hard to test because of these issues in dependencies meaning that for many files, clang doesn't even get to the RAFT part. In fact after I upgraded to clang 13 and updated some of the dependent packages, I still discovered new issues within RAFT sources because they were simply not compiled before.
So what we could do is to just ignore the errors for now and gradually change things as more and more code will be covered with newer packages and newer clang versions

@github-actions github-actions bot removed the CMake label Jan 3, 2022
@MatthiasKohl
Copy link
Contributor Author

@cjnolet I've added a few changes I had in the pipeline which make things compatible with CUDA 11.5, plus a few other RAFT sources which can only be compiled with a newer clang version and updated thrust.

Can you review these changes so that we can already merge those?

Right now, libcudacxx and cuco cannot be compiled device-side.
I can still check whether they can be compiled host-side which would already be nice.
But I feel like that isn't really enough for a project like RAFT where probably 50% of code is device-side, and especially the important code is device-side, so before spending more time on this, I'd prefer having the dependent projects work with device-side compilation.

@MatthiasKohl
Copy link
Contributor Author

rerun tests

@cjnolet cjnolet changed the base branch from branch-22.02 to branch-22.04 January 24, 2022 20:09
Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

Since RAFT is still somewhat coupled to cuml's C++ code, can you open a PR in cuml w/ the get_raft.cmake pinned to this branch just so we can make sure it doesn't break? Overall the changes look good.

@MatthiasKohl
Copy link
Contributor Author

@cjnolet sorry I didn't see your comments on this PR (somehow missed the notifications), I'll address them ASAP

@MatthiasKohl MatthiasKohl requested a review from a team as a code owner February 11, 2022 18:22
@cjnolet cjnolet removed the request for review from a team February 13, 2022 00:46
@MatthiasKohl
Copy link
Contributor Author

@cjnolet you might have seen this draft PR on cuml, which I'm using to make sure that cuml CI is still passing with these changes: rapidsai/cuml#4571

Note that I had to add some more changes to raft in order to make sure that RAFT sources themselves are compiling with Clang: - cpp/include/raft/cuda_utils.cuh lines 697-728 : I added overloads for the __ldcv/__ldcg/__stwt CUDA functions which are unknown to clang

@MatthiasKohl
Copy link
Contributor Author

MatthiasKohl commented Feb 14, 2022

@cjnolet CI on cuml is passing with the latest changes from this PR (see rapidsai/cuml#4571)
It seems like CI here on the RAFT PR isn't being run for some reason. EDIT: actually, it is being run but unfortunately, it looks like one of the Rng tests (MeanError) is not passing.

Apart from that, I'm still awaiting your final review for the latest changes since the compiler-specific stuff might not be what you'd like to do for RAFT in general.

@cjnolet
Copy link
Member

cjnolet commented Feb 14, 2022

rerun tests

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

I'm still thinking through the best way to isolate and document the files that can be safely compiled with a CUDA vs non-CUDA-enabled compiler while keeping the API consistent.

Thanks again for these changes! I really just have a couple minor-ish questions and one small change.

* Ceiling division operation
* Re-declared here from raft/cuda_utils.cuh since we cannot include CUDA files
*/
template <typename IntType>
Copy link
Member

Choose a reason for hiding this comment

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

since we cannot include CUDA files

Can you explain what you mean by this? I think I'm misunderstanding only because I notice this file has kernels in it. Is it the __CUDA_ARCH__ that's not allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for raising this again!
Given the comment, I must have thought that this file was compiled from a .cpp file (thus with a non-CUDA-enabled compiler). I actually don't think this was the case, and these changes don't make any sense to me anymore, so I reverted them and they don't seem to affect clang compilation at all.

@MatthiasKohl
Copy link
Contributor Author

@cjnolet @achirkin would it be possible to review the latest changes again? I've made the following changes:

  1. Using __align__ instead of alignas in device code which clang accepts
  2. No more weird things around __ldcv and similar functions. I simply added these intrinsics in an include which is added for CUDA compilation with clang, see the new header file under cpp/scripts
  3. I reverted the changes around ceildiv in cluster/detail/kmeans.cuh

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

This looks good from my end. Thanks for doing this! It will be very useful once we are able to run clang-tidy across the entire codebase.

@cjnolet
Copy link
Member

cjnolet commented Feb 16, 2022

Also hoping to get final thoughts from @achirkin before merging.

Copy link
Contributor

@achirkin achirkin left a comment

Choose a reason for hiding this comment

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

Looks great to me, looking forward to using clang-tidy in all cuda files!

@MatthiasKohl
Copy link
Contributor Author

Thanks guys! I had to fix one final line in kmeans.cuh since my last two merges messed up the includes slightly, but CI in both RAFT and cuml should be passing now.

@cjnolet
Copy link
Member

cjnolet commented Feb 16, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit b2a88c2 into rapidsai:branch-22.04 Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp feature request New feature or request non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Fix clang-tidy errors
3 participants