作为初学者一直,经过多次的上网搜索你一定会看到迈克老狼的向量加法的示例,不知道你是否和我一样,刚开始并不是很准确的知道他的add.cl写的代码的意思,源码如下:

  1. #pragma OPENCL EXTENSION cl_amd_printf : enable
  2. __kernel void vecadd(__global const float* a, __global const float* b, __global float* c)
  3.  
  4. {
  5.  
  6. int x = get_global_id();
  7.  
  8. int y = get_global_id();
  9.  
  10. int width = get_global_size();
  11.  
  12. int height = get_global_size();
  13.  
  14. if(x == && y ==)
  15.  
  16. printf("%d, %d,%d,%d,%d,%d\n",get_local_size(),get_local_size(),get_local_id(),
  17.  
  18. get_local_id(),get_group_id(),get_group_id());
  19.  
  20. c[x + y * width] = a[x + y * width] + b[x + y * width];
  21.  
  22. }
  23.  
  24. 我们在k

这里面我把二维的这些值全部罗列出来如下:

int idx = get_global_id(0);
int idy = get_global_id(1);

uint wiWidth = get_global_size(0);
uint wiHeight = get_global_size(1);

uint gix_t = get_group_id(0);
uint giy_t = get_group_id(1);

uint num_of_blocks_x = get_num_groups(0);
uint num_of_blocks_y = get_num_groups(1);

uint lix = get_local_id(0);
uint liy = get_local_id(1);

你会奇怪为什么他的add.cl优化会这么写:

  1. c[x + y * width] = a[x + y * width] + b[x + y * width];

下面进行分析:

add.cpp关键的代码部分如下(只罗列出部分代码):

  1. #define width 8//256
  2. #define height 16//256
  3. #define NWITEMS width*height//262144
  4.  
  5. size_t globalThreads[] = {width, height};
  6. size_t localx, localy;
  7.  
  8. localx = 2;
  9. localy = 4;
  10.  
  11. size_t localThreads[] = {localx, localy};
  12.  
  13. clEnqueueNDRangeKernel( queue,
  14. kernel,
  15. 2,
  16. NULL,
  17. globalThreads,
  18. localThreads, 0, NULL, &ev);

我自己的add.cl代码如下(里面添加啦打印,以便我们可以看出结果):

  1.   int idx = get_global_id();
  2. int idy = get_global_id();
  3.  
  4. uint wiWidth = get_global_size();
  5. uint wiHeight = get_global_size();
  6. printf("Magnum Global idx = %d, idy = %d, sizeX =%d,sizeY =%d\n",idx,idy,wiWidth,wiHeight);
  7.  
  8. uint gix_t = get_group_id();
  9. uint giy_t = get_group_id();
  10. uint num_of_blocks_x = get_num_groups();
  11. uint num_of_blocks_y = get_num_groups();
  12.  
  13. printf("Magnum Group idx = %d, idy = %d, blockX=%d,blockY=%d\n",gix_t,gix_t,num_of_blocks_x,num_of_blocks_y);
  14.  
  15. uint lix = get_local_id();
  16. uint liy = get_local_id();
  17.  
  18. uint LocalX = get_local_size();
  19. uint LocalY = get_local_size();
  20.  
  21. printf("Magnum Local idx = %d, idy = %d, localX=%d,localY=%d\n\n",lix,liy,LocalX,LocalY);

