From 044b83ae33af1b08cbd906b76ce3f9d59697bd59 Mon Sep 17 00:00:00 2001 From: Yael Dekel Date: Fri, 1 Jun 2018 14:04:39 -0700 Subject: [PATCH] Add a macro for cases where the '.dll' suffix is needed by the DllImport attribute --- src/Microsoft.ML.FastTree/Dataset/DenseIntArray.cs | 4 ++-- src/Microsoft.ML.FastTree/Dataset/IntArray.cs | 6 ++++++ .../Dataset/SegmentIntArray.cs | 14 +++++++------- .../Dataset/SparseIntArray.cs | 4 ++-- src/Microsoft.ML.FastTree/FastTreeRanking.cs | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.ML.FastTree/Dataset/DenseIntArray.cs b/src/Microsoft.ML.FastTree/Dataset/DenseIntArray.cs index 508a6a5229..e0ff7abb46 100644 --- a/src/Microsoft.ML.FastTree/Dataset/DenseIntArray.cs +++ b/src/Microsoft.ML.FastTree/Dataset/DenseIntArray.cs @@ -69,13 +69,13 @@ public override IntArray[] Split(int[][] assignment) } #if USE_FASTTREENATIVE - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall)] private unsafe static extern int C_Sumup_float( int numBits, byte* pData, int* pIndices, float* pSampleOutputs, double* pSampleOutputWeights, FloatType* pSumTargetsByBin, double* pSumTargets2ByBin, int* pCountByBin, int totalCount, double totalSampleOutputs, double totalSampleOutputWeights); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall)] private unsafe static extern int C_Sumup_double( int numBits, byte* pData, int* pIndices, double* pSampleOutputs, double* pSampleOutputWeights, FloatType* pSumTargetsByBin, double* pSumTargets2ByBin, int* pCountByBin, diff --git a/src/Microsoft.ML.FastTree/Dataset/IntArray.cs b/src/Microsoft.ML.FastTree/Dataset/IntArray.cs index 3d9dbddf03..f8f9ea6286 100644 --- a/src/Microsoft.ML.FastTree/Dataset/IntArray.cs +++ b/src/Microsoft.ML.FastTree/Dataset/IntArray.cs @@ -23,6 +23,12 @@ public enum IntArrayBits { Bits32 = 32, Bits16 = 16, Bits10 = 10, Bits8 = 8, Bit /// public abstract class IntArray : IEnumerable { +#if USE_DLL_SUFFIX + public const string NativeDll = "FastTreeNative.dll"; +#else + public const string NativeDll = "FastTreeNative"; +#endif + // The level of compression to use with features. // 0x1 - Use 10 bit. // 0x2 - diff --git a/src/Microsoft.ML.FastTree/Dataset/SegmentIntArray.cs b/src/Microsoft.ML.FastTree/Dataset/SegmentIntArray.cs index 3bbd33407b..df94d7b7eb 100644 --- a/src/Microsoft.ML.FastTree/Dataset/SegmentIntArray.cs +++ b/src/Microsoft.ML.FastTree/Dataset/SegmentIntArray.cs @@ -493,29 +493,29 @@ public unsafe static void SegmentFindOptimalCost31(uint[] array, int len, out lo } #pragma warning disable TLC_GeneralName // Externs follow their own rules. - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] private unsafe static extern void C_SegmentFindOptimalPath21(uint* valv, int valc, long* pBits, int* pTransitions); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] private unsafe static extern void C_SegmentFindOptimalPath15(uint* valv, int valc, long* pBits, int* pTransitions); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] private unsafe static extern void C_SegmentFindOptimalPath7(uint* valv, int valc, long* pBits, int* pTransitions); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] private unsafe static extern void C_SegmentFindOptimalCost15(uint* valv, int valc, long* pBits); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] private unsafe static extern void C_SegmentFindOptimalCost31(uint* valv, int valc, long* pBits); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall)] private unsafe static extern int C_SumupSegment_float( uint* pData, byte* pSegType, int* pSegLength, int* pIndices, float* pSampleOutputs, double* pSampleOutputWeights, float* pSumTargetsByBin, double* pSumWeightsByBin, int* pCountByBin, int totalCount, double totalSampleOutputs); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall)] private unsafe static extern int C_SumupSegment_double( uint* pData, byte* pSegType, int* pSegLength, int* pIndices, double* pSampleOutputs, double* pSampleOutputWeights, diff --git a/src/Microsoft.ML.FastTree/Dataset/SparseIntArray.cs b/src/Microsoft.ML.FastTree/Dataset/SparseIntArray.cs index 133d35936b..cdf4166ea8 100644 --- a/src/Microsoft.ML.FastTree/Dataset/SparseIntArray.cs +++ b/src/Microsoft.ML.FastTree/Dataset/SparseIntArray.cs @@ -489,12 +489,12 @@ public override void Sumup(SumupInputData input, FeatureHistogram histogram) } #if USE_FASTTREENATIVE - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall)] private unsafe static extern int C_SumupDeltaSparse_float(int numBits, byte* pValues, byte* pDeltas, int numDeltas, int* pIndices, float* pSampleOutputs, double* pSampleOutputWeights, float* pSumTargetsByBin, double* pSumTargets2ByBin, int* pCountByBin, int totalCount, double totalSampleOutputs, double totalSampleOutputWeights); - [DllImport("FastTreeNative", CallingConvention = CallingConvention.StdCall)] + [DllImport(NativeDll, CallingConvention = CallingConvention.StdCall)] private unsafe static extern int C_SumupDeltaSparse_double(int numBits, byte* pValues, byte* pDeltas, int numDeltas, int* pIndices, double* pSampleOutputs, double* pSampleOutputWeights, double* pSumTargetsByBin, double* pSumTargets2ByBin, int* pCountByBin, int totalCount, double totalSampleOutputs, double totalSampleOutputWeights); diff --git a/src/Microsoft.ML.FastTree/FastTreeRanking.cs b/src/Microsoft.ML.FastTree/FastTreeRanking.cs index 7f89858e00..1a9dd1069e 100644 --- a/src/Microsoft.ML.FastTree/FastTreeRanking.cs +++ b/src/Microsoft.ML.FastTree/FastTreeRanking.cs @@ -1026,7 +1026,7 @@ private static void PermutationSort(int[] permutation, double[] scores, short[] })); } - [DllImport("FastTreeNative", EntryPoint = "C_GetDerivatives", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + [DllImport(IntArray.NativeDll, EntryPoint = "C_GetDerivatives", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] private unsafe static extern void GetDerivatives( int numDocuments, int begin, int* pPermutation, short* pLabels, double* pScores, double* pLambdas, double* pWeights, double* pDiscount,