在CUDA文档中,我发现cudaDeviceGetAttribute是一个__host__ __device__函数.所以我想我可以在我的__global__函数中调用它来获取我的设备的一些属性.可悲的是,它似乎意味着不同的东西,因为如果我把它放入一个__device__函数并从我的全局调用它,我会得到一个编译错误事件.
是否可以在我的GPU上调用cudaDeviceGetAttribute?或者其他什么__host__ __device__意思?
这是我的源代码:
__device__ void GetAttributes(int* unique)
{
cudaDeviceAttr attr = cudaDevAttrMaxThreadsPerBlock;
cudaDeviceGetAttribute(unique, attr, 0);
}
__global__ void ClockTest(int* a, int* b, long* return_time, int* unique)
{
clock_t start = clock();
//some complex calculations
*a = *a + *b;
*b = *a + *a;
GetAttributes(unique);
*a = *a + *b - *a;
clock_t end = clock();
*return_time = end - start;
}
int main()
{
int a = 2;
int …Run Code Online (Sandbox Code Playgroud)