From c5057f8aee6589352ed7b9ca989305dad4f9a75c Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Fri, 18 Sep 2015 10:44:39 +0200 Subject: [PATCH] add test for accelerate framework --- modules/math/accelerate.cmake | 36 ++++++++++++ modules/math/cblas.cmake | 9 +-- modules/math/lapacke.cmake | 9 +-- test/cxx_accelerate/cmake/autocmake.cfg | 15 +++++ test/cxx_accelerate/src/CMakeLists.txt | 7 +++ test/cxx_accelerate/src/example.cpp | 77 +++++++++++++++++++++++++ test/cxx_cblas/src/example.cpp | 4 -- test/test.py | 7 +++ 8 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 modules/math/accelerate.cmake create mode 100644 test/cxx_accelerate/cmake/autocmake.cfg create mode 100644 test/cxx_accelerate/src/CMakeLists.txt create mode 100644 test/cxx_accelerate/src/example.cpp diff --git a/modules/math/accelerate.cmake b/modules/math/accelerate.cmake new file mode 100644 index 0000000..2e6a277 --- /dev/null +++ b/modules/math/accelerate.cmake @@ -0,0 +1,36 @@ +#.rst: +# +# Find and link to ACCELERATE. +# +# Variables defined:: +# +# ACCELERATE_FOUND - describe me, uncached +# ACCELERATE_LIBRARIES - describe me, uncached +# ACCELERATE_INCLUDE_DIR - describe me, uncached +# +# autocmake.cfg configuration:: +# +# docopt: --accelerate Find and link to ACCELERATE [default: False]. +# define: '-DENABLE_ACCELERATE=%s' % arguments['--accelerate'] +# fetch: https://github.com/scisoft/autocmake/raw/master/modules/find/find_libraries.cmake +# https://github.com/scisoft/autocmake/raw/master/modules/find/find_include_files.cmake + +option(ENABLE_ACCELERATE "Find and link to ACCELERATE" OFF) + +if(ENABLE_ACCELERATE) + include(find_libraries) + include(find_include_files) + + set(ACCELERATE_FOUND FALSE) + set(ACCELERATE_LIBRARIES "NOTFOUND") + set(ACCELERATE_INCLUDE_DIR "NOTFOUND") + + _find_library(Accelerate cblas_dgemm ACCELERATE_LIBRARIES) + _find_include_dir(Accelerate.h /usr ACCELERATE_INCLUDE_DIR) + + if(NOT "${ACCELERATE_LIBRARIES}" MATCHES "NOTFOUND") + if(NOT "${ACCELERATE_INCLUDE_DIR}" MATCHES "NOTFOUND") + set(ACCELERATE_FOUND TRUE) + endif() + endif() +endif() diff --git a/modules/math/cblas.cmake b/modules/math/cblas.cmake index 47a11c5..a5b57b0 100644 --- a/modules/math/cblas.cmake +++ b/modules/math/cblas.cmake @@ -25,13 +25,8 @@ if(ENABLE_CBLAS) set(CBLAS_LIBRARIES "NOTFOUND") set(CBLAS_INCLUDE_DIR "NOTFOUND") - if(APPLE) - _find_library(Accelerate cblas_dgemm CBLAS_LIBRARIES) - _find_include_dir(Accelerate.h /usr CBLAS_INCLUDE_DIR) - else() - _find_library(cblas cblas_dgemm CBLAS_LIBRARIES) - _find_include_dir(cblas.h /usr CBLAS_INCLUDE_DIR) - endif() + _find_library(cblas cblas_dgemm CBLAS_LIBRARIES) + _find_include_dir(cblas.h /usr CBLAS_INCLUDE_DIR) if(NOT "${CBLAS_LIBRARIES}" MATCHES "NOTFOUND") if(NOT "${CBLAS_INCLUDE_DIR}" MATCHES "NOTFOUND") diff --git a/modules/math/lapacke.cmake b/modules/math/lapacke.cmake index e7dfcad..a05d5e2 100644 --- a/modules/math/lapacke.cmake +++ b/modules/math/lapacke.cmake @@ -25,13 +25,8 @@ if(ENABLE_LAPACKE) set(LAPACKE_LIBRARIES "NOTFOUND") set(LAPACKE_INCLUDE_DIR "NOTFOUND") -# if(APPLE) -# _find_library(Accelerate cblas_dgemm LAPACKE_LIBRARIES) -# _find_include_dir(Accelerate.h /usr LAPACKE_INCLUDE_DIR) -# else() - _find_library(lapacke LAPACKE_dgesv LAPACKE_LIBRARIES) - _find_include_dir(lapacke.h /usr LAPACKE_INCLUDE_DIR) -# endif() + _find_library(lapacke LAPACKE_dgesv LAPACKE_LIBRARIES) + _find_include_dir(lapacke.h /usr LAPACKE_INCLUDE_DIR) if(NOT "${LAPACKE_LIBRARIES}" MATCHES "NOTFOUND") if(NOT "${LAPACKE_INCLUDE_DIR}" MATCHES "NOTFOUND") diff --git a/test/cxx_accelerate/cmake/autocmake.cfg b/test/cxx_accelerate/cmake/autocmake.cfg new file mode 100644 index 0000000..5c91c67 --- /dev/null +++ b/test/cxx_accelerate/cmake/autocmake.cfg @@ -0,0 +1,15 @@ +[project] +name: example +min_cmake_version: 2.8 + +[cxx] +source: ../../../modules/cxx.cmake + +[math] +source: ../../../modules/math/accelerate.cmake + +[default_build_paths] +source: ../../../modules/default_build_paths.cmake + +[src] +source: ../../../modules/src.cmake diff --git a/test/cxx_accelerate/src/CMakeLists.txt b/test/cxx_accelerate/src/CMakeLists.txt new file mode 100644 index 0000000..a236e24 --- /dev/null +++ b/test/cxx_accelerate/src/CMakeLists.txt @@ -0,0 +1,7 @@ +if(ACCELERATE_FOUND) + include_directories(${ACCELERATE_INCLUDE_DIR}) + add_executable(example example.cpp) + target_link_libraries(example ${ACCELERATE_LIBRARIES}) +else() + message(FATAL_ERROR "ACCELERATE library not found") +endif() diff --git a/test/cxx_accelerate/src/example.cpp b/test/cxx_accelerate/src/example.cpp new file mode 100644 index 0000000..3f32f58 --- /dev/null +++ b/test/cxx_accelerate/src/example.cpp @@ -0,0 +1,77 @@ +#include +#include + +#include "Accelerate/Accelerate.h" + +bool test_lapack() +{ + const int n = 3; + + double a[n*n]; + double b[n]; + + a[0] = 2.00; + a[1] = 1.00; + a[2] = 3.00; + a[3] = 2.00; + a[4] = 6.00; + a[5] = 8.00; + a[6] = 6.00; + a[7] = 8.00; + a[8] = 18.00; + + b[0] = 1.00; + b[1] = 3.00; + b[2] = 5.00; + + int ierr; + int ipiv[n]; + + ierr = LAPACKE_dgesv(CblasColMajor, n, 1, a, n, ipiv, b, n); + if (ierr != 0) + { + fprintf(stderr, "\ndgesv failure with error %i\n", ierr); + } + + const double small = 1.0e-12; + + if (abs(b[0] + 0.50) <= small && + abs(b[1] - 0.25) <= small && + abs(b[2] - 0.25) <= small) + { + return true; + } + + return false; +} + +bool test_blas() +{ + const int n = 10; + + double a[n*n]; + double b[n*n]; + double c[n*n]; + + for (int i = 0; i < n*n; i++) + { + a[i] = 1.0; + b[i] = 2.0; + c[i] = 0.0; + } + + cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, a, n, b, n, 0.0, c, n); + + bool passed = true; + for (int i = 0; i < n*n; i++) + { + if (abs(c[i]) - 20.00 > 0.0) passed = false; + } + + return passed; +} + +int main() +{ + if (test_lapack() and test_blas()) printf("PASSED"); +} diff --git a/test/cxx_cblas/src/example.cpp b/test/cxx_cblas/src/example.cpp index 23469cc..19a710e 100644 --- a/test/cxx_cblas/src/example.cpp +++ b/test/cxx_cblas/src/example.cpp @@ -1,11 +1,7 @@ #include #include -#ifdef __APPLE__ -#include "Accelerate/Accelerate.h" -#else #include "cblas.h" -#endif int main() { diff --git a/test/test.py b/test/test.py index 87844ff..dd5dc99 100644 --- a/test/test.py +++ b/test/test.py @@ -139,6 +139,7 @@ def test_fc_blas(): configure_build_and_exe('fc_blas', 'python setup.py --fc=gfortran --cmake-options="-DMATH_LIB_SEARCH_ORDER=\'OPENBLAS;ATLAS;MKL;SYSTEM_NATIVE\'"') +@skip_on_osx def test_cxx_cblas(): configure_build_and_exe('cxx_cblas', 'python setup.py --cxx=g++ --cblas') @@ -147,10 +148,16 @@ def test_fc_lapack(): configure_build_and_exe('fc_lapack', 'python setup.py --fc=gfortran --cmake-options="-DMATH_LIB_SEARCH_ORDER=\'OPENBLAS;ATLAS;MKL;SYSTEM_NATIVE\'"') +@skip_on_osx def test_cxx_lapacke(): configure_build_and_exe('cxx_lapacke', 'python setup.py --cxx=g++ --lapacke --cblas') +@skip_on_linux +def test_cxx_accelerate(): + configure_build_and_exe('cxx_accelerate', 'python setup.py --cxx=g++ --accelerate') + + def test_python_interpreter(): configure_build_and_exe('python_interpreter', 'python setup.py --cxx=g++')