- Notifications
You must be signed in to change notification settings - Fork 5.9k
Demostration of cmake refine for HIP support. #9165
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
Conversation
sabreshao commented Mar 16, 2018
- Add option WITH_AMD_GPU.
- Add cmake/hip.cmake for HIP toolchain.
- Some external module such as eigen may need HIP port.
- Add macro hip_library/hip_binary/hip_test to cmake/generic.cmake.
- Add one HIP source concat.hip.cu as an example. Each .cu may have its corresponding .hip.cu.
1. Add option WITH_AMD_GPU. 2. Add cmake/hip.cmake for HIP toolchain. 3. Some external module such as eigen may need HIP port. 4. Add macro hip_library/hip_binary/hip_test to cmake/generic.cmake. 5. Add one HIP source concat.hip.cu as an example. Each .cu may have its corresponding .hip.cu.
CMakeLists.txt Outdated
| endif() | ||
| | ||
| if(WITH_AMD_GPU) | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 73-74 could be removed since there is nothing between them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
cmake/external/eigen.cmake Outdated
| INSTALL_COMMAND "" | ||
| TEST_COMMAND "" | ||
| ) | ||
| INCLUDE_DIRECTORIES(${EIGEN_SOURCE_DIR}/src/extern_eigen3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(WITH_AMD_GPU) SET(GIT_REPOSITORY "https://github.com/sabreshao/hipeigen.git") SET(GIT_TAG 0cba03ff9f8f9f70bbd92ac5857b031aa8fed6f9) else() SET(GIT_REPOSITORY "https://github.com/RLovelett/eigen.git") SET(GIT_TAG 0cba03ff9f8f9f70bbd92ac5857b031aa8fed6f9) endif() ExternalProject_Add( extern_eigen3 ${EXTERNAL_PROJECT_LOG_ARGS} GIT_REPOSITORY ${GIT_REPOSITORY} GIT_TAG ${GIT_TAG} ... ) may be more cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In AMD GPU build, use hipeigen instead since it includes necessary patches for HIP.
| include_directories("/opt/rocm/hiprand/include") | ||
| include_directories("/opt/rocm/rocrand/include") | ||
| include_directories("/opt/rocm/rccl/include") | ||
| include_directories("/opt/rocm/thrust") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could /opt/rocm/include etc be a relative path like ${CUDA_INCLUDE_DIRS}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until now no such thing is defined in HIP/ROCm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we don't have such define. NV defines /usr/local/cuda as the symbolic link, that's why they need those env vars so users can define those to point to the absolute CUDA paths.
cmake/hip.cmake Outdated
| list(APPEND HIP_HCC_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}) | ||
| elseif(CMAKE_BUILD_TYPE STREQUAL "Release") | ||
| # Disable optimization since one eigen symbol will be removed in math_function.cu | ||
| #list(APPEND HIP_HCC_FLAGS ${CMAKE_CXX_FLAGS_RELEASE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 31-32 could be removed if not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
| ${op_common_deps}) | ||
| elseif (WITH_AMD_GPU) | ||
| hip_library(${TARGET} SRCS ${cc_srcs} ${hip_cc_srcs} ${miopen_cu_cc_srcs} ${mkldnn_cc_srcs} ${hip_srcs} DEPS | ||
| ${op_library_DEPS} ${op_common_deps}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the definitions of ${hip_cc_srcs}, ${miopen_cu_cc_srcs} and ${hip_srcs}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refined paddle/fluid/operators/CMakeLists.txt .
| @@ -1,9 +1,16 @@ | |||
| if(WITH_PYTHON) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of updating this pybind/CMakeLists.txt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason of updating pybind/CMakeLists.txt is that shared library which refers any HIP kernel must be linked with hipcc rather than gcc.
1. Add option WITH_AMD_GPU. 2. Add cmake/hip.cmake for HIP toolchain. 3. Some external module such as eigen may need HIP port. 4. Add macro hip_library/hip_binary/hip_test to cmake/generic.cmake. 5. Add one HIP source concat.hip.cu as an example. Each .cu may have its corresponding .hip.cu.
reyoung left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. There are some tiny comments. However, do not let them block this PR.
| include_directories("/opt/rocm/rccl/include") | ||
| include_directories("/opt/rocm/thrust") | ||
| | ||
| list(APPEND EXTERNAL_LIBS "-L/opt/rocm/lib/ -lhip_hcc") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many hard codes in this file. Maybe we can modify the FindHip.cmake after this PR?
| | ||
| list(APPEND EXTERNAL_LIBS "-L/opt/rocm/lib/ -lhip_hcc") | ||
| | ||
| set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -fPIC -DPADDLE_WITH_HIP -std=c++14" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use c++14 by default? Paddle is currently using c++11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sabreshao , could you check the c++14 option here? This is not required by HIP as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunway513 @reyoung c++14 is to enable "function return type deduction in lambda", which may be needed in following PR.
| @sabreshao thanks for the PR! The CI seems to fail, can you take a look? (PR can not be merged if CI fails) |
Fix CI.
reyoung left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!