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?