在OpenACC pragma行中使用struct数据类型

时间:2022-02-25 19:59:04

I'm using the CAPS OpenACC compiler. I've tried to use dynamic array inside of the struct data type in the OpenACC pragma lines. My code like that:

我正在使用CAPS OpenACC编译器。我试图在OpenACC pragma行中的struct数据类型中使用动态数组。我的代码是这样的:

struct Structure{
        int val[n];
        int length;
        int *valdyn;   
};
#pragma acc parallel copyin(sa,sb) copyout(c[0:n])
{
    #pragma acc loop 
    for (int i = 0; i < n; i++)
     c[i] = sa.valdyn[i] + sb.valdyn[i];
} 

It was compiled successfully. But when i tried to run, i got these errors

它编译成功。但是当我试图跑步时,我遇到了这些错误

terminate called after throwing an instance of 'hmpperr::DeviceError'
  what():  cuCtxSynchronize() failed: Launch failed (700)

So my question is that is there any way to use struct data types together with OpenACC? Moreover My case is also valid for struct in struct like that:

所以我的问题是有没有办法将结构数据类型与OpenACC一起使用?此外,我的情况对结构中的struct也有效:

struct Structure{
    int val[20];
    int length; 
    struct Other_Struct *Residue ;
    int *valdyn;    
};

1 个解决方案

#1


5  

In OpenACC, you can only use pointers to contiguous data in OpenACC data clauses - otherwise the compiler does not know how to copy the data to the device. In general, you can use Struct types as long as they don't have pointers or arrays to other data structures. You have to pass a pointer to val rather than a pointer to the structure that holds it, so for example:

在OpenACC中,您只能使用指向OpenACC数据子句中连续数据的指针 - 否则编译器不知道如何将数据复制到设备。通常,您可以使用Struct类型,只要它们没有指向其他数据结构的指针或数组即可。您必须将指针传递给val而不是指向保存它的结构的指针,例如:

struct Structure{  
    int val[n];
    int length;
    int *valdyn;   
};
int * sa_valdyn = sa.valdyn;
int * sb_valdyn = sb.valdyn;
#pragma acc parallel copyin(sa_valdyn[0:n],sb_valdyn[0:n]) copyout(c[0:n])
{
#pragma acc loop 
for (int i = 0; i < n; i++)
 c[i] = sa_valdyn[i] + sb_valdyn[i];
}

should work. Note also that you need to know the size of valdyn in order to copy the data to the device.

应该管用。另请注意,您需要知道valdyn的大小才能将数据复制到设备。

#1


5  

In OpenACC, you can only use pointers to contiguous data in OpenACC data clauses - otherwise the compiler does not know how to copy the data to the device. In general, you can use Struct types as long as they don't have pointers or arrays to other data structures. You have to pass a pointer to val rather than a pointer to the structure that holds it, so for example:

在OpenACC中,您只能使用指向OpenACC数据子句中连续数据的指针 - 否则编译器不知道如何将数据复制到设备。通常,您可以使用Struct类型,只要它们没有指向其他数据结构的指针或数组即可。您必须将指针传递给val而不是指向保存它的结构的指针,例如:

struct Structure{  
    int val[n];
    int length;
    int *valdyn;   
};
int * sa_valdyn = sa.valdyn;
int * sb_valdyn = sb.valdyn;
#pragma acc parallel copyin(sa_valdyn[0:n],sb_valdyn[0:n]) copyout(c[0:n])
{
#pragma acc loop 
for (int i = 0; i < n; i++)
 c[i] = sa_valdyn[i] + sb_valdyn[i];
}

should work. Note also that you need to know the size of valdyn in order to copy the data to the device.

应该管用。另请注意,您需要知道valdyn的大小才能将数据复制到设备。