输出的结果如下:

  1. Magnum Global idx = , idy = , sizeX =,sizeY =
  2. Magnum Group idx = , idy = , blockX=,blockY=
  3. Magnum Local idx = , idy = , localX=,localY=
  4.  
  5. Magnum Global idx = , idy = , sizeX =,sizeY =
  6. Magnum Group idx = , idy = , blockX=,blockY=
  7. Magnum Local idx = , idy = , localX=,localY=
  8.  
  9. Magnum Global idx = , idy = , sizeX =,sizeY =
  10. Magnum Group idx = , idy = , blockX=,blockY=
  11. Magnum Local idx = , idy = , localX=,localY=
  12.  
  13. Magnum Global idx = , idy = , sizeX =,sizeY =
  14. Magnum Group idx = , idy = , blockX=,blockY=
  15. Magnum Local idx = , idy = , localX=,localY=
  16.  
  17. Magnum Global idx = , idy = , sizeX =,sizeY =
  18. Magnum Group idx = , idy = , blockX=,blockY=
  19. Magnum Local idx = , idy = , localX=,localY=
  20.  
  21. Magnum Global idx = , idy = , sizeX =,sizeY =
  22. Magnum Group idx = , idy = , blockX=,blockY=
  23. Magnum Local idx = , idy = , localX=,localY=
  24.  
  25. Magnum Global idx = , idy = , sizeX =,sizeY =
  26. Magnum Group idx = , idy = , blockX=,blockY=
  27. Magnum Local idx = , idy = , localX=,localY=
  28.  
  29. Magnum Global idx = , idy = , sizeX =,sizeY =
  30. Magnum Group idx = , idy = , blockX=,blockY=
  31. Magnum Local idx = , idy = , localX=,localY=
  32.  
  33. Magnum Global idx = , idy = , sizeX =,sizeY =
  34. Magnum Group idx = , idy = , blockX=,blockY=
  35. Magnum Local idx = , idy = , localX=,localY=
  36.  
  37. Magnum Global idx = , idy = , sizeX =,sizeY =
  38. Magnum Group idx = , idy = , blockX=,blockY=
  39. Magnum Local idx = , idy = , localX=,localY=
  40.  
  41. Magnum Global idx = , idy = , sizeX =,sizeY =
  42. Magnum Group idx = , idy = , blockX=,blockY=
  43. Magnum Local idx = , idy = , localX=,localY=
  44.  
  45. Magnum Global idx = , idy = , sizeX =,sizeY =
  46. Magnum Group idx = , idy = , blockX=,blockY=
  47. Magnum Local idx = , idy = , localX=,localY=
  48.  
  49. Magnum Global idx = , idy = , sizeX =,sizeY =
  50. Magnum Group idx = , idy = , blockX=,blockY=
  51. Magnum Local idx = , idy = , localX=,localY=
  52.  
  53. Magnum Global idx = , idy = , sizeX =,sizeY =
  54. Magnum Group idx = , idy = , blockX=,blockY=
  55. Magnum Local idx = , idy = , localX=,localY=
  56.  
  57. Magnum Global idx = , idy = , sizeX =,sizeY =
  58. Magnum Group idx = , idy = , blockX=,blockY=
  59. Magnum Local idx = , idy = , localX=,localY=
  60.  
  61. Magnum Global idx = , idy = , sizeX =,sizeY =
  62. Magnum Group idx = , idy = , blockX=,blockY=
  63. Magnum Local idx = , idy = , localX=,localY=
  64.  
  65. Magnum Global idx = , idy = , sizeX =,sizeY =
  66. Magnum Group idx = , idy = , blockX=,blockY=
  67. Magnum Local idx = , idy = , localX=,localY=
  68.  
  69. Magnum Global idx = , idy = , sizeX =,sizeY =
  70. Magnum Group idx = , idy = , blockX=,blockY=
  71. Magnum Local idx = , idy = , localX=,localY=
  72.  
  73. Magnum Global idx = , idy = , sizeX =,sizeY =
  74. Magnum Group idx = , idy = , blockX=,blockY=
  75. Magnum Local idx = , idy = , localX=,localY=
  76.  
  77. Magnum Global idx = , idy = , sizeX =,sizeY =
  78. Magnum Group idx = , idy = , blockX=,blockY=
  79. Magnum Local idx = , idy = , localX=,localY=
  80.  
  81. Magnum Global idx = , idy = , sizeX =,sizeY =
  82. Magnum Group idx = , idy = , blockX=,blockY=
  83. Magnum Local idx = , idy = , localX=,localY=
  84.  
  85. Magnum Global idx = , idy = , sizeX =,sizeY =
  86. Magnum Group idx = , idy = , blockX=,blockY=
  87. Magnum Local idx = , idy = , localX=,localY=
  88.  
  89. Magnum Global idx = , idy = , sizeX =,sizeY =
  90. Magnum Group idx = , idy = , blockX=,blockY=
  91. Magnum Local idx = , idy = , localX=,localY=
  92.  
  93. Magnum Global idx = , idy = , sizeX =,sizeY =
  94. Magnum Group idx = , idy = , blockX=,blockY=
  95. Magnum Local idx = , idy = , localX=,localY=
  96.  
  97. Magnum Global idx = , idy = , sizeX =,sizeY =
  98. Magnum Group idx = , idy = , blockX=,blockY=
  99. Magnum Local idx = , idy = , localX=,localY=
  100.  
  101. Magnum Global idx = , idy = , sizeX =,sizeY =
  102. Magnum Group idx = , idy = , blockX=,blockY=
  103. Magnum Local idx = , idy = , localX=,localY=
  104.  
  105. Magnum Global idx = , idy = , sizeX =,sizeY =
  106. Magnum Group idx = , idy = , blockX=,blockY=
  107. Magnum Local idx = , idy = , localX=,localY=
  108.  
  109. Magnum Global idx = , idy = , sizeX =,sizeY =
  110. Magnum Group idx = , idy = , blockX=,blockY=
  111. Magnum Local idx = , idy = , localX=,localY=
  112.  
  113. Magnum Global idx = , idy = , sizeX =,sizeY =
  114. Magnum Group idx = , idy = , blockX=,blockY=
  115. Magnum Local idx = , idy = , localX=,localY=
  116.  
  117. Magnum Global idx = , idy = , sizeX =,sizeY =
  118. Magnum Group idx = , idy = , blockX=,blockY=
  119. Magnum Local idx = , idy = , localX=,localY=
  120.  
  121. Magnum Global idx = , idy = , sizeX =,sizeY =
  122. Magnum Group idx = , idy = , blockX=,blockY=
  123. Magnum Local idx = , idy = , localX=,localY=
  124.  
  125. Magnum Global idx = , idy = , sizeX =,sizeY =
  126. Magnum Group idx = , idy = , blockX=,blockY=
  127. Magnum Local idx = , idy = , localX=,localY=
  128.  
  129. Magnum Global idx = , idy = , sizeX =,sizeY =
  130. Magnum Group idx = , idy = , blockX=,blockY=
  131. Magnum Local idx = , idy = , localX=,localY=
  132.  
  133. Magnum Global idx = , idy = , sizeX =,sizeY =
  134. Magnum Group idx = , idy = , blockX=,blockY=
  135. Magnum Local idx = , idy = , localX=,localY=
  136.  
  137. Magnum Global idx = , idy = , sizeX =,sizeY =
  138. Magnum Group idx = , idy = , blockX=,blockY=
  139. Magnum Local idx = , idy = , localX=,localY=
  140.  
  141. Magnum Global idx = , idy = , sizeX =,sizeY =
  142. Magnum Group idx = , idy = , blockX=,blockY=
  143. Magnum Local idx = , idy = , localX=,localY=
  144.  
  145. Magnum Global idx = , idy = , sizeX =,sizeY =
  146. Magnum Group idx = , idy = , blockX=,blockY=
  147. Magnum Local idx = , idy = , localX=,localY=
  148.  
  149. Magnum Global idx = , idy = , sizeX =,sizeY =
  150. Magnum Group idx = , idy = , blockX=,blockY=
  151. Magnum Local idx = , idy = , localX=,localY=
  152.  
  153. Magnum Global idx = , idy = , sizeX =,sizeY =
  154. Magnum Group idx = , idy = , blockX=,blockY=
  155. Magnum Local idx = , idy = , localX=,localY=
  156.  
  157. Magnum Global idx = , idy = , sizeX =,sizeY =
  158. Magnum Group idx = , idy = , blockX=,blockY=
  159. Magnum Local idx = , idy = , localX=,localY=
  160.  
  161. Magnum Global idx = , idy = , sizeX =,sizeY =
  162. Magnum Group idx = , idy = , blockX=,blockY=
  163. Magnum Local idx = , idy = , localX=,localY=
  164.  
  165. Magnum Global idx = , idy = , sizeX =,sizeY =
  166. Magnum Group idx = , idy = , blockX=,blockY=
  167. Magnum Local idx = , idy = , localX=,localY=
  168.  
  169. Magnum Global idx = , idy = , sizeX =,sizeY =
  170. Magnum Group idx = , idy = , blockX=,blockY=
  171. Magnum Local idx = , idy = , localX=,localY=
  172.  
  173. Magnum Global idx = , idy = , sizeX =,sizeY =
  174. Magnum Group idx = , idy = , blockX=,blockY=
  175. Magnum Local idx = , idy = , localX=,localY=
  176.  
  177. Magnum Global idx = , idy = , sizeX =,sizeY =
  178. Magnum Group idx = , idy = , blockX=,blockY=
  179. Magnum Local idx = , idy = , localX=,localY=
  180.  
  181. Magnum Global idx = , idy = , sizeX =,sizeY =
  182. Magnum Group idx = , idy = , blockX=,blockY=
  183. Magnum Local idx = , idy = , localX=,localY=
  184.  
  185. Magnum Global idx = , idy = , sizeX =,sizeY =
  186. Magnum Group idx = , idy = , blockX=,blockY=
  187. Magnum Local idx = , idy = , localX=,localY=
  188.  
  189. Magnum Global idx = , idy = , sizeX =,sizeY =
  190. Magnum Group idx = , idy = , blockX=,blockY=
  191. Magnum Local idx = , idy = , localX=,localY=
  192.  
  193. Magnum Global idx = , idy = , sizeX =,sizeY =
  194. Magnum Group idx = , idy = , blockX=,blockY=
  195. Magnum Local idx = , idy = , localX=,localY=
  196.  
  197. Magnum Global idx = , idy = , sizeX =,sizeY =
  198. Magnum Group idx = , idy = , blockX=,blockY=
  199. Magnum Local idx = , idy = , localX=,localY=
  200.  
  201. Magnum Global idx = , idy = , sizeX =,sizeY =
  202. Magnum Group idx = , idy = , blockX=,blockY=
  203. Magnum Local idx = , idy = , localX=,localY=
  204.  
  205. Magnum Global idx = , idy = , sizeX =,sizeY =
  206. Magnum Group idx = , idy = , blockX=,blockY=
  207. Magnum Local idx = , idy = , localX=,localY=
  208.  
  209. Magnum Global idx = , idy = , sizeX =,sizeY =
  210. Magnum Group idx = , idy = , blockX=,blockY=
  211. Magnum Local idx = , idy = , localX=,localY=
  212.  
  213. Magnum Global idx = , idy = , sizeX =,sizeY =
  214. Magnum Group idx = , idy = , blockX=,blockY=
  215. Magnum Local idx = , idy = , localX=,localY=
  216.  
  217. Magnum Global idx = , idy = , sizeX =,sizeY =
  218. Magnum Group idx = , idy = , blockX=,blockY=
  219. Magnum Local idx = , idy = , localX=,localY=
  220.  
  221. Magnum Global idx = , idy = , sizeX =,sizeY =
  222. Magnum Group idx = , idy = , blockX=,blockY=
  223. Magnum Local idx = , idy = , localX=,localY=
  224.  
  225. Magnum Global idx = , idy = , sizeX =,sizeY =
  226. Magnum Group idx = , idy = , blockX=,blockY=
  227. Magnum Local idx = , idy = , localX=,localY=
  228.  
  229. Magnum Global idx = , idy = , sizeX =,sizeY =
  230. Magnum Group idx = , idy = , blockX=,blockY=
  231. Magnum Local idx = , idy = , localX=,localY=
  232.  
  233. Magnum Global idx = , idy = , sizeX =,sizeY =
  234. Magnum Group idx = , idy = , blockX=,blockY=
  235. Magnum Local idx = , idy = , localX=,localY=
  236.  
  237. Magnum Global idx = , idy = , sizeX =,sizeY =
  238. Magnum Group idx = , idy = , blockX=,blockY=
  239. Magnum Local idx = , idy = , localX=,localY=
  240.  
  241. Magnum Global idx = , idy = , sizeX =,sizeY =
  242. Magnum Group idx = , idy = , blockX=,blockY=
  243. Magnum Local idx = , idy = , localX=,localY=
  244.  
  245. Magnum Global idx = , idy = , sizeX =,sizeY =
  246. Magnum Group idx = , idy = , blockX=,blockY=
  247. Magnum Local idx = , idy = , localX=,localY=
  248.  
  249. Magnum Global idx = , idy = , sizeX =,sizeY =
  250. Magnum Group idx = , idy = , blockX=,blockY=
  251. Magnum Local idx = , idy = , localX=,localY=
  252.  
  253. Magnum Global idx = , idy = , sizeX =,sizeY =
  254. Magnum Group idx = , idy = , blockX=,blockY=
  255. Magnum Local idx = , idy = , localX=,localY=
  256.  
  257. Magnum Global idx = , idy = , sizeX =,sizeY =
  258. Magnum Group idx = , idy = , blockX=,blockY=
  259. Magnum Local idx = , idy = , localX=,localY=
  260.  
  261. Magnum Global idx = , idy = , sizeX =,sizeY =
  262. Magnum Group idx = , idy = , blockX=,blockY=
  263. Magnum Local idx = , idy = , localX=,localY=
  264.  
  265. Magnum Global idx = , idy = , sizeX =,sizeY =
  266. Magnum Group idx = , idy = , blockX=,blockY=
  267. Magnum Local idx = , idy = , localX=,localY=
  268.  
  269. Magnum Global idx = , idy = , sizeX =,sizeY =
  270. Magnum Group idx = , idy = , blockX=,blockY=
  271. Magnum Local idx = , idy = , localX=,localY=
  272.  
  273. Magnum Global idx = , idy = , sizeX =,sizeY =
  274. Magnum Group idx = , idy = , blockX=,blockY=
  275. Magnum Local idx = , idy = , localX=,localY=
  276.  
  277. Magnum Global idx = , idy = , sizeX =,sizeY =
  278. Magnum Group idx = , idy = , blockX=,blockY=
  279. Magnum Local idx = , idy = , localX=,localY=
  280.  
  281. Magnum Global idx = , idy = , sizeX =,sizeY =
  282. Magnum Group idx = , idy = , blockX=,blockY=
  283. Magnum Local idx = , idy = , localX=,localY=
  284.  
  285. Magnum Global idx = , idy = , sizeX =,sizeY =
  286. Magnum Group idx = , idy = , blockX=,blockY=
  287. Magnum Local idx = , idy = , localX=,localY=
  288.  
  289. Magnum Global idx = , idy = , sizeX =,sizeY =
  290. Magnum Group idx = , idy = , blockX=,blockY=
  291. Magnum Local idx = , idy = , localX=,localY=
  292.  
  293. Magnum Global idx = , idy = , sizeX =,sizeY =
  294. Magnum Group idx = , idy = , blockX=,blockY=
  295. Magnum Local idx = , idy = , localX=,localY=
  296.  
  297. Magnum Global idx = , idy = , sizeX =,sizeY =
  298. Magnum Group idx = , idy = , blockX=,blockY=
  299. Magnum Local idx = , idy = , localX=,localY=
  300.  
  301. Magnum Global idx = , idy = , sizeX =,sizeY =
  302. Magnum Group idx = , idy = , blockX=,blockY=
  303. Magnum Local idx = , idy = , localX=,localY=
  304.  
  305. Magnum Global idx = , idy = , sizeX =,sizeY =
  306. Magnum Group idx = , idy = , blockX=,blockY=
  307. Magnum Local idx = , idy = , localX=,localY=
  308.  
  309. Magnum Global idx = , idy = , sizeX =,sizeY =
  310. Magnum Group idx = , idy = , blockX=,blockY=
  311. Magnum Local idx = , idy = , localX=,localY=
  312.  
  313. Magnum Global idx = , idy = , sizeX =,sizeY =
  314. Magnum Group idx = , idy = , blockX=,blockY=
  315. Magnum Local idx = , idy = , localX=,localY=
  316.  
  317. Magnum Global idx = , idy = , sizeX =,sizeY =
  318. Magnum Group idx = , idy = , blockX=,blockY=
  319. Magnum Local idx = , idy = , localX=,localY=
  320.  
  321. Magnum Global idx = , idy = , sizeX =,sizeY =
  322. Magnum Group idx = , idy = , blockX=,blockY=
  323. Magnum Local idx = , idy = , localX=,localY=
  324.  
  325. Magnum Global idx = , idy = , sizeX =,sizeY =
  326. Magnum Group idx = , idy = , blockX=,blockY=
  327. Magnum Local idx = , idy = , localX=,localY=
  328.  
  329. Magnum Global idx = , idy = , sizeX =,sizeY =
  330. Magnum Group idx = , idy = , blockX=,blockY=
  331. Magnum Local idx = , idy = , localX=,localY=
  332.  
  333. Magnum Global idx = , idy = , sizeX =,sizeY =
  334. Magnum Group idx = , idy = , blockX=,blockY=
  335. Magnum Local idx = , idy = , localX=,localY=
  336.  
  337. Magnum Global idx = , idy = , sizeX =,sizeY =
  338. Magnum Group idx = , idy = , blockX=,blockY=
  339. Magnum Local idx = , idy = , localX=,localY=
  340.  
  341. Magnum Global idx = , idy = , sizeX =,sizeY =
  342. Magnum Group idx = , idy = , blockX=,blockY=
  343. Magnum Local idx = , idy = , localX=,localY=
  344.  
  345. Magnum Global idx = , idy = , sizeX =,sizeY =
  346. Magnum Group idx = , idy = , blockX=,blockY=
  347. Magnum Local idx = , idy = , localX=,localY=
  348.  
  349. Magnum Global idx = , idy = , sizeX =,sizeY =
  350. Magnum Group idx = , idy = , blockX=,blockY=
  351. Magnum Local idx = , idy = , localX=,localY=
  352.  
  353. Magnum Global idx = , idy = , sizeX =,sizeY =
  354. Magnum Group idx = , idy = , blockX=,blockY=
  355. Magnum Local idx = , idy = , localX=,localY=
  356.  
  357. Magnum Global idx = , idy = , sizeX =,sizeY =
  358. Magnum Group idx = , idy = , blockX=,blockY=
  359. Magnum Local idx = , idy = , localX=,localY=
  360.  
  361. Magnum Global idx = , idy = , sizeX =,sizeY =
  362. Magnum Group idx = , idy = , blockX=,blockY=
  363. Magnum Local idx = , idy = , localX=,localY=
  364.  
  365. Magnum Global idx = , idy = , sizeX =,sizeY =
  366. Magnum Group idx = , idy = , blockX=,blockY=
  367. Magnum Local idx = , idy = , localX=,localY=
  368.  
  369. Magnum Global idx = , idy = , sizeX =,sizeY =
  370. Magnum Group idx = , idy = , blockX=,blockY=
  371. Magnum Local idx = , idy = , localX=,localY=
  372.  
  373. Magnum Global idx = , idy = , sizeX =,sizeY =
  374. Magnum Group idx = , idy = , blockX=,blockY=
  375. Magnum Local idx = , idy = , localX=,localY=
  376.  
  377. Magnum Global idx = , idy = , sizeX =,sizeY =
  378. Magnum Group idx = , idy = , blockX=,blockY=
  379. Magnum Local idx = , idy = , localX=,localY=
  380.  
  381. Magnum Global idx = , idy = , sizeX =,sizeY =
  382. Magnum Group idx = , idy = , blockX=,blockY=
  383. Magnum Local idx = , idy = , localX=,localY=
  384.  
  385. Magnum Global idx = , idy = , sizeX =,sizeY =
  386. Magnum Group idx = , idy = , blockX=,blockY=
  387. Magnum Local idx = , idy = , localX=,localY=
  388.  
  389. Magnum Global idx = , idy = , sizeX =,sizeY =
  390. Magnum Group idx = , idy = , blockX=,blockY=
  391. Magnum Local idx = , idy = , localX=,localY=
  392.  
  393. Magnum Global idx = , idy = , sizeX =,sizeY =
  394. Magnum Group idx = , idy = , blockX=,blockY=
  395. Magnum Local idx = , idy = , localX=,localY=
  396.  
  397. Magnum Global idx = , idy = , sizeX =,sizeY =
  398. Magnum Group idx = , idy = , blockX=,blockY=
  399. Magnum Local idx = , idy = , localX=,localY=
  400.  
  401. Magnum Global idx = , idy = , sizeX =,sizeY =
  402. Magnum Group idx = , idy = , blockX=,blockY=
  403. Magnum Local idx = , idy = , localX=,localY=
  404.  
  405. Magnum Global idx = , idy = , sizeX =,sizeY =
  406. Magnum Group idx = , idy = , blockX=,blockY=
  407. Magnum Local idx = , idy = , localX=,localY=
  408.  
  409. Magnum Global idx = , idy = , sizeX =,sizeY =
  410. Magnum Group idx = , idy = , blockX=,blockY=
  411. Magnum Local idx = , idy = , localX=,localY=
  412.  
  413. Magnum Global idx = , idy = , sizeX =,sizeY =
  414. Magnum Group idx = , idy = , blockX=,blockY=
  415. Magnum Local idx = , idy = , localX=,localY=
  416.  
  417. Magnum Global idx = , idy = , sizeX =,sizeY =
  418. Magnum Group idx = , idy = , blockX=,blockY=
  419. Magnum Local idx = , idy = , localX=,localY=
  420.  
  421. Magnum Global idx = , idy = , sizeX =,sizeY =
  422. Magnum Group idx = , idy = , blockX=,blockY=
  423. Magnum Local idx = , idy = , localX=,localY=
  424.  
  425. Magnum Global idx = , idy = , sizeX =,sizeY =
  426. Magnum Group idx = , idy = , blockX=,blockY=
  427. Magnum Local idx = , idy = , localX=,localY=
  428.  
  429. Magnum Global idx = , idy = , sizeX =,sizeY =
  430. Magnum Group idx = , idy = , blockX=,blockY=
  431. Magnum Local idx = , idy = , localX=,localY=
  432.  
  433. Magnum Global idx = , idy = , sizeX =,sizeY =
  434. Magnum Group idx = , idy = , blockX=,blockY=
  435. Magnum Local idx = , idy = , localX=,localY=
  436.  
  437. Magnum Global idx = , idy = , sizeX =,sizeY =
  438. Magnum Group idx = , idy = , blockX=,blockY=
  439. Magnum Local idx = , idy = , localX=,localY=
  440.  
  441. Magnum Global idx = , idy = , sizeX =,sizeY =
  442. Magnum Group idx = , idy = , blockX=,blockY=
  443. Magnum Local idx = , idy = , localX=,localY=
  444.  
  445. Magnum Global idx = , idy = , sizeX =,sizeY =
  446. Magnum Group idx = , idy = , blockX=,blockY=
  447. Magnum Local idx = , idy = , localX=,localY=
  448.  
  449. Magnum Global idx = , idy = , sizeX =,sizeY =
  450. Magnum Group idx = , idy = , blockX=,blockY=
  451. Magnum Local idx = , idy = , localX=,localY=
  452.  
  453. Magnum Global idx = , idy = , sizeX =,sizeY =
  454. Magnum Group idx = , idy = , blockX=,blockY=
  455. Magnum Local idx = , idy = , localX=,localY=
  456.  
  457. Magnum Global idx = , idy = , sizeX =,sizeY =
  458. Magnum Group idx = , idy = , blockX=,blockY=
  459. Magnum Local idx = , idy = , localX=,localY=
  460.  
  461. Magnum Global idx = , idy = , sizeX =,sizeY =
  462. Magnum Group idx = , idy = , blockX=,blockY=
  463. Magnum Local idx = , idy = , localX=,localY=
  464.  
  465. Magnum Global idx = , idy = , sizeX =,sizeY =
  466. Magnum Group idx = , idy = , blockX=,blockY=
  467. Magnum Local idx = , idy = , localX=,localY=
  468.  
  469. Magnum Global idx = , idy = , sizeX =,sizeY =
  470. Magnum Group idx = , idy = , blockX=,blockY=
  471. Magnum Local idx = , idy = , localX=,localY=
  472.  
  473. Magnum Global idx = , idy = , sizeX =,sizeY =
  474. Magnum Group idx = , idy = , blockX=,blockY=
  475. Magnum Local idx = , idy = , localX=,localY=
  476.  
  477. Magnum Global idx = , idy = , sizeX =,sizeY =
  478. Magnum Group idx = , idy = , blockX=,blockY=
  479. Magnum Local idx = , idy = , localX=,localY=
  480.  
  481. Magnum Global idx = , idy = , sizeX =,sizeY =
  482. Magnum Group idx = , idy = , blockX=,blockY=
  483. Magnum Local idx = , idy = , localX=,localY=
  484.  
  485. Magnum Global idx = , idy = , sizeX =,sizeY =
  486. Magnum Group idx = , idy = , blockX=,blockY=
  487. Magnum Local idx = , idy = , localX=,localY=
  488.  
  489. Magnum Global idx = , idy = , sizeX =,sizeY =
  490. Magnum Group idx = , idy = , blockX=,blockY=
  491. Magnum Local idx = , idy = , localX=,localY=
  492.  
  493. Magnum Global idx = , idy = , sizeX =,sizeY =
  494. Magnum Group idx = , idy = , blockX=,blockY=
  495. Magnum Local idx = , idy = , localX=,localY=
  496.  
  497. Magnum Global idx = , idy = , sizeX =,sizeY =
  498. Magnum Group idx = , idy = , blockX=,blockY=
  499. Magnum Local idx = , idy = , localX=,localY=
  500.  
  501. Magnum Global idx = , idy = , sizeX =,sizeY =
  502. Magnum Group idx = , idy = , blockX=,blockY=
  503. Magnum Local idx = , idy = , localX=,localY=
  504.  
  505. Magnum Global idx = , idy = , sizeX =,sizeY =
  506. Magnum Group idx = , idy = , blockX=,blockY=
  507. Magnum Local idx = , idy = , localX=,localY=
  508.  
  509. Magnum Global idx = , idy = , sizeX =,sizeY =
  510. Magnum Group idx = , idy = , blockX=,blockY=
  511. Magnum Local idx = , idy = , localX=,localY=

