Skip to content

Instantly share code, notes, and snippets.

@sachith-1
Created August 7, 2021 06:45
Show Gist options
  • Save sachith-1/3e146804d73f9039984486e793db1e0c to your computer and use it in GitHub Desktop.
Save sachith-1/3e146804d73f9039984486e793db1e0c to your computer and use it in GitHub Desktop.
int main() {
int n1, n2, sum;
int *dN1, *dN2, *dSum;
int size = sizeof(int);
// allocate device memory
cudaMalloc((void **)&dN1, size);
cudaMalloc((void **)&dN2, size);
cudaMalloc((void **)&dSum, size);
n1 = 10;
n2 = 15;
//copy from host memory to device memory
cudaMemcpy(dN1, &n1, size, cudaMemcpyHostToDevice);
cudaMemcpy(dN2, &n2, size, cudaMemcpyHostToDevice);
dim3 Dg(2, 2, 1);
dim3 Db(2, 2, 4);
getSum << <Dg, Db >> > (dN1, dN2, dSum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment