1

私はちょうどこれを読んだ:

std::future のステータスを取得する

の機能は模倣しているようにConcurrency::completion_future見えるので、std::future同様のことができると思いましたが、この比較的単純な例は失敗します。

#include <assert.h>
#include <chrono>
#include <iostream>
#include <amp.h>

int main()
{
    using namespace Concurrency;
    int big = 1000000; // this should take a while to send back to the host
    array_view<int> av(big);

    parallel_for_each(extent<1>(big), [=](index<1> idx) restrict(amp)
    {
        av[idx] = idx[0];
    });
    int i = 0;
    completion_future future = av.synchronize_async();

    // this should be false; how could it instantly sent back so much data?
    bool const gpuFinished = future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;

    assert(!gpuFinished); // FAIL! why?

    future.wait();

    system("pause");
}

なぜそのアサートは失敗するのでしょうか?

4

2 に答える 2

1

免責事項: 私は AMP の専門家ではありません。

私の知る限り、array_viewそれ自体は何も表していません。それはあなたが何かに結びつける必要がある単なるビューです。したがって、基本的に、あなたのコードは私には意味がありません。同期する必要があるバックエンド メモリが CPU にありません。

次のコードを試してください。

#include <assert.h>
#include <chrono>
#include <iostream>
#include <amp.h>
#include <numeric>

int main()
{
    using namespace Concurrency;
    using namespace std;
    int big = 100000000; // this should take a while to send back to the host
    vector<int> vec(big);
    iota(begin(vec), end(vec), 0);
    array_view<int, 1> av(big, vec);

    parallel_for_each(Concurrency::extent<1>(big), [=](index<1> idx) restrict(amp)
    {
        av[idx] = av[idx] * av[idx];
    });
    int i = 0;
    completion_future future = av.synchronize_async();

    // this should be false; how could it instantly sent back so much data?
    bool const gpuFinished = future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;

    assert(!gpuFinished); // FAIL! why?

    future.wait();
    std::cout << vec[5];
}

期待どおりに動作するのは、あなたの変更にすぎません。

于 2013-11-15T08:53:44.737 に答える