从从这个结果首先能说明几个问题:

首先我们在:

  1. clEnqueueNDRangeKernel( queue, kernel, , NULL, globalThreads, localThreads, 0, NULL, &ev); 设置维度是2,否则add.cl中所有类似get_local_size(1)将只会返回一。
  2. 设置GlobaThreads 和 LocalThreads 不一定是 GlobalThreads= {8, 8}; 也可以不相等,LocalThreads也是一样。
  3. 理解opencl中的内存分布可以理解为二维数组,而且内存寻址的方向就像是:左上角(0,0)为原点,一行一行的扫描下去。
  4. WorkGroup的大小,目前我认为X,Y可以分开来理解(后面若发现错误我会及时改正) WorkGroup number(x) = GlobalThread(x)/LocalThread(x).
  5. 最小的单位是LocalX * LocalY, 然后用总的GlobalThreads按照这个单位进行分割成一个一个的组。每个二维的小单位还是一行一行的扫描过去的。目前我们的这个是8*16,你会发现总的Thread也是8*16,对应的每一个线程执行一次加法操作,有人会问可不可以不用这么多呢,用4*16个Threads,每个线程里面做两次加法动作,其实是可以的,这个原则是根据你的具体的Device来说的,当前我们说的是Device是GPU,比如你的GPU当前支持最大的线程数是1024*1024,这种情况,你不用多的,而是用少的线程来做,会降低你的效率,你需要尽可能的让Device满负荷工作这样才能达到提高运算速度。

