Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/FBGEMM.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliamTambellini <william.tambellini@gmail.com>2019-01-14 22:05:42 +0300
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>2019-01-14 22:08:48 +0300
commit9a59fbd05f1df91db548547753d8b0e7a79c031e (patch)
tree792d64f90f57330fdc5c7316886c759b9f37f2d6
parent36309fc56728e32b5d78c3be85b48a93f00ed0bf (diff)
FP16Benchmark: Allow fp32 comparison using cblas (#56)
Summary: FP16Benchmark: Allow comparison against fp32 using any local cblas library if MKL not found. Pull Request resolved: https://github.com/pytorch/FBGEMM/pull/56 Reviewed By: jianyuh Differential Revision: D13645545 Pulled By: dskhudia fbshipit-source-id: ca98e84bfb85eb3b0edebad664d211c3af8db309
-rw-r--r--.gitignore1
-rw-r--r--bench/CMakeLists.txt11
-rw-r--r--bench/FP16Benchmark.cc28
3 files changed, 33 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..567609b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt
index cc07014..a58eed7 100644
--- a/bench/CMakeLists.txt
+++ b/bench/CMakeLists.txt
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
find_package(MKL)
+if (NOT ${MKL_FOUND})
+ find_package(BLAS)
+endif()
+
#benchmarks
macro(add_benchmark BENCHNAME)
add_executable(${BENCHNAME} ${ARGN}
@@ -13,11 +17,18 @@ macro(add_benchmark BENCHNAME)
target_link_libraries(${BENCHNAME} fbgemm)
add_dependencies(${BENCHNAME} fbgemm)
if(${MKL_FOUND})
+ message(STATUS "MKL_LIBRARIES= ${MKL_LIBRARIES}")
target_include_directories(${BENCHNAME} PRIVATE "${MKL_INCLUDE_DIR}")
target_link_libraries(${BENCHNAME} "${MKL_LIBRARIES}")
target_compile_options(${BENCHNAME} PRIVATE
"-DUSE_MKL")
endif()
+ if (${BLAS_FOUND})
+ message(STATUS "BLAS_LIBRARIES= ${BLAS_LIBRARIES}")
+ target_compile_options(${BENCHNAME} PRIVATE "-DUSE_BLAS")
+ target_link_libraries(${BENCHNAME} "${BLAS_LIBRARIES}")
+ endif()
+
set_target_properties(${BENCHNAME} PROPERTIES FOLDER test)
endmacro()
diff --git a/bench/FP16Benchmark.cc b/bench/FP16Benchmark.cc
index c42ee29..efb043d 100644
--- a/bench/FP16Benchmark.cc
+++ b/bench/FP16Benchmark.cc
@@ -12,6 +12,10 @@
#include <mkl.h>
#endif
+#ifdef USE_BLAS
+#include <cblas.h>
+#endif
+
#ifdef _OPENMP
#include <omp.h>
#endif
@@ -101,7 +105,7 @@ void performance_test() {
// warm up MKL and fbgemm
// check correctness at the same time
for (auto w = 0; w < 3; w++) {
-#ifdef USE_MKL
+#if defined(USE_MKL) || defined(USE_BLAS)
cblas_sgemm(
CblasRowMajor,
CblasNoTrans,
@@ -121,19 +125,29 @@ void performance_test() {
cblas_gemm_compute(
matrix_op_t::NoTranspose, m, A.data(), Bp, beta, C_fb.data());
-#ifdef USE_MKL
+#if defined(USE_MKL) || defined(USE_BLAS)
// Compare results
for (auto i = 0; i < C_ref.size(); i++) {
- // printf("%f %f\n", C_ref[i], C_fb[i]);
- assert(std::abs(C_ref[i] - C_fb[i]) < 1e-3);
+ if (std::abs(C_ref[i] - C_fb[i]) > 1e-3) {
+ fprintf(
+ stderr,
+ "Error: too high diff between fp32 ref %f and fp16 %f\n",
+ C_ref[i],
+ C_fb[i]);
+ return;
+ }
}
#endif
}
chrono::time_point<chrono::system_clock> t_begin, t_end;
-#ifdef USE_MKL
+#if defined(USE_MKL) || defined(USE_BLAS)
// Gold via MKL sgemm
+#if defined(USE_MKL)
type = "MKL_FP32";
+#else
+ type = "BLAS_FP32";
+#endif
ttot = 0;
for (auto it = -3; it < NITER; it++) {
if (flush) {
@@ -166,7 +180,7 @@ void performance_test() {
gflops = nflops / ttot / 1e9;
gbs = nbytes / ttot / 1e9;
printf(
- "\n%15s m = %5d n = %5d k = %5d Gflops = %8.4lf GBytes = %8.4lf\n",
+ "\n%30s m = %5d n = %5d k = %5d Gflops = %8.4lf GBytes = %8.4lf\n",
type.c_str(),
m,
n,
@@ -199,7 +213,7 @@ void performance_test() {
gflops = nflops / ttot / 1e9;
gbs = nbytes / ttot / 1e9;
printf(
- "%15s m = %5d n = %5d k = %5d Gflops = %8.4lf GBytes = %8.4lf\n",
+ "%30s m = %5d n = %5d k = %5d Gflops = %8.4lf GBytes = %8.4lf\n",
type.c_str(),
m,
n,