openmp调用要卸载到gpu的函数

问题描述 投票:1回答:1

我有这样的代码:

void foo(arr1,arr2,x,y,cnt1)
{ #pragma omp target data map (to: arr1, arr2, x, y, cnt1)
   #pragma omp target teams distribute parrallel for colapse(12)    
     for ........{
      for ......{
       ...............{
       int arr3[50];
         for (i=1; i<13; i++){
            arr3 [ arr1[i] ] = arr3 [ arr[1] ] + 1;
             }
         for (j=1; j<13; j++)              
          if (arr3[j] == 10) printf(ok);   // here is the problem 
      }
     }
    }

for (x=1; x<10; x++){
 for (y=1; y<10; y++){     
  some code here ......
   array arr1 is always the same, arr2 and variable cnt1 are updated (different every time)
    foo(arr1,arr2,x,y,cnt1);

    }
   }

问题是代码将for j循环冻结为int。

有人可以帮我吗?

c++ function gpu openmp target
1个回答
0
投票

我认为这里可能有两个问题。

首先,target data仅描述如何在卸载的设备上设置内存。您需要添加另一个编译指示才能在设备上实际执行代码。

第二,target data中的to类型仅将存储器复制到设备。即使在设备上执行了下一个代码块,也不会复制任何结果。

我的猜测是您想要类似的东西

target data map( to: ...)

[target data map( to: ...)指定您要将其复制到设备上,然后再复制回来,以便可以查看结果。

[#pragma omp target data map (tofrom: arr1, arr2, x, y, cnt1) #pragma omp target teams distribute parallel for for (int i = 0; i < N; i++) {/* blah blah */} 说您想在GPU上的块/线程之间分配for循环的迭代。

检查tofrom以获取更多有用的示例。

© www.soinside.com 2019 - 2024. All rights reserved.