C ++ AMP-超额预订还是合作阻止?
C ++ AMP如何处理阻塞?
How does C++ AMP handle blocking?
运行中的并发可视化程序,我注意到我有很多额外的工作线程正在运行.实际上,每个活动的parallel_for_each,wait或copy调用都有一个额外的工作线程(同步").在我的具体情况下大约是32 额外的工作线程.
Running concurrency visualizer I noticed that I have a lot of extra worker threads running. Practically one extra worker thread (which is "synchronizing") for every active parallel_for_each, wait, or copy call. Which in my specific case is around 32 extra worker threads.
这是设计使然吗?还是我可能做错了什么?
Is this by design? Or am I possibly doing something wrong?
Dragon89,
对您所看到的内容的一种可能解释是:
- 您的程序正在使用PPL任务(由合作调度程序支持),这些任务用于执行C ++ AMP操作. http://msdn.microsoft.com/en-us/library/dd984036.aspx
- C ++ AMP阻止操作(例如wait()或copy())不是基于任务的,因此不会将基础线程放弃给合作调度程序.
- 您的程序创建了新的PPL任务,由于现有任务在非合作"的wait()和copy()上被阻止,因此调度程序决定为任务创建一个新线程.
- Your program is using PPL tasks (which are backed by a cooperative scheduler) and these task to perform C++ AMP operations. http://msdn.microsoft.com/en-us/library/dd984036.aspx
- C++ AMP blocking operations such as wait() or copy() are not based on tasks, therefore would not relinquish underlying thread to the cooperative scheduler.
- Your program creates new PPL tasks, and since existing tasks are blocked on "non-cooperative" wait() and copy(), the scheduler decides to create a new thread for a task.
在这种情况下,请考虑使用我们的异步API,例如copy_async或syncnize_async.这些函数会将命令发送给加速器,而不会阻塞您的线程.仅在需要结果时 您确实要等待().
If that is the case, please consider using our asynchronous APIs, such as copy_async or synchronize_async. These functions would send the command to accelerator and not block your thread. Only when the results are needed you do wait().
除了主线程之外,还有一个后台线程处理异步操作,并且由于我们的许多同步操作都是使用异步操作构建的,因此您还会看到该线程.
您在Concurrency Visualizer中看到的其余线程(http://blogs.msdn.com/b/nativeconcurrency/archive/2012/03/09/analyzing-c- amp-code-the-concurrency-visualizer.aspx ) 可能来自IHV驱动程序,在装有AMD和NVIDIA卡的计算机上,我看到3个由AMD创建的工作线程,1个具有NVIDIA堆栈的工作线程,以及1个来自D3D11参考设备的工作线程.
The remaining threads that you see in Concurrency Visualizer (http://blogs.msdn.com/b/nativeconcurrency/archive/2012/03/09/analyzing-c-amp-code-with-the-concurrency-visualizer.aspx) are likely coming from the IHV drivers, on my machine with AMD and NVIDIA card, I see 3 worker threads created by AMD, 1 worker thread with NVIDIA stack, and 1 worker thread from D3D11 reference device.
希望有帮助,
Simon