#!/bin/bash
# Create new cocolib defs and lib config file
cp cocolib/defs.h.in cocolib/defs.h
rm -f extra_libs.inc
touch extra_libs.inc
# Check for nVidias CUDA compiler
echo "Testing for 'nvcc' compiler ..."
if test "$(which nvcc)" == ""
then
echo
echo "*** FAILED TO LOCATE CUDA COMPILER ***"
echo
echo "The CUDA compiler 'nvcc' is not in the current path."
echo "To compile cocolib and the examples, download and install the"
echo "CUDA toolkit version 4.2 or higher.
echo ""
echo "On many apt-based distributions, it is available as a package"
echo "'nvidia-cuda-toolkit' or similar.
echo ""
echo" Otherwise, you may obtain it from the CUDA zone on"
echo "www.nvidia.com".
echo
echo "After manual installation, make sure your PATH variable includes the"
echo "install path to the 'nvcc' executable (default /usr/local/cuda/bin)."
echo
exit
else
echo " nVidia CUDA compiler detected ... " `which nvcc`
fi
source local_flags.inc
# Check for supported toolkit version
# OUTDATED TEST, SHOULD ALWAYS WORK NOW
# SINCE IT'S PART OF THE PACKAGE DATABASE
#
#nvcc_test=$(nvcc --version | grep "release 4.2")
#if [ -z "$nvcc_test" ]; then
# echo "WARNING: CUDA toolkit is not version 4.2."
# echo " If you have a lower version number,"
# echo " you have to make sure to use gcc version 4.4"
# echo " or older."
#else
# echo " CUDA toolkit version 4.2 detected."
#fi
# Check if minimal example compiles
echo "Testing minimal example compilation ..."
nvcc -o ./config_tests/test_compute_capability ./config_tests/test_compute_capability.cu -lcudart
if [ $? -ne 0 ]; then
echo " ERROR: compiler returned an error."
exit
else
echo " compiled successfully."
fi
# Check compute capability of the device
rm -f extra_nvcc_flags.inc
touch extra_nvcc_flags.inc
./config_tests/test_compute_capability
COMPUTE_CAPABILITY=$?
if [ $COMPUTE_CAPABILITY -lt 13 ]; then
echo "WARNING: Your GPU has compute capability less than 1.3."
echo " This is not completely supported by cocolib - some algorithms may fail."
else
echo " GPU compute capability at least 1.3, which is good."
echo "#define COMPUTE_API_BUFFER_TYPE float*" >> cocolib/defs.h
echo "#define COMPUTE_API_CUDA_CAPABILITY "$COMPUTE_CAPABILITY >> cocolib/defs.h
#
# Vanilla GPU architecture
#
# echo "NVFLAGS += --gpu-architecture sm_13" >> extra_nvcc_flags.inc
#
# Use the following instead to optimize GPU architecture - this will invalidate the
# reference results, since exact numeric results will now depend on compiler optimization
# strategy.
#
echo "NVFLAGS += --gpu-architecture sm_"$COMPUTE_CAPABILITY >> extra_nvcc_flags.inc
echo "Configuring nvcc for compute capability "$COMPUTE_CAPABILITY"."
#
fi
# Check for GSL library
echo "Testing for GSL library ..."
nvcc -o ./config_tests/test_gsl ./config_tests/test_gsl.cu -lgsl -lgslcblas -I$LOCAL_INCLUDE_PATH -L$LOCAL_LIB_PATH -m64 -lcudart
if [ $? -ne 0 ]; then
echo " ERROR: compiler returned an error."
echo " GSL library might not be installed."
echo " On Ubuntu systems, this is the package libgsl0-dev."
exit
else
echo " compiled successfully."
fi
./config_tests/test_gsl
if [ $? -ne 0 ]; then
echo "WARNING: GSL example returned an error code."
echo " Something might be wrong with the installation."
else
echo " run successfully."
fi
# Check for ANN library
echo "Testing for ANN library ..."
nvcc -o ./config_tests/test_ann ./config_tests/test_ann.cu -lann -I$LOCAL_INCLUDE_PATH -L$LOCAL_LIB_PATH -m64
if [ $? -ne 0 ]; then
echo " failed to compile ANN library example."
echo " the library is probably not installed,"
echo " cocolib will compile without ANN support."
echo "//#define LIB_ANN" >> cocolib/defs.h
else
echo " compiled successfully, library seems to be installed."
echo "#define LIB_ANN" >> cocolib/defs.h
echo "LIBS += -lann" >> extra_libs.inc
fi
echo "#endif" >> cocolib/defs.h
# QT4 development tools
echo "Testing for qt4 development tools ..."
qt4_test=$(qmake-qt4 --version | grep "version 4.")
if [ -z "$qt4_test" ]; then
echo " ERROR: failed to detect Qt4."
echo " Make sure you have libqt4-dev installed."
exit
else
echo " success."
fi
# creating CUDA project files
echo "Generating CUDA project files ..."
cp ./cocolib.pro.cuda ./cocolib.pro
sed -i '1i# AUTO-GENERATED BY CONFIGURE, DO NOT EDIT\n' ./cocolib.pro
cp ./cocolib/cocolib.pro.cuda ./cocolib/cocolib.pro
sed -i '1i# AUTO-GENERATED BY CONFIGURE, DO NOT EDIT\n' ./cocolib/cocolib.pro
cp ./examples++/examples++.pro.cuda ./examples++/examples++.pro
sed -i '1i# AUTO-GENERATED BY CONFIGURE, DO NOT EDIT\n' ./examples++/examples++.pro
# run qmake to create Makefile
echo "Running 'qmake-qt4' for cocolib ..."
qmake-qt4 cocolib.pro
if [ $? -ne 0 ]; then
echo " ERROR: qmake-qt4 returned an error."
exit
else
echo " success."
fi
# clean up
echo "Cleaning up previous builds ..."
make --quiet clean
# done.
echo "Ready, run 'make' to build cocolib."