build libtorch with the same mkl as Matlab
Labels: oncall: binaries, triaged, module: mkl

### 🐛 Describe the bug

after doing a matrix multiplication in mex function, matlab crushes because of different mkl using Matlab and libtorch.
How can I use the same MKL that matlab uses, or somehow make it compatible.

this is the trace that I get.

--------------------------------------------------------------------------------
          Segmentation violation detected at 2022-07-09 20:17:30 +0200
--------------------------------------------------------------------------------

Configuration:
  Crash Decoding           : Disabled - No sandbox or build area path
  Crash Mode               : continue (default)
  Default Encoding         : UTF-8
  Deployed                 : false
  Desktop Environment      : ubuntu:GNOME
  GNU C Library            : 2.27 stable
  Graphics Driver          : Uninitialized hardware 
  Graphics card 1          : 0x10de ( 0x10de ) 0x1e90 Version 495.29.5.0 (0-0-0)
  Graphics card 2          : 0x8086 ( 0x8086 ) 0x3e9b Version 0.0.0.0 (0-0-0)
  Java Version             : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  MATLAB Architecture      : glnxa64
  MATLAB Entitlement ID    : 8786298
  MATLAB Root              : /usr/local/MATLAB/R2022a
  MATLAB Version           : 9.12.0.1975300 (R2022a) Update 3
  OpenGL                   : hardware
  Operating System         : Ubuntu 18.04.6 LTS
  Process ID               : 7612
  Processor ID             : x86 Family 6 Model 158 Stepping 10, GenuineIntel
  Session Key              : d4230444-ddaf-42e5-a573-924e2acf3f37
  Window System            : The X.Org Foundation (12008000), display :1

Fault Count: 6


Abnormal termination:
Segmentation violation

Current Thread: 'MCR 0 interpret' id 139819670337280

Register State (from fault):
  RAX = 0000000000000018  RBX = 0000000000000001
  RCX = 0000002400000050  RDX = 00007f27b8066c60
  RSP = 00007f2a4dc7ef58  RBP = 0000000000000000
  RSI = 0000000000000a80  RDI = 00000000000000c0

   R8 = 00007fb7b8066d40   R9 = 00007f27b8200700
  R10 = 00007f27b8066c00  R11 = 0000006c000000f0
  R12 = 0000000000003e80  R13 = 00000000000000c0
  R14 = 0000000000000000  R15 = 0000000000000a80

  RIP = 00007f27b6123da4  EFL = 0000000000010206

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f27b6123da4        /usr/local/MATLAB/R2022a/bin/glnxa64/mkl.so+63008164 mkl_blas_avx2_sgemm_scopy_down24_ea+00000164


Abnormal termination:
Segmentation violation

Current Thread: 'MCR 0 interpret' id 139812355454720

Register State (from fault):
  RAX = 0000000000000018  RBX = 0000000000000001
  RCX = 0000002400000050  RDX = 00007f27b806ea60
  RSP = 00007f2899c81f58  RBP = 0000000000001f80
  RSI = 0000000000000a80  RDI = 00000000000000c0

   R8 = 00007fb7b806eb40   R9 = 00007f27b87e8700
  R10 = 00007f27b806ea00  R11 = 0000006c000000f0
  R12 = 0000000000003e80  R13 = 00000000000000c0
  R14 = 0000000000000000  R15 = 0000000000000a80

  RIP = 00007f27b6123da4  EFL = 0000000000010206

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f27b6123da4        /usr/local/MATLAB/R2022a/bin/glnxa64/mkl.so+63008164 mkl_blas_avx2_sgemm_scopy_down24_ea+00000164


Abnormal termination:
Segmentation violation

Current Thread: 'MCR 0 interpret' id 139812372449024

Register State (from fault):
  RAX = 0000000000000018  RBX = 0000000000000001
  RCX = 0000002400000050  RDX = 00007f27b8073e60
  RSP = 00007f289acb6ed8  RBP = 0000000000003480
  RSI = 0000000000000a00  RDI = 00000000000000c0

   R8 = 00007fb7b8073f40   R9 = 00007f27b8bd8700
  R10 = 00007f27b8073e00  R11 = 0000006c000000f0
  R12 = 0000000000003e80  R13 = 00000000000000c0
  R14 = 0000000000000000  R15 = 0000000000000a00

  RIP = 00007f27b6123da4  EFL = 0000000000010206

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f27b6123da4        /usr/local/MATLAB/R2022a/bin/glnxa64/mkl.so+63008164 mkl_blas_avx2_sgemm_scopy_down24_ea+00000164


Abnormal termination:
Segmentation violation

Current Thread: 'MCR 0 interpret' id 139812354402048

Register State (from fault):
  RAX = 0000000000000018  RBX = 0000000000000001
  RCX = 0000002400000050  RDX = 00007f27b8071460
  RSP = 00007f2899b80f58  RBP = 0000000000002a00
  RSI = 0000000000000a80  RDI = 00000000000000c0

   R8 = 00007fb7b8071540   R9 = 00007f27b89e0700
  R10 = 00007f27b8071400  R11 = 0000006c000000f0
  R12 = 0000000000003e80  R13 = 00000000000000c0
  R14 = 0000000000000000  R15 = 0000000000000a80

  RIP = 00007f27b6123da4  EFL = 0000000000010206

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f27b6123da4        /usr/local/MATLAB/R2022a/bin/glnxa64/mkl.so+63008164 mkl_blas_avx2_sgemm_scopy_down24_ea+00000164


Abnormal termination:
Segmentation violation

Current Thread: 'MCR 0 interpret' id 139812863497984

Register State (from fault):
  RAX = 0000000000000018  RBX = 0000000000000001
  RCX = 0000002400000050  RDX = 00007f27b806c060
  RSP = 00007f28b8103fd8  RBP = 0000000000001500
  RSI = 0000000000000a80  RDI = 00000000000000c0

   R8 = 00007fb7b806c140   R9 = 00007f27b85f0700
  R10 = 00007f27b806c000  R11 = 0000006c000000f0
  R12 = 0000000000003e80  R13 = 00000000000000c0
  R14 = 0000000000000000  R15 = 0000000000000a80

  RIP = 00007f27b6123da4  EFL = 0000000000010206

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f27b6123da4        /usr/local/MATLAB/R2022a/bin/glnxa64/mkl.so+63008164 mkl_blas_avx2_sgemm_scopy_down24_ea+00000164


Abnormal termination:
Segmentation violation

Current Thread: 'MCR 0 interpret' id 139811983693568

Register State (from fault):
  RAX = 0000000000000018  RBX = 0000000000000001
  RCX = 0000002400000050  RDX = 00007f27b8069660
  RSP = 00007f28839f7fd8  RBP = 0000000000000a80
  RSI = 0000000000000a80  RDI = 00000000000000c0

   R8 = 00007fb7b8069740   R9 = 00007f27b83f8700
  R10 = 00007f27b8069600  R11 = 0000006c000000f0
  R12 = 0000000000003e80  R13 = 00000000000000c0
  R14 = 0000000000000000  R15 = 0000000000000a80

  RIP = 00007f27b6123da4  EFL = 0000000000010206

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f27b6123da4        /usr/local/MATLAB/R2022a/bin/glnxa64/mkl.so+63008164 mkl_blas_avx2_sgemm_scopy_down24_ea+00000164

### Versions

I'm using this version

https://download.pytorch.org/libtorch/cu116/libtorch-cxx11-abi-shared-with-deps-1.12.0%2Bcu116.zip

cc @ezyang @seemethere @malfet