[clblas] 32/125: Make GTest work on OS X

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Fri May 29 06:57:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository clblas.

commit a414380026aa7bc1f0927c785c14aaf2d1304e6a
Author: Christian Kellner <christian at kellner.me>
Date:   Tue Nov 5 15:04:44 2013 +0100

    Make GTest work on OS X
    
    * Link against the Accelerate framework for BLAS
    * Use cblas for _dotu, et al. calls
    * No need for a fortran compiler since we are using Accelerate
---
 src/CMakeLists.txt                         | 10 ++++++++--
 src/tests/BlasBase.cpp                     |  2 ++
 src/tests/CMakeLists.txt                   | 18 ++++++++++--------
 src/tests/correctness/blas-lapack.c        | 13 ++++++++++++-
 src/tests/correctness/blas-lapack.h        |  2 +-
 src/tests/correctness/test-correctness.cpp |  8 ++++++--
 src/tests/timer.c                          | 24 ++++++++++++++++++++++++
 7 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a515242..76547fc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,7 +38,7 @@ if( CMAKE_GENERATOR MATCHES "NMake" )
 endif( )
 
 # If we are on linux, and we wish to link with the netlib BLAS implementation, we need to have a valid fortran compiler
-if( NOT CORR_TEST_WITH_ACML AND NOT WIN32)
+if( NOT CORR_TEST_WITH_ACML AND NOT WIN32 AND NOT APPLE )
   project(clBLAS Fortran C CXX )
 else( )
   project(clBLAS C CXX)
@@ -123,7 +123,13 @@ endif()
 # TODO: maybe this could be written using the FindBLAS module in the future
 if( BUILD_TEST )
 	if(NOT CORR_TEST_WITH_ACML)
-		find_package( Netlib COMPONENTS BLAS REQUIRED )
+	        if(APPLE)
+			find_library(BLAS_LIBRARIES Accelerate)
+		       	MARK_AS_ADVANCED(BLAS_LIBRARIES)
+		       	message(STATUS "Using Accelerate framework on Mac OS-X")
+	       	else()
+			find_package( Netlib COMPONENTS BLAS REQUIRED )
+              	endif()
 	else( )
 		# Find ACML BLAS implementation
 		# platform dependent ACML subdirectory
diff --git a/src/tests/BlasBase.cpp b/src/tests/BlasBase.cpp
index 8590599..c012803 100644
--- a/src/tests/BlasBase.cpp
+++ b/src/tests/BlasBase.cpp
@@ -506,6 +506,8 @@ BlasBase::printEnvInfo(void)
     #else
             std::cout << "(x32)" << std::endl;
     #endif
+#elif defined( __APPLE__ )
+        std::cout << "Apple OS X" << std::endl;
 #else
         std::cout << "Linux" << std::endl;
 #endif
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 61f5e84..d4a03f7 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -268,7 +268,9 @@ endif( )
 
 # Library with functions for time measurement. In Windows they are included automatically
 if(UNIX)
-    set(TIME_LIBRARY "rt")
+    if(NOT APPLE)
+        set(TIME_LIBRARY "rt")
+    endif()
     set(THREAD_LIBRARY "pthread")
 endif()
 
@@ -334,7 +336,7 @@ if( GTEST_FOUND )
 					  ${CORR_HEADERS} ${TESTS_HEADERS})
 		set_target_properties( test-short PROPERTIES COMPILE_DEFINITIONS SHORT_TESTS )
 
-		if( NOT CORR_TEST_WITH_ACML AND NOT WIN32)
+		if( NOT CORR_TEST_WITH_ACML AND NOT WIN32 AND NOT APPLE)
 			set_target_properties( test-correctness PROPERTIES LINKER_LANGUAGE Fortran )
 			set_target_properties( test-medium PROPERTIES LINKER_LANGUAGE Fortran )
 			set_target_properties( test-short PROPERTIES LINKER_LANGUAGE Fortran )
