Merge pull request #236 from ChrisKitching/friendlyCmake
[HIPIFY] Make the cmake build system more friendly
This commit is contained in:
+21
-25
@@ -1,6 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
project(hip)
|
||||
|
||||
#############################
|
||||
# Options
|
||||
#############################
|
||||
option(BUILD_HIPIFY_CLANG "Enable building the CUDA->HIP converter" OFF)
|
||||
|
||||
#############################
|
||||
# Setup config generation
|
||||
#############################
|
||||
@@ -120,13 +125,6 @@ else()
|
||||
message(FATAL_ERROR "Don't know where to install HIP. Please specify absolute path using -DCMAKE_INSTALL_PREFIX")
|
||||
endif()
|
||||
|
||||
# Check if we need to build hipify-clang
|
||||
if(NOT DEFINED HIPIFY_CLANG_LLVM_DIR)
|
||||
if(DEFINED ENV{HIPIFY_CLANG_LLVM_DIR})
|
||||
set(HIPIFY_CLANG_LLVM_DIR $ENV{HIPIFY_CLANG_LLVM_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Check if we need to enable ATP marker
|
||||
if(NOT DEFINED COMPILE_HIP_ATP_MARKER)
|
||||
if(NOT DEFINED ENV{COMPILE_HIP_ATP_MARKER})
|
||||
@@ -142,7 +140,9 @@ add_to_config(_buildInfo COMPILE_HIP_ATP_MARKER)
|
||||
# Build steps
|
||||
#############################
|
||||
# Build clang hipify if enabled
|
||||
add_subdirectory(hipify-clang)
|
||||
if (BUILD_HIPIFY_CLANG)
|
||||
add_subdirectory(hipify-clang)
|
||||
endif()
|
||||
|
||||
# Build hip_hcc if platform is hcc
|
||||
if(HIP_PLATFORM STREQUAL "hcc")
|
||||
@@ -287,23 +287,19 @@ set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/packages/hip_base)
|
||||
configure_file(packaging/hip_base.txt ${BUILD_DIR}/CMakeLists.txt @ONLY)
|
||||
configure_file(packaging/hip_base.postinst ${BUILD_DIR}/postinst @ONLY)
|
||||
configure_file(packaging/hip_base.prerm ${BUILD_DIR}/prerm @ONLY)
|
||||
if(NOT BUILD_HIPIFY_CLANG)
|
||||
add_custom_target(pkg_hip_base COMMAND ${CMAKE_COMMAND} .
|
||||
COMMAND rm -rf *.deb *.rpm *.tar.gz
|
||||
COMMAND make package
|
||||
COMMAND cp *.deb ${PROJECT_BINARY_DIR}
|
||||
COMMAND cp *.rpm ${PROJECT_BINARY_DIR}
|
||||
COMMAND cp *.tar.gz ${PROJECT_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${BUILD_DIR})
|
||||
else()
|
||||
add_custom_target(pkg_hip_base COMMAND ${CMAKE_COMMAND} .
|
||||
COMMAND rm -rf *.deb *.rpm *.tar.gz
|
||||
COMMAND make package
|
||||
COMMAND cp *.deb ${PROJECT_BINARY_DIR}
|
||||
COMMAND cp *.rpm ${PROJECT_BINARY_DIR}
|
||||
COMMAND cp *.tar.gz ${PROJECT_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${BUILD_DIR}
|
||||
DEPENDS hipify-clang)
|
||||
|
||||
add_custom_target(pkg_hip_base COMMAND ${CMAKE_COMMAND} .
|
||||
COMMAND rm -rf *.deb *.rpm *.tar.gz
|
||||
COMMAND make package
|
||||
COMMAND cp *.deb ${PROJECT_BINARY_DIR}
|
||||
COMMAND cp *.rpm ${PROJECT_BINARY_DIR}
|
||||
COMMAND cp *.tar.gz ${PROJECT_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${BUILD_DIR}
|
||||
)
|
||||
|
||||
# Packaging needs to wait for hipify-clang to build if it's enabled...
|
||||
if (BUILD_HIPIFY_CLANG)
|
||||
add_dependencies(pkg_hip_base hipify-clang)
|
||||
endif()
|
||||
|
||||
# Package: hip_hcc
|
||||
|
||||
+17
-22
@@ -1,31 +1,17 @@
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
project(hipify-clang)
|
||||
|
||||
set(BUILD_HIPIFY_CLANG 0 CACHE INTERNAL "")
|
||||
find_package(LLVM REQUIRED)
|
||||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}:")
|
||||
message(STATUS " - CMake module path: ${LLVM_CMAKE_DIR}")
|
||||
message(STATUS " - Include path : ${LLVM_INCLUDE_DIRS}")
|
||||
message(STATUS " - Binary path : ${LLVM_TOOLS_BINARY_DIR}")
|
||||
|
||||
if (HIPIFY_CLANG_LLVM_DIR)
|
||||
find_package(LLVM PATHS ${HIPIFY_CLANG_LLVM_DIR} REQUIRED NO_DEFAULT_PATH)
|
||||
else()
|
||||
message(STATUS "hipify-clang will not be built. To build it please specify absolute path to LLVM 3.8 or higher using HIPIFY_CLANG_LLVM_DIR")
|
||||
return()
|
||||
endif()
|
||||
|
||||
option(HIPIFY_CLANG_TESTS "Build the tests for hipify-clang, if lit is installed" ON)
|
||||
|
||||
# Disable the tests if `lit` or `FileCheck` is not installed.
|
||||
find_program(LIT_COMMAND lit)
|
||||
find_program(FILECHECK_COMMAND FileCheck)
|
||||
find_program(SOCAT_COMMAND socat)
|
||||
if (NOT LIT_COMMAND OR NOT FILECHECK_COMMAND OR NOT SOCAT_COMMAND)
|
||||
set(HIPIFY_CLANG_TESTS OFF CACHE INTERNAL "")
|
||||
message(STATUS "hipify-clang's tests are not being built because `lit`,`FileCheck` or `socat` could not be found.")
|
||||
endif()
|
||||
option(HIPIFY_CLANG_TESTS "Build the tests for hipify-clang, if lit is installed" OFF)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
|
||||
include(AddLLVM)
|
||||
|
||||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
|
||||
include_directories(${LLVM_INCLUDE_DIRS})
|
||||
link_directories(${LLVM_LIBRARY_DIRS})
|
||||
add_definitions(${LLVM_DEFINITIONS})
|
||||
@@ -81,6 +67,17 @@ install(TARGETS hipify-clang DESTINATION bin)
|
||||
if (HIPIFY_CLANG_TESTS)
|
||||
find_package(PythonInterp 2.7 REQUIRED EXACT)
|
||||
|
||||
function (require_program PROGRAM_NAME)
|
||||
find_program(FOUND_PROGRAM ${PROGRAM_NAME})
|
||||
if (NOT FOUND_PROGRAM)
|
||||
message(FATAL_ERROR "Can't find ${PROGRAM_NAME}. Either set HIPIFY_CLANG_TESTS to OFF to disable hipify tests, or install the missing program.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
require_program(lit)
|
||||
require_program(FileCheck)
|
||||
require_program(socat)
|
||||
|
||||
# Populates CUDA_TOOLKIT_ROOT_DIR, which is then applied to the lit config to give the
|
||||
# value of --cuda-path for the test runs.
|
||||
find_package(CUDA REQUIRED)
|
||||
@@ -102,5 +99,3 @@ if (HIPIFY_CLANG_TESTS)
|
||||
add_dependencies(test-hipify-clang test-hipify)
|
||||
set_target_properties(test-hipify-clang PROPERTIES FOLDER "Tests")
|
||||
endif()
|
||||
|
||||
set(BUILD_HIPIFY_CLANG 1 CACHE INTERNAL "")
|
||||
|
||||
+45
-44
@@ -1,3 +1,7 @@
|
||||
# hipify-clang
|
||||
|
||||
`hipify-clang` is a clang-based tool to automatically translate CUDA source code into portable HIP C++.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<!-- toc -->
|
||||
@@ -9,68 +13,65 @@
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## Using hipify-clang
|
||||
## Build and install
|
||||
|
||||
`hipify-clang` is a clang-based tool which can automate the translation of CUDA source code into portable HIP C++.
|
||||
The tool can automatically add extra HIP arguments (notably the "hipLaunchParm" required at the beginning of every HIP kernel call).
|
||||
`hipify-clang` has some additional dependencies explained below and can be built as a separate make step. The instructions below are specifically for **Ubuntu 14.04** and **Ubuntu 16.04**.
|
||||
### Dependencies
|
||||
|
||||
### Build and install
|
||||
`hipify-clang` requires clang+llvm of at least version 3.8.
|
||||
|
||||
- Download and unpack clang+llvm 3.8 binary package preqrequisite.
|
||||
In most cases, you can get a suitable version of clang+llvm with your package manager.
|
||||
|
||||
Failing that, you can [download a release archive](http://releases.llvm.org/), extract it somewhere, and set
|
||||
[CMAKE_PREFIX_PATH](https://cmake.org/cmake/help/v3.0/variable/CMAKE_PREFIX_PATH.html) so `cmake` can find it.
|
||||
|
||||
### Build
|
||||
|
||||
Assuming this repository is at `./HIP`:
|
||||
|
||||
**Ubuntu 14.04**:
|
||||
```shell
|
||||
wget http://llvm.org/releases/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
|
||||
tar xvfJ clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
|
||||
```
|
||||
**Ubuntu 16.04**:
|
||||
```shell
|
||||
wget http://llvm.org/releases/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
|
||||
tar xvfJ clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
|
||||
```
|
||||
mkdir build inst
|
||||
|
||||
- Enable build of hipify-clang and specify path to LLVM.
|
||||
|
||||
Note HIPIFY_CLANG_LLVM_DIR must be a full absolute path to the location extracted above. Here's an example assuming we extract the clang 3.8 package into ~/HIP/clang+llvm-3.8.0/
|
||||
```shell
|
||||
cd HIP
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DHIPIFY_CLANG_LLVM_DIR=~/HIP/clang+llvm-3.8.0/ -DCMAKE_BUILD_TYPE=Release ..
|
||||
make
|
||||
make install
|
||||
cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=../inst \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_HIPIFY_CLANG=ON \
|
||||
../HIP
|
||||
|
||||
make -j install
|
||||
```
|
||||
|
||||
### Running and using hipify-clang
|
||||
The binary can then be found at `./inst/bin/hipify-clang`.
|
||||
|
||||
`hipify-clang` performs an initial compile of the CUDA source code into a "symbol tree", and thus needs access to the appropriate header files.
|
||||
### Test
|
||||
|
||||
In the case when `hipify-clang` doesn't find cuda headers, it reports various errors about unknown keywords (e.g. '\__global\__'), API function names (e.g. 'cudaMalloc'), syntax (e.g. 'foo<<<1,n>>>(...)'), etc.
|
||||
`hipify-clang` has unit tests using LLVM [`lit`](https://llvm.org/docs/CommandGuide/lit.html)/[`FileCheck`](https://llvm.org/docs/CommandGuide/FileCheck.html).
|
||||
|
||||
To install CUDA headers, download the "deb(network)" variant of the target installer.
|
||||
To run it:
|
||||
1. Ensure `lit` and `FileCheck` are installed - these are distributed with LLVM.
|
||||
2. Ensure `socat` is installed - your distro almost certainly has a package for this.
|
||||
3. Build with the `HIPIFY_CLANG_TESTS` option turned on.
|
||||
4. `make test-hipify`
|
||||
|
||||
**Ubuntu 14.04**:
|
||||
```shell
|
||||
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb
|
||||
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
|
||||
sudo apt-get update && sudo apt-get install cuda-minimal-build-7-5 cuda-curand-dev-7-5
|
||||
```
|
||||
**Ubuntu 16.04**:
|
||||
```shell
|
||||
wget http://archive.ubuntu.com/ubuntu/pool/multiverse/n/nvidia-cuda-toolkit/nvidia-cuda-toolkit_7.5.18-0ubuntu1_amd64.deb
|
||||
sudo dpkg -i nvidia-cuda-toolkit_7.5.18-0ubuntu1_amd64.deb
|
||||
sudo apt-get update && sudo apt-get install cuda-minimal-build-7-5 cuda-curand-dev-7-5
|
||||
```
|
||||
To set additional options like Language Selection (only "-x cuda" is supported), Preprocessor Definition (-D), Include Path (-I), etc., options delimiter "--" should be used before them, for instance:
|
||||
## Running and using hipify-clang
|
||||
|
||||
To process a file, `hipify-clang` needs access to the same headers that would be needed to compile it with clang.
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
./hipify-clang -print-stats sort_kernel.cu -- -x cuda -I/srv/git/HIP/include -I/usr/local/cuda-7.5/include -DX=1
|
||||
hipify-clang square.cu -- \
|
||||
-x cuda \
|
||||
--cuda-path=/opt/cuda \
|
||||
--cuda-gpu-arch=sm_30 \
|
||||
-isystem /opt/cuda/samples/common/inc
|
||||
```
|
||||
|
||||
Delimiter "--" is used to separate hipify-clang options (before the delimiter) from clang options (after the delimiter). It is strongly recommended to always specify the delimiter, even if there are no clang specific options at all, in order to avoid possible errors regarding compilation database; in such case delimeter should be the last option in hipify-clang's command line.
|
||||
`hipify-clang` arguments are given first, followed by a separator, and then the arguments you'd pass to `clang` if you
|
||||
were compiling the input file. The [Clang manual for compiling CUDA](https://llvm.org/docs/CompileCudaWithLLVM.html#compiling-cuda-code)
|
||||
may be useful.
|
||||
|
||||
Option "-x cuda" is also worth specifying in order to convert source CUDA files with extensions other than standard extensions (*.cu, *.cuh).
|
||||
For a list of `hipify-clang` options, run `hipify-clang --help`.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
|
||||
Referens i nytt ärende
Block a user