Skip to content

Commit a95c36f

Browse files
committed
add a test_cblas_snrm2 to our test project and compare the results.
1 parent aae39a4 commit a95c36f

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

apps/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ target_link_libraries(test_streaming_scenario ${PROJECT_NAME} ${DISKANN_TOOLS_TC
2828
add_executable(test_insert_deletes_consolidate test_insert_deletes_consolidate.cpp)
2929
target_link_libraries(test_insert_deletes_consolidate ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::program_options)
3030

31+
add_executable(test_open_blas test_open_blas.cpp)
32+
target_include_directories(test_open_blas PRIVATE ${DISKANN_MKL_INCLUDE_DIRECTORIES})
33+
target_link_libraries(test_open_blas ${PROJECT_NAME} ${DISKANN_MKL_LINK_LIBRARIES})
3134
if (MSVC AND USE_OPENBLAS)
32-
add_executable(test_open_blas test_open_blas.cpp)
3335
target_link_libraries(test_open_blas ${PROJECT_NAME} ${OPENBLAS_LIBRARIES})
3436
target_include_directories(test_open_blas PRIVATE ${OPENBLAS_INCLUDE_DIR})
37+
# Comment out the following if you don't want to use OpenBLAS:
38+
target_compile_definitions(test_open_blas PRIVATE -DUSE_OPENBLAS)
3539
endif()
3640

3741
if (NOT MSVC)

apps/test_open_blas.cpp

+47-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,60 @@
1+
#ifdef USE_OPENBLAS
12
#include <cblas.h>
3+
#include <openblas_config.h>
4+
#else
5+
#include <mkl.h>
6+
#endif
7+
28
#include <stdio.h>
39
#include <vector>
4-
#include <chrono>
10+
#include <cmath>
11+
12+
int test_cblas_snrm2();
513

614
// A temporary test just to play with OpenBLAS
715
int main(int argc, char **argv)
816
{
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();
1024

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+
}
1533

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+
}
1936

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};
2240

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
2446

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+
2559
return 0;
26-
}
60+
}

0 commit comments

Comments
 (0)