をこれは、未回答のリストから、この質問を削除するには、ここに提供非常に遅く答えです。私はOPがすでに解決策を見つけたと確信していますが(2012年5月以降:-))、私は次のことが他のユーザにとって有用であると考えています。
@talonmiesで指摘されているように、この問題は融合ギャザーの削減によって解決できます。このソリューションは、Thurstのpermutation_iterator
とreduce
のアプリケーションです。 permutation_iterator
は、indices
配列内のインデックスに従って、ターゲット配列x
を(暗黙的に)並べ替えることができます。 reduce
は、(暗黙的に)並べ替えられた配列の合計を実行します。上記の例では便宜
#include <thrust/iterator/permutation_iterator.h>
#include <thrust/reduce.h>
#include <thrust/device_vector.h>
// this example fuses a gather operation with a reduction for
// greater efficiency than separate gather() and reduce() calls
int main(void)
{
// gather locations
thrust::device_vector<int> map(4);
map[0] = 3;
map[1] = 1;
map[2] = 0;
map[3] = 5;
// array to gather from
thrust::device_vector<int> source(6);
source[0] = 10;
source[1] = 20;
source[2] = 30;
source[3] = 40;
source[4] = 50;
source[5] = 60;
// fuse gather with reduction:
// sum = source[map[0]] + source[map[1]] + ...
int sum = thrust::reduce(thrust::make_permutation_iterator(source.begin(), map.begin()),
thrust::make_permutation_iterator(source.begin(), map.end()));
// print sum
std::cout << "sum is " << sum << std::endl;
return 0;
}
に対して報告の下
このアプリケーションはsource
がx
の役割を果たしながら、map
、indices
の役割を果たし、Thrust's documentationの一部です。あなたが反復する場合、
int sum = thrust::reduce(thrust::make_permutation_iterator(source.begin(), map.begin()),
thrust::make_permutation_iterator(source.begin(), map.begin()+N));
に次の行
int sum = thrust::reduce(thrust::make_permutation_iterator(source.begin(), map.begin()),
thrust::make_permutation_iterator(source.begin(), map.end()));
を変更するのに十分であろう(用語数の減少を反復)あなたのコメントで追加の質問については
インデックス配列map
の最初のN
の用語にのみ適用されます。
最後に、global_array
をホストから使用する可能性については、これはデバイスに常駐するベクターであることに気付くはずです。したがって、最初にホストに移動するにはcudaMemcpyFromSymbol
が必要です。
あなたは何をしようとしているのかもう少し説明できますか?合計は合計金額ですか(つまり、あなたの 'support'関数が融合集約であると思われますか)、それとも何か他のものですか?あなたがデバイス機能として 'サポート 'を表示することを選択した何らかの理由はありますか、それとも基本的に無関係なのでしょうか? – talonmies
推力を使用する場合は、適切なC++スタイルのIMOでコーディングする必要があります。 – leftaroundabout
@talonmiesあなたは私の問題を単に「融合集約」と言いました。それはまさに私が探していたものです!しかし、いくつかの事があります:*スラストクイックスタートガイド*(permutation_iterator)の例から、それらは完全な配列を反復するだけです。その代わりに、私は特定の数(上記のforループのように)を反復したいと思います。どうやってやるの ?そして、私はデバイスからglobal_array [N]をコピーする必要がありますか? – davideberdin