쿠다 (CUDA)를 배우기 시작했습니다. 나는 계승을 계산하는 프로그램을 썼다. 코드가 작동하지만, 계단식을 더 계산할 때 잘못된 값이 12 개가됩니다. CUDA가 잘못된 가치를 얻는 이유는 무엇입니까? 이 문제를 해결하는 방법? 이것은 내 코드입니다.쿠다 팩토리얼 값이 잘못되었습니다.
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <conio.h>
#define CUPRINTF cuPrintf
__device__ int silnia(int n)
{
if (n<2)
return 1; //silnia z 0 i 1 wynosi 1
return n*silnia(n - 1);
}
__global__ void kernel(int *a)
{
*a = silnia(15);
}
int main()
{
cudaEvent_t start, stop;
float elapsedTime;
cudaEventCreate(&start);
cudaEventRecord(start, 0);
int *dev_a,a;
cudaEventRecord(start);
cudaMalloc((void**)&dev_a, sizeof(int));
kernel << <1, 1 >> >(dev_a);
cudaMemcpy(&a, dev_a, sizeof(int), cudaMemcpyDeviceToHost);
cudaEventCreate(&stop);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&elapsedTime, start, stop);
printf("Elapsed time : %f ms\n", elapsedTime);
printf("%d", a);
getch();
return 0;
}
도움을 청합니다.
아마도 13! 32 비트 정수에 맞지 않습니다. – Mysticial