1. Two-D arrays using
1#include <iostream>2#include <cstdlib>3 using namespacestd;4 5 Static Const intROW =Ten;6 Static Const intCOL =5;7 8 intMain () {9 int* * Array = (int**)malloc(row*sizeof(int*));Ten int* Data = (int*)malloc(row*col*sizeof(int)); One A //Initialize the data - for(intI=0; i<row*col; i++) { -Data[i] =i; the } - - //Initialize the array - for(intI=0; i<row; i++) { +Array[i] = data + i*COL; - } + A //Output the array at for(intI=0; i<row; i++) - for(intj=0; j<col; J + +) { -cout << Array[i][j] <<Endl; - } - - Free(array); in Free(data); - to return 0; +}
Reference documents:
[1] What are the best Cuda open source codes? : https://www.zhihu.com/question/29036289/answer/42971562
[2] cuda one-dimensional matrix addition: http://tech.it168.com/a2009/1112/807/000000807771.shtml
[3] Cuda two-dimensional matrix addition: http://www.cnblogs.com/jugg1024/p/4349243.html
[4] NVIDIA CUDA Runtime API:HTTP://DOCS.NVIDIA.COM/CUDA/CUDA-RUNTIME-API/INDEX.HTML#AXZZ4G8M3LWLQ
Cuda Learning and Summary 2