Skip to content

Commit

Permalink
cpu: gemm: fix data race during initialization (#363)
Browse files Browse the repository at this point in the history
* Fix data race in gemm.cpp

* Use std::call_once in gemm lazy initialization

* remove redundant header
  • Loading branch information
ezhulenev authored and Roman Dubtsov committed Dec 12, 2018
1 parent a7c5f53 commit 763513e
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/cpu/gemm/gemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,9 @@ mkldnn_status_t extended_sgemm(const char *transa, const char *transb,
}
#endif
//Generate jit kernel and call sgemm with bias
volatile static int initialized = 0;
if (!initialized) {
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
if (!initialized) {
mkldnn::impl::cpu::initialize();
initialized = 1;
}
}
static std::once_flag initialized;
std::call_once(initialized, [] { mkldnn::impl::cpu::initialize(); });

if (bias)
gemm_bias_impl[trA][trB]->call(
transa, transb, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc,
Expand Down

0 comments on commit 763513e

Please sign in to comment.