add test for accelerate framework
This commit is contained in:
parent
d4596c6f95
commit
c5057f8aee
36
modules/math/accelerate.cmake
Normal file
36
modules/math/accelerate.cmake
Normal file
@ -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()
|
@ -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")
|
||||
|
@ -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")
|
||||
|
15
test/cxx_accelerate/cmake/autocmake.cfg
Normal file
15
test/cxx_accelerate/cmake/autocmake.cfg
Normal file
@ -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
|
7
test/cxx_accelerate/src/CMakeLists.txt
Normal file
7
test/cxx_accelerate/src/CMakeLists.txt
Normal file
@ -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()
|
77
test/cxx_accelerate/src/example.cpp
Normal file
77
test/cxx_accelerate/src/example.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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");
|
||||
}
|
@ -1,11 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "Accelerate/Accelerate.h"
|
||||
#else
|
||||
#include "cblas.h"
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -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++')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user