source: trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/HeuristicLab.NativeInterpreter-0.1/DllImporter.cs @ 16266

Last change on this file since 16266 was 16266, checked in by bburlacu, 21 months ago

#2958: Add native interpreter dll wrapper as external lib.

File size: 2.7 KB
Line 
1using System;
2using System.Runtime.InteropServices;
3
4namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
5  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
6  public struct NativeInstruction {
7    public byte opcode;
8    public ushort narg;
9    public int childIndex;
10    public double value;
11    public double weight;
12
13    public IntPtr buf;
14    public IntPtr data;
15  }
16
17  public class NativeWrapper {
18    private const string x86dll = "hl-native-interpreter-msvc-x86.dll";
19    private const string x64dll = "hl-native-interpreter-msvc-x64.dll";
20
21    private readonly static bool is64;
22
23    static NativeWrapper() {
24      is64 = Environment.Is64BitProcess;
25    }
26
27    public static double GetValue(NativeInstruction[] code, int len, int row) {
28      return is64 ? GetValue64(code, len, row) : GetValue32(code, len, row);
29    }
30
31    public static void GetValues(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result) {
32      if (is64)
33        GetValues64(code, len, rows, nRows, result);
34      else
35        GetValues32(code, len, rows, nRows, result);
36    }
37
38    public static void GetValuesVectorized(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result) {
39      if (is64)
40        GetValuesVectorized64(code, len, rows, nRows, result);
41      else
42        GetValuesVectorized32(code, len, rows, nRows, result);
43    }
44
45    [DllImport(x86dll, EntryPoint = "GetValue", CallingConvention = CallingConvention.Cdecl)]
46    internal static extern double GetValue32(NativeInstruction[] code, int len, int row);
47
48    [DllImport(x86dll, EntryPoint = "GetValues", CallingConvention = CallingConvention.Cdecl)]
49    internal static extern void GetValues32(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
50
51    [DllImport(x86dll, EntryPoint = "GetValuesVectorized", CallingConvention = CallingConvention.Cdecl)]
52    internal static extern void GetValuesVectorized32(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
53
54    [DllImport(x64dll, EntryPoint = "GetValue", CallingConvention = CallingConvention.Cdecl)]
55    internal static extern double GetValue64(NativeInstruction[] code, int len, int row);
56
57    [DllImport(x64dll, EntryPoint = "GetValues", CallingConvention = CallingConvention.Cdecl)]
58    internal static extern void GetValues64(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
59
60    [DllImport(x64dll, EntryPoint = "GetValuesVectorized", CallingConvention = CallingConvention.Cdecl)]
61    internal static extern void GetValuesVectorized64(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
62  }
63}
Note: See TracBrowser for help on using the repository browser.