继续分析为什么 NDRange改成二维的之后,add.cl变成:

  1. c[x + y * width] = a[x + y * width] + b[x + y * width];
  2.  
  3. 因为在CPU端每个 C[8*16],通过打印可以在这里C[x+y*width],x 最大是7width8,y最大是17,只有这样才能做完所有的向量相加。

使用二维NDRange workgroup的更多相关文章

  1. OpenCL 学习step by step (5) 使用二维NDRange workgroup

    http://www.cnblogs.com/mikewolf2002/archive/2012/09/07/2675634.html 在本教程中,我们使用二维NDRange来设置workgroup, ...

  2. Javascript生成二维码(QR)

    网络上已经有非常多的二维码编码和解码工具和代码,很多都是服务器端的,也就是说需要一台服务器才能提供二维码的生成.本着对服务器性能的考虑,这种小事情都让服务器去做,感觉对不住服务器,尤其是对于大流量的网 ...

  3. iOS二维码生成、识别、扫描等

    二维码扫描 前言: 最近的项目中使用到了二维码,二维码这个模块功能也完成:觉得还是有必要总结一下用来做记录.好长时间没有写二维码了都忘记在差不多了,重新拾起来还是挻快的. 二维码使用场景: 生活中有很 ...

  4. 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo

    有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...

  5. 免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)

    在生活中有一种东西几乎已经快要成为我们的另一个电子”身份证“,那就是二维码.无论是在软件开发的过程中,还是在普通用户的日常中,几乎都离不开二维码.二维码 (dimensional barcode) , ...

  6. 基于SignalR的消息推送与二维码描登录实现

    1 概要说明 使用微信扫描登录相信大家都不会陌生吧,二维码与手机结合产生了不同应用场景,基于二维码的应用更是比较广泛.为了满足ios.android客户端与web短信平台的结合,特开发了基于Singl ...

  7. 微信小程序的机会在于重新理解群组与二维码

    历时一年,唯一一个尚未发布就获得Pony Ma与Allen Zhang站台的产品:微信小程序,将于2017年1月9日正式上线了.我很期待.唯一要警惕的是:防止长考出臭棋. 在上线前夕,我对于如何借助小 ...

  8. javaScript生成二维码(支持中文,生成logo)

    资料搜索 选择star最多的两个 第一个就是用的比较多的jquery.qrcode.js(但不支持中文,不能带logo)啦,第二个支持ie6+,支持中文,根据第二个源代码,使得,jquery.qrco ...

  9. 微信小程序二维码推广统计

    微信小程序可以通过生成带参数的二维码,那么这个参数是可以通过APP的页面进行监控的 这样就可以统计每个二维码的推广效果. 今天由好推二维码推出的小程序统计工具HotApp小程序统计也推出了带参数二维码 ...

