延迟分配array_view同步问题 [英] Lazy allocated array_view synchronization problem

查看:92
本文介绍了延迟分配array_view同步问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定在VS2013中使用新的延迟分配的array_view,但是似乎存在派生视图的同步问题.我的根视图是线性的,以允许仅在1级视图上进行重塑和其他操作.

I decided to use the new lazily allocated array_view in VS2013, but there seems to be a synchronization problem with derived views. My root view is linear to allow reshaping and other operations that can only be done on rank 1 views.

如果我创建线性视图和派生的形状视图,然后通过形状视图进行初始化,则修改不会与线性视图同步.我认为问题在于线性视图尚未在任何地方进行延迟初始化,因此AMP 即使它们似乎具有相同的主缓冲区指针,运行时也不会连接它们.初始化后,如果我在parallel_for_each中使用线性视图,则全为0.诸如同步和刷新之类的事情似乎没有任何作用.

If I create a linear view and a derived shaped view, then initialize through the shaped view, the modification is not synchronized with the linear view. I think the problem is that the linear view has not been lazily initialized anywhere yet, so the AMP runtime is not connecting them, even though they do seem to have the same master buffer pointer. After initialization, if I use the linear view in a parallel_for_each, it's just all 0's. Things like synchronize and refresh don't seem to make any difference.

我想念什么吗?

谢谢埃德

考虑:

#include <amp.h>
using namespace concurrency;

int _tmain(int argc, _TCHAR* argv[])
{
    array_view<float, 1> linear_view(6);
    array_view<float, 2> shaped_view = linear_view.view_as(extent<2>(3, 2));

    // shaped initialize on CPU
    for (int i = 1, r = 0; r < shaped_view.extent[0]; ++r) {
	for (int c = 0; c < shaped_view.extent[1]; ++c) {
	    shaped_view(r, c) = (float)i++;
	}
    }

    // linear operation, we'll just do a simple copy
    array_view<float, 1> result(linear_view.extent);

    parallel_for_each(result.extent, [=](index<1>& idx) restrict(amp) {
	result[idx] = linear_view[idx];
    });

    // these should all be 1.0
    float lval = linear_view(0);	// 1.0 good
    float sval = shaped_view(0, 0);	// 1.0 good
    float rval = result(0);		// 0.0 NOT GOOD!!, should be 1.0

    return 0;
}

推荐答案

嗯,很好奇...请注意,我没有查看语言规范,它可能包含答案,但这是一个猜测:如果将结果显式复制到与数据源关联的array_view中,会发生什么情况?

Hmm, curious...do note I haven't looked at the language specification, which might hold answers, but here's a guess: what happens if you explicitly copy result into an array_view that is associated with a data source, something like:

...
vector<float> foo(linear_view.extent.size(), 0.0f);
array_view<float, 1> result_foo(foo);
foo.copy_to(result_foo);

float rval = result_foo(0);
...


这篇关于延迟分配array_view同步问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