1

cuda环境装上之后核函数<<<>>>内的参数总是有问题

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include
using namespace std;
#define N 10
global void add(const int a, const int *b, int *c){
int tid = blockIdx.x;
if (tid < N){
c[tid] = a[tid] + b[tid];
}
}
int main(){
int a[N], b[N], c[N];
int *dev_a, *dev_b, *dev_c;
cudaMalloc((void
*)&dev_a, N*sizeof(int));
cudaMalloc((void**)&dev_b, N*sizeof(int));
cudaMalloc((void**)&dev_c, N*sizeof(int));
for (int i = 0; i < N; i++){
a[i] = -i;
b[i] = i*i;
}
cudaMemcpy(dev_a, a, N*sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(dev_b, b, N*sizeof(int), cudaMemcpyHostToDevice);
add<<>>(dev_a,dev_b, dev_c);
cudaMemcpy(c, dev_c, N*sizeof(int), cudaMemcpyHostToDevice);
for (int i = 0; i < N; i++){
printf("%d+%d=%d\n",a[i], b[i], c[i]);
}
cudaFree(dev_a);
cudaFree(dev_b);
cudaFree(dev_c);
return 0;
}
提示 add<<>>(dev_a,dev_b, dev_c);语句的第一个“1”要输入表达式

查看全部
MondayC
MondayC
2016/04/13 08:44
  • cuda
  • c
  • 点赞
  • 收藏
  • 回答
    私信

1个回复