@@ -346,9 +348,9 @@ if( GTEST_FOUND )
 				target_link_libraries(test-medium ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
 				target_link_libraries(test-short ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
 			else( )
-				target_link_libraries(test-correctness BLAS_LIBRARIES ${GTEST_LIBRARIES} clBLAS)
-				target_link_libraries(test-medium BLAS_LIBRARIES ${GTEST_LIBRARIES} clBLAS)
-				target_link_libraries(test-short BLAS_LIBRARIES ${GTEST_LIBRARIES} clBLAS)
+				target_link_libraries(test-correctness ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
+				target_link_libraries(test-medium ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
+				target_link_libraries(test-short ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} clBLAS)
 			endif( )
 		else( )
 			if( NETLIB_FOUND )
@@ -356,9 +358,9 @@ if( GTEST_FOUND )
 				target_link_libraries(test-medium ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
 				target_link_libraries(test-short ${Netlib_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
 			else( )
-				target_link_libraries(test-correctness BLAS_LIBRARIES ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
-				target_link_libraries(test-medium BLAS_LIBRARIES ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
-				target_link_libraries(test-short BLAS_LIBRARIES ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
+				target_link_libraries(test-correctness ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
+				target_link_libraries(test-medium ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
+				target_link_libraries(test-short ${BLAS_LIBRARIES} ${GTEST_LIBRARIES} ${OPENCL_LIBRARIES} ${runtime.library} )
 			endif( )
 		endif( )
     endif( )
diff --git a/src/tests/correctness/blas-lapack.c b/src/tests/correctness/blas-lapack.c
index a010b7b..4c93104 100644
--- a/src/tests/correctness/blas-lapack.c
+++ b/src/tests/correctness/blas-lapack.c
@@ -24,6 +24,9 @@
 #if !defined CORR_TEST_WITH_ACML
 
 #include "blas-lapack.h"
+#if defined(__APPLE__)
+#include <Accelerate/Accelerate.h>
+#endif
 
 void
 sgemv(char transa, int m, int n, float alpha, float *a, int lda, float *x, int incx, float beta, float *y, int incy)
@@ -639,8 +642,10 @@ complex cdotu( int n, complex *x, int incx, complex *y, int incy)
 {
     complex ans;
 
-    #if defined( _WIN32 ) || defined( _WIN64 )
+#if defined( _WIN32 ) || defined( _WIN64 )
         ans = cdotu_(&n, x, &incx, y, &incy);
+    #elif defined( __APPLE__)
+        cblas_cdotu_sub(n, x, incx, y, incy, &ans);
     #else
         cdotusub_(&n, x, &incx, y, &incy, &ans);
     #endif
@@ -654,6 +659,8 @@ doublecomplex zdotu( int n, doublecomplex *x, int incx,  doublecomplex *y, int i
 
     #if defined( _WIN32 ) || defined( _WIN64 )
         ans = zdotu_(&n, x, &incx, y, &incy);
+    #elif defined(__APPLE__)
+        cblas_zdotu_sub(n, x, incx, y, incy, &ans);
     #else
         zdotusub_(&n, x, &incx, y, &incy, &ans);
     #endif
@@ -667,6 +674,8 @@ complex cdotc( int n, complex *x, int incx, complex *y, int incy)
 
     #if defined( _WIN32 ) || defined( _WIN64 )
         ans = cdotc_(&n, x, &incx, y, &incy);
+    #elif defined(__APPLE__)
+        cblas_cdotc_sub(n, x, incx, y, incy, &ans);
     #else
         cdotcsub_(&n, x, &incx, y, &incy, &ans);
     #endif
@@ -680,6 +689,8 @@ doublecomplex zdotc( int n, doublecomplex *x, int incx,  doublecomplex *y, int i
 
     #if defined( _WIN32 ) || defined( _WIN64 )
         ans = zdotc_(&n, x, &incx, y, &incy);
+    #elif defined(__APPLE__)
+        cblas_zdotc_sub(n, x, incx, y, incy, &ans);
     #else
         zdotcsub_(&n, x, &incx, y, &incy, &ans);
     #endif
diff --git a/src/tests/correctness/blas-lapack.h b/src/tests/correctness/blas-lapack.h
index 6dc55ee..d2db1aa 100644
--- a/src/tests/correctness/blas-lapack.h
+++ b/src/tests/correctness/blas-lapack.h
@@ -1164,7 +1164,7 @@ void zcopy_(int *n, doublecomplex *x, int *incx, doublecomplex *y, int *incy);
 float sdot_(int *n, float *x, int *incx, float* y, int *incy);
 double ddot_(int *n, double *x, int *incx, double* y, int *incy);
 
-#if defined( _WIN32 ) || defined( _WIN64 )
+#if defined( _WIN32 ) || defined( _WIN64 ) || defined( __APPLE__)
     complex cdotu_(int *n, complex *x, int *incx, complex* y, int *incy);
     doublecomplex zdotu_(int *n, doublecomplex *x, int *incx, doublecomplex* y, int *incy);
     complex cdotc_(int *n, complex *x, int *incx, complex* y, int *incy);
diff --git a/src/tests/correctness/test-correctness.cpp b/src/tests/correctness/test-correctness.cpp
index 950382e..7a1a084 100644
--- a/src/tests/correctness/test-correctness.cpp
+++ b/src/tests/correctness/test-correctness.cpp
@@ -205,7 +205,11 @@ const ComplexLong alphaBetaRange[] = {{50,50}, {20,20}};
 const ComplexLong alphaBeta = {10,10};
 const ComplexLong sflagRange[] = {{-1,0}, {0,0}, {1,0}, {-2,0}};
 
+const ComplexLong rotCosMedium = {0, 3};
+const ComplexLong rotSinMedium = {0, 4};
 
+const ComplexLong rotCosShort = {1, 6};
+const ComplexLong rotSinShort = {1, 2};
 
 #ifdef DO_SPL
 
@@ -316,10 +320,10 @@ INSTANTIATE_TEST_CASE_P(ALL_ROTM, ROTM, Combine(
 #ifdef DO_ROT
 #if defined(SHORT_TESTS)
 INSTANTIATE_TEST_CASE_P(Small_ROT, ROT, Combine(
-        Values(1, 5, 10, 20), Values(1, 6), Values(1, -1), Values(1, 6), Values(1, -1), Values(1, 6), Values(1, 2), Values(1)));
+        Values(1, 5, 10, 20), Values(1, 6), Values(1, -1), Values(1, 6), Values(1, -1), Values(rotCosShort), Values(rotSinShort), Values(1)));
 #elif defined(MEDIUM_TESTS)
 INSTANTIATE_TEST_CASE_P(Medium_ROT, ROT, Combine(
-        Values(64,128,256,512), Values(0,3), Values(1, -3, 3, 1), Values(0,3), Values(1, -3, 3, 1), Values(0, 3), Values(0, 4), Values(1)));
+        Values(64,128,256,512), Values(0,3), Values(1, -3, 3, 1), Values(0,3), Values(1, -3, 3, 1), Values(rotCosMedium), Values(rotSinMedium), Values(1)));
 #else
 INSTANTIATE_TEST_CASE_P(ALL_ROT, ROT, Combine(
         ValuesIn(completeRange), ValuesIn(offsetRange), ValuesIn(incs), ValuesIn(offsetRange), ValuesIn(incs),
diff --git a/src/tests/timer.c b/src/tests/timer.c
index e304f4f..8b9c54d 100644
--- a/src/tests/timer.c
+++ b/src/tests/timer.c
@@ -79,6 +79,30 @@ sleepTime(nano_time_t time) {
 
 #include <time.h>
 
+#ifdef __APPLE__
+#include <sys/time.h>
+// we dont have clock_gettime on mac, fake it
+// NB: this is *not* nano-second precision
+#define CLOCK_REALTIME 0
+static int
+clock_gettime(int time_id, struct timespec *t)
+{
+  struct timeval nuc;
+  int err;
+
+  err = gettimeofday(&nuc, NULL);
+  if (err != 0) {
+    return err;
+  }
+
+  t->tv_sec = nuc.tv_sec;
+  t->tv_nsec = nuc.tv_usec * 1000;
+
+  return 0;
+}
+#endif
+
+
 nano_time_t
 conv2nanosec(nano_time_t t)
 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clblas.git



More information about the debian-science-commits mailing list