1

説明できない動作を再現するコードは次のとおりです。

main.cpp

#include <iostream>
#include <openacc.h>

extern "C" int findme(float *ARRAY);

int main(){
    float *ARRAY = new float [10];
    int position;

    ARRAY[0] = 97.7302;
    ARRAY[1] = 108.154;
    ARRAY[2] = 99.8558;
    ARRAY[3] = 88.9383;
    ARRAY[4] = 98.4755;
    ARRAY[5] = 109.186;
    ARRAY[6] = 107.205;
    ARRAY[7] = 110.886;
    ARRAY[8] = 86.0737;
    ARRAY[9] = 94.9976;

    #pragma acc enter data copyin(ARRAY[0:10])

    #pragma acc host_data use_device(ARRAY)
        position = findme(ARRAY);

    #pragma acc exit data delete(ARRAY[0:10])

    std::cout << position << std::endl;
}

findme.cu

#include <thrust/binary_search.h>
#include <thrust/device_vector.h>
#include <thrust/functional.h>
#include <thrust/sort.h>

extern "C" int findme(float *ARRAY){
    thrust::device_ptr<float> ARRAY_ptr(ARRAY);
    thrust::device_vector<float> ARRAY_SORTED(10);
    thrust::copy(ARRAY_ptr, ARRAY_ptr+10, ARRAY_SORTED.begin());
    thrust::sort(ARRAY_SORTED.begin(), ARRAY_SORTED.end(), thrust::less<float>());
    thrust::device_vector<float>::iterator iter = thrust::lower_bound(ARRAY_SORTED.begin(), ARRAY_SORTED.end(), 100);

    return iter - ARRAY_SORTED.begin();
}

1 バイトのデバイスからホストへの転送が 1 つあります (8 バイトのデバイスからホストへの転送はposition int.

ここに画像の説明を入力

...そして 1 つのホストからデバイスへの 4 バイトの転送...

ここに画像の説明を入力

...説明できません。のコピーARRAYはスクリーンショットには表示されませんが、ホストからデバイスへの転送 (40 バイト) の [詳細] タブに含まれていることに注意してください。どのデータが正確に転送されているかについての手がかりはありますか? それらはスラスト アルゴリズムに固有のものであり、したがって避けられないものですか?

4

0 に答える 0