1
+ #ifdef USE_OPENBLAS
1
2
#include < cblas.h>
3
+ #include < openblas_config.h>
4
+ #else
5
+ #include < mkl.h>
6
+ #endif
7
+
2
8
#include < stdio.h>
3
9
#include < vector>
4
- #include < chrono>
10
+ #include < cmath>
11
+
12
+ int test_cblas_snrm2 ();
5
13
6
14
// A temporary test just to play with OpenBLAS
7
15
int main (int argc, char **argv)
8
16
{
9
- printf (" Compute alpha*A*B+beta*C using OpenBLAS cblas_dgemm \n " );
17
+ #ifdef USE_OPENBLAS
18
+ printf (" Using Open BLAS.... \n\n " );
19
+ #else
20
+ printf (" Using Intel MKL.... \n\n " );
21
+ #endif
22
+
23
+ auto errorCode = test_cblas_snrm2 ();
10
24
11
- int size = 100 ;
12
- int m = size, k = size, n = size;
13
- int lda = size, ldb = size, ldc = size;
14
- double alpha = 1.0 , beta = 2.0 ;
25
+ if (errorCode == 0 )
26
+ {
27
+ printf (" \n Completed Successfully. \n " );
28
+ }
29
+ else
30
+ {
31
+ printf (" \n Completed With ERRORs. \n " );
32
+ }
15
33
16
- std::vector<double > A (m * k);
17
- std::vector<double > B (k * n);
18
- std::vector<double > C (m * n);
34
+ return errorCode;
35
+ }
19
36
20
- cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, A.data (), lda, B.data (), ldb, beta, C.data (),
21
- ldc);
37
+ int test_cblas_snrm2 ()
38
+ {
39
+ std::vector<float > vectorA{1.4 , 2.6 , 3.7 , 0.45 , 12 , 100.3 };
22
40
23
- printf (" Completed Successfully. \n " );
41
+ #ifdef USE_OPENBLAS
42
+ float result = cblas_snrm2 ((blasint)vectorA.size (), vectorA.data (), (blasint)1 );
43
+ #else
44
+ float result = cblas_snrm2 ((MKL_INT)vectorA.size (), vectorA.data (), (MKL_INT)1 );
45
+ #endif
24
46
47
+ #ifdef USE_OPENBLAS
48
+ // Expected result from intelMKL: 101.127167
49
+ if (std::fabs (result - 101.127167 ) > 1 .0e-4f )
50
+ {
51
+ printf (" OPEN BLAS value (%f) is not matching with Intel MKL value (101.127167)... \n\n " , result);
52
+ printf (" Validation FAILED :( \n " );
53
+ return 1 ;
54
+ }
55
+ #else
56
+ printf (" cblas_snrm2 result: %f \n\n " , result);
57
+ #endif
58
+
25
59
return 0 ;
26
- }
60
+ }
0 commit comments