Browse Source

Merge pull request #271 from cuda/mkl_memory

Added MKL memory functions and updated mkl_build.sh
cuda
Christoph Ruegg 12 years ago
parent
commit
39936c7eb6
  1. 1
      MathNet.Numerics.All.sln.DotSettings
  2. 1
      MathNet.Numerics.sln.DotSettings
  3. 13
      src/NativeProviders/Linux/mkl_build.sh
  4. 2
      src/NativeProviders/MKL/lapack.cpp
  5. 30
      src/NativeProviders/MKL/memory.c
  6. 1
      src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj
  7. 3
      src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj.filters
  8. 68
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  9. 20
      src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs

1
MathNet.Numerics.All.sln.DotSettings

@ -71,5 +71,6 @@ OTHER DEALINGS IN THE SOFTWARE.
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TFQMR/@EntryIndexedValue">TFQMR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WH/@EntryIndexedValue">WH</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>

1
MathNet.Numerics.sln.DotSettings

@ -103,6 +103,7 @@ OTHER DEALINGS IN THE SOFTWARE.&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TFQMR/@EntryIndexedValue">TFQMR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WH/@EntryIndexedValue">WH</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
</wpf:ResourceDictionary>

13
src/NativeProviders/Linux/mkl_build.sh

@ -1,11 +1,16 @@
#Note: g++ multilib must be installed
export INTEL=/opt/intel
export MKL=$INTEL/mkl
export OPENMP=$INTEL/composerxe/lib
export OUT=../../../out/MKL/Linux
g++ -std=c++11 -DGCC -m64 --shared -fPIC -o ../../../../MKL/Linux/x64/MathNet.Numerics.MKL.dll -I$MKL/include -I../Common ../MKL/vector_functions.c ../MKL/blas.c ../MKL/lapack.cpp -Wl,--start-group $MKL/lib/intel64/libmkl_intel_lp64.a $MKL/lib/intel64/libmkl_intel_thread.a $MKL/lib/intel64/libmkl_core.a -Wl,--end-group -L$OPENMP/intel64 -liomp5 -lpthread -lm
mkdir -p $OUT/x64
mkdir -p $OUT/x86
cp $OPENMP/intel64/libiomp5.so ../../../../MKL/Linux/x64/
g++ -std=c++11 -DGCC -m64 --shared -fPIC -o $OUT/x64/MathNet.Numerics.MKL.dll -I$MKL/include -I../Common ../MKL/memory.c ../MKL/capabilities.cpp ../MKL/vector_functions.c ../MKL/blas.c ../MKL/lapack.cpp -Wl,--start-group $MKL/lib/intel64/libmkl_intel_lp64.a $MKL/lib/intel64/libmkl_intel_thread.a $MKL/lib/intel64/libmkl_core.a -Wl,--end-group -L$OPENMP/intel64 -liomp5 -lpthread -lm
g++ -std=c++11 -DGCC -m32 --shared -fPIC -o ../../../../MKL/Linux/x86/MathNet.Numerics.MKL.dll -I$MKL/include -I../Common ../MKL/vector_functions.c ../MKL/blas.c ../MKL/lapack.cpp -Wl,--start-group $MKL/lib/ia32/libmkl_intel.a $MKL/lib/ia32/libmkl_intel_thread.a $MKL/lib/ia32/libmkl_core.a -Wl,--end-group -L$OPENMP/ia32 -liomp5 -lpthread -lm
cp $OPENMP/intel64/libiomp5.so $OUT/x64/
cp $OPENMP/ia32/libiomp5.so ../../../../MKL/Linux/x86/
g++ -std=c++11 -DGCC -m32 --shared -fPIC -o $OUT/x86/MathNet.Numerics.MKL.dll -I$MKL/include -I../Common ../MKL/memory.c ../MKL/capabilities.cpp ../MKL/vector_functions.c ../MKL/blas.c ../MKL/lapack.cpp -Wl,--start-group $MKL/lib/ia32/libmkl_intel.a $MKL/lib/ia32/libmkl_intel_thread.a $MKL/lib/ia32/libmkl_core.a -Wl,--end-group -L$OPENMP/ia32 -liomp5 -lpthread -lm
cp $OPENMP/ia32/libiomp5.so $OUT/x86/

