Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3044_variableScaling/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/HeuristicLab.NativeInterpreter-0.1/DllImporter.cs @ 18242

Last change on this file since 18242 was 16333, checked in by bburlacu, 6 years ago

#2958: Native interpreter dlls: statically link against the visual C++ runtime

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 static 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    // x86
46    [DllImport(x86dll, EntryPoint = "GetValue", CallingConvention = CallingConvention.Cdecl)]
47    internal static extern double GetValue32(NativeInstruction[] code, int len, int row);
48
49    [DllImport(x86dll, EntryPoint = "GetValues", CallingConvention = CallingConvention.Cdecl)]
50    internal static extern void GetValues32(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
51
52    [DllImport(x86dll, EntryPoint = "GetValuesVectorized", CallingConvention = CallingConvention.Cdecl)]
53    internal static extern void GetValuesVectorized32(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
54
55    // x64
56    [DllImport(x64dll, EntryPoint = "GetValue", CallingConvention = CallingConvention.Cdecl)]
57    internal static extern double GetValue64(NativeInstruction[] code, int len, int row);
58
59    [DllImport(x64dll, EntryPoint = "GetValues", CallingConvention = CallingConvention.Cdecl)]
60    internal static extern void GetValues64(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
61
62    [DllImport(x64dll, EntryPoint = "GetValuesVectorized", CallingConvention = CallingConvention.Cdecl)]
63    internal static extern void GetValuesVectorized64(NativeInstruction[] code, int len, int[] rows, int nRows, double[] result);
64  }
65}
Note: See TracBrowser for help on using the repository browser.