From 720f90cc667029857f381ae2d838df2fd92ccb1d Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Wed, 30 Mar 2011 22:30:49 +0800 Subject: [PATCH] native: reorg'ed and started ACML provider --- src/NativeWrappers/ACML/blas.c | 80 ++ src/NativeWrappers/ACML/lapack.cpp | 923 ++++++++++++++++++ src/NativeWrappers/GotoBlas2/blas.c | 2 +- src/NativeWrappers/GotoBlas2/blas.h | 6 - .../{Common => GotoBlas2}/clapack.h | 0 .../{Common => GotoBlas2}/f2c.h | 0 src/NativeWrappers/GotoBlas2/lapack.h | 1 - src/NativeWrappers/{Common => MKL}/blas.c | 22 +- src/NativeWrappers/MKL/blas.h | 9 - src/NativeWrappers/{Common => MKL}/lapack.cpp | 115 +-- src/NativeWrappers/MKL/vector_functions.c | 17 +- .../Windows/ACMLWrapper/ACMKWrapper.vcxproj | 161 +++ .../ACMLWrapper/ACMKWrapper.vcxproj.filters | 33 + .../GotoBLAS2/GotoBLAS2Wrapper.vcxproj | 5 +- .../GotoBLAS2Wrapper.vcxproj.filters | 7 +- .../Windows/MKL/MKLWrapper.vcxproj | 8 +- .../Windows/MKL/MKLWrapper.vcxproj.filters | 16 +- src/NativeWrappers/Windows/NativeWrappers.sln | 17 +- 18 files changed, 1309 insertions(+), 113 deletions(-) create mode 100644 src/NativeWrappers/ACML/blas.c create mode 100644 src/NativeWrappers/ACML/lapack.cpp delete mode 100644 src/NativeWrappers/GotoBlas2/blas.h rename src/NativeWrappers/{Common => GotoBlas2}/clapack.h (100%) rename src/NativeWrappers/{Common => GotoBlas2}/f2c.h (100%) rename src/NativeWrappers/{Common => MKL}/blas.c (72%) delete mode 100644 src/NativeWrappers/MKL/blas.h rename src/NativeWrappers/{Common => MKL}/lapack.cpp (80%) create mode 100644 src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj create mode 100644 src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj.filters diff --git a/src/NativeWrappers/ACML/blas.c b/src/NativeWrappers/ACML/blas.c new file mode 100644 index 00000000..8086bfbf --- /dev/null +++ b/src/NativeWrappers/ACML/blas.c @@ -0,0 +1,80 @@ +#include "acml.h" +#include "wrapper_common.h" + +enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114}; + +DLLEXPORT void s_axpy(const int n, const float alpha, float x[], float y[]){ + saxpy(n, alpha, x, 1, y, 1); +} + +DLLEXPORT void d_axpy(const int n, const double alpha, double x[], double y[]){ + daxpy(n, alpha, x, 1, y, 1); +} + +DLLEXPORT void c_axpy(const int n, complex alpha, complex x[], complex y[]){ + caxpy(n, &alpha, x, 1, y, 1); +} + +DLLEXPORT void z_axpy(const int n, doublecomplex alpha, doublecomplex x[], doublecomplex y[]){ + zaxpy(n, &alpha, x, 1, y, 1); +} + +DLLEXPORT void s_scale(const int n, const float alpha, float x[]){ + sscal(n, alpha, x, 1); +} + +DLLEXPORT void d_scale(const int n, const double alpha, double x[]){ + dscal(n, alpha, x, 1); +} + +DLLEXPORT void c_scale(const int n, complex alpha, complex x[]){ + cscal(n, &alpha, x, 1); +} + +DLLEXPORT void z_scale(const int n, doublecomplex alpha, doublecomplex x[]){ + zscal(n, &alpha, x, 1); +} + +DLLEXPORT float s_dot_product(const int n, float x[], float y[]){ + return sdot(n, x, 1, y, 1); +} + +DLLEXPORT double d_dot_product(const int n, double x[], double y[]){ + return ddot(n, x, 1, y, 1); +} + +DLLEXPORT complex c_dot_product(const int n, complex x[], complex y[]){ + return cdotu(n, x, 1, y, 1); +} + +DLLEXPORT doublecomplex z_dot_product(int n, doublecomplex x[], doublecomplex y[]){ + return zdotu(n, x, 1, y, 1); +} + +DLLEXPORT void s_matrix_multiply(const enum TRANSPOSE transA, const enum TRANSPOSE transB, const int m, const int n, const int k, float alpha, float x[], float y[], float beta, float c[]){ + int lda = transA == CblasNoTrans ? m : k; + int ldb = transB == CblasNoTrans ? k : n; + + sgemm(transA, transB, m, n, k, alpha, x, lda, y, ldb, beta, c, m); +} + +DLLEXPORT void d_matrix_multiply(const enum TRANSPOSE transA, const enum TRANSPOSE transB, const int m, const int n, const int k, double alpha, double x[], double y[], double beta, double c[]){ + int lda = transA == CblasNoTrans ? m : k; + int ldb = transB == CblasNoTrans ? k : n; + + dgemm(transA, transB, m, n, k, alpha, x, lda, y, ldb, beta, c, m); +} + +DLLEXPORT void c_matrix_multiply(const enum TRANSPOSE transA, const enum TRANSPOSE transB, const int m, const int n, const int k, complex alpha, complex x[], complex y[], complex beta, complex c[]){ + int lda = transA == CblasNoTrans ? m : k; + int ldb = transB == CblasNoTrans ? k : n; + + cgemm(transA, transB, m, n, k, &alpha, x, lda, y, ldb, &beta, c, m); +} + +DLLEXPORT void z_matrix_multiply(const enum TRANSPOSE transA, const enum TRANSPOSE transB, const int m, const int n, const int k, doublecomplex alpha, doublecomplex x[], doublecomplex y[], doublecomplex beta, doublecomplex c[]){ + int lda = transA == CblasNoTrans ? m : k; + int ldb = transB == CblasNoTrans ? k : n; + + zgemm(transA, transB, m, n, k, &alpha, x, lda, y, ldb, &beta, c, m); +} diff --git a/src/NativeWrappers/ACML/lapack.cpp b/src/NativeWrappers/ACML/lapack.cpp new file mode 100644 index 00000000..f62fca8e --- /dev/null +++ b/src/NativeWrappers/ACML/lapack.cpp @@ -0,0 +1,923 @@ +#include "acml.h" +#include "wrapper_common.h" +#include + +extern "C"{ + + DLLEXPORT int s_lu_factor(int m, float a[], int ipiv[]) + { + int info = 0; + sgetrf(m, m, a, m,ipiv,&info); + for(int i = 0; i < m; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int d_lu_factor(int m, double a[], int ipiv[]) + { + int info = 0; + dgetrf(m, m,a, m, ipiv, &info); + for(int i = 0; i < m; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int c_lu_factor(int m, complex a[], int ipiv[]) + { + int info = 0; + cgetrf(m, m, a, m,ipiv, &info); + for(int i = 0; i < m; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int z_lu_factor(int m, doublecomplex a[], int ipiv[]) + { + int info = 0; + zgetrf(m, m, a, m, ipiv, &info); + for(int i = 0; i < m; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int s_lu_inverse(int n, float a[], float work[], int lwork) + { + int* ipiv = new int[n]; + int info = 0; + sgetrf(n, n, a, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + return info; + } + + SGETRI(&n, a, &n, ipiv, work, &lwork, &info); + delete[] ipiv; + return info; + } + + DLLEXPORT int d_lu_inverse(int n, double a[], double work[], int lwork) + { + int* ipiv = new int[n]; + int info = 0; + dgetrf(n, n, a, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + return info; + } + + DGETRI(&n, a, &n, ipiv, work, &lwork, &info); + delete[] ipiv; + return info; + } + + DLLEXPORT int c_lu_inverse(int n, complex a[], complex work[], int lwork) + { + int* ipiv = new int[n]; + int info = 0; + cgetrf(n, n, a, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + return info; + } + + CGETRI(&n, a, &n, ipiv, work, &lwork, &info); + delete[] ipiv; + return info; + } + + DLLEXPORT int z_lu_inverse(int n, doublecomplex a[], doublecomplex work[], int lwork) + { + int* ipiv = new int[n]; + int info = 0; + zgetrf(n, n, a, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + return info; + } + + ZGETRI(&n, a, &n, ipiv, work, &lwork, &info); + delete[] ipiv; + return info; + } + + DLLEXPORT int s_lu_inverse_factored(int n, float a[], int ipiv[], float work[], int lwork) + { + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + int info = 0; + SGETRI(&n, a, &n, ipiv, work, &lwork, &info); + + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int d_lu_inverse_factored(int n, double a[], int ipiv[], double work[], int lwork) + { + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + int info = 0; + DGETRI(&n, a, &n, ipiv, work, &lwork, &info); + + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int c_lu_inverse_factored(int n, complex a[], int ipiv[], complex work[], int lwork) + { + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + int info = 0; + CGETRI(&n, a, &n, ipiv, work, &lwork, &info); + + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int z_lu_inverse_factored(int n, doublecomplex a[], int ipiv[], doublecomplex work[], int lwork) + { + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + int info = 0; + ZGETRI(&n, a, &n, ipiv, work, &lwork, &info); + + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int s_lu_solve_factored(int n, int nrhs, float a[], int ipiv[], float b[]) + { + int info = 0; + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + char trans ='N'; + sgetrs(trans, n, nrhs, a, n, ipiv, b, n, &info); + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int d_lu_solve_factored(int n, int nrhs, double a[], int ipiv[], double b[]) + { + int info = 0; + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + char trans ='N'; + dgetrs(trans, n, nrhs, a, n, ipiv, b, n, &info); + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int c_lu_solve_factored(int n, int nrhs, complex a[], int ipiv[], complex b[]) + { + int info = 0; + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + char trans ='N'; + cgetrs(trans, n, nrhs, a, n, ipiv, b, n, &info); + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int z_lu_solve_factored(int n, int nrhs, doublecomplex a[], int ipiv[], doublecomplex b[]) + { + int info = 0; + int i; + for(i = 0; i < n; ++i ){ + ipiv[i] += 1; + } + + char trans ='N'; + zgetrs(trans, n, nrhs, a, n, ipiv, b, n, &info); + for(i = 0; i < n; ++i ){ + ipiv[i] -= 1; + } + return info; + } + + DLLEXPORT int s_lu_solve(int n, int nrhs, float a[], float b[]) + { + float* clone = new float[n*n]; + std::memcpy(clone, a, n*n*sizeof(float)); + + int* ipiv = new int[n]; + int info = 0; + sgetrf(n, n, clone, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + delete[] clone; + return info; + } + + char trans ='N'; + sgetrs(trans, n, nrhs, clone, n, ipiv, b, n, &info); + delete[] ipiv; + delete[] clone; + return info; + } + + DLLEXPORT int d_lu_solve(int n, int nrhs, double a[], double b[]) + { + double* clone = new double[n*n]; + std::memcpy(clone, a, n*n*sizeof(double)); + + int* ipiv = new int[n]; + int info = 0; + dgetrf(n, n, clone, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + delete[] clone; + return info; + } + + char trans ='N'; + dgetrs(trans, n, nrhs, clone, n, ipiv, b, n, &info); + delete[] ipiv; + delete[] clone; + return info; + } + + DLLEXPORT int c_lu_solve(int n, int nrhs, complex a[], complex b[]) + { + complex* clone = new complex[n*n]; + std::memcpy(clone, a, n*n*sizeof(complex)); + + int* ipiv = new int[n]; + int info = 0; + cgetrf(n, n, clone, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + delete[] clone; + return info; + } + + char trans ='N'; + cgetrs(trans, n, nrhs, clone, n, ipiv, b, n, &info); + delete[] ipiv; + delete[] clone; + return info; + } + + DLLEXPORT int z_lu_solve(int n, int nrhs, doublecomplex a[], doublecomplex b[]) + { + doublecomplex* clone = new doublecomplex[n*n]; + std::memcpy(clone, a, n*n*sizeof(doublecomplex)); + + int* ipiv = new int[n]; + int info = 0; + zgetrf(n, n, clone, n, ipiv, &info); + + if (info != 0){ + delete[] ipiv; + delete[] clone; + return info; + } + + char trans ='N'; + zgetrs(trans, n, nrhs, clone, n, ipiv, b, n, &info); + delete[] ipiv; + delete[] clone; + return info; + } + + DLLEXPORT int s_cholesky_factor(int n, float a[]){ + char uplo = 'L'; + int info = 0; + spotrf(uplo, n, a, n, &info); + for (int i = 0; i < n; ++i) + { + int index = i * n; + for (int j = 0; j < n && i > j; ++j) + { + a[index + j] = 0; + } + } + return info; + } + + DLLEXPORT int d_cholesky_factor(int n, double* a){ + char uplo = 'L'; + int info = 0; + dpotrf(uplo, n, a, n, &info); + for (int i = 0; i < n; ++i) + { + int index = i * n; + for (int j = 0; j < n && i > j; ++j) + { + a[index + j] = 0; + } + } + return info; + } + + DLLEXPORT int c_cholesky_factor(int n, complex a[]){ + char uplo = 'L'; + int info = 0; + complex zero = {0.0f, 0.0f}; + cpotrf(uplo, n, a, n, &info); + for (int i = 0; i < n; ++i) + { + int index = i * n; + for (int j = 0; j < n && i > j; ++j) + { + a[index + j] = zero; + } + } + return info; + } + + DLLEXPORT int z_cholesky_factor(int n, doublecomplex a[]){ + char uplo = 'L'; + int info = 0; + doublecomplex zero = {0.0, 0.0}; + zpotrf(uplo, n, a, n, &info); + for (int i = 0; i < n; ++i) + { + int index = i * n; + for (int j = 0; j < n && i > j; ++j) + { + a[index + j] = zero; + } + } + return info; + } + + DLLEXPORT int s_cholesky_solve(int n, int nrhs, float a[], float b[]) + { + float* clone = new float[n*n]; + std::memcpy(clone, a, n*n*sizeof(float)); + char uplo = 'L'; + int info = 0; + spotrf(uplo, n, clone, n, &info); + + if (info != 0){ + delete[] clone; + return info; + } + + spotrs(uplo, n, nrhs, clone, n, b, n, &info); + return info; + } + + DLLEXPORT int d_cholesky_solve(int n, int nrhs, double a[], double b[]) + { + double* clone = new double[n*n]; + std::memcpy(clone, a, n*n*sizeof(double)); + char uplo = 'L'; + int info = 0; + dpotrf(uplo, n, clone, n, &info); + + if (info != 0){ + delete[] clone; + return info; + } + + dpotrs(uplo, n, nrhs, clone, n, b, n, &info); + return info; + } + + DLLEXPORT int c_cholesky_solve(int n, int nrhs, complex a[], complex b[]) + { + complex* clone = new complex[n*n]; + std::memcpy(clone, a, n*n*sizeof(complex)); + char uplo = 'L'; + int info = 0; + cpotrf(uplo, n, clone, n, &info); + + if (info != 0){ + delete[] clone; + return info; + } + + cpotrs(uplo, n, nrhs, clone, n, b, n, &info); + return info; + } + + DLLEXPORT int z_cholesky_solve(int n, int nrhs, doublecomplex a[], doublecomplex b[]) + { + doublecomplex* clone = new doublecomplex[n*n]; + std::memcpy(clone, a, n*n*sizeof(doublecomplex)); + char uplo = 'L'; + int info = 0; + zpotrf(uplo, n, clone, n, &info); + + if (info != 0){ + delete[] clone; + return info; + } + + zpotrs(uplo, n, nrhs, clone, n, b, n, &info); + return info; + } + + DLLEXPORT int s_cholesky_solve_factored(int n, int nrhs, float a[], float b[]) + { + char uplo = 'L'; + int info = 0; + spotrs(uplo, n, nrhs, a, n, b, n, &info); + return info; + } + + DLLEXPORT int d_cholesky_solve_factored(int n, int nrhs, double a[], double b[]) + { + char uplo = 'L'; + int info = 0; + dpotrs(uplo, n, nrhs, a, n, b, n, &info); + return info; + } + + DLLEXPORT int c_cholesky_solve_factored(int n, int nrhs, complex a[], complex b[]) + { + char uplo = 'L'; + int info = 0; + cpotrs(uplo, n, nrhs, a, n, b, n, &info); + return info; + } + + DLLEXPORT int z_cholesky_solve_factored(int n, int nrhs, doublecomplex a[], doublecomplex b[]) + { + char uplo = 'L'; + int info = 0; + zpotrs(uplo, n, nrhs, a, n, b, n, &info); + return info; + } + + DLLEXPORT int s_qr_factor(int m, int n, float r[], float tau[], float q[], float work[], int len) + { + int info = 0; + SGEQRF(&m, &n, r, &m, tau, work, &len, &info); + + for (int i = 0; i < m; ++i) + { + for (int j = 0; j < m && j < n; ++j) + { + if (i > j) + { + q[j * m + i] = r[j * m + i]; + } + } + } + + //compute the q elements explicitly + if (m <= n) + { + SORGQR(&m, &m, &m, q, &m, tau, work, &len, &info); + } + else + { + SORGQR(&m, &n, &n, q, &m, tau, work, &len, &info); + } + + return info; + } + + DLLEXPORT int d_qr_factor(int m, int n, double r[], double tau[], double q[], double work[], int len) + { + int info = 0; + DGEQRF(&m, &n, r, &m, tau, work, &len, &info); + + for (int i = 0; i < m; ++i) + { + for (int j = 0; j < m && j < n; ++j) + { + if (i > j) + { + q[j * m + i] = r[j * m + i]; + } + } + } + + //compute the q elements explicitly + if (m <= n) + { + DORGQR(&m, &m, &m, q, &m, tau, work, &len, &info); + } + else + { + DORGQR(&m, &n, &n, q, &m, tau, work, &len, &info); + } + + return info; + } + + DLLEXPORT int c_qr_factor(int m, int n, complex r[], complex tau[], complex q[], complex work[], int len) + { + int info = 0; + CGEQRF(&m, &n, r, &m, tau, work, &len, &info); + + for (int i = 0; i < m; ++i) + { + for (int j = 0; j < m && j < n; ++j) + { + if (i > j) + { + q[j * m + i] = r[j * m + i]; + } + } + } + + //compute the q elements explicitly + if (m <= n) + { + CUNGQR(&m, &m, &m, q, &m, tau, work, &len, &info); + } + else + { + CUNGQR(&m, &n, &n, q, &m, tau, work, &len, &info); + } + + return info; + } + + DLLEXPORT int z_qr_factor(int m, int n, doublecomplex r[], doublecomplex tau[], doublecomplex q[], doublecomplex work[], int len) + { + int info = 0; + ZGEQRF(&m, &n, r, &m, tau, work, &len, &info); + + for (int i = 0; i < m; ++i) + { + for (int j = 0; j < m && j < n; ++j) + { + if (i > j) + { + q[j * m + i] = r[j * m + i]; + } + } + } + + //compute the q elements explicitly + if (m <= n) + { + ZUNGQR(&m, &m, &m, q, &m, tau, work, &len, &info); + } + else + { + ZUNGQR(&m, &n, &n, q, &m, tau, work, &len, &info); + } + + return info; + } + + DLLEXPORT int s_qr_solve(int m, int n, int bn, float r[], float b[], float x[], float work[], int len) + { + int info = 0; + float* clone_r = new float[m*n]; + std::memcpy(clone_r, r, m*n*sizeof(float)); + + float* tau = new float[std::max(1, std::min(m,n))]; + SGEQRF(&m, &n, clone_r, &m, tau, work, &len, &info); + + if (info != 0) + { + delete[] clone_r; + delete[] tau; + return info; + } + + float* clone_b = new float[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(float)); + + char side ='L'; + char tran = 'T'; + char upper = 'U'; + char not = 'N'; + SORMQR(&side, &tran, &m, &bn, &n, clone_r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + strsm(side, upper, not, not, n, bn, 1.0, clone_r, m, clone_b, m); + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_r; + delete[] tau; + delete[] clone_b; + return info; + } + + DLLEXPORT int d_qr_solve(int m, int n, int bn, double r[], double b[], double x[], double work[], int len) + { + int info = 0; + double* clone_r = new double[m*n]; + std::memcpy(clone_r, r, m*n*sizeof(double)); + + double* tau = new double[std::max(1, std::min(m,n))]; + DGEQRF(&m, &n, clone_r, &m, tau, work, &len, &info); + + if (info != 0) + { + delete[] clone_r; + delete[] tau; + return info; + } + + double* clone_b = new double[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(double)); + + char side ='L'; + char tran = 'T'; + char upper = 'U'; + char not = 'N'; + + DORMQR(&side, &tran, &m, &bn, &n, clone_r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + dtrsm(side, upper, not, not, n, bn, 1.0, clone_r, m, clone_b, m); + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_b; + delete[] tau; + delete[] clone_r; + return info; + } + + DLLEXPORT int c_qr_solve(int m, int n, int bn, complex r[], complex b[], complex x[], complex work[], int len) + { + int info = 0; + complex* clone_r = new complex[m*n]; + std::memcpy(clone_r, r, m*n*sizeof(complex)); + + complex* tau = new complex[std::min(m,n)]; + CGEQRF(&m, &n, clone_r, &m, tau, work, &len, &info); + + if (info != 0) + { + delete[] clone_r; + delete[] tau; + return info; + } + + char side ='L'; + char tran = 'C'; + char upper = 'U'; + char not = 'N'; + + complex* clone_b = new complex[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(complex)); + + CUNMQR(&side, &tran, &m, &bn, &n, clone_r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + complex one = {1.0, 0.0}; + ctrsm(side, upper, not, not, n, bn, &one, clone_r, m, clone_b, m); + + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_r; + delete[] tau; + delete[] clone_b; + return info; + } + + DLLEXPORT int z_qr_solve(int m, int n, int bn, doublecomplex r[], doublecomplex b[], doublecomplex x[], doublecomplex work[], int len) + { + int info = 0; + doublecomplex* clone_r = new doublecomplex[m*n]; + std::memcpy(clone_r, r, m*n*sizeof(doublecomplex)); + + doublecomplex* tau = new doublecomplex[std::min(m,n)]; + ZGEQRF(&m, &n, clone_r, &m, tau, work, &len, &info); + + if (info != 0) + { + delete[] clone_r; + delete[] tau; + return info; + } + + char side ='L'; + char tran = 'C'; + char upper = 'U'; + char not = 'N'; + + doublecomplex* clone_b = new doublecomplex[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(doublecomplex)); + + ZUNMQR(&side, &tran, &m, &bn, &n, clone_r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + doublecomplex one = {1.0, 0.0}; + ztrsm(side, upper, not, not, n, bn, &one, clone_r, m, clone_b, m); + + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_r; + delete[] tau; + delete[] clone_b; + return info; + } + + DLLEXPORT int s_qr_solve_factored(int m, int n, int bn, float r[], float b[], float tau[], float x[], float work[], int len) + { + char side ='L'; + char tran = 'T'; + char upper = 'U'; + char not = 'N'; + int info = 0; + + float* clone_b = new float[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(float)); + + SORMQR(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + strsm(side, upper, not, not, n, bn, 1.0, r, m, clone_b, m); + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_b; + return info; + } + + DLLEXPORT int d_qr_solve_factored(int m, int n, int bn, double r[], double b[], double tau[], double x[], double work[], int len) + { + char side ='L'; + char tran = 'T'; + char upper = 'U'; + char not = 'N'; + int info = 0; + + double* clone_b = new double[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(double)); + + DORMQR(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + dtrsm(side, upper, not, not, n, bn, 1.0, r, m, clone_b, m); + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_b; + return info; + } + + DLLEXPORT int c_qr_solve_factored(int m, int n, int bn, complex r[], complex b[], complex tau[], complex x[], complex work[], int len) + { + char side ='L'; + char tran = 'C'; + char upper = 'U'; + char not = 'N'; + int info = 0; + + complex* clone_b = new complex[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(complex)); + + CUNMQR(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + complex one = {1.0f, 0.0f}; + ctrsm(side, upper, not, not, n, bn, &one, r, m, clone_b, m); + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_b; + return info; + } + + DLLEXPORT int z_qr_solve_factored(int m, int n, int bn, doublecomplex r[], doublecomplex b[], doublecomplex tau[], doublecomplex x[], doublecomplex work[], int len) + { + char side ='L'; + char tran = 'C'; + char upper = 'U'; + char not = 'N'; + int info = 0; + + doublecomplex* clone_b = new doublecomplex[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(doublecomplex)); + + ZUNMQR(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info, 1, 1); + doublecomplex one = {1.0, 0.0}; + ztrsm(side, upper, not, not, n, bn, &one, r, m, clone_b, m); + + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < bn; ++j) + { + x[j * n + i] = clone_b[j * m + i]; + } + } + + delete[] clone_b; + return info; + } + + DLLEXPORT int s_svd_factor(bool compute_vectors, int m, int n, float a[], float s[], float u[], float v[], float work[], int len) + { + int info = 0; + char job = compute_vectors ? 'A' : 'N'; + SGESVD(&job, &job, &m, &n, a, &m, s, u, &m, v, &n, work, &len, &info, 1, 1); + return info; + } + + DLLEXPORT int d_svd_factor(bool compute_vectors, int m, int n, double a[], double s[], double u[], double v[], double work[], int len) + { + int info = 0; + char job = compute_vectors ? 'A' : 'N'; + DGESVD(&job, &job, &m, &n, a, &m, s, u, &m, v, &n, work, &len, &info, 1, 1); + return info; + } + + DLLEXPORT int c_svd_factor(bool compute_vectors, int m, int n, complex a[], complex s[], complex u[], complex v[], complex work[], int len) + { + int info = 0; + int dim_s = std::min(m,n); + float* rwork = new float[5 * dim_s]; + float* s_local = new float[dim_s]; + char job = compute_vectors ? 'A' : 'N'; + CGESVD(&job, &job, &m, &n, a, &m, s_local, u, &m, v, &n, work, &len, rwork, &info, 1 ,1); + + for(int index = 0; index < dim_s; ++index){ + complex value = {s_local[index], 0.0f}; + s[index] = value; + } + + delete[] rwork; + delete[] s_local; + return info; + } + + DLLEXPORT int z_svd_factor(bool compute_vectors, int m, int n, doublecomplex a[], doublecomplex s[], doublecomplex u[], doublecomplex v[], doublecomplex work[], int len) + { + int info = 0; + int dim_s = std::min(m,n); + double* rwork = new double[5 * std::min(m, n)]; + double* s_local = new double[dim_s]; + char job = compute_vectors ? 'A' : 'N'; + ZGESVD(&job, &job, &m, &n, a, &m, s_local, u, &m, v, &n, work, &len, rwork, &info, 1, 1); + + for(int index = 0; index < dim_s; ++index){ + doublecomplex value = {s_local[index], 0.0f}; + s[index] = value; + } + + delete[] rwork; + delete[] s_local; + return info; + } +} \ No newline at end of file diff --git a/src/NativeWrappers/GotoBlas2/blas.c b/src/NativeWrappers/GotoBlas2/blas.c index cc5f48c0..f635d6ce 100644 --- a/src/NativeWrappers/GotoBlas2/blas.c +++ b/src/NativeWrappers/GotoBlas2/blas.c @@ -1,4 +1,4 @@ -#include "blas.h" +#include "cblas.h" #include "wrapper_common.h" #include DLLEXPORT void s_axpy(int n, float alpha, float x[], float y[]){ diff --git a/src/NativeWrappers/GotoBlas2/blas.h b/src/NativeWrappers/GotoBlas2/blas.h deleted file mode 100644 index aace12d8..00000000 --- a/src/NativeWrappers/GotoBlas2/blas.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef BLAS_H -#define BLAS_H - -#include "cblas.h" - -#endif diff --git a/src/NativeWrappers/Common/clapack.h b/src/NativeWrappers/GotoBlas2/clapack.h similarity index 100% rename from src/NativeWrappers/Common/clapack.h rename to src/NativeWrappers/GotoBlas2/clapack.h diff --git a/src/NativeWrappers/Common/f2c.h b/src/NativeWrappers/GotoBlas2/f2c.h similarity index 100% rename from src/NativeWrappers/Common/f2c.h rename to src/NativeWrappers/GotoBlas2/f2c.h diff --git a/src/NativeWrappers/GotoBlas2/lapack.h b/src/NativeWrappers/GotoBlas2/lapack.h index 3dbcb9c8..d9186ae6 100644 --- a/src/NativeWrappers/GotoBlas2/lapack.h +++ b/src/NativeWrappers/GotoBlas2/lapack.h @@ -1,7 +1,6 @@ #ifndef LAPACK_H #define LAPACK_H - extern "C"{ #include "f2c.h" #include "clapack.h" diff --git a/src/NativeWrappers/Common/blas.c b/src/NativeWrappers/MKL/blas.c similarity index 72% rename from src/NativeWrappers/Common/blas.c rename to src/NativeWrappers/MKL/blas.c index 55f89385..8399fc3a 100644 --- a/src/NativeWrappers/Common/blas.c +++ b/src/NativeWrappers/MKL/blas.c @@ -1,4 +1,4 @@ -#include "blas.h" +#include "mkl_cblas.h" #include "wrapper_common.h" DLLEXPORT void s_axpy(const int n, const float alpha, const float x[], float y[]){ @@ -9,11 +9,11 @@ DLLEXPORT void d_axpy(const int n, const double alpha, const double x[], double cblas_daxpy(n, alpha, x, 1, y, 1); } -DLLEXPORT void c_axpy(const int n, const Complex8 alpha, const Complex8 x[], Complex8 y[]){ +DLLEXPORT void c_axpy(const int n, const MKL_Complex8 alpha, const MKL_Complex8 x[], MKL_Complex8 y[]){ cblas_caxpy(n, &alpha, x, 1, y, 1); } -DLLEXPORT void z_axpy(const int n, const Complex16 alpha, const Complex16 x[], Complex16 y[]){ +DLLEXPORT void z_axpy(const int n, const MKL_Complex16 alpha, const MKL_Complex16 x[], MKL_Complex16 y[]){ cblas_zaxpy(n, &alpha, x, 1, y, 1); } @@ -25,11 +25,11 @@ DLLEXPORT void d_scale(const int n, const double alpha, double x[]){ cblas_dscal(n, alpha, x, 1); } -DLLEXPORT void c_scale(const int n, const Complex8 alpha, Complex8 x[]){ +DLLEXPORT void c_scale(const int n, const MKL_Complex8 alpha, MKL_Complex8 x[]){ cblas_cscal(n, &alpha, x, 1); } -DLLEXPORT void z_scale(const int n, const Complex16 alpha, Complex16 x[]){ +DLLEXPORT void z_scale(const int n, const MKL_Complex16 alpha, MKL_Complex16 x[]){ cblas_zscal(n, &alpha, x, 1); } @@ -41,14 +41,14 @@ DLLEXPORT double d_dot_product(const int n, const double x[], const double y[]){ return cblas_ddot(n, x, 1, y, 1); } -DLLEXPORT Complex8 c_dot_product(const int n, const Complex8 x[], const Complex8 y[]){ - Complex8 ret; +DLLEXPORT MKL_Complex8 c_dot_product(const int n, const MKL_Complex8 x[], const MKL_Complex8 y[]){ + MKL_Complex8 ret; cblas_cdotu_sub(n, x, 1, y, 1, &ret); return ret; } -DLLEXPORT Complex16 z_dot_product(const int n, const Complex16 x[], const Complex16 y[]){ - Complex16 ret; +DLLEXPORT MKL_Complex16 z_dot_product(const int n, const MKL_Complex16 x[], const MKL_Complex16 y[]){ + MKL_Complex16 ret; cblas_zdotu_sub(n, x, 1, y, 1, &ret); return ret; } @@ -67,14 +67,14 @@ DLLEXPORT void d_matrix_multiply(const enum CBLAS_TRANSPOSE transA, const enum C cblas_dgemm(CblasColMajor, transA, transB, m, n, k, alpha, x, lda, y, ldb, beta, c, m); } -DLLEXPORT void c_matrix_multiply(const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const int m, const int n, const int k, const Complex8 alpha, const Complex8 x[], const Complex8 y[], const Complex8 beta, Complex8 c[]){ +DLLEXPORT void c_matrix_multiply(const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const int m, const int n, const int k, const MKL_Complex8 alpha, const MKL_Complex8 x[], const MKL_Complex8 y[], const MKL_Complex8 beta, MKL_Complex8 c[]){ int lda = transA == CblasNoTrans ? m : k; int ldb = transB == CblasNoTrans ? k : n; cblas_cgemm(CblasColMajor, transA, transB, m, n, k, &alpha, x, lda, y, ldb, &beta, c, m); } -DLLEXPORT void z_matrix_multiply(const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const int m, const int n, const int k, const Complex16 alpha, const Complex16 x[], const Complex16 y[], const Complex16 beta, Complex16 c[]){ +DLLEXPORT void z_matrix_multiply(const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const int m, const int n, const int k, const MKL_Complex16 alpha, const MKL_Complex16 x[], const MKL_Complex16 y[], const MKL_Complex16 beta, MKL_Complex16 c[]){ int lda = transA == CblasNoTrans ? m : k; int ldb = transB == CblasNoTrans ? k : n; diff --git a/src/NativeWrappers/MKL/blas.h b/src/NativeWrappers/MKL/blas.h deleted file mode 100644 index 05d46b6c..00000000 --- a/src/NativeWrappers/MKL/blas.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef BLAS_H -#define BLAS_H - -#include "mkl_cblas.h" - -typedef MKL_Complex8 Complex8; -typedef MKL_Complex16 Complex16; - -#endif diff --git a/src/NativeWrappers/Common/lapack.cpp b/src/NativeWrappers/MKL/lapack.cpp similarity index 80% rename from src/NativeWrappers/Common/lapack.cpp rename to src/NativeWrappers/MKL/lapack.cpp index 922538ef..65df68ce 100644 --- a/src/NativeWrappers/Common/lapack.cpp +++ b/src/NativeWrappers/MKL/lapack.cpp @@ -1,4 +1,5 @@ -#include "lapack.h" +#include "mkl_lapack.h" +#include "mkl_cblas.h" #include "wrapper_common.h" #include @@ -13,12 +14,12 @@ extern "C"{ return dlange_(&norm, &m, &n, a, &m, work); } - DLLEXPORT float c_matrix_norm(char norm, int m, int n, Complex8 a[], float work[]) + DLLEXPORT float c_matrix_norm(char norm, int m, int n, MKL_Complex8 a[], float work[]) { return clange_(&norm, &m, &n, a, &m, work); } - DLLEXPORT double z_matrix_norm(char norm, int m, int n, Complex16 a[], double work[]) + DLLEXPORT double z_matrix_norm(char norm, int m, int n, MKL_Complex16 a[], double work[]) { return zlange_(&norm, &m, &n, a, &m, work); } @@ -43,7 +44,7 @@ extern "C"{ return info; } - DLLEXPORT int c_lu_factor(int m, Complex8 a[], int ipiv[]) + DLLEXPORT int c_lu_factor(int m, MKL_Complex8 a[], int ipiv[]) { int info = 0; cgetrf_(&m,&m,a,&m,ipiv,&info); @@ -53,7 +54,7 @@ extern "C"{ return info; } - DLLEXPORT int z_lu_factor(int m, Complex16 a[], int ipiv[]) + DLLEXPORT int z_lu_factor(int m, MKL_Complex16 a[], int ipiv[]) { int info = 0; zgetrf_(&m,&m,a,&m,ipiv,&info); @@ -95,7 +96,7 @@ extern "C"{ return info; } - DLLEXPORT int c_lu_inverse(int n, Complex8 a[], Complex8 work[], int lwork) + DLLEXPORT int c_lu_inverse(int n, MKL_Complex8 a[], MKL_Complex8 work[], int lwork) { int* ipiv = new int[n]; int info = 0; @@ -111,7 +112,7 @@ extern "C"{ return info; } - DLLEXPORT int z_lu_inverse(int n, Complex16 a[], Complex16 work[], int lwork) + DLLEXPORT int z_lu_inverse(int n, MKL_Complex16 a[], MKL_Complex16 work[], int lwork) { int* ipiv = new int[n]; int info = 0; @@ -158,7 +159,7 @@ extern "C"{ return info; } - DLLEXPORT int c_lu_inverse_factored(int n, Complex8 a[], int ipiv[], Complex8 work[], int lwork) + DLLEXPORT int c_lu_inverse_factored(int n, MKL_Complex8 a[], int ipiv[], MKL_Complex8 work[], int lwork) { int i; for(i = 0; i < n; ++i ){ @@ -174,7 +175,7 @@ extern "C"{ return info; } - DLLEXPORT int z_lu_inverse_factored(int n, Complex16 a[], int ipiv[], Complex16 work[], int lwork) + DLLEXPORT int z_lu_inverse_factored(int n, MKL_Complex16 a[], int ipiv[], MKL_Complex16 work[], int lwork) { int i; for(i = 0; i < n; ++i ){ @@ -222,7 +223,7 @@ extern "C"{ return info; } - DLLEXPORT int c_lu_solve_factored(int n, int nrhs, Complex8 a[], int ipiv[], Complex8 b[]) + DLLEXPORT int c_lu_solve_factored(int n, int nrhs, MKL_Complex8 a[], int ipiv[], MKL_Complex8 b[]) { int info = 0; int i; @@ -238,7 +239,7 @@ extern "C"{ return info; } - DLLEXPORT int z_lu_solve_factored(int n, int nrhs, Complex16 a[], int ipiv[], Complex16 b[]) + DLLEXPORT int z_lu_solve_factored(int n, int nrhs, MKL_Complex16 a[], int ipiv[], MKL_Complex16 b[]) { int info = 0; int i; @@ -298,10 +299,10 @@ extern "C"{ return info; } - DLLEXPORT int c_lu_solve(int n, int nrhs, Complex8 a[], Complex8 b[]) + DLLEXPORT int c_lu_solve(int n, int nrhs, MKL_Complex8 a[], MKL_Complex8 b[]) { - Complex8* clone = new Complex8[n*n]; - std::memcpy(clone, a, n*n*sizeof(Complex8)); + MKL_Complex8* clone = new MKL_Complex8[n*n]; + std::memcpy(clone, a, n*n*sizeof(MKL_Complex8)); int* ipiv = new int[n]; int info = 0; @@ -320,10 +321,10 @@ extern "C"{ return info; } - DLLEXPORT int z_lu_solve(int n, int nrhs, Complex16 a[], Complex16 b[]) + DLLEXPORT int z_lu_solve(int n, int nrhs, MKL_Complex16 a[], MKL_Complex16 b[]) { - Complex16* clone = new Complex16[n*n]; - std::memcpy(clone, a, n*n*sizeof(Complex16)); + MKL_Complex16* clone = new MKL_Complex16[n*n]; + std::memcpy(clone, a, n*n*sizeof(MKL_Complex16)); int* ipiv = new int[n]; int info = 0; @@ -372,10 +373,10 @@ extern "C"{ return info; } - DLLEXPORT int c_cholesky_factor(int n, Complex8 a[]){ + DLLEXPORT int c_cholesky_factor(int n, MKL_Complex8 a[]){ char uplo = 'L'; int info = 0; - Complex8 zero = {0.0f, 0.0f}; + MKL_Complex8 zero = {0.0f, 0.0f}; cpotrf_(&uplo, &n, a, &n, &info); for (int i = 0; i < n; ++i) { @@ -388,10 +389,10 @@ extern "C"{ return info; } - DLLEXPORT int z_cholesky_factor(int n, Complex16 a[]){ + DLLEXPORT int z_cholesky_factor(int n, MKL_Complex16 a[]){ char uplo = 'L'; int info = 0; - Complex16 zero = {0.0, 0.0}; + MKL_Complex16 zero = {0.0, 0.0}; zpotrf_(&uplo, &n, a, &n, &info); for (int i = 0; i < n; ++i) { @@ -438,10 +439,10 @@ extern "C"{ return info; } - DLLEXPORT int c_cholesky_solve(int n, int nrhs, Complex8 a[], Complex8 b[]) + DLLEXPORT int c_cholesky_solve(int n, int nrhs, MKL_Complex8 a[], MKL_Complex8 b[]) { - Complex8* clone = new Complex8[n*n]; - std::memcpy(clone, a, n*n*sizeof(Complex8)); + MKL_Complex8* clone = new MKL_Complex8[n*n]; + std::memcpy(clone, a, n*n*sizeof(MKL_Complex8)); char uplo = 'L'; int info = 0; cpotrf_(&uplo, &n, clone, &n, &info); @@ -455,10 +456,10 @@ extern "C"{ return info; } - DLLEXPORT int z_cholesky_solve(int n, int nrhs, Complex16 a[], Complex16 b[]) + DLLEXPORT int z_cholesky_solve(int n, int nrhs, MKL_Complex16 a[], MKL_Complex16 b[]) { - Complex16* clone = new Complex16[n*n]; - std::memcpy(clone, a, n*n*sizeof(Complex16)); + MKL_Complex16* clone = new MKL_Complex16[n*n]; + std::memcpy(clone, a, n*n*sizeof(MKL_Complex16)); char uplo = 'L'; int info = 0; zpotrf_(&uplo, &n, clone, &n, &info); @@ -488,7 +489,7 @@ extern "C"{ return info; } - DLLEXPORT int c_cholesky_solve_factored(int n, int nrhs, Complex8 a[], Complex8 b[]) + DLLEXPORT int c_cholesky_solve_factored(int n, int nrhs, MKL_Complex8 a[], MKL_Complex8 b[]) { char uplo = 'L'; int info = 0; @@ -496,7 +497,7 @@ extern "C"{ return info; } - DLLEXPORT int z_cholesky_solve_factored(int n, int nrhs, Complex16 a[], Complex16 b[]) + DLLEXPORT int z_cholesky_solve_factored(int n, int nrhs, MKL_Complex16 a[], MKL_Complex16 b[]) { char uplo = 'L'; int info = 0; @@ -562,7 +563,7 @@ extern "C"{ return info; } - DLLEXPORT int c_qr_factor(int m, int n, Complex8 r[], Complex8 tau[], Complex8 q[], Complex8 work[], int len) + DLLEXPORT int c_qr_factor(int m, int n, MKL_Complex8 r[], MKL_Complex8 tau[], MKL_Complex8 q[], MKL_Complex8 work[], int len) { int info = 0; cgeqrf_(&m, &n, r, &m, tau, work, &len, &info); @@ -591,7 +592,7 @@ extern "C"{ return info; } - DLLEXPORT int z_qr_factor(int m, int n, Complex16 r[], Complex16 tau[], Complex16 q[], Complex16 work[], int len) + DLLEXPORT int z_qr_factor(int m, int n, MKL_Complex16 r[], MKL_Complex16 tau[], MKL_Complex16 q[], MKL_Complex16 work[], int len) { int info = 0; zgeqrf_(&m, &n, r, &m, tau, work, &len, &info); @@ -695,13 +696,13 @@ extern "C"{ return info; } - DLLEXPORT int c_qr_solve(int m, int n, int bn, Complex8 r[], Complex8 b[], Complex8 x[], Complex8 work[], int len) + DLLEXPORT int c_qr_solve(int m, int n, int bn, MKL_Complex8 r[], MKL_Complex8 b[], MKL_Complex8 x[], MKL_Complex8 work[], int len) { int info = 0; - Complex8* clone_r = new Complex8[m*n]; - std::memcpy(clone_r, r, m*n*sizeof(Complex8)); + MKL_Complex8* clone_r = new MKL_Complex8[m*n]; + std::memcpy(clone_r, r, m*n*sizeof(MKL_Complex8)); - Complex8* tau = new Complex8[std::min(m,n)]; + MKL_Complex8* tau = new MKL_Complex8[std::min(m,n)]; cgeqrf_(&m, &n, clone_r, &m, tau, work, &len, &info); if (info != 0) @@ -714,11 +715,11 @@ extern "C"{ char side ='L'; char tran = 'C'; - Complex8* clone_b = new Complex8[m*bn]; - std::memcpy(clone_b, b, m*bn*sizeof(Complex8)); + MKL_Complex8* clone_b = new MKL_Complex8[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(MKL_Complex8)); cunmqr_(&side, &tran, &m, &bn, &n, clone_r, &m, tau, clone_b, &m, work, &len, &info); - Complex8 one = {1.0, 0.0}; + MKL_Complex8 one = {1.0, 0.0}; cblas_ctrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, bn, &one, clone_r, m, clone_b, m); for (int i = 0; i < n; ++i) @@ -735,13 +736,13 @@ extern "C"{ return info; } - DLLEXPORT int z_qr_solve(int m, int n, int bn, Complex16 r[], Complex16 b[], Complex16 x[], Complex16 work[], int len) + DLLEXPORT int z_qr_solve(int m, int n, int bn, MKL_Complex16 r[], MKL_Complex16 b[], MKL_Complex16 x[], MKL_Complex16 work[], int len) { int info = 0; - Complex16* clone_r = new Complex16[m*n]; - std::memcpy(clone_r, r, m*n*sizeof(Complex16)); + MKL_Complex16* clone_r = new MKL_Complex16[m*n]; + std::memcpy(clone_r, r, m*n*sizeof(MKL_Complex16)); - Complex16* tau = new Complex16[std::min(m,n)]; + MKL_Complex16* tau = new MKL_Complex16[std::min(m,n)]; zgeqrf_(&m, &n, clone_r, &m, tau, work, &len, &info); if (info != 0) @@ -754,11 +755,11 @@ extern "C"{ char side ='L'; char tran = 'C'; - Complex16* clone_b = new Complex16[m*bn]; - std::memcpy(clone_b, b, m*bn*sizeof(Complex16)); + MKL_Complex16* clone_b = new MKL_Complex16[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(MKL_Complex16)); zunmqr_(&side, &tran, &m, &bn, &n, clone_r, &m, tau, clone_b, &m, work, &len, &info); - Complex16 one = {1.0, 0.0}; + MKL_Complex16 one = {1.0, 0.0}; cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, bn, &one, clone_r, m, clone_b, m); for (int i = 0; i < n; ++i) @@ -821,17 +822,17 @@ extern "C"{ return info; } - DLLEXPORT int c_qr_solve_factored(int m, int n, int bn, Complex8 r[], Complex8 b[], Complex8 tau[], Complex8 x[], Complex8 work[], int len) + DLLEXPORT int c_qr_solve_factored(int m, int n, int bn, MKL_Complex8 r[], MKL_Complex8 b[], MKL_Complex8 tau[], MKL_Complex8 x[], MKL_Complex8 work[], int len) { char side ='L'; char tran = 'C'; int info = 0; - Complex8* clone_b = new Complex8[m*bn]; - std::memcpy(clone_b, b, m*bn*sizeof(Complex8)); + MKL_Complex8* clone_b = new MKL_Complex8[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(MKL_Complex8)); cunmqr_(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info); - Complex8 one = {1.0f, 0.0f}; + MKL_Complex8 one = {1.0f, 0.0f}; cblas_ctrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, bn, &one, r, m, clone_b, m); for (int i = 0; i < n; ++i) { @@ -845,17 +846,17 @@ extern "C"{ return info; } - DLLEXPORT int z_qr_solve_factored(int m, int n, int bn, Complex16 r[], Complex16 b[], Complex16 tau[], Complex16 x[], Complex16 work[], int len) + DLLEXPORT int z_qr_solve_factored(int m, int n, int bn, MKL_Complex16 r[], MKL_Complex16 b[], MKL_Complex16 tau[], MKL_Complex16 x[], MKL_Complex16 work[], int len) { char side ='L'; char tran = 'C'; int info = 0; - Complex16* clone_b = new Complex16[m*bn]; - std::memcpy(clone_b, b, m*bn*sizeof(Complex16)); + MKL_Complex16* clone_b = new MKL_Complex16[m*bn]; + std::memcpy(clone_b, b, m*bn*sizeof(MKL_Complex16)); zunmqr_(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info); - Complex16 one = {1.0, 0.0}; + MKL_Complex16 one = {1.0, 0.0}; cblas_ztrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, bn, &one, r, m, clone_b, m); for (int i = 0; i < n; ++i) @@ -886,7 +887,7 @@ extern "C"{ return info; } - DLLEXPORT int c_svd_factor(bool compute_vectors, int m, int n, Complex8 a[], Complex8 s[], Complex8 u[], Complex8 v[], Complex8 work[], int len) + DLLEXPORT int c_svd_factor(bool compute_vectors, int m, int n, MKL_Complex8 a[], MKL_Complex8 s[], MKL_Complex8 u[], MKL_Complex8 v[], MKL_Complex8 work[], int len) { int info = 0; int dim_s = std::min(m,n); @@ -896,7 +897,7 @@ extern "C"{ cgesvd_(&job, &job, &m, &n, a, &m, s_local, u, &m, v, &n, work, &len, rwork, &info); for(int index = 0; index < dim_s; ++index){ - Complex8 value = {s_local[index], 0.0f}; + MKL_Complex8 value = {s_local[index], 0.0f}; s[index] = value; } @@ -905,7 +906,7 @@ extern "C"{ return info; } - DLLEXPORT int z_svd_factor(bool compute_vectors, int m, int n, Complex16 a[], Complex16 s[], Complex16 u[], Complex16 v[], Complex16 work[], int len) + DLLEXPORT int z_svd_factor(bool compute_vectors, int m, int n, MKL_Complex16 a[], MKL_Complex16 s[], MKL_Complex16 u[], MKL_Complex16 v[], MKL_Complex16 work[], int len) { int info = 0; int dim_s = std::min(m,n); @@ -915,7 +916,7 @@ extern "C"{ zgesvd_(&job, &job, &m, &n, a, &m, s_local, u, &m, v, &n, work, &len, rwork, &info); for(int index = 0; index < dim_s; ++index){ - Complex16 value = {s_local[index], 0.0f}; + MKL_Complex16 value = {s_local[index], 0.0f}; s[index] = value; } diff --git a/src/NativeWrappers/MKL/vector_functions.c b/src/NativeWrappers/MKL/vector_functions.c index 28716fe9..7e379a8f 100644 --- a/src/NativeWrappers/MKL/vector_functions.c +++ b/src/NativeWrappers/MKL/vector_functions.c @@ -1,5 +1,4 @@ #include "mkl_vml.h" -#include "blas.h" #include "wrapper_common.h" @@ -35,34 +34,34 @@ DLLEXPORT void d_vector_divide( const int n, const double x[], const double y[], vdDiv( n, x, y, result ); } -DLLEXPORT void c_vector_add( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){ +DLLEXPORT void c_vector_add( const int n, const MKL_Complex8 x[], const MKL_Complex8 y[], MKL_Complex8 result[] ){ vcAdd( n, x, y, result ); } -DLLEXPORT void c_vector_subtract( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){ +DLLEXPORT void c_vector_subtract( const int n, const MKL_Complex8 x[], const MKL_Complex8 y[], MKL_Complex8 result[] ){ vcSub( n, x, y, result ); } -DLLEXPORT void c_vector_multiply( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){ +DLLEXPORT void c_vector_multiply( const int n, const MKL_Complex8 x[], const MKL_Complex8 y[], MKL_Complex8 result[] ){ vcMul( n, x, y, result ); } -DLLEXPORT void c_vector_divide( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){ +DLLEXPORT void c_vector_divide( const int n, const MKL_Complex8 x[], const MKL_Complex8 y[], MKL_Complex8 result[] ){ vcDiv( n, x, y, result ); } -DLLEXPORT void z_vector_add( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ +DLLEXPORT void z_vector_add( const int n, const MKL_Complex16 x[], const MKL_Complex16 y[], MKL_Complex16 result[] ){ vzAdd( n, x, y, result ); } -DLLEXPORT void z_vector_subtract( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ +DLLEXPORT void z_vector_subtract( const int n, const MKL_Complex16 x[], const MKL_Complex16 y[], MKL_Complex16 result[] ){ vzSub( n, x, y, result ); } -DLLEXPORT void z_vector_multiply( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ +DLLEXPORT void z_vector_multiply( const int n, const MKL_Complex16 x[], const MKL_Complex16 y[], MKL_Complex16 result[] ){ vzMul( n, x, y, result ); } -DLLEXPORT void z_vector_divide( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ +DLLEXPORT void z_vector_divide( const int n, const MKL_Complex16 x[], const MKL_Complex16 y[], MKL_Complex16 result[] ){ vzDiv( n, x, y, result ); } diff --git a/src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj b/src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj new file mode 100644 index 00000000..adde35e4 --- /dev/null +++ b/src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB} + Win32Proj + ACMKWrapper + ACMLWrapper + + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;ACMKWRAPPER_EXPORTS;%(PreprocessorDefinitions) + ..\..\Common;C:\AMD\acml4.4.0\ifort32_mp\include;%(AdditionalIncludeDirectories) + + + Windows + true + C:\AMD\acml4.4.0\ifort32_mp\lib;%(AdditionalLibraryDirectories) + libacml_mp_dll.lib;kernel32.lib;user32.lib; + $(OutDir)MathNET.Numerics.ACML.dll + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;ACMKWRAPPER_EXPORTS;%(PreprocessorDefinitions) + ..\..\Common;C:\AMD\acml4.4.0\ifort64_mp\include;%(AdditionalIncludeDirectories) + + + Windows + true + C:\AMD\acml4.4.0\ifort64_mp\lib;%(AdditionalLibraryDirectories) + libacml_mp_dll.lib;kernel32.lib;user32.lib; + $(OutDir)MathNET.Numerics.ACML.dll + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;ACMKWRAPPER_EXPORTS;%(PreprocessorDefinitions) + ..\..\Common;C:\AMD\acml4.4.0\ifort32_mp\include;%(AdditionalIncludeDirectories) + + + Windows + true + true + true + C:\AMD\acml4.4.0\ifort32_mp\lib;%(AdditionalLibraryDirectories) + libacml_mp_dll.lib;kernel32.lib;user32.lib; + $(OutDir)MathNET.Numerics.ACML.dll + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;ACMKWRAPPER_EXPORTS;%(PreprocessorDefinitions) + ..\..\Common;C:\AMD\acml4.4.0\ifort64_mp\include;%(AdditionalIncludeDirectories) + + + Windows + true + true + true + C:\AMD\acml4.4.0\ifort64_mp\lib;%(AdditionalLibraryDirectories) + libacml_mp_dll.lib;kernel32.lib;user32.lib; + $(OutDir)MathNET.Numerics.ACML.dll + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj.filters b/src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj.filters new file mode 100644 index 00000000..30541be3 --- /dev/null +++ b/src/NativeWrappers/Windows/ACMLWrapper/ACMKWrapper.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Resource Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj b/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj index 7537f043..860dc11a 100644 --- a/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj +++ b/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj @@ -154,10 +154,9 @@ - - - + + diff --git a/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj.filters b/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj.filters index f2614fd4..43d3b2ef 100644 --- a/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj.filters +++ b/src/NativeWrappers/Windows/GotoBLAS2/GotoBLAS2Wrapper.vcxproj.filters @@ -23,16 +23,13 @@ Header Files - - Header Files - Header Files - + Header Files - + Header Files diff --git a/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj b/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj index 3d29c457..b44de55f 100644 --- a/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj +++ b/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj @@ -184,15 +184,17 @@ - - - + + + + + diff --git a/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj.filters b/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj.filters index 500b8076..5d4163bf 100644 --- a/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj.filters +++ b/src/NativeWrappers/Windows/MKL/MKLWrapper.vcxproj.filters @@ -15,9 +15,6 @@ - - Header Files - Header Files @@ -26,17 +23,22 @@ - + Source Files - + Source Files - + Source Files - + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/src/NativeWrappers/Windows/NativeWrappers.sln b/src/NativeWrappers/Windows/NativeWrappers.sln index 060864f3..c1a2e939 100644 --- a/src/NativeWrappers/Windows/NativeWrappers.sln +++ b/src/NativeWrappers/Windows/NativeWrappers.sln @@ -3,7 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}" ProjectSection(SolutionItems) = preProject - ..\Common\blas.c = ..\Common\blas.c ..\Common\resource.h = ..\Common\resource.h ..\Common\resource.rc = ..\Common\resource.rc ..\Common\WindowsDLL.cpp = ..\Common\WindowsDLL.cpp @@ -18,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GotoBLAS2Wrapper", "GotoBLA EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GotoBLAS2WrapperTests", "GotoBLAS2WrapperTests\GotoBLAS2WrapperTests.csproj", "{56FFAB18-CAA6-4913-8123-610872BFD60A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACMLWrapper", "ACMLWrapper\ACMKWrapper.vcxproj", "{8774BCBE-27D0-44D2-A1B3-8ED705E252CB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,6 +82,20 @@ Global {56FFAB18-CAA6-4913-8123-610872BFD60A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {56FFAB18-CAA6-4913-8123-610872BFD60A}.Release|Win32.ActiveCfg = Release|Any CPU {56FFAB18-CAA6-4913-8123-610872BFD60A}.Release|x64.ActiveCfg = Release|Any CPU + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|Any CPU.ActiveCfg = Debug|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|Mixed Platforms.Build.0 = Debug|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|Win32.ActiveCfg = Debug|Win32 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|Win32.Build.0 = Debug|Win32 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|x64.ActiveCfg = Debug|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Debug|x64.Build.0 = Debug|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|Any CPU.ActiveCfg = Release|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|Mixed Platforms.Build.0 = Release|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|Win32.ActiveCfg = Release|Win32 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|Win32.Build.0 = Release|Win32 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|x64.ActiveCfg = Release|x64 + {8774BCBE-27D0-44D2-A1B3-8ED705E252CB}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE