2

スラストを使用して配列 c の合計を見つけていますが、「エラー: 式にはクラス型が必要です」というコンパイラ エラーが発生し続けます。

float tot = thrust::reduce(c.begin(), c.end());

これは機能していないコード行です。c は float 配列であり、他の 2 つの配列の要素の合計です。

乾杯

4

3 に答える 3

5

にポインタを渡すことができますthrust::reduce。ホストメモリに配列へのポインタがある場合、次のようなことができます:

float tot = thrust::reduce(c, c + N); // N is the length of c in words

thrust::device_ptrポインタがデバイス メモリ内の配列を指している場合は、最初にキャストする必要があります。

thrust::device_ptr<float> cptr = thrust::device_pointer_cast(c);
float tot = thrust::reduce(cptr, cptr + N); // N is the length of c in words
于 2012-04-16T20:33:56.653 に答える
4

c はorthrustなどの型でなければなりません。thrust::host_vectorthrust::device_vector

于 2012-04-16T16:35:32.623 に答える
3

Thrust の github ページには、thrust::reduce の例があります。オブジェクトのインスタンスではないため、単純な古い配列で .begin() を呼び出すことはできません。つまり、意味がありません。例として、以下のコードで配列 "b" に対して .begin() を呼び出すようなものです。

int main(void)
{
    thrust::host_vector<float> a(10);
    float b[10];

    thrust::fill(a.begin(), a.end(), 1.0);
    thrust::fill(b, b+10, 2.0);

    cout << "a: " << thrust::reduce(a.begin(), a.end()) << endl;
    cout << "b: " << thrust::reduce(b, b+10) << endl;

    return 0;
}
于 2012-04-16T16:48:27.453 に答える