PPL Parallel_for crashes - VS2010 vr. VS11
-
2012年4月26日 下午 09:23
Code that I had previously written with the PPL library in VS2010 now crashes randomly under V11. Has then been changes that I'm not aware of or are there any known issues
#include <amp.h>
#include <ppl.h>
using namespace concurrency;
void __stdcall float_to_char(long w, long h, float* buf, unsigned char* buf2) {
parallel_for((int)0, (int)h, [&](int y) {
int offset=(w*y);
for (int x=0;x<w;x++){
buf2[offset]=buf[offset];
offset++;
}
});
}
所有回覆
-
2012年4月27日 下午 09:42
This appears to be the same problem as with Parallel_For_each
The code crashes even if all of the inside body is commented out, so it's not a code problem.
However I was able to compile and run the parallel_for_each code finally when I found that we had an XP compatibilty flag set, which isn't the case here. Quick dumb question while I'm there? Will the parallel_for, which was previously handled by PPL, now only run in Windows 8? I'm on 7.
Unhandled exception at at 0x75BAB9BC Microsoft C++ exception: Concurrency::scheduler_resource_allocation_error at memory location 0x0018F094.
//
// Hand it off to the OS:
//
EHTRACE_EXIT;
#if defined(_M_X64) && defined(_NTSUBSET_)
RtlRaiseException( (PEXCEPTION_RECORD) &ThisException );
#else
RaiseException( ThisException.ExceptionCode,
ThisException.ExceptionFlags,
ThisException.NumberParameters,
(PULONG_PTR)&ThisException.params );
#endif
} <-- This was the break point in the debugger... -
2012年4月28日 上午 02:01
Hi Dan,
I think we may need more context on how to invoke your function.
Simply put it into the main function in following way , it won't repro on VS11 Beta or our most recent internal version.
#include <amp.h> #include <ppl.h> using namespace concurrency; void __stdcall float_to_char(long w, long h, float* buf, unsigned char* buf2) { parallel_for((int)0, (int)h, [&](int y) { int offset=(w*y); for (int x=0;x<w;x++){ buf2[offset]=buf[offset]; offset++; } }); } int main() { float *buffer = new float[10000]; unsigned char *buffer2 = new unsigned char [10000]; for (int i = 0; i < 1000; i++) { // try 1000 times float_to_char(100, 100, buffer, buffer2); } return 0; }
Hong -
2012年4月28日 下午 03:33
I'm calling from VB. There, I said it. I know, I'm evil.
-
2012年4月28日 下午 05:27Sorry for the sarcasm. Sometimes us old guys just have to support old code.
-
2012年4月28日 下午 08:35
I couldn't get this to crash in a C project. So, back to the drawing board on what's going on.
#include <amp.h>
#include <ppl.h>
using namespace concurrency;
void __stdcall float_to_char(long w, long h, float* buf, unsigned char* buf2) {
parallel_for((int)0, (int)h, [&](int y) {
int offset=(w*y);
for (int x=0;x<w;x++){
buf2[offset]=(unsigned char) buf[offset];
offset++;
}
});
}
int main()
{
int w=320;
int h=200;
float *buffer = new float[w*h];
unsigned char *buffer2 = new unsigned char [w*h];
for (int i = 0; i < 1000; i++)
{
// try 1000 times
float_to_char(w, h, buffer, buffer2);
}
//free memory
delete [] buffer;
delete [] buffer2;
return 0;
} -
2012年4月29日 下午 05:51
Ok, a few more questions. Both AMP and PPL seem to define their own concurrency namespaces. What exactly am I using when I use Parallel_for under VS11? Previously when I compiled under 2010, I used the /MT flag, I didn't need to include additional dependencies. Under 11 I needed to supply the AMP related dll. Since I was able to compile and run the above example, I'm assuming that is the only additional dependency I need. So, I'm probably barking up the wrong tree.
-
2012年4月30日 下午 04:48擁有者
Hi Dan,
parallel_for is PPL.
1. Can this be repro-ed without the /MT flag?
2. Can you take a look at the global objects? do you have any global objects related to the concurrency namespace? You might be crossing dll boundaries (i.e. allocating in one and freeing in the other).
Regards,
Rahul V. Patil
-
2012年5月1日 下午 10:43
So far I can't make any of it that uses Parallel_for not crash no matter what I do when I call from VB6. This is code that has been stable for months under VS2010.
And no I don't think I'm crossing any dll boundries. I just have these few functions in a dll and that's it.
-
2012年5月2日 上午 12:08擁有者
Hi Dan,
We have a hunch. There was a bug in the Developer preview, when mixing C++ AMP and PPL. Can you try excluding amp.h (and other amp related code)?
If it still fails, please feel free to email me. [ r_ a_ h_ u_ l d o t p_ a_ t_ i_ l a t m_ i_ c_ r_ o_ s_ o_ f_ t_ d o t c_ o_ m (delete all underscores and spaces; replace dot with ‘.’ and at with ‘@’).]
Thanks for your patience!
Rahul V. Patil
-
2012年5月2日 下午 06:55I'm planning on trying a single function DLL with just PPL and a fresh VB project and see if I get different results. It's just 3 or 4 items down the list of things to do right now.
-
2012年5月3日 下午 06:52
I can't simplify much more than this. This is the whole DLL, minus the .def file that defines the one function...
This crashes consistently whenever I call from VB (old VB, not .net). This is code that compiles and runs fine with 2010. And in 11 it's causing an exception before the code on the inside is being executed. even if I comment it out, it still crashes.
#include <Windows.h>
#include <ppl.h>
using namespace concurrency;
//function prototype
void __stdcall float_to_char(long w, long h, float* buf, unsigned char* buf2);
//dll entry point
BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason,
LPVOID Reserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
}
return TRUE;
}
//our function
void __stdcall float_to_char(long w, long h, float* buf, unsigned char* buf2) {
parallel_for((int)0, (int)h, [&](int y) {
int offset=(w*y);
for (int x=0;x<w;x++){
buf2[offset]=(unsigned char) buf[offset];
offset++;
}
});
}
- 已編輯 Dan Ritchie 2012年5月3日 下午 06:53
-
2012年5月3日 下午 07:30
I've compiled this with the /MD flag and it is now functioning.
- 已提議為解答 DanielMothMicrosoft Employee, Owner 2012年5月11日 上午 06:08
- 已標示為解答 DanielMothMicrosoft Employee, Owner 2012年5月17日 上午 03:58

