In der CUDA-Dokumentation habe ich festgestellt, dass cudaDeviceGetAttribute eine __host__ __device__
-Funktion ist. Also dachte ich, ich könnte es in meiner __global__
Funktion nennen, um einige Attribute meines Gerätes zu bekommen. Leider scheint es etwas anderes zu bedeuten, weil ich ein Kompilierfehlerereignis erhalte, wenn ich es in eine __device__
Funktion bringe und diese aus meinem globalen herausrufe.Kann ich eine __host__ __device__ Funktion nicht von einer __device__ Funktion aufrufen?
Ist es möglich, cudaDeviceGetAttribute auf meiner GPU aufzurufen? oder was bedeutet sonst __host__ __device__
?
Hier ist meine Quellcode:
__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 b = 3;
long time = 0;
int uni;
int* dev_a;
int* dev_b;
long* dev_time;
int* unique;
for (int i = 0; i < 10; ++i) {
cudaMalloc(&dev_a, sizeof(int));
cudaMalloc(&dev_b, sizeof(int));
cudaMalloc(&dev_time, sizeof(long));
cudaMalloc(&unique, sizeof(int));
cudaMemcpy(dev_a, &a, sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(dev_b, &b, sizeof(int), cudaMemcpyHostToDevice);
ClockTest <<<1,1>>>(dev_a, dev_b, dev_time, unique);
cudaMemcpy(&a, dev_a, sizeof(int), cudaMemcpyDeviceToHost);
cudaMemcpy(&time, dev_time, sizeof(long), cudaMemcpyDeviceToHost);
cudaMemcpy(&uni, unique, sizeof(int), cudaMemcpyDeviceToHost);
cudaFree(&dev_a);
cudaFree(&dev_b);
cudaFree(&dev_time);
cudaFree(&unique);
printf("%d\n", time);
printf("unique: %d\n", uni);
cudaDeviceReset();
}
return 0;
}
Warum möchten Sie diese Informationen in CUDA-Code erhalten? Warum kannst du nicht von der CPU anrufen und in die GPU gehen? –
Ich weiß, dass ich es von der CPU weitergeben konnte, aber für mein Projekt ist es notwendig, dass die Informationen aus Sicherheitsgründen im Gerät selbst gesammelt werden. –