diff --git a/src/NativeProviders/MKL/memory.c b/src/NativeProviders/MKL/memory.c index e5ec9f21..b5148d7a 100644 --- a/src/NativeProviders/MKL/memory.c +++ b/src/NativeProviders/MKL/memory.c @@ -1,7 +1,7 @@ #include "wrapper_common.h" #include "mkl.h" -#if GCC +#if GCC extern "C" { #endif @@ -18,13 +18,13 @@ DLLEXPORT int disable_fast_mm(void) { } DLLEXPORT MKL_INT64 mem_stat(int* AllocatedBuffers) { - return mkl_mem_stat(AllocatedBuffers); + return mkl_mem_stat(AllocatedBuffers); } DLLEXPORT MKL_INT64 peak_mem_usage(int mode) { return mkl_peak_mem_usage(mode); } -#if GCC +#if GCC } #endif \ No newline at end of file diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs index 6d0dd6e4..2e351d57 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2014 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -67,7 +67,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl Double = 0x20 } - public enum MklMemoryRequestMode : int + internal enum MklMemoryRequestMode : int { /// /// Disable gathering memory usage @@ -210,7 +210,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// /// Disable the MKL memory pool. May impact performance. /// - public void DisableMklMemoryPool() + public void DisableMemoryPool() { if (SafeNativeMethods.query_capability(67) < 1) { @@ -221,7 +221,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl } /// - /// Retrieves information about the the MKL memory pool. + /// Retrieves information about the MKL memory pool. /// /// On output, returns the number of memory buffers allocated. /// Returns the number of bytes allocated to all memory buffers. @@ -235,19 +235,45 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl return SafeNativeMethods.mem_stat(out allocatedBuffers); } + /// + /// Enable gathering of peak memory statistics of the MKL memory pool. + /// + public void EnablePeakMemoryStatistics() + { + if (SafeNativeMethods.query_capability(67) < 1) + { + throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version."); + } + + SafeNativeMethods.peak_mem_usage((int)MklMemoryRequestMode.Enable); + } + + /// + /// Disable gathering of peak memory statistics of the MKL memory pool. + /// + public void DisablePeakMemoryStatistics() + { + if (SafeNativeMethods.query_capability(67) < 1) + { + throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version."); + } + + SafeNativeMethods.peak_mem_usage((int)MklMemoryRequestMode.Disable); + } + /// /// Measures peak memory usage of the MKL memory pool. /// - /// The request mode. - /// The peak memory usage. - public long PeakMemoryUsage(MklMemoryRequestMode mode) + /// Whether the usage counter should be reset. + /// The peak number of bytes allocated to all memory buffers. + public long PeakMemoryStatistics(bool reset = true) { if (SafeNativeMethods.query_capability(67) < 1) { throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version."); } - return SafeNativeMethods.peak_mem_usage((int)mode); + return SafeNativeMethods.peak_mem_usage((int)(reset ? MklMemoryRequestMode.PeakMemoryReset : MklMemoryRequestMode.PeakMemory)); } public override string ToString()