- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there!
I'm trying to offload some code to the Xeon Phi in my MFC application, however when I run the application and get to the offload command I get an 0xC0000005: Access violation reading location exception. The project is built with the Visual C++ compiler and I use the Intel C++ compiler for the file that has the offload code. If I do the exact same thing in a win32 console application everything works fine.
I have also tried creating a static library with the Offload code in a separate project with the Intel C++ compiler and linking that to my MFC project, this gave the exact same result: also the access violation exception. The same issue with a DLL instead of the static library.
I couldn't find any info if it is even possible to use the Xeon Phi in combination with MFC, does anyone know if and how this can be done?
The project properties are a standard MFC project with the following changes:
- C/C++>Language>Run Time Type Information> NO (/GR-)
- C/C++>General>Additional Include Directories> $(WindowsSDK_IncludePath)
If I run this application on the actual machine with the Xeon Phi it results in a BSOD with WHEA_UNCORRECTABLE_ERROR.
I have attached a very basic MFC project that gives me the exception too. It tries to call the following function and the exception occurs as soon as the offload target command is used. How ever if I use the same function in an win32 console project everything works fine.
#include "Offload.h" #include <stdio.h> #include <stdlib.h> #include <omp.h> int GetNumProcs() { int totalProcs = 0; #pragma offload target(mic) { totalProcs = omp_get_num_procs(); } printf("Num procs = %d", totalProcs); return totalProcs; }
Any help is greatly appreciated!
Gerco
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sergey,
Thanks for the quick response. I have attached a simple MFC project that calls a test function that uses the offload pragma. The GetNumProcs() function works fine if called from a win32 project but it gives the access violation exception in the MFC project.
I don't do any calls on AFX_MANAGE_STATE(...) but maybe one of the MFC classes does this?
If you need anymore details please let me know.
Gerco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear (name withheld),
Would you please edit your profile to enable sharing your name. Note, if you wish, you can use an alias (pick one you can live with).
My KNC system is currently setup to run Linux, so I cannot test. When it was, the following would work for me on
C# (managed) -> C++ DLL (managed) -> Fortran DLL (unmanaged) -> offload -> Fortran .so on KNC (2)
What you may need to do is to take your Offload.cpp and place it into a new project that produces an unmanaged DLL.
Note, for debugging, there is (I found) a quirk and work around. The quirk was, after an edit session, the debugger could not directly place a breakpoint into the unmanaged code from the IDE until after I (you) stepped into the code. Only then would the debugger know the application was a mixture of managed and unmanaged code. I added a little "Here_I_am" function that did nothing but increment a static variable and return. I placed a call to this in the managed program at/near startup. Then for debugging the unmanaged code, place a break at the function call and then step into the locator. The first time you do this the debugger may ask if the code is unmanaged and where the source folder is located. You may also need to look at the properties of your managed code project in the Debug property pages. I seem to recall there is a check box to indicate if the debugger will be debugging managed/unmanaged code.
I hope this gets you going.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you try this:
... int GetNumProcs() { AFX_MANAGE_STATE( _afxModuleAddrThis ); int totalProcs = 0; #pragma offload target(mic) { totalProcs = omp_get_num_procs(); } printf("Num procs = %d", totalProcs); return totalProcs; } ...
Also, run Debug configuration step-by step and take a look in an Output Window for a last DLL loaded, any errors, or exceptions. I'd like to see a full output from the Output Window when the crash happens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry that I don't have a MIC to reproduce your problem.
Please show which instruction your program crashed at. I suppose that you are using Visual Studio because you write MFC codes. Configure your IDE (Debug --> Exception --> Win32 Exception --> tick the corresponding Thrown' check box) so that your program stops at the problem instruction.
Show the screen of disassembly including nearby instructions / source codes. In addition, show the call stack to locate which modules (right click the call stack window --> check to display module name) are involved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been trying all of the suggestions but if I want to call AFX_MANAGE_STATE I have to include afx.h in Offload.cpp which gives me the following compilation error: Offload.cpp(7): error : *MIC* cannot open source file "afx.h"
I have attached the full build output.
I have also attached the full output window when the crash happens. The breakpoint is triggered in the CWinApp deconstructor. I have also attached a screenshot of the breakpoint and the top of the call stack at that moment.
And yes, if I comment out the call to GetNumProcs the application works fine. If I comment out just the line with the #pragma offload it also works. I tried the offload pragma with just empty brackets under it, that also produces the crash.
Gerco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From your call stack, your program crashed at the destructor of the CWinApp object. 'liboffload!doexit' was called by 'liboffload!__offload_target_acquire' which was called at line 14 of your GetNumProcs function.
Please check whether 'omp_get_num_procs()' had been called before call to the function '__offload_target_acquire'
My best guess is to use the OFFLOAD_INIT=on_start environment variable. Otherwise add your #pragma offload directive to the beginning of the WinMain function......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The crash also happens without the omp_get_num_procs() function call.
Also I don't think OFFLOAD_INIT=on_start is going to help because I'm currently not testing on a machine with the coprocessor. Because I get the exact same exception on my laptop I use to develop.
I can't add #pragma offload to the beginning of the program since that is MFC code that is being compiled with VC++.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Gerco N. wrote:
I can't add #pragma offload to the beginning of the program since that is MFC code that is being compiled with VC++.
Run with Debug build then copy the contents of 'WinMain' to your own source file...... Then set the entry function to your own 'WinMain'......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Gerco N. wrote:
The crash also happens without the omp_get_num_procs() function call.
Also I don't think OFFLOAD_INIT=on_start is going to help because I'm currently not testing on a machine with the coprocessor. Because I get the exact same exception on my laptop I use to develop.
I can't add #pragma offload to the beginning of the program since that is MFC code that is being compiled with VC++.
Any update of the problem?
To clarify uncertainty, you need to show where 'liboffload!__offload_target_acquire()' was called at line 14 of your 'GetNumProcs' file. When your IDE catch the access violation exception, double click the 'GetNumProcs' stack frame in the call stack window. Then you'll be at line 14 of the 'GetNumProcs' file. Right click on the source file window and choose 'disassembly' to open the disassembly window. You'll see where the '__offload_target_acquire()' function was called. Finally capture the screen and show it here.
![](/skins/images/B7BA37F9CE4B52FF7CAE1FB0388839C8/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page