-5
무엇이 잘못되었는지는 모르지만 두 벡터를 함께 추가하려고하지만 오류가 발생합니다. 나는 몇 가지 튜토리얼을 바라 보았다하지만 문제 표시되지 않는이 내 오류입니다 :CUDA 커널 매개 변수 비 호환성
argument of type "int **" is incompatible with parameter of type "int *"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void addKernel(int* c, int* a, int* b)
{
int i = threadIdx.x;
c[i] = a[i] + b[i];
}
int main()
{
const int arraySize = 5;
int a[arraySize] = { 1, 2, 3, 4, 5 };
int b[arraySize] = { 10, 20, 30, 40, 50 };
int c[arraySize] = { 0 };
int *d_a[arraySize];
int *d_b[arraySize];
int *d_c[arraySize];
cudaMalloc((void **)&d_a, arraySize*sizeof(int));
cudaMalloc((void **)&d_b, arraySize*sizeof(int));
cudaMalloc((void **)&d_c, arraySize*sizeof(int));
cudaMemcpy(d_a, a, arraySize*sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_b, b, arraySize*sizeof(int), cudaMemcpyHostToDevice);
dim3 block(5, 1, 1);
dim3 grid(1, 1, 1);
addKernel<<<block,grid>>>(d_c, d_a, d_b);
cudaMemcpy(c, d_c, arraySize*sizeof(int), cudaMemcpyDeviceToHost);
cudaFree(d_a);
cudaFree(d_b);
cudaFree(d_c);
printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n",
c[0], c[1], c[2], c[3], c[4]);
getchar();
return 0;
}
문제가 * 정확히 * 설명대로 컴파일러. 'd_a','d_b','d_C'는 포인터가 아니라 포인터의 배열입니다. 이 문제를 해결하면 코드가 * – talonmies
이되었습니다. 감사합니다. – user3542517
@talonmies이 게시물에 대한 짧은 답변을 제공해 주시겠습니까? 나는 그것을 upvote 것이다. – JackOLantern