access violation while using mex interface
Hi,
I've been using CPPEvalWrapper.cpp for a while along with mex interface for my matlab scripts and it was working fine. Suddenly, for now obvious(for me) reason, I started getting two access violation errors.
This is the piece of code that fails:
` char *input_path = mxArrayToString(prhs[0]);
mexPrintf("Model path is: %s\n", input_path);
std::string func = "GetEvalF";
auto hModule = LoadLibrary(_T("evaldll.dll"));
mexPrintf("First library loaded");
auto procAddress = GetProcAddress(hModule, func.c_str());
auto getEvalProc = (GetEvalProc<float>)procAddress;
IEvaluateModel<float> *model;
getEvalProc(&model);//FAIL HERE
`
Here is the error message I get:
[ 1] 0x00007ffa3e422efa \Documents\GitHub\CNTK\Source\Extensibility\CPPEvalClient\CPPEvalClient.mexw64+00012026 std::_Tree_buy<std::pair<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > const ,std::vector<float,std::allocator<float> > * __ptr64>,std::allocator<std::pair<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > const ,std::vector<float,std::allocator<float> > * __ptr64> > >::_Buynode<std::pair<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >,std::vector<float,std::allocator<float> > * __ptr64> >+00000010
The same message is shown two times in a row.
Any clues?
Thanks
Are you building the EvalDLL.dll (and EvalWrapper) from the code in the repository, or just using the binaries from the binary drop?
Are you able to run the CPPEvalClient from C++ without matlab? I want to see if the problem is repeatable using the C++ example in the source code.
Thanks.
Gaizka
Hi @gaizkan
thanks for your reply. I've rebuilt EvalDLL.dll. I did manage to build standalone application, now when I try to run this application in fails on the following line:
std::map<std::wstring, size_t> inDims;
With this message:
Unhandled exception at 0x00007FFF1CDEA1C8 (KernelBase.dll) in CPPEvalClient.exe: 0xC06D007E: Module not found (parameters: 0x000000911E80E840).
The funniest thing is that I can both build executable and run it on a different computer.
Any ideas? Thanks
It seems it does not find the DLL, or one of its dependencies.
Could try to copy all DLLs from the CNTK build folder over to your binary location, not just EvalDLL.dll?
And then try this:
Rundll32 Evaldll.32 Test
If it says "Function Test not found" then the DLL was loaded successfully, and your program should work as well.
Hi,
I have tried what you suggested - I've got this error "Entry not found"
I've started from scratch - downloaded source code again, compiled executable from this wrapper - perfectly works. Once I try to use it as a mex function - it consistently fails on the line
model->CreateNetwork(final_path);
Here is the full function I'm using:
` void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char *input_path = mxArrayToString(prhs[0]);
mexPrintf("Model path is: %s\n", input_path);
std::string func = "GetEvalF";
auto hModule = LoadLibrary(_T("evaldll.dll"));
mexPrintf("First library loaded\n");
auto procAddress = GetProcAddress(hModule, func.c_str());
auto getEvalProc = (GetEvalProc<float>)procAddress;
IEvaluateModel<float> *model;
getEvalProc(&model);
char * final_path;
sprintf(final_path, "modelPath=\"%s\"", input_path);
// model->CreateNetwork(final_path); } `
I'm in despair. The thing that it was working absolutely normally 3 days ago. Any ideas?
So if I understand correctly:
- You are able to run past the
getEvalProc(&model); - But now it throws an exception when calling
model->CreateNetwork(final_path);
Have you tried loading the model specified in final_path inside the CPPEvalClient code?
Have you tried loading the 01_OneHidden model (which you can train from the Examples\MNIST\Config\01_OneHidden.cntk) inside your mex interface?
Sometimes if the client is not a 64-bit application some issues come up, are you compiling your client with x64?
Can you give me the exact date (and if possible the commit hash) of the pull that last worked for you?
Hi @gaizkan
Your two assumptions are correct. For my mex test I'm using absolutely the same model for executables. I do not know the commit hash, but I have a feeling this will not help us anyway, because executables can be run on two different machines, whereas mex fails on both in the same way - on the line specified. Any chance I could provide you with minimum working example and compilation command for matlab so that you could try it on your machine?
Thanks
Hi, Unfortunately I don't have matlab or the matlab expertise. What is the exception you get when running? Thanks, Gaizka
Looking at your code, shouldn't you initialize final_path with a buffer e.g.:
char* final_path = new char[100];
preferably use a string:
std::string networkConfiguration; networkConfiguration += "modelPath=\"" + modelFilePath + "\""; model->CreateNetwork(networkConfiguration);
Let me know about the exception.
Thanks,
Gaizka
Hi, I've tried both ways. Both failed.
The exception is not useful here :( It is:
[ 0] 0x00007ff8b27d1a5f C:\GitHub\CNTK\Source\Extensibility\CPPEvalClient\CPPEvalClient.mexw64+00006751 wmain+00002175
Thanks, Sofeikov
Hi, I met the same problem with sofeikov. I'm trying to run the example CPPEvalClient project in the source code. I met the problem
exception at 0x00007FF96BE01F28 (KernelBase.dll) in CPPEvalClient.exe: 0xC06D007E: Module not found (parameters: 0x0000009CA87DEB60).
I check the Call Stack in Visual Studio, I get the following info:
kernelbase.pdb not loaded kernelbase.pdb contains the debug information required to find the source for the module KernelBase.dll
Module Information Version: 10.0.10586.306 (th2_release_sec.160422-1850)
Original Location C:\Windows\System32\KernelBase.dll
The computer is running Windows10 64 bit. I find two KernelBase.dll in C:\Windows\System32 and C:\Windows\SystemWOW64 respectively. Is it possible that some code goes to the wrong KernelBase.dll? I copied one of the two files into the same folder with EvalDll.dll. Both of them did not work. I try to set C:\Windows\SystemWOW64 as the first item in Path Environment variable, it still got same error info.
I run the command
Rundll32 Evaldll.32 Test
and got the following error:
There was a problem starting Evaldll.32 The specified module could not be found.
I can train/test a CNTK model correctly using "cntk.exe configFile=xxxx". Could you give some suggestions? Thank you all.
Zhengchen
A couple of clarifications:
- There is no EvalDll.32 it is EvalDll.dll
- You do not need to copy KernelBase.dll (That is an operating system file).
The binaries are built in x64, you'll need to setup your architecture selection through the Configuration Manager to be x64. Can you run CPPEvalClient from Visual Studio? There should be a Debug_CpuOnly configuration available. If so, in which line is the exception thrown? Also, you will need the 01_Hidden model from the MNIST Example in order to run CPPEvalClient successfully.
@sofeikov : One more thing you could try is linking directly to the EvalDLL.lib instead of loading it dynamically. Refer to the current CPPEvalClient on how this is done.
Do you link debug against debug and release against release?
Am 13.07.2016 um 14:05 schrieb Gaizka Navarro <[email protected]mailto:[email protected]>:
@sofeikovhttps://github.com/sofeikov : One more thing you could try is linking directly to the EvalDLL.lib instead of loading it dynamically. Refer to the current CPPEvalClient on how this is done.
You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/Microsoft/CNTK/issues/571#issuecomment-232335222, or mute the threadhttps://github.com/notifications/unsubscribe/ALtRQYcvR0YStNgytI-0IKHGu4fg_t75ks5qVNR0gaJpZM4Iy2DV.
Hi All,
Thank you for your reply. I change the dlls to libs, and load them in Visual Studio. Now it works. Thanks again.
Hi All, I have the same issue... I wrote my own DLL-wrapper but stuck with a call of model->CreateNetwork(networkConfiguration). I've tried all kind of linking - it does not help.
The result: 000007FEFD509E65 90 nop 000007FEFD509E64 C3 ret crash --> 000007FEFD509E5D 4881C4C8000000 add rsp, 0xc8 000007FEFD509E57 FF1543140400 call qword near [rip+0x41443] ; NlsUpdateLocale (kernelbase.dll) 000007FEFD509E52 488D4C2420 lea rcx, [rsp+0x20] 000007FEFD509E4E 894C2438 mov [rsp+0x38], ecx 000007FEFD509E48 0F853A0A0000 jnz dword 0x7fefd50a888 000007FEFD509E45 4D85C9 test r9, r9 000007FEFD509E40 48894C2428 mov [rsp+0x28], rcx 000007FEFD509E3C 89542424 mov [rsp+0x24], edx 000007FEFD509E37 4889442430 mov [rsp+0x30], rax 000007FEFD509E35 33C9 xor ecx, ecx 000007FEFD509E31 894C2420 mov [rsp+0x20], ecx 000007FEFD509E2A 488D05EFFFFFFF lea rax, [rip-0x11] 000007FEFD509E27 83E201 and edx, 0x1 000007FEFD509E20 4881ECC8000000 sub rsp, 0xc8 Unhandled exception 0xC06D007E
I use this code:
` CNTK2M_API int __stdcall c2M_open(char *FilePath, unsigned __int64 &cnn, char *FilePathOut) { std::string Outmsg; if (FilePath == NULL) return(-1); if (_ann >= ANNMAX) return(-1);
std::string modelFilePath(FilePath);
GetEvalF(&model);
cnn = (unsigned __int64)&model;
if (model == NULL) {
Outmsg = "Model NULL!";
std::strcpy(FilePathOut, Outmsg.c_str());
return(-1);
}
std::string networkConfiguration;
networkConfiguration = "modelPath=\"" + modelFilePath + "\"";
std::strcpy(FilePathOut, networkConfiguration.c_str()); // just for check to be sure for correct string
//return(-1);
model->CreateNetwork(networkConfiguration);
//return(-1);
` I would be very grateful for any help. Thanks.
I'm trying to make a full static linking lib for Evaldll. I use Release_CpuOnly. For Evaldll changed config type to Static lib, "runtime library" changed to "Multi-threaded (/MT)". While linking with my application I got error: error LNK2001: unresolved external symbol __imp_GetEvalF
I've check a lot of possible reasons, but for nothing... My be somebody have experience with that and give me a direction? Thanks.
Hi @Henry-White , It seems you didn't add the Additional Dependencies in the project. Try to add these and make sure your program can find them. EvalDll.lib Common.lib SequenceTrainingLib.lib Math.lib ComputationNetworkLib.lib ActionsLib.lib
Hi @ZhangZhengchen. I very appreciated for your respond. To achieve a clear result I tied to a make static linking for CPPEvalClient anf I got the same result (so all libs included, configuration "Release_CpuOnly", first out for EvalDLL, second for CPPEvalClient) :
1>------ Skipped Build: Project: MathCUDA, Configuration: Release x64 ------ 1>Project not selected to build for this solution configuration 2>------ Build started: Project: EvalDll, Configuration: Release_CpuOnly x64 ------ 2> Appending C:\Users\admin\Source\Repos\cntk\x64.build\Release_CpuOnly\Source\EvalDll\CNTKEval.obj 2> Appending C:\Users\admin\Source\Repos\cntk\x64.build\Release_CpuOnly\Source\EvalDll\dllmain.obj 2> Appending C:\Users\admin\Source\Repos\cntk\x64.build\Release_CpuOnly\Source\EvalDll\BrainScriptParser.obj 2> Appending C:\Users\admin\Source\Repos\cntk\x64.build\Release_CpuOnly\Source\EvalDll\BrainScriptEvaluator.obj 2> EvalDll.vcxproj -> C:\Users\admin\Source\Repos\cntk\x64\Release_CpuOnly\EvalDll.lib ========== Build: 1 succeeded, 0 failed, 6 up-to-date, 1 skipped ========== 1>------ Skipped Build: Project: MathCUDA, Configuration: Release x64 ------ 1>Project not selected to build for this solution configuration 2>------ Build started: Project: CPPEvalClient, Configuration: Release_CpuOnly x64 ------ 2>CPPEvalClient.obj : error LNK2001: unresolved external symbol __imp_GetEvalF 2>C:\Users\admin\Source\Repos\cntk\x64\Release_CpuOnly\CPPEvalClient.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 7 up-to-date, 1 skipped ==========
I've solved this problem by removing all dllexport statements and dllmain interfaces, but stuck with another (fatal error LNK1104: cannot open file 'msmpi.lib', but this is another story - working on it). CNTK does not adapted well for static linking. I'm not a member of this developing group, so I just can only offer, but I suppose that it would be useful to add some config.h in all modules where could be put all API defines, depending only on one define (for example, with values: STATIC or DYNAMIC).
This is belated but since I just joined CNTK I thought I should comment on this anyway. The way to debug these issues is to open your mex file in Visual studio and set a breakpoint near the location of your problem. Then on the menubar go to Debug -> Attach to Process and select Matlab. Then go to your Matlab prompt and run your mex function. It should hit the breakpoint and you will then be able to debug your code in Visual Studio.