oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

Does MKLDNN has TBB support

Open mingfeima opened this issue 8 years ago • 7 comments

Can MKLDNN be compiled with TBB instead of OpenMP?

mingfeima avatar May 30 '18 01:05 mingfeima

Hi @mingfeima,

Currently Intel MKL-DNN cannot be built with TBB. But we are looking into supporting it. No ETA though.

Could you explain why you need TBB and what the use case is? Is it inference only or both inference and training?

emfomenk avatar May 30 '18 02:05 emfomenk

@emfomenk TBB is recently introduced into PyTorch as facebook developers consider

  • TBB is a more modern interface and has better interaction with C++11
  • mkl-blas with TBB has better performance than OpenMP, they quote this
  • TBB has msvc support while OpenMP4.0 doesn't so TBB is better for Windows support

however, this is causing great performance drop for CPU, see issue #7903, as a result of resource competition.

Is it possible for TBB and OpenMP to operate peacefully under one process?

mingfeima avatar May 30 '18 02:05 mingfeima

Alas OpenMP RT is not aware of TBB run in parallel.

If OpenMP parallel regions are executed not in parallel with TBB threads (i.e. if you have linear model, and Intel MKL-DNN primitives use OpenMP, while all non-MKL-DNN primitives use TBB) -- you should be fine.

There are some techniques how you can make those two runtimes co-exist. In particular it is highly recommended to set KMP_BLOCKTIME environment variable to a small value (0, 1, or ~20). See this doc.

emfomenk avatar May 30 '18 02:05 emfomenk

@emfomenk thanks so much on the update, i will try that out.

mingfeima avatar May 30 '18 05:05 mingfeima

@mingfeima, it's important to note that the claim that Intel MKL BLAS performance with TBB threading is better than with OpenMP is incorrect. Assuming that a throughput bound function like SGEMM is executed on full system or resources can be statically partitioned (say, threads are pinned to a socket or a few cores) performance with OpenMP will be better. The article you refer to considers very specific scenario when several Intel MKL functions are executed in parallel and OpenMP thread pools spawned from several different threads are competing for compute resources (this is called 'oversubscription'). For that scenario using TBB threading indeed results in better application level performance.

vpirogov avatar May 30 '18 14:05 vpirogov

There were bits of useful information posted in Pytorch thread. Copying these here for interested people to find.

The question of OpenMP and TBB threading composability is discussed in details in Scipy proceedings. The core of recommendation for peaceful coexistence between runtimes suggested in the article is the following:

export KMP_BLOCKTIME=1
export KMP_COMPOSABILITY=mode=exclusive

vpirogov avatar Jun 18 '18 21:06 vpirogov

@emfomenk https://software.intel.com/en-us/articles/using-intel-mkl-and-intel-tbb-in-the-same-application

why can they compile mkl with tbb

huitailang949494 avatar Jul 10 '18 11:07 huitailang949494