2
src/NativeProviders/MKL/lapack.cpp

@ -1,4 +1,4 @@
#include <algorithm>
#include <algorithm>
#include <complex>
#define MKL_Complex8 std::complex<float>
#define MKL_Complex16 std::complex<double>

30
src/NativeProviders/MKL/memory.c

@ -0,0 +1,30 @@
#include "wrapper_common.h"
#include "mkl.h"
#if GCC
extern "C" {
#endif
DLLEXPORT void free_buffers(void) {
mkl_free_buffers();
}
DLLEXPORT void thread_free_buffers(void) {
mkl_thread_free_buffers();
}
DLLEXPORT int disable_fast_mm(void) {
return mkl_disable_fast_mm();
}
DLLEXPORT MKL_INT64 mem_stat(int* AllocatedBuffers) {
return mkl_mem_stat(AllocatedBuffers);
}
DLLEXPORT MKL_INT64 peak_mem_usage(int mode) {
return mkl_peak_mem_usage(mode);
}
#if GCC
}
#endif

1
src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj

@ -293,6 +293,7 @@
<ClCompile Include="..\..\MKL\capabilities.cpp" />
<ClCompile Include="..\..\MKL\blas.c" />
<ClCompile Include="..\..\MKL\lapack.cpp" />
<ClCompile Include="..\..\MKL\memory.c" />
<ClCompile Include="..\..\MKL\vector_functions.c" />
</ItemGroup>
<ItemGroup>

3
src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj.filters

@ -30,6 +30,9 @@
<ClCompile Include="..\..\MKL\capabilities.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\MKL\memory.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\Common\resource.rc">

68
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

@ -67,6 +67,29 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
Double = 0x20
}
public enum MklMemoryRequestMode : int
{
/// <summary>
/// Disable gathering memory usage
/// </summary>
Disable = 0,
/// <summary>
/// Enable gathering memory usage
/// </summary>
Enable = 1,
/// <summary>
/// Return peak memory usage
/// </summary>
PeakMemory = 2,
/// <summary>
/// Return peak memory usage and reset counter
/// </summary>
PeakMemoryReset = -1
}
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
@ -163,10 +186,55 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
}
/// <summary>
/// Frees the memory allocated to the MKL memory pool.
/// </summary>
public void FreeBuffers()
{
SafeNativeMethods.free_buffers();
}
/// <summary>
/// Frees the memory allocated to the MKL memory pool on the current thread.
/// </summary>
public void ThreadFreeBuffers()
{
SafeNativeMethods.thread_free_buffers();
}
/// <summary>
/// Disable the MKL memory pool. May impact performance.
/// </summary>
public void DisableMklMemoryPool()
{
SafeNativeMethods.disable_fast_mm();
}
/// <summary>
/// Retrieves information about the the MKL memory pool.
/// </summary>
/// <param name="allocatedBuffers">On output, returns the number of memory buffers allocated.</param>
/// <returns>Returns the number of bytes allocated to all memory buffers.</returns>
public long MemoryStatistics(out int allocatedBuffers)
{
return SafeNativeMethods.mem_stat(out allocatedBuffers);
}
/// <summary>
/// Measures peak memory usage of the MKL memory pool.
/// </summary>
/// <param name="mode">The request mode.</param>
/// <returns>The peak memory usage.</returns>
public long PeakMemoryUsage(MklMemoryRequestMode mode)
{
return SafeNativeMethods.peak_mem_usage((int)mode);
}
public override string ToString()
{
return string.Format("Intel MKL ({1}; revision {0})", _nativeRevision, _nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
}
}
}

20
src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs

@ -2,7 +2,7 @@
// Math.NET Numerics, part of the Math.NET Project
// http://mathnet.opensourcedotnet.info
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -60,6 +60,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void set_max_threads(int num_threads);
#region Memory
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void free_buffers();
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void thread_free_buffers();
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int disable_fast_mm();
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern long mem_stat([Out]out int allocatedBuffers);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern long peak_mem_usage(int mode);
#endregion Memory
#region BLAS
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]

Loading…
Cancel
Save