From ec59836cc29a70272fd79afdf37bb91d2dd78262 Mon Sep 17 00:00:00 2001 From: Victor Baybekov Date: Fri, 23 Aug 2024 21:05:38 +0200 Subject: [PATCH] WIP Save edits before monorepo reorg --- docs/Magma_CMake.txt | 3 + src/Spreads.BLAS/BLAS.CBLAS.cs | 156 +++++++++++++++++++------- src/Spreads.BLAS/DataTypes/Complex.cs | 80 ++----------- src/Spreads.BLAS/Native/MKL.CBLAS.cs | 34 +++--- src/Spreads.BLAS/Native/MKL.cs | 70 ++++++------ src/Spreads.BLAS/Native/OpenBLAS.cs | 14 +-- src/Spreads.BLAS/Spreads.BLAS.csproj | 4 + tools/BindGen/HighLevelGen.cs | 78 ++++++++----- tools/BindGen/Program.cs | 47 ++++---- 9 files changed, 268 insertions(+), 218 deletions(-) create mode 100644 docs/Magma_CMake.txt diff --git a/docs/Magma_CMake.txt b/docs/Magma_CMake.txt new file mode 100644 index 0000000..429f4b4 --- /dev/null +++ b/docs/Magma_CMake.txt @@ -0,0 +1,3 @@ +cmake .. -G "Ninja" -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_LINKER=lld-link -DCMAKE_BUILD_TYPE=Release -DLAPACK_LIBRARIES="C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.1.216\windows\mkl\lib\intel64_win\mkl_intel_lp64_dll.lib;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.1.216\windows\mkl\lib\intel64_win\mkl_intel_thread_dll.lib;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.1.216\windows\compiler\lib\intel64_win\libiomp5md.lib" -DMKLROOT="C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.1.216\windows\mkl" -DGPU_TARGET="Kepler Maxwell Pascal" + +"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" \ No newline at end of file diff --git a/src/Spreads.BLAS/BLAS.CBLAS.cs b/src/Spreads.BLAS/BLAS.CBLAS.cs index f13e6cc..754a746 100644 --- a/src/Spreads.BLAS/BLAS.CBLAS.cs +++ b/src/Spreads.BLAS/BLAS.CBLAS.cs @@ -2,6 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +using System; using Spreads.Native; // ReSharper disable InconsistentNaming @@ -21,6 +22,17 @@ public static float Sasum(int n, float* x, int incX) return OpenBLAS.CBLAS.Sasum(n, x, incX); } + public static float Sasum(int n, Span x, int incX) + { + fixed (float* xP = x) + { + if (MKL.IsSupoprted) + return MKL.CBLAS.Sasum(n, xP, incX); + + return OpenBLAS.CBLAS.Sasum(n, xP, incX); + } + } + public static double Dasum(int n, double* x, int incX) { if (MKL.IsSupoprted) @@ -40,6 +52,21 @@ public static void Saxpby(int n, float alpha, float* x, int incX, float beta, fl OpenBLAS.CBLAS.Saxpby(n, alpha, x, incX, beta, y, incY); } + public static void Saxpby(int n, float alpha, Span x, int incX, float beta, Span y, int incY) + { + fixed (float* xP = x) + fixed (float* yP = x) + { + if (MKL.IsSupoprted) + { + MKL.CBLAS.Saxpby(n, alpha, xP, incX, beta, yP, incY); + return; + } + + OpenBLAS.CBLAS.Saxpby(n, alpha, xP, incX, beta, yP, incY); + } + } + public static void Daxpby(int n, double alpha, double* x, int incX, double beta, double* y, int incY) { if (MKL.IsSupoprted) @@ -288,7 +315,8 @@ public static float Sdsdot(int n, float sb, float* x, int incX, float* y, int in return OpenBLAS.CBLAS.Sdsdot(n, sb, x, incX, y, incY); } - public static void Sgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, float alpha, float* a, int ldA, float* x, int incX, float beta, float* y, + public static void Sgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, float alpha, float* a, int ldA, float* x, int incX, float beta, + float* y, int incY) { if (MKL.IsSupoprted) @@ -300,7 +328,8 @@ public static void Sgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Sgbmv(matrixLayout, transA, m, n, kL, kU, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Dgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, double alpha, double* a, int ldA, double* x, int incX, double beta, double* y, + public static void Dgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, double alpha, double* a, int ldA, double* x, int incX, double beta, + double* y, int incY) { if (MKL.IsSupoprted) @@ -312,7 +341,8 @@ public static void Dgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Dgbmv(matrixLayout, transA, m, n, kL, kU, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Cgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, + public static void Cgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, + int incX, System.IntPtr beta, System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -324,7 +354,8 @@ public static void Cgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Cgbmv(matrixLayout, transA, m, n, kL, kU, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Zgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, + public static void Zgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int n, int kL, int kU, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, + int incX, System.IntPtr beta, System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -336,7 +367,8 @@ public static void Zgbmv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Zgbmv(matrixLayout, transA, m, n, kL, kU, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Sgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, float alpha, float* a, int ldA, float* b, int ldB, float beta, + public static void Sgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, float alpha, float* a, int ldA, float* b, int ldB, + float beta, float* c, int ldC) { if (MKL.IsSupoprted) @@ -348,7 +380,8 @@ public static void Sgemm(MatrixLayout matrixLayout, Transpose transA, Transpose OpenBLAS.CBLAS.Sgemm(matrixLayout, transA, transB, m, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Dgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, double alpha, double* a, int ldA, double* b, int ldB, double beta, + public static void Dgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, double alpha, double* a, int ldA, double* b, int ldB, + double beta, double* c, int ldC) { if (MKL.IsSupoprted) @@ -360,7 +393,8 @@ public static void Dgemm(MatrixLayout matrixLayout, Transpose transA, Transpose OpenBLAS.CBLAS.Dgemm(matrixLayout, transA, transB, m, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Cgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Cgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, + System.IntPtr b, int ldB, System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -372,7 +406,8 @@ public static void Cgemm(MatrixLayout matrixLayout, Transpose transA, Transpose OpenBLAS.CBLAS.Cgemm(matrixLayout, transA, transB, m, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Zgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Zgemm(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, + System.IntPtr b, int ldB, System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -384,7 +419,8 @@ public static void Zgemm(MatrixLayout matrixLayout, Transpose transA, Transpose OpenBLAS.CBLAS.Zgemm(matrixLayout, transA, transB, m, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Cgemm3m(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Cgemm3m(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, + System.IntPtr b, int ldB, System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -396,7 +432,8 @@ public static void Cgemm3m(MatrixLayout matrixLayout, Transpose transA, Transpos OpenBLAS.CBLAS.Cgemm3m(matrixLayout, transA, transB, m, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Zgemm3m(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Zgemm3m(MatrixLayout matrixLayout, Transpose transA, Transpose transB, int m, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, + System.IntPtr b, int ldB, System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -419,7 +456,8 @@ public static void Sgemv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Sgemv(matrixLayout, transA, m, n, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Dgemv(MatrixLayout matrixLayout, Transpose transA, int m, int n, double alpha, double* a, int ldA, double* x, int incX, double beta, double* y, int incY) + public static void Dgemv(MatrixLayout matrixLayout, Transpose transA, int m, int n, double alpha, double* a, int ldA, double* x, int incX, double beta, double* y, + int incY) { if (MKL.IsSupoprted) { @@ -430,7 +468,8 @@ public static void Dgemv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Dgemv(matrixLayout, transA, m, n, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Cgemv(MatrixLayout matrixLayout, Transpose transA, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, + public static void Cgemv(MatrixLayout matrixLayout, Transpose transA, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, + System.IntPtr beta, System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -442,7 +481,8 @@ public static void Cgemv(MatrixLayout matrixLayout, Transpose transA, int m, int OpenBLAS.CBLAS.Cgemv(matrixLayout, transA, m, n, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Zgemv(MatrixLayout matrixLayout, Transpose transA, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, + public static void Zgemv(MatrixLayout matrixLayout, Transpose transA, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, + System.IntPtr beta, System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -520,7 +560,8 @@ public static void Zgeru(MatrixLayout matrixLayout, int m, int n, System.IntPtr OpenBLAS.CBLAS.Zgeru(matrixLayout, m, n, alpha, x, incX, y, incY, a, ldA); } - public static void Chbmv(MatrixLayout matrixLayout, UpLo uplo, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, + public static void Chbmv(MatrixLayout matrixLayout, UpLo uplo, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, + System.IntPtr beta, System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -532,7 +573,8 @@ public static void Chbmv(MatrixLayout matrixLayout, UpLo uplo, int n, int k, Sys OpenBLAS.CBLAS.Chbmv(matrixLayout, uplo, n, k, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Zhbmv(MatrixLayout matrixLayout, UpLo uplo, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, + public static void Zhbmv(MatrixLayout matrixLayout, UpLo uplo, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, + System.IntPtr beta, System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -544,7 +586,8 @@ public static void Zhbmv(MatrixLayout matrixLayout, UpLo uplo, int n, int k, Sys OpenBLAS.CBLAS.Zhbmv(matrixLayout, uplo, n, k, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Chemm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, System.IntPtr beta, + public static void Chemm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, + System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -556,7 +599,8 @@ public static void Chemm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, i OpenBLAS.CBLAS.Chemm(matrixLayout, side, uplo, m, n, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Zhemm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, System.IntPtr beta, + public static void Zhemm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, + System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -568,7 +612,8 @@ public static void Zhemm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, i OpenBLAS.CBLAS.Zhemm(matrixLayout, side, uplo, m, n, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Chemv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, System.IntPtr y, + public static void Chemv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, + System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -580,7 +625,8 @@ public static void Chemv(MatrixLayout matrixLayout, UpLo uplo, int n, System.Int OpenBLAS.CBLAS.Chemv(matrixLayout, uplo, n, alpha, a, ldA, x, incX, beta, y, incY); } - public static void Zhemv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, System.IntPtr y, + public static void Zhemv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr x, int incX, System.IntPtr beta, + System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -614,7 +660,8 @@ public static void Zher(MatrixLayout matrixLayout, UpLo uplo, int n, double alph OpenBLAS.CBLAS.Zher(matrixLayout, uplo, n, alpha, x, incX, a, ldA); } - public static void Cher2(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr x, int incX, System.IntPtr y, int incY, System.IntPtr a, int ldA) + public static void Cher2(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr x, int incX, System.IntPtr y, int incY, System.IntPtr a, + int ldA) { if (MKL.IsSupoprted) { @@ -625,7 +672,8 @@ public static void Cher2(MatrixLayout matrixLayout, UpLo uplo, int n, System.Int OpenBLAS.CBLAS.Cher2(matrixLayout, uplo, n, alpha, x, incX, y, incY, a, ldA); } - public static void Zher2(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr x, int incX, System.IntPtr y, int incY, System.IntPtr a, int ldA) + public static void Zher2(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr x, int incX, System.IntPtr y, int incY, System.IntPtr a, + int ldA) { if (MKL.IsSupoprted) { @@ -636,7 +684,8 @@ public static void Zher2(MatrixLayout matrixLayout, UpLo uplo, int n, System.Int OpenBLAS.CBLAS.Zher2(matrixLayout, uplo, n, alpha, x, incX, y, incY, a, ldA); } - public static void Cher2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, float beta, + public static void Cher2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, + float beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -648,7 +697,8 @@ public static void Cher2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Cher2k(matrixLayout, uplo, trans, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Zher2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, double beta, + public static void Zher2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, + double beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -660,7 +710,8 @@ public static void Zher2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Zher2k(matrixLayout, uplo, trans, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Cherk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, float alpha, System.IntPtr a, int ldA, float beta, System.IntPtr c, int ldC) + public static void Cherk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, float alpha, System.IntPtr a, int ldA, float beta, System.IntPtr c, + int ldC) { if (MKL.IsSupoprted) { @@ -671,7 +722,8 @@ public static void Cherk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Cherk(matrixLayout, uplo, trans, n, k, alpha, a, ldA, beta, c, ldC); } - public static void Zherk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, double alpha, System.IntPtr a, int ldA, double beta, System.IntPtr c, int ldC) + public static void Zherk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, double alpha, System.IntPtr a, int ldA, double beta, System.IntPtr c, + int ldC) { if (MKL.IsSupoprted) { @@ -682,7 +734,8 @@ public static void Zherk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Zherk(matrixLayout, uplo, trans, n, k, alpha, a, ldA, beta, c, ldC); } - public static void Chpmv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr ap, System.IntPtr x, int incX, System.IntPtr beta, System.IntPtr y, + public static void Chpmv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr ap, System.IntPtr x, int incX, System.IntPtr beta, + System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -694,7 +747,8 @@ public static void Chpmv(MatrixLayout matrixLayout, UpLo uplo, int n, System.Int OpenBLAS.CBLAS.Chpmv(matrixLayout, uplo, n, alpha, ap, x, incX, beta, y, incY); } - public static void Zhpmv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr ap, System.IntPtr x, int incX, System.IntPtr beta, System.IntPtr y, + public static void Zhpmv(MatrixLayout matrixLayout, UpLo uplo, int n, System.IntPtr alpha, System.IntPtr ap, System.IntPtr x, int incX, System.IntPtr beta, + System.IntPtr y, int incY) { if (MKL.IsSupoprted) @@ -1065,7 +1119,8 @@ public static void Zswap(int n, System.IntPtr x, int incX, System.IntPtr y, int OpenBLAS.CBLAS.Zswap(n, x, incX, y, incY); } - public static void Ssymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, float alpha, float* a, int ldA, float* b, int ldB, float beta, float* c, int ldC) + public static void Ssymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, float alpha, float* a, int ldA, float* b, int ldB, float beta, float* c, + int ldC) { if (MKL.IsSupoprted) { @@ -1076,7 +1131,8 @@ public static void Ssymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, i OpenBLAS.CBLAS.Ssymm(matrixLayout, side, uplo, m, n, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Dsymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, double alpha, double* a, int ldA, double* b, int ldB, double beta, double* c, int ldC) + public static void Dsymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, double alpha, double* a, int ldA, double* b, int ldB, double beta, + double* c, int ldC) { if (MKL.IsSupoprted) { @@ -1087,7 +1143,8 @@ public static void Dsymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, i OpenBLAS.CBLAS.Dsymm(matrixLayout, side, uplo, m, n, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Csymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, System.IntPtr beta, + public static void Csymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, + System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -1099,7 +1156,8 @@ public static void Csymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, i OpenBLAS.CBLAS.Csymm(matrixLayout, side, uplo, m, n, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Zsymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, System.IntPtr beta, + public static void Zsymm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, int ldB, + System.IntPtr beta, System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -1177,7 +1235,8 @@ public static void Dsyr2(MatrixLayout matrixLayout, UpLo uplo, int n, double alp OpenBLAS.CBLAS.Dsyr2(matrixLayout, uplo, n, alpha, x, incX, y, incY, a, ldA); } - public static void Ssyr2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, float alpha, float* a, int ldA, float* b, int ldB, float beta, float* c, int ldC) + public static void Ssyr2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, float alpha, float* a, int ldA, float* b, int ldB, float beta, float* c, + int ldC) { if (MKL.IsSupoprted) { @@ -1188,7 +1247,8 @@ public static void Ssyr2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Ssyr2k(matrixLayout, uplo, trans, n, k, alpha, a, ldA, b, ldB, beta, c, ldC); } - public static void Dsyr2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, double alpha, double* a, int ldA, double* b, int ldB, double beta, double* c, + public static void Dsyr2k(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, double alpha, double* a, int ldA, double* b, int ldB, double beta, + double* c, int ldC) { if (MKL.IsSupoprted) @@ -1246,7 +1306,8 @@ public static void Dsyrk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Dsyrk(matrixLayout, uplo, trans, n, k, alpha, a, ldA, beta, c, ldC); } - public static void Csyrk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr beta, System.IntPtr c, + public static void Csyrk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr beta, + System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -1258,7 +1319,8 @@ public static void Csyrk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, OpenBLAS.CBLAS.Csyrk(matrixLayout, uplo, trans, n, k, alpha, a, ldA, beta, c, ldC); } - public static void Zsyrk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr beta, System.IntPtr c, + public static void Zsyrk(MatrixLayout matrixLayout, UpLo uplo, Transpose trans, int n, int k, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr beta, + System.IntPtr c, int ldC) { if (MKL.IsSupoprted) @@ -1446,7 +1508,8 @@ public static void Ztpsv(MatrixLayout matrixLayout, UpLo uplo, Transpose transA, OpenBLAS.CBLAS.Ztpsv(matrixLayout, uplo, transA, diag, n, ap, x, incX); } - public static void Strmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, float alpha, float* a, int ldA, float* b, int ldB) + public static void Strmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, float alpha, float* a, int ldA, float* b, + int ldB) { if (MKL.IsSupoprted) { @@ -1457,7 +1520,8 @@ public static void Strmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, T OpenBLAS.CBLAS.Strmm(matrixLayout, side, uplo, transA, diag, m, n, alpha, a, ldA, b, ldB); } - public static void Dtrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, double alpha, double* a, int ldA, double* b, int ldB) + public static void Dtrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, double alpha, double* a, int ldA, + double* b, int ldB) { if (MKL.IsSupoprted) { @@ -1468,7 +1532,8 @@ public static void Dtrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, T OpenBLAS.CBLAS.Dtrmm(matrixLayout, side, uplo, transA, diag, m, n, alpha, a, ldA, b, ldB); } - public static void Ctrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Ctrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, + int ldA, System.IntPtr b, int ldB) { if (MKL.IsSupoprted) @@ -1480,7 +1545,8 @@ public static void Ctrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, T OpenBLAS.CBLAS.Ctrmm(matrixLayout, side, uplo, transA, diag, m, n, alpha, a, ldA, b, ldB); } - public static void Ztrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Ztrmm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, + int ldA, System.IntPtr b, int ldB) { if (MKL.IsSupoprted) @@ -1536,7 +1602,8 @@ public static void Ztrmv(MatrixLayout matrixLayout, UpLo uplo, Transpose transA, OpenBLAS.CBLAS.Ztrmv(matrixLayout, uplo, transA, diag, n, a, ldA, x, incX); } - public static void Strsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, float alpha, float* a, int ldA, float* b, int ldB) + public static void Strsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, float alpha, float* a, int ldA, float* b, + int ldB) { if (MKL.IsSupoprted) { @@ -1547,7 +1614,8 @@ public static void Strsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, T OpenBLAS.CBLAS.Strsm(matrixLayout, side, uplo, transA, diag, m, n, alpha, a, ldA, b, ldB); } - public static void Dtrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, double alpha, double* a, int ldA, double* b, int ldB) + public static void Dtrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, double alpha, double* a, int ldA, + double* b, int ldB) { if (MKL.IsSupoprted) { @@ -1558,7 +1626,8 @@ public static void Dtrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, T OpenBLAS.CBLAS.Dtrsm(matrixLayout, side, uplo, transA, diag, m, n, alpha, a, ldA, b, ldB); } - public static void Ctrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Ctrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, + int ldA, System.IntPtr b, int ldB) { if (MKL.IsSupoprted) @@ -1570,7 +1639,8 @@ public static void Ctrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, T OpenBLAS.CBLAS.Ctrsm(matrixLayout, side, uplo, transA, diag, m, n, alpha, a, ldA, b, ldB); } - public static void Ztrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, int ldA, System.IntPtr b, + public static void Ztrsm(MatrixLayout matrixLayout, SideCblas side, UpLo uplo, Transpose transA, DiagCblas diag, int m, int n, System.IntPtr alpha, System.IntPtr a, + int ldA, System.IntPtr b, int ldB) { if (MKL.IsSupoprted) diff --git a/src/Spreads.BLAS/DataTypes/Complex.cs b/src/Spreads.BLAS/DataTypes/Complex.cs index f026780..10fb4f6 100644 --- a/src/Spreads.BLAS/DataTypes/Complex.cs +++ b/src/Spreads.BLAS/DataTypes/Complex.cs @@ -3,64 +3,12 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. using System; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Spreads.DataTypes { - [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 8)] - public readonly struct ComplexDouble : IEquatable - { - [FieldOffset(0)] - public readonly double Real; - - [FieldOffset(8)] - public readonly double Imaginary; - - public ComplexDouble(double real, double imaginary) - { - Real = real; - Imaginary = imaginary; - } - - public void Deconstruct(out double real, out double imaginary) - { - real = Real; - imaginary = Imaginary; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ComplexDouble other) - { - return Real.Equals(other.Real) && Imaginary.Equals(other.Imaginary); - } - - public override bool Equals(object obj) - { - return obj is ComplexDouble other && Equals(other); - } - - public override int GetHashCode() - { - unchecked - { - return (Real.GetHashCode() * 397) ^ Imaginary.GetHashCode(); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(ComplexDouble x, ComplexDouble y) - { - return x.Equals(y); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(ComplexDouble x, ComplexDouble y) - { - return !x.Equals(y); - } - } - [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] public readonly struct ComplexFloat : IEquatable { @@ -83,15 +31,9 @@ public void Deconstruct(out float real, out float imaginary) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ComplexFloat other) - { - return Real.Equals(other.Real) && Imaginary.Equals(other.Imaginary); - } + public bool Equals(ComplexFloat other) => Real.Equals(other.Real) && Imaginary.Equals(other.Imaginary); - public override bool Equals(object obj) - { - return obj is ComplexFloat other && Equals(other); - } + public override bool Equals(object obj) => obj is ComplexFloat other && Equals(other); public override int GetHashCode() { @@ -102,15 +44,15 @@ public override int GetHashCode() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(ComplexFloat x, ComplexFloat y) - { - return x.Equals(y); - } + public static bool operator ==(ComplexFloat x, ComplexFloat y) => x.Equals(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(ComplexFloat x, ComplexFloat y) - { - return !x.Equals(y); - } + public static bool operator !=(ComplexFloat x, ComplexFloat y) => !x.Equals(y); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Complex(ComplexFloat value) => new Complex(value.Real, value.Imaginary); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static explicit operator ComplexFloat(Complex value) => new ComplexFloat((float)value.Real, (float)value.Imaginary); } } \ No newline at end of file diff --git a/src/Spreads.BLAS/Native/MKL.CBLAS.cs b/src/Spreads.BLAS/Native/MKL.CBLAS.cs index 1e9a992..dc71134 100644 --- a/src/Spreads.BLAS/Native/MKL.CBLAS.cs +++ b/src/Spreads.BLAS/Native/MKL.CBLAS.cs @@ -573,52 +573,52 @@ public static class CBLAS public static extern void Zher2k(MatrixLayout matrixLayout, UpLoCblas uplo, TransCblas trans, int N, int K, IntPtr alpha, IntPtr A, int lda, IntPtr B, int ldb, double beta, IntPtr C, int ldc); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Simatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Simatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, float alpha, float* AB, ulong lda, ulong ldb); + public static extern void Simatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, float alpha, float* AB, ulong lda, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Dimatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Dimatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, double alpha, double* AB, ulong lda, ulong ldb); + public static extern void Dimatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, double alpha, double* AB, ulong lda, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Cimatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Cimatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, Spreads.DataTypes.ComplexFloat alpha, IntPtr AB, ulong lda, ulong ldb); + public static extern void Cimatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, DataTypes.ComplexFloat alpha, IntPtr AB, ulong lda, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Zimatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Zimatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, IntPtr alpha, IntPtr AB, ulong lda, ulong ldb); + public static extern void Zimatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, IntPtr alpha, IntPtr AB, ulong lda, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Somatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Somatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, float alpha, float* A, ulong lda, float* B, ulong ldb); + public static extern void Somatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, float alpha, float* A, ulong lda, float* B, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Domatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Domatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, double alpha, double* A, ulong lda, double* B, ulong ldb); - + public static extern void Domatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, double alpha, double* A, ulong lda, double* B, ulong ldb); + [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Comatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Comatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, Spreads.DataTypes.ComplexFloat alpha, IntPtr A, ulong lda, IntPtr B, ulong ldb); + public static extern void Comatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, DataTypes.ComplexFloat alpha, IntPtr A, ulong lda, IntPtr B, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Zomatcopy", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Zomatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, IntPtr alpha, IntPtr A, ulong lda, IntPtr B, ulong ldb); + public static extern void Zomatcopy(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, IntPtr alpha, IntPtr A, ulong lda, IntPtr B, ulong ldb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Somatcopy2", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Somatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, float alpha, float* A, ulong lda, ulong stridea, float* B, ulong ldb, ulong strideb); + public static extern void Somatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, float alpha, float* A, ulong lda, ulong stridea, float* B, ulong ldb, ulong strideb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Domatcopy2", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Domatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, double alpha, double* A, ulong lda, ulong stridea, double* B, ulong ldb, ulong strideb); + public static extern void Domatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, double alpha, double* A, ulong lda, ulong stridea, double* B, ulong ldb, ulong strideb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Comatcopy2", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Comatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, DataTypes.ComplexFloat alpha, IntPtr A, ulong lda, ulong stridea, IntPtr B, ulong ldb, ulong strideb); + public static extern void Comatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, DataTypes.ComplexFloat alpha, IntPtr A, ulong lda, ulong stridea, IntPtr B, ulong ldb, ulong strideb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Zomatcopy2", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Zomatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, IntPtr alpha, IntPtr A, ulong lda, ulong stridea, IntPtr B, ulong ldb, ulong strideb); + public static extern void Zomatcopy2(MatrixLayoutChar matrixLayout, TransChar trans, ulong rows, ulong cols, IntPtr alpha, IntPtr A, ulong lda, ulong stridea, IntPtr B, ulong ldb, ulong strideb); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Somatadd", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Somatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, float alpha, float* A, ulong lda, float beta, float* B, ulong ldb, float* C, ulong ldc); + public static extern void Somatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, float alpha, float* A, ulong lda, float beta, float* B, ulong ldb, float* C, ulong ldc); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Domatadd", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Domatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, double alpha, double* A, ulong lda, double beta, double* B, ulong ldb, double* C, ulong ldc); + public static extern void Domatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, double alpha, double* A, ulong lda, double beta, double* B, ulong ldb, double* C, ulong ldc); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Comatadd", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Comatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, DataTypes.ComplexFloat alpha, IntPtr A, ulong lda, Spreads.DataTypes.ComplexFloat beta, IntPtr B, ulong ldb, IntPtr C, ulong ldc); + public static extern void Comatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, DataTypes.ComplexFloat alpha, IntPtr A, ulong lda, Spreads.DataTypes.ComplexFloat beta, IntPtr B, ulong ldb, IntPtr C, ulong ldc); [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", EntryPoint = "MKL_Zomatadd", CallingConvention = CallingConvention.Cdecl)] - internal static extern void Zomatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, IntPtr alpha, IntPtr A, ulong lda, IntPtr beta, IntPtr B, ulong ldb, IntPtr C, ulong ldc); + public static extern void Zomatadd(MatrixLayoutChar matrixLayout, TransChar transa, TransChar transb, ulong rows, ulong cols, IntPtr alpha, IntPtr A, ulong lda, IntPtr beta, IntPtr B, ulong ldb, IntPtr C, ulong ldc); } } } \ No newline at end of file diff --git a/src/Spreads.BLAS/Native/MKL.cs b/src/Spreads.BLAS/Native/MKL.cs index 598068f..05e46b4 100644 --- a/src/Spreads.BLAS/Native/MKL.cs +++ b/src/Spreads.BLAS/Native/MKL.cs @@ -29,103 +29,103 @@ private static bool MklWorks() return false; } - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Version")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Version")] public static extern void GetVersion(System.IntPtr ver); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Version_String")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Version_String")] public static extern void GetVersionString(sbyte* buffer, int len); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Free_Buffers")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Free_Buffers")] public static extern void FreeBuffers(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Thread_Free_Buffers")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Thread_Free_Buffers")] public static extern void ThreadFreeBuffers(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Mem_Stat")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Mem_Stat")] public static extern long MemStat(int* nbuffers); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Peak_Mem_Usage")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Peak_Mem_Usage")] public static extern long PeakMemUsage(int reset); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Cpu_Clocks")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Cpu_Clocks")] public static extern void GetCpuClocks(ulong* _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Cpu_Frequency")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Cpu_Frequency")] public static extern double GetCpuFrequency(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Max_Cpu_Frequency")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Max_Cpu_Frequency")] public static extern double GetMaxCpuFrequency(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Clocks_Frequency")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Clocks_Frequency")] public static extern double GetClocksFrequency(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Num_Threads_Local")] - public static extern int SetNumThreadsLocal(int nth); + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Num_Threads_Local")] + public static extern int SetNumThreadsLocal(int numThreads); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Num_Threads")] - public static extern void SetNumThreads(int nth); + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Num_Threads")] + public static extern void SetNumThreads(int numThreads); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Max_Threads")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Max_Threads")] public static extern int GetMaxThreads(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Num_Stripes")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Num_Stripes")] public static extern void SetNumStripes(int nstripes); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Num_Stripes")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Num_Stripes")] public static extern int GetNumStripes(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Domain_Set_Num_Threads")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Domain_Set_Num_Threads")] public static extern int DomainSetNumThreads(int nth, int MKL_DOMAIN); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Domain_Get_Max_Threads")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Domain_Get_Max_Threads")] public static extern int DomainGetMaxThreads(int MKL_DOMAIN); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Dynamic")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Dynamic")] public static extern void SetDynamic(int bool_MKL_DYNAMIC); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Dynamic")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Get_Dynamic")] public static extern int GetDynamic(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Enable_Instructions")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Enable_Instructions")] public static extern int EnableInstructions(int _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Interface_Layer")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Interface_Layer")] public static extern int SetInterfaceLayer(int code); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Threading_Layer")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Threading_Layer")] public static extern int SetThreadingLayer(int code); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "mkl_set_xerbla")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "mkl_set_xerbla")] public static extern System.IntPtr SetXerbla(System.IntPtr xerbla); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "mkl_set_progress")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "mkl_set_progress")] public static extern System.IntPtr SetProgress(System.IntPtr progress); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_CBWR_Get")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_CBWR_Get")] public static extern int CBWRGet(int _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_CBWR_Set")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_CBWR_Set")] public static extern int CBWRSet(int _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_CBWR_Get_Auto_Branch")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_CBWR_Get_Auto_Branch")] public static extern int CBWRGetAutoBranch(); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Env_Mode")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Env_Mode")] public static extern int SetEnvMode(int _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Verbose")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Verbose")] public static extern int Verbose(int _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Verbose_Output_File")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Verbose_Output_File")] public static extern int VerboseOutputFile(sbyte* _0); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Exit_Handler")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Exit_Handler")] public static extern void SetExitHandler(System.IntPtr h); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Memory_Limit")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Set_Memory_Limit")] public static extern int SetMemoryLimit(int mem_type, ulong limit); - [SuppressUnmanagedCodeSecurity, DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Finalize")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MKL_Finalize")] public static extern void Finalize(); } } \ No newline at end of file diff --git a/src/Spreads.BLAS/Native/OpenBLAS.cs b/src/Spreads.BLAS/Native/OpenBLAS.cs index 0a928b7..e11b2e0 100644 --- a/src/Spreads.BLAS/Native/OpenBLAS.cs +++ b/src/Spreads.BLAS/Native/OpenBLAS.cs @@ -27,22 +27,22 @@ private static bool Init() return false; } - [SuppressUnmanagedCodeSecurity, DllImport("openblas", CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_set_num_threads")] - public static extern void SetNumThreads(int num_threads); + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_set_num_threads")] + public static extern void SetNumThreads(int numThreads); - [SuppressUnmanagedCodeSecurity, DllImport("openblas", CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_num_threads")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_num_threads")] public static extern int GetNumThreads(); - [SuppressUnmanagedCodeSecurity, DllImport("openblas", CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_num_procs")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_num_procs")] public static extern int GetNumProcs(); - [SuppressUnmanagedCodeSecurity, DllImport("openblas", CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_config")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_config")] public static extern sbyte* GetConfig(); - [SuppressUnmanagedCodeSecurity, DllImport("openblas", CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_corename")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_corename")] public static extern sbyte* GetCorename(); - [SuppressUnmanagedCodeSecurity, DllImport("openblas", CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_parallel")] + [SuppressUnmanagedCodeSecurity, DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "openblas_get_parallel")] public static extern int GetParallel(); } } \ No newline at end of file diff --git a/src/Spreads.BLAS/Spreads.BLAS.csproj b/src/Spreads.BLAS/Spreads.BLAS.csproj index 577b81e..7d7a446 100644 --- a/src/Spreads.BLAS/Spreads.BLAS.csproj +++ b/src/Spreads.BLAS/Spreads.BLAS.csproj @@ -31,5 +31,9 @@ / + + + + diff --git a/tools/BindGen/HighLevelGen.cs b/tools/BindGen/HighLevelGen.cs index 2a8aef9..b6a0519 100644 --- a/tools/BindGen/HighLevelGen.cs +++ b/tools/BindGen/HighLevelGen.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Reflection; using System.Text; +using CppSharp.AST; +using Type = System.Type; // ReSharper disable HeapView.BoxingAllocation @@ -12,13 +14,16 @@ namespace BindGen public class HighLevelGen { private readonly string _apiName; + private readonly ASTContext _mklContext; + private readonly ASTContext _obContext; - public HighLevelGen(string apiName) + public HighLevelGen(string apiName, ASTContext mklContext, ASTContext obContext) { _apiName = apiName; - + _mklContext = mklContext; + _obContext = obContext; } - + /// /// Generate high level API for all shared functions and the ones available in OB /// @@ -33,36 +38,59 @@ public void GenForTypes(Type tOb, Type tMk) .ToDictionary(x => x.Name, x => x); var sharedMethods = obMethods.Join(mkMethods, x => x.Key, x => x.Key, - (x, y) => (x, y)) - .Select(t => (t.x.Key, t.x.Value, t.y.Value)) - .OrderBy(t => t.Key.Substring(1)) - .ThenBy(t => - { - var c = t.Key.ToLower()[0]; - switch (c) + (x, y) => (x: x, y)) + .Select<(KeyValuePair x, KeyValuePair y), (string MethodName, MethodInfo obMethodInfo, MethodInfo mklMethodInfo)>(t => + (t.x.Key, t.x.Value, t.y.Value)) + .GroupBy(t => t.MethodName.Substring(1)) + .ToDictionary(x => x.Key, + x => { - case 's': - return 0; - case 'd': - return 1; - case 'c': - return 2; - default: - return 3; + return x.OrderBy(t => + { + var c = t.MethodName.ToLower()[0]; + switch (c) + { + case 's': + return 0; + case 'd': + return 1; + case 'c': + return 2; + default: + return 3; + } + }).ToArray(); } - }) - .ToArray(); + ); + + Directory.CreateDirectory(@"..\..\Generated\HighLevel"); var sb = new StringBuilder(); - - foreach (var sharedMethod in sharedMethods) + foreach (var sharedMethod in sharedMethods.Values.SelectMany(x => x)) { GenMethod(sharedMethod, sb); } - - Directory.CreateDirectory(@"..\..\Generated\HighLevel"); - File.WriteAllText($@"..\..\Generated\HighLevel\{_apiName}.cspart", sb.ToString()); + + var sb2 = new StringBuilder(); + foreach (var (methodFamily, methodInfos) in sharedMethods) + { + GenMethodFamily(methodFamily, methodInfos, sb2); + } + // File.WriteAllText($@"..\..\Generated\HighLevel\{_apiName}2.cspart", sb.ToString()); + + } + + private void GenMethodFamily(string methodFamily, (string MethodName, MethodInfo obMethodInfo, MethodInfo mklMethodInfo)[] methodInfos, StringBuilder sb2) + { + if (methodInfos.Length != 4) + { + Console.WriteLine($"method family is not 4: {methodFamily}"); + foreach (var (methodName, _, _) in methodInfos) + { + Console.WriteLine($"\t {methodName}"); + } + } } private void GenMethod((string methodName, MethodInfo ob, MethodInfo mk) m, StringBuilder sb) diff --git a/tools/BindGen/Program.cs b/tools/BindGen/Program.cs index a66f2b8..cdc567d 100644 --- a/tools/BindGen/Program.cs +++ b/tools/BindGen/Program.cs @@ -23,18 +23,21 @@ public static void Main(string[] args) var mklLibrary = new MklLibrary(); ConsoleDriver.Run(mklLibrary); var mklAst = mklLibrary.AstCtx; - // new HighLevelGen("CBLAS").GenForTypes(typeof(Spreads.Native.OpenBLAS.CBLAS), typeof(Spreads.Native.MKL.CBLAS)); - // new HighLevelGen("LAPACKE").GenForTypes(typeof(Spreads.Native.OpenBLAS.LAPACKE), typeof(Spreads.Native.MKL.LAPACKE)); - ConsoleDriver.Run(new OpenBlasLibrary()); - Console.WriteLine(mklAst); + var openBlasLibrary = new OpenBlasLibrary(); + ConsoleDriver.Run(openBlasLibrary); + var obAst = openBlasLibrary.AstCtx; + + new HighLevelGen("CBLAS", mklAst, obAst).GenForTypes(typeof(Spreads.Native.OpenBLAS.CBLAS), typeof(Spreads.Native.MKL.CBLAS)); + new HighLevelGen("LAPACKE", mklAst, obAst).GenForTypes(typeof(Spreads.Native.OpenBLAS.LAPACKE), typeof(Spreads.Native.MKL.LAPACKE)); + } } public class MklLibrary : ILibrary { - public ASTContext AstCtx { get; set; } - + public ASTContext AstCtx { get; set; } + public void Preprocess(Driver driver, ASTContext ctx) { driver.Context.TypeMaps.TypeMaps.Add("MKL_Complex8", new ComplexFloat()); @@ -73,7 +76,7 @@ public void Preprocess(Driver driver, ASTContext ctx) { fortranFn.ExplicitlyIgnore(); } - + } public void Postprocess(Driver driver, ASTContext ctx) @@ -81,7 +84,6 @@ public void Postprocess(Driver driver, ASTContext ctx) AstCtx = ctx; } - public void Setup(Driver driver) { var options = driver.Options; @@ -91,7 +93,7 @@ public void Setup(Driver driver) options.Verbose = true; options.GenerateSingleCSharpFile = false; options.GenerateFunctionTemplates = false; - + options.DryRun = true; driver.Options.CheckSymbols = false; var module = options.AddModule("mkl_rt"); @@ -101,15 +103,15 @@ public void Setup(Driver driver) module.Headers.Add("mkl_service.h"); module.Headers.Add("mkl_cblas.h"); module.Headers.Add("mkl_lapacke.h"); - + // TODO Add those to Native.MKL module.Headers.Add("mkl_trans.h"); - module.Headers.Add("mkl_vml.h"); - module.Headers.Add("mkl_vsl.h"); - module.Headers.Add("mkl_rci.h"); - + // module.Headers.Add("mkl_vml.h"); + // module.Headers.Add("mkl_vsl.h"); + // module.Headers.Add("mkl_rci.h"); + module.OutputNamespace = "Spreads.Native.MKL"; - + driver.ParserOptions.Verbose = true; } @@ -125,15 +127,15 @@ public void GenerateCode(Driver driver, List outputs) public class OpenBlasLibrary : ILibrary { - public ASTContext AstCtx { get; set; } - + public ASTContext AstCtx { get; set; } + public void Preprocess(Driver driver, ASTContext ctx) { driver.Context.TypeMaps.TypeMaps.Add("openblas_complex_float", new ComplexFloat()); driver.Context.TypeMaps.TypeMaps.Add("openblas_complex_double", new ComplexDouble()); driver.Context.TypeMaps.TypeMaps.Add("lapack_complex_float", new ComplexFloat()); driver.Context.TypeMaps.TypeMaps.Add("lapack_complex_double", new ComplexDouble()); - + driver.Context.TypeMaps.TypeMaps.Add("double _Complex", new ComplexDouble()); driver.Context.TypeMaps.TypeMaps.Add("CBLAS_ORDER", new CBLAS_LAYOUT()); driver.Context.TypeMaps.TypeMaps.Add("CBLAS_TRANSPOSE", new CBLAS_TRANSPOSE()); @@ -160,7 +162,8 @@ public void Setup(Driver driver) options.Verbose = true; options.GenerateSingleCSharpFile = false; options.GenerateFunctionTemplates = false; - + options.DryRun = true; + driver.Options.CheckSymbols = false; var module = options.AddModule("libopenblas"); @@ -206,7 +209,7 @@ public class ComplexDouble : TypeMap public override bool IsIgnored => false; public override bool IsValueType => true; - + public override Type CSharpSignatureType(TypePrinterContext ctx) { return new CustomType("Spreads.DataTypes.ComplexDouble"); @@ -286,7 +289,7 @@ public override Type CSharpSignatureType(TypePrinterContext ctx) public class RemoveFunctionPrefixPass : TranslationUnitPass { private string[] Prefixes = new[] { "cblas_", "LAPACKE_", "MKL_", "openblas_" }; - + public override bool VisitFunctionDecl(Function function) { foreach (string prefix in Prefixes) @@ -297,7 +300,7 @@ public override bool VisitFunctionDecl(Function function) return false; } } - + return true; } }