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

[ROCm] add support for ROCm/HIP device #6086

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

jeffdaily
Copy link

To build for ROCm:

./helpers/hipify.sh
mkdir build
cd build
cmake -DUSE_ROCM=1 ..

CUDA source files are hipified in-place using the helper script before running cmake. The "cuda" device is re-used for rocm, so device=cuda will work the same for rocm builds.

Summary of changes:

  • CMakeLists.txt ROCm updates, also replace glob with explicit file list
  • support both warpSize 32 and 64
  • helpers/hipify.sh script added
  • .gitignore to ignore generated hip source files *.prehip
  • disable compiler warnings
  • move __device__ template function PercentileDevice into header
  • bug fixes for __host__ __define__

- CMakeLists.txt ROCm updates, also replace glob with explicit file list
- initial warpSize interop changes
- helpers/hipify.sh script added
- .gitignore to ignore generated hip source files
- disable compiler warnings
- move PercentileDevice __device__ template function into header
- bug fixes for __host__ __define__ and __HIP__ preprocessor symbols
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Thanks for your interest in LightGBM. Since I'm not aware of any prior conversation in this project about adding support like this, we have some questions before spending time supporting this.

  • what is ROCm/HIP? Where can we read to learn more?
  • what is the value of this addition to LightGBM's users? What does this offer that the OpenCL-based and CUDA-based builds of LightGBM don't already offer?
    • this project's OpenCL-based GPU build is already struggling from a severe lack of maintenance... I'm very skeptical of taking on a third GPU build
  • how might we test this? What types of devices should we expect to be supported?

@shiyu1994
Copy link
Collaborator

@jeffdaily Thank you, this is very exciting! @jameslamb ROCm is the counterpart of CUDA for AMD GPU. I don't have any prior discussion with @jeffdaily about this. But it is very exciting if we can enlarge the devices supported by LightGBM.

@jeffdaily
Copy link
Author

Apologies for coming out of nowhere with this. We use LightGBM; the OpenCL-based 'gpu' device already works on our AMD GPUs. But we were curious if we could get better performance if we ported the 'cuda' device to AMD GPUs. This started as a proof of concept, but it seemed useful to share even in its current state.

Using the GPU-Tutorial, here are my results on our MI210.

what is evaluated CPU GPU/OpenCL "cuda" but really ROCm
correctness auc : 0.821268
18.547533 seconds
auc : 0.821268
20.386780 seconds
auc : 0.821268
9.049307 seconds
speed objective=binary metric=auc 22.604444 seconds 18.028674 seconds 7.787303 seconds
speed objective=regression_l2 metric=l2 18.961535 seconds 14.491217 seconds 7.871302 seconds

@jeffdaily
Copy link
Author

  • what is ROCm/HIP? Where can we read to learn more?

https://rocm.docs.amd.com/en/latest/rocm.html

  • what is the value of this addition to LightGBM's users? What does this offer that the OpenCL-based and CUDA-based builds of LightGBM don't already offer?

See the perf results from the comment above.

  • this project's OpenCL-based GPU build is already struggling from a severe lack of maintenance... I'm very skeptical of taking on a third GPU build
  • how might we test this? What types of devices should we expect to be supported?

Here is the current list of supported AMD GPUs.

To test this, you'll need to run on one of the supported AMD GPUs. How is the cuda device currently tested?

@ibustany
Copy link

ibustany commented Sep 8, 2023

Thank you and kudos Jeff!
This work has been much needed!
Best regards,
Ismail

@jameslamb
Copy link
Collaborator

To test this, you'll need to run on one of the supported AMD GPUs. How is the cuda device currently tested?

We run a VM in Azure with a Tesla V100 on it, and schedule jobs onto it via GitHub Actions.

