Browse Source

native wrappers: wrapped cholesky, dot product, and added add/subtract/multiple vector functions for MKL

la-knuth
Marcus Cuda 17 years ago
parent
commit
c1c3b95477
  1. 12
      src/NativeWrappers/ATLAS/ATLASWrapper.vcproj
  2. 5
      src/NativeWrappers/ATLAS/blas.h
  3. 64
      src/NativeWrappers/ATLAS/lapack.cpp
  4. 30
      src/NativeWrappers/Common/blas.c
  5. 10
      src/NativeWrappers/Common/common.h
  6. 16
      src/NativeWrappers/MKL/MKLWrapper.vcproj
  7. 7
      src/NativeWrappers/MKL/blas.h
  8. 72
      src/NativeWrappers/MKL/lapack.cpp
  9. 14
      src/NativeWrappers/MKL/vector_functions.c
  10. 1
      src/NativeWrappers/NativeWrappers.sln

12
src/NativeWrappers/ATLAS/ATLASWrapper.vcproj

@ -40,7 +40,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\ATLAS&quot;;C:\cygwin\tmp\ATLAS\include"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\Common&quot;;&quot;C:\source\mathnet-marcus\src\NativeWrappers\ATLAS&quot;;C:\cygwin\tmp\ATLAS\include"
PreprocessorDefinitions="_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -115,7 +115,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\ATLAS&quot;;C:\cygwin\tmp\ATLAS\include"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\Common&quot;;&quot;C:\source\mathnet-marcus\src\NativeWrappers\ATLAS&quot;;C:\cygwin\tmp\ATLAS\include"
PreprocessorDefinitions="_WINDOWS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
@ -177,6 +177,10 @@
RelativePath="..\Common\blas.c"
>
</File>
<File
RelativePath=".\lapack.cpp"
>
</File>
<File
RelativePath="..\Common\WindowsDLL.cpp"
>
@ -191,6 +195,10 @@
RelativePath=".\blas.h"
>
</File>
<File
RelativePath="..\Common\common.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"

5
src/NativeWrappers/ATLAS/blas.h

@ -1,4 +1,9 @@
#ifndef BLAS_H
#define BLAS_H
#include "cblas.h"
typedef struct { float real; float imag; } Complex8;
typedef struct { double real; double imag; } Complex16;
#endif

64
src/NativeWrappers/ATLAS/lapack.cpp

@ -0,0 +1,64 @@
#include "common.h"
#include "blas.h"
#include "clapack.h"
extern "C" {
DLLEXPORT int s_cholesky_factor(int n, float a[]){
int info = clapack_spotrf(CblasColMajor, CblasLower, n, a, n);
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){
int info = clapack_dpotrf(CblasColMajor, CblasLower, n, a, n);
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, Complex8 a[]){
int info = clapack_cpotrf(CblasColMajor, CblasLower, n, a, n);
Complex8 zero;
zero.real = 0.0;
zero.real = 0.0;
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, Complex16 a[]){
int info = clapack_zpotrf(CblasColMajor, CblasLower, n, a, n);
Complex16 zero;
zero.real = 0.0;
zero.real = 0.0;
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;
}
}

30
src/NativeWrappers/Common/blas.c

@ -1,10 +1,5 @@
#include "blas.h"
#ifdef _WINDOWS
#define DLLEXPORT __declspec( dllexport )
#else
#define DLLEXPORT
#endif
#include "common.h"
DLLEXPORT void s_axpy( const int n, const float alpha, const float x[], float y[]){
cblas_saxpy(n, alpha, x, 1, y, 1);
@ -38,3 +33,26 @@ DLLEXPORT void z_scale(const int n, const Complex16 alpha, Complex16 x[]){
cblas_zscal(n, &alpha, x, 1);
}
DLLEXPORT float s_dot_product(const int n, const float x[], const float y[]){
return cblas_sdot(n, x, 1, y, 1);
}
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;
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;
cblas_zdotu_sub(n, x, 1, y, 1, &ret);
return ret;
}

10
src/NativeWrappers/Common/common.h

@ -0,0 +1,10 @@
#ifndef COMMON_H
#define COMMON_H
#ifdef _WINDOWS
#define DLLEXPORT __declspec( dllexport )
#else
#define DLLEXPORT
#endif
#endif

16
src/NativeWrappers/MKL/MKLWrapper.vcproj

@ -118,7 +118,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\Common&quot;;&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
PreprocessorDefinitions="_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -272,7 +272,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\Common&quot;;&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
PreprocessorDefinitions="_WINDOWS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
@ -335,6 +335,14 @@
RelativePath="..\Common\blas.c"
>
</File>
<File
RelativePath=".\lapack.cpp"
>
</File>
<File
RelativePath=".\vector_functions.c"
>
</File>
<File
RelativePath="..\Common\WindowsDLL.cpp"
>
@ -349,6 +357,10 @@
RelativePath=".\blas.h"
>
</File>
<File
RelativePath="..\Common\common.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"

7
src/NativeWrappers/MKL/blas.h

@ -1,4 +1,9 @@
#ifndef BLAS_H
#define BLAS_H
#include "mkl_cblas.h"
typedef MKL_Complex8 Complex8;
typedef MKL_Complex16 Complex16;
typedef MKL_Complex16 Complex16;
#endif

72
src/NativeWrappers/MKL/lapack.cpp

@ -0,0 +1,72 @@
#include "common.h"
#include "blas.h"
#include "mkl_lapack.h"
extern "C" {
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, Complex8 a[]){
char uplo = 'L';
int info = 0;
Complex8 zero;
zero.real = 0.0;
zero.real = 0.0;
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, Complex16 a[]){
char uplo = 'L';
int info = 0;
Complex16 zero;
zero.real = 0.0;
zero.real = 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;
}
}

14
src/NativeWrappers/MKL/vector_functions.c

@ -0,0 +1,14 @@
#include "mkl_vml.h"
#include "common.h"
DLLEXPORT void d_vector_add( const int n, const double x[], const double y[], double ret[]){
vdAdd( n, x, y, ret );
}
DLLEXPORT void d_vector_subtract( const int n, const double x[], const double y[], double ret[]){
vdSub( n, x, y, ret );
}
DLLEXPORT void d_vector_multiply( const int n, const double x[], const double y[], double ret[]){
vdMul( n, x, y, ret );
}

1
src/NativeWrappers/NativeWrappers.sln

@ -4,6 +4,7 @@ Microsoft Visual Studio Solution File, Format Version 10.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}"
ProjectSection(SolutionItems) = preProject
Common\blas.c = Common\blas.c
Common\common.h = Common\common.h
Common\resource.h = Common\resource.h
Common\resource.rc = Common\resource.rc
Common\WindowsDLL.cpp = Common\WindowsDLL.cpp

Loading…
Cancel
Save