Skip to content

Commit

Permalink
Adding parameter to install.sh to build for cuda backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent Knox committed Sep 5, 2017
1 parent 2b95a1a commit bc48c56
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
*.exe
*.out
*.app

# Tool meta-data
.vscode
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ option( BUILD_SHARED_LIBS "Build hipBLAS as a shared library" ON )

# Find HCC/HIP dependencies
if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" )
message( STATUS "Building for ROCm backend" )
find_package( hcc REQUIRED CONFIG PATHS /opt/rocm )
elseif( CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" )
message( STATUS "Building for ROCm backend" )
find_package( hip REQUIRED CONFIG PATHS /opt/rocm )
else( )
message( AUTHOR_WARNING "hipblas library probably won't build without either the hcc or hipcc compilers. Set the CXX environment variable to specify your desired compiler" )
message( STATUS "Building for CUDA backend" )
endif( )

# CMake list of machine targets
Expand Down
19 changes: 16 additions & 3 deletions clients/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if( NOT TARGET hipblas )
find_package( hipblas CONFIG PATHS /opt/rocm/hipblas )

if( NOT hipblas_FOUND )
message( FATAL_ERROR "rocBLAS is a required dependency and is not found; try adding hipblas path to CMAKE_PREFIX_PATH")
message( FATAL_ERROR "hipBLAS is a required dependency and is not found; try adding hipblas path to CMAKE_PREFIX_PATH")
endif( )
endif( )

Expand All @@ -57,7 +57,18 @@ set( hipblas_benchmark_common
../common/hipblas_template_specialization.cpp
)

add_executable( hipblas-test ${hipblas_test_source} ${hipblas_benchmark_common} )
if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" OR CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" )
# ROCm path
add_executable( hipblas-test ${hipblas_test_source} ${hipblas_benchmark_common} )
else( )
# Nvidia path
# If HiP is not installed in default path, user can append to CMAKE_MODULE_PATH
list( APPEND CMAKE_MODULE_PATH /opt/rocm/hip/cmake )
find_package( HIP REQUIRED ) # Using module mode;
find_package( CUDA REQUIRED ) # Using module mode; packaged in cmake

add_executable( hipblas-test ${hipblas_test_source} ${hipblas_benchmark_common} )
endif( )

set( THREADS_PREFER_PTHREAD_FLAG ON )
find_package( Threads REQUIRED )
Expand Down Expand Up @@ -89,14 +100,16 @@ endif( )

target_link_libraries( hipblas-test PRIVATE cblas lapack ${GTEST_LIBRARIES} ${Boost_LIBRARIES} )

if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" )
if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" OR CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" )
# Remove following when hcc is fixed; hcc emits following spurious warning ROCm v1.6.1
# "clang-5.0: warning: argument unused during compilation: '-isystem /opt/rocm/include'"
target_compile_options( hipblas-test PRIVATE -Wno-unused-command-line-argument )

foreach( target ${AMDGPU_TARGETS} )
target_link_libraries( hipblas-test PRIVATE --amdgpu-target=${target} )
endforeach( )
else( )
target_link_libraries( hipblas-test PRIVATE ${CUDA_LIBRARIES} )
endif( )

set_target_properties( hipblas-test PROPERTIES DEBUG_POSTFIX "-d" CXX_EXTENSIONS NO )
Expand Down
24 changes: 20 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function display_help()
echo " [-i|--install] install after build"
echo " [-d|--dependencies] install build dependencies"
echo " [-c|--clients] build library clients too (combines with -i & -d)"
echo " [--cuda] build library for cuda backend"
}

# #################################################
Expand All @@ -46,6 +47,7 @@ function display_help()
install_package=false
install_dependencies=false
build_clients=false
build_cuda=false

# #################################################
# Parameter parsing
Expand All @@ -54,7 +56,7 @@ build_clients=false
# check if we have a modern version of getopt that can handle whitespace and long parameters
getopt -T
if [[ $? -eq 4 ]]; then
GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,dependencies: --options hicd -- "$@")
GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,dependencies,cuda --options hicd -- "$@")
else
echo "Need a new version of getopt"
exit 1
Expand Down Expand Up @@ -82,6 +84,9 @@ while true; do
-c|--clients)
build_clients=true
shift ;;
--cuda)
build_cuda=true
shift ;;
--) shift ; break ;;
*) echo "Unexpected command line parameter received; aborting";
exit 1
Expand All @@ -103,7 +108,14 @@ rm -rf ${build_dir}
# #################################################
if [[ "${install_dependencies}" == true ]]; then
# dependencies needed for hipblas and clients to build
library_dependencies_ubuntu=( "make" "cmake-curses-gui" "hip_hcc" "hcc" "pkg-config" )
library_dependencies_ubuntu=( "make" "cmake-curses-gui" "pkg-config" "hip_hcc" )
if [[ "${build_cuda}" == false ]]; then
library_dependencies_ubuntu+=( "hcc" "rocblas" )
else
# Ideally, this could be cuda-cublas-dev, but the package name has a version number in it
library_dependencies_ubuntu+=( "cuda" )
fi

client_dependencies_ubuntu=( "gfortran" "libboost-program-options-dev" )

sudo apt update
Expand All @@ -119,7 +131,7 @@ if [[ "${install_dependencies}" == true ]]; then
# Dependencies required by library client apps
if [[ "${build_clients}" == true ]]; then
for package in "${client_dependencies_ubuntu[@]}"; do
if [[ $(dpkg-query --show --showformat='${db:Status-Abbrev}\n' ${package} 2> /dev/null | grep -q "ii"; echo $?) -ne 0 ]]; then
if [[ $(dpkg-query --show --showformat='${db:Status-Abbrev}\n' ${package} 2> /dev/null | grep -q "ii"; echo $?) -ne 0 ]]; then
printf "\033[32mInstalling \033[33m${package}\033[32m from distro package manager\033[0m\n"
sudo apt install -y --no-install-recommends ${package}
fi
Expand All @@ -142,7 +154,11 @@ pushd .
# configure
# #################################################
mkdir -p ${build_dir}/release && cd ${build_dir}/release
export CXX=/opt/rocm/bin/hcc

if [[ "${build_cuda}" == false ]]; then
export CXX=/opt/rocm/bin/hcc
fi

if [[ "${build_clients}" == true ]]; then
cmake -DBUILD_CLIENTS_TESTS=ON ../..
else
Expand Down
15 changes: 9 additions & 6 deletions library/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ else( )

target_link_libraries( hipblas PRIVATE ${CUDA_CUBLAS_LIBRARIES} )

target_include_directories( hipblas PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${HIP_PATH}/include>
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}> )

target_compile_definitions( hipblas PRIVATE __HIP_PLATFORM_NVCC__ )
target_include_directories( hipblas
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
PUBLIC
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${hip_INCLUDE_DIRS}>
)

target_compile_definitions( hipblas PUBLIC __HIP_PLATFORM_NVCC__ )
set_target_properties( hipblas PROPERTIES DEBUG_POSTFIX "-d" OUTPUT_NAME hipblas-nvcc )
endif( )

Expand Down

0 comments on commit bc48c56

Please sign in to comment.