چرا وقتی با کودا برنامه نویسی میکنم جواب صفر میگیرم
سلام من کد جمع کردن دو بردار 5 عضوی را در کودا می نویسم ولی وقتی جواب میگیرم تمام حاصل جمع ها رو صفر نشون میده.لطفا راهنمایی بفرمائید؟
ویندوز من 7 و toolkit9.1 و sdk مربوطه رو به همراه visual studio 2013 نصب کرده ام.
#include"cuda_runtime.h" #include"device_launch_parameters.h" #include<stdio.h> #include<conio.h> #include<iostream> __global__ void arith(int *a, int *b, int *c,int n) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < n) { c[i] = a[i] + b[i]; } } int main(){ const int count = 5; int ha[] = { 1, 2, 3, 4, 5 }; int hb[] = { 10, 20, 30, 40, 50 }; int hc[count]; int *da, *db, *dc; cudaMalloc(&da, count * sizeof(int)); cudaMalloc(&db, count * sizeof(int)); cudaMalloc(&dc, count * sizeof(int)); cudaMemcpy(da, ha, count * sizeof(int), cudaMemcpyHostToDevice); cudaMemcpy(db, hb, count * sizeof(int), cudaMemcpyHostToDevice); arith << <1, count >> >(da, db, dc, count); cudaMemcpy(hc, dc, count * sizeof(int), cudaMemcpyDeviceToHost); for (int j = 0; j < count; ++j)printf("t%dt + t %dt =t %dn", ha[j], hb[j], hc[j]); getchar(); }