随机推荐

  1. java对象初始化顺序的简单验证

    以下这段小程序对调用对象构造函数时,父类构造函数.成员变量初始化函数,以及非静态初始化块调用顺序进行验证,不考虑静态成员及静态初始化块. public class Derive extends Bas ...

  2. 《sort命令的k选项大讨论》-linux命令五分钟系列之二十七

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  3. WORDPRESS插件开发(二)HELLO WORLD改进版

    在上一篇文章中WORDPRESS插件开发(一)HELLO WORLD,演示了Hello World的最简单实现,只是在每篇文章的后面加入Hello World字符,而且字符也是写死的. 如果用户需要自 ...

  4. linux命令之chown命令

    发布:JB01   来源:脚本学堂     [大 中 小] 本文介绍下,linux系统中用于文件与目录权限管理的命令 chown命令的用法,chown将指定文件的拥有者改为指定的用户或组.有需要的朋友 ...

  5. php操作memcache的用法、详解和方法介绍

    1.简介 memcache模块是一个高效的守护进程,提供用于内存缓存的过程式程序和面向对象的方便的接口,特别是对于设计动态web程序时减少对数据库的访问. memcache也提供用于通信对话(sess ...

  6. Echart..js插件渲染报错 data.length<1?

    问题 getJSON提交 返回数据正常,在传入参数进行序列化,渲染报表时报错 option.data.length < 1. 分析  1.可能情况一: . 可自己明明是getJSON()把渲染放 ...

  7. HTML 中<style>中</style>里面<!-- -->标签是干嘛的

    baidu:没什么用,这个主要是针对低版本的浏览器<!-- -->是html的注释标签,高版本的浏览器会识别<style>标签是样式表,并忽略里面的html注释标签,会解析它, ...

  8. 【C语言】37个关键字

    C语言37个关键字 一.相关基础知识 年. 关键字:是由系统定义的,不能重新做其他定义的字符,且每个关键字已经赋予了不同的意义,让编程者能够使用来告诉编译器完成不同的工作PS:C语言严格区分大小写,i ...

  9. [swift]可选类型

    可选类型 <Swift权威指南>第2章千里之行始于足下——Swift语言基础,本章挑选了Swift语言的最基本特性加以介绍.尽管这些特性只占Swift全部特性的很少一部分,但却是所有的Sw ...

  10. C# 在SQLite数据库中存储图像 z

    C# 在SQLite数据库中存储图像 更多 0 C# SQLite   建表语句 CREATE TABLE [ImageStore]([ImageStore_Id] INTEGER NOT NULL ...