0

I have trouble calling Cntk functions from C#. The header file I'm using is CNTKLibraryC.h from a binary CNTK installation, and the DLL that I load is Cntk.Core-2.5.dll from the same installation. My interop signature for CNTK_LoadModel at the moment:

[DllImport(DllName, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr CNTK_LoadModel( IntPtr modelFilePath, IntPtr device, out IntPtr model);

This "works" if I use the model file name (run through Marshal.StringToHGlobalUni()) for both modelFilePath and device, but I can't call CNTK_ReleaseModel afterwards for then the program crashes. Sometimes I also succeed if I pass a non-existing path to modelFilePath, so it's obvious that the second argument is taken as the model file name, contrary to what the function signature suggests. I suspect there's something I've overlooked here. I am not used to calling native 64 bit DLLs from C#, only 32 bit. What, for instance, is the correct calling convention?

Yngve Moe
  • 410
  • 2
  • 8
  • There is a CNTK [C# library](https://learn.microsoft.com/en-us/cognitive-toolkit/using-cntk-with-csharp). Does that not do what you need instead of calling C++? – Jon Mar 24 '18 at 08:28
  • 1
    It isn't .net Core compatible yet, as opposed to the native .dll/.so approach, and I need to run some things cross-platform ASAP. – Yngve Moe Mar 24 '18 at 13:27

0 Answers0