Are you aware of any free CI service supporting AMD GPUs? Otherwise, since I see you work for AMD and since merging this might further AMD's interests... would AMD maybe be willing to fund testing resources for this project? Maybe that's something you and @shiyu1994 (the only maintainer here who's employed by Microsoft) could coordinate?

@jeffdaily
Copy link
Author

Are you aware of any free CI service supporting AMD GPUs? Otherwise, since I see you work for AMD and since merging this might further AMD's interests... would AMD maybe be willing to fund testing resources for this project? Maybe that's something you and @shiyu1994 (the only maintainer here who's employed by Microsoft) could coordinate?

Microsoft does have an AMD GPU deployment. I'm aware of it being used for onnxruntime CI purposes. I wonder if some of those resources could be used here? @shiyu1994?

@jeffdaily
Copy link
Author

Noting that the only CI failure currently is not related to my changes. It seems to be a perhaps temporary environment setup issue for that job.

@shiyu1994
Copy link
Collaborator

I have access to some AMD MI100 GPUs. But we still need separate budget for an agent with an AMD GPU if we want to test automatically in ci. Do you think it is acceptable if I run the tests for AMD GPU offline without an additional agent for ci? Given that the code for GPU version is shared by both CUDA and ROCm. @jameslamb @guolinke @jeffdaily.

@jameslamb
Copy link
Collaborator

Do you think it is acceptable if I run the tests for AMD GPU offline without an additional agent for ci?

If you feel confident in these changes based on that, and you think the added complexity in the CUDA code is worth it, that's fine with me. I'll defer to your opinion.

But without a CI job, there's a high risk that future refactorings will break this support again.

@jameslamb jameslamb dismissed their stale review September 13, 2023 14:11

dismissing

@jameslamb
Copy link
Collaborator

I dismissed my review, so that it doesn't block merging. My initial questions have been answered, thanks very much for those links and all that information!

@shiyu1994 and @guolinke seem excited about this addition... that's good enough for me 😊

I'll defer to them to review the code, as I know very little about CUDA.

@shiyu1994
Copy link
Collaborator

@jeffdaily Thanks for the great work! I'll review this in the next few days.

@shiyu1994
Copy link
Collaborator

shiyu1994 commented Dec 1, 2023

Thanks again for the contribution. I just got a Windows server with AMD MI25 GPU. I'm trying to use that server as a CI agent. Hopefully it won't be difficult.

@jameslamb jameslamb requested review from jameslamb and removed request for jameslamb April 16, 2024 01:30
@StrikerRUS
Copy link
Collaborator

It's a pity that such wonderful PR was abandoned! 😢

Quite interesting that HIP code can be run on NVIDIA cards!
https://rocm.docs.amd.com/projects/HIP/en/docs-6.0.0/how_to_guides/install.html
ROCm/HIP#3310

I believe that we'll be able to run HIP code on our NVIDIA CI machine. It's not perfect and doesn't guarantee that code works well on AMD, but at least it guarantee that code isn't broken.

@shiyu1994
Copy link
Collaborator

It's a pity that such wonderful PR was abandoned! 😢

Quite interesting that HIP code can be run on NVIDIA cards! https://rocm.docs.amd.com/projects/HIP/en/docs-6.0.0/how_to_guides/install.html ROCm/HIP#3310

I believe that we'll be able to run HIP code on our NVIDIA CI machine. It's not perfect and doesn't guarantee that code works well on AMD, but at least it guarantee that code isn't broken.

I'm picking this up. Let's merge this recently.

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

@shiyu1994 thanks for picking this up!

I left one quick blocking suggestion, but haven't otherwise reviewed this. Will you please @ me once CI is passing? I can give a more thorough review then.

CMakeLists.txt Outdated Show resolved Hide resolved
Co-authored-by: James Lamb <jaylamb20@gmail.com>
@StrikerRUS
Copy link
Collaborator

@shiyu1994

I'm picking this up.

That's just awesome! Thanks!

Copy link
Collaborator

@shiyu1994 shiyu1994 left a comment

Choose a reason for hiding this comment

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

@jeffdaily Thanks for your contribution. Will wait for other reviewers for more comments.

@shiyu1994
Copy link
Collaborator

@jameslamb Hi James, you may review this now. The CI issues have been fixed.

@shiyu1994
Copy link
Collaborator

It's a pity that such wonderful PR was abandoned! 😢

Quite interesting that HIP code can be run on NVIDIA cards! https://rocm.docs.amd.com/projects/HIP/en/docs-6.0.0/how_to_guides/install.html ROCm/HIP#3310

I believe that we'll be able to run HIP code on our NVIDIA CI machine. It's not perfect and doesn't guarantee that code works well on AMD, but at least it guarantee that code isn't broken.

What about we enable this with a separate PR.

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

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

@shiyu1994 Thanks a lot for pushing this PR forward. I left some initial comments about CMake and CI.

do
find ${DIR} -name "*.${EXT}" -exec sh -c '
echo "hipifying $1 in-place"
hipify-perl "$1" -inplace &
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do we get hipify-perl script?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is installed when installing HIP.
https://github.com/ROCm/HIP/blob/master/INSTALL.md

@@ -0,0 +1,16 @@
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this file should be added in a follow-up PR in which we'll enable hipifying at our CI or will request users hipify localy before suggesting a CUDA-related PRs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. We can postpone this to the next PR for ROCm.

message(STATUS "ALLFEATS_DEFINES: ${ALLFEATS_DEFINES}")
message(STATUS "FULLDATA_DEFINES: ${FULLDATA_DEFINES}")

function(add_histogram hsize hname hadd hconst hdir)
Copy link
Collaborator

@StrikerRUS StrikerRUS Dec 17, 2024

Choose a reason for hiding this comment

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

How this function differs from existing one for CUDA? Can we reuse it or merge these two functions into one?

function(add_histogram hsize hname hadd hconst hdir)

)
endfunction()

foreach(hsize _16_64_256)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question as for add_histogram function. Can we [incapsulate this for-loop into a function and] reuse it with CUDA and HIP?

endforeach()
endif()

if(USE_HDFS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

HDFS support was dropped some time ago. This if block should be removed.

target_link_libraries(_lightgbm PRIVATE ${histograms})
endif()

if(USE_HDFS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this.

@@ -644,6 +729,20 @@ if(USE_CUDA)
target_link_libraries(_lightgbm PRIVATE ${histograms})
endif()

if(USE_ROCM)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we merge CUDA and HIP with if( USE_CUDA OR USE_ROCM) here?

@StrikerRUS
Copy link
Collaborator

@shiyu1994

What about we enable this with a separate PR.

Yeah, I support separating PRs: this one with modifications of CUDA files and CMake, a following-up PR with CI jobs for ROCm and hipifying scripts.

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

Successfully merging this pull request may close these issues.

5 participants