使用二维NDRange workgroup
作为初学者一直,经过多次的上网搜索你一定会看到迈克老狼的向量加法的示例,不知道你是否和我一样,刚开始并不是很准确的知道他的add.cl写的代码的意思,源码如下:
- #pragma OPENCL EXTENSION cl_amd_printf : enable
- __kernel void vecadd(__global const float* a, __global const float* b, __global float* c)
- {
- int x = get_global_id();
- int y = get_global_id();
- int width = get_global_size();
- int height = get_global_size();
- if(x == && y ==)
- printf("%d, %d,%d,%d,%d,%d\n",get_local_size(),get_local_size(),get_local_id(),
- get_local_id(),get_group_id(),get_group_id());
- c[x + y * width] = a[x + y * width] + b[x + y * width];
- }
- 我们在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优化会这么写:
- c[x + y * width] = a[x + y * width] + b[x + y * width];
下面进行分析:
add.cpp关键的代码部分如下(只罗列出部分代码):
- #define width 8//256
- #define height 16//256
- #define NWITEMS width*height//262144
- size_t globalThreads[] = {width, height};
- size_t localx, localy;
- localx = 2;
- localy = 4;
- size_t localThreads[] = {localx, localy};
- clEnqueueNDRangeKernel( queue,
- kernel,
- 2,
- NULL,
- globalThreads,
- localThreads, 0, NULL, &ev);
我自己的add.cl代码如下(里面添加啦打印,以便我们可以看出结果):
- int idx = get_global_id();
- int idy = get_global_id();
- uint wiWidth = get_global_size();
- uint wiHeight = get_global_size();
- printf("Magnum Global idx = %d, idy = %d, sizeX =%d,sizeY =%d\n",idx,idy,wiWidth,wiHeight);
- uint gix_t = get_group_id();
- uint giy_t = get_group_id();
- uint num_of_blocks_x = get_num_groups();
- uint num_of_blocks_y = get_num_groups();
- printf("Magnum Group idx = %d, idy = %d, blockX=%d,blockY=%d\n",gix_t,gix_t,num_of_blocks_x,num_of_blocks_y);
- uint lix = get_local_id();
- uint liy = get_local_id();
- uint LocalX = get_local_size();
- uint LocalY = get_local_size();
- printf("Magnum Local idx = %d, idy = %d, localX=%d,localY=%d\n\n",lix,liy,LocalX,LocalY);
输出的结果如下:
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
- Magnum Global idx = , idy = , sizeX =,sizeY =
- Magnum Group idx = , idy = , blockX=,blockY=
- Magnum Local idx = , idy = , localX=,localY=
从从这个结果首先能说明几个问题:
首先我们在:
- clEnqueueNDRangeKernel( queue, kernel, , NULL, globalThreads, localThreads, 0, NULL, &ev); 设置维度是2,否则add.cl中所有类似get_local_size(1)将只会返回一。
- 设置GlobaThreads 和 LocalThreads 不一定是 GlobalThreads= {8, 8}; 也可以不相等,LocalThreads也是一样。
- 理解opencl中的内存分布可以理解为二维数组,而且内存寻址的方向就像是:左上角(0,0)为原点,一行一行的扫描下去。
- WorkGroup的大小,目前我认为X,Y可以分开来理解(后面若发现错误我会及时改正) WorkGroup number(x) = GlobalThread(x)/LocalThread(x).
- 最小的单位是LocalX * LocalY, 然后用总的GlobalThreads按照这个单位进行分割成一个一个的组。每个二维的小单位还是一行一行的扫描过去的。目前我们的这个是8*16,你会发现总的Thread也是8*16,对应的每一个线程执行一次加法操作,有人会问可不可以不用这么多呢,用4*16个Threads,每个线程里面做两次加法动作,其实是可以的,这个原则是根据你的具体的Device来说的,当前我们说的是Device是GPU,比如你的GPU当前支持最大的线程数是1024*1024,这种情况,你不用多的,而是用少的线程来做,会降低你的效率,你需要尽可能的让Device满负荷工作这样才能达到提高运算速度。
继续分析为什么 NDRange改成二维的之后,add.cl变成:
- c[x + y * width] = a[x + y * width] + b[x + y * width];
- 因为在CPU端每个 C[8*16],通过打印可以在这里C[x+y*width],x 最大是7,width是8,y最大是17,只有这样才能做完所有的向量相加。
使用二维NDRange workgroup的更多相关文章
- OpenCL 学习step by step (5) 使用二维NDRange workgroup
http://www.cnblogs.com/mikewolf2002/archive/2012/09/07/2675634.html 在本教程中,我们使用二维NDRange来设置workgroup, ...
- Javascript生成二维码(QR)
网络上已经有非常多的二维码编码和解码工具和代码,很多都是服务器端的,也就是说需要一台服务器才能提供二维码的生成.本着对服务器性能的考虑,这种小事情都让服务器去做,感觉对不住服务器,尤其是对于大流量的网 ...
- iOS二维码生成、识别、扫描等
二维码扫描 前言: 最近的项目中使用到了二维码,二维码这个模块功能也完成:觉得还是有必要总结一下用来做记录.好长时间没有写二维码了都忘记在差不多了,重新拾起来还是挻快的. 二维码使用场景: 生活中有很 ...
- 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo
有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...
- 免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)
在生活中有一种东西几乎已经快要成为我们的另一个电子”身份证“,那就是二维码.无论是在软件开发的过程中,还是在普通用户的日常中,几乎都离不开二维码.二维码 (dimensional barcode) , ...
- 基于SignalR的消息推送与二维码描登录实现
1 概要说明 使用微信扫描登录相信大家都不会陌生吧,二维码与手机结合产生了不同应用场景,基于二维码的应用更是比较广泛.为了满足ios.android客户端与web短信平台的结合,特开发了基于Singl ...
- 微信小程序的机会在于重新理解群组与二维码
历时一年,唯一一个尚未发布就获得Pony Ma与Allen Zhang站台的产品:微信小程序,将于2017年1月9日正式上线了.我很期待.唯一要警惕的是:防止长考出臭棋. 在上线前夕,我对于如何借助小 ...
- javaScript生成二维码(支持中文,生成logo)
资料搜索 选择star最多的两个 第一个就是用的比较多的jquery.qrcode.js(但不支持中文,不能带logo)啦,第二个支持ie6+,支持中文,根据第二个源代码,使得,jquery.qrco ...
- 微信小程序二维码推广统计
微信小程序可以通过生成带参数的二维码,那么这个参数是可以通过APP的页面进行监控的 这样就可以统计每个二维码的推广效果. 今天由好推二维码推出的小程序统计工具HotApp小程序统计也推出了带参数二维码 ...
随机推荐
- java对象初始化顺序的简单验证
以下这段小程序对调用对象构造函数时,父类构造函数.成员变量初始化函数,以及非静态初始化块调用顺序进行验证,不考虑静态成员及静态初始化块. public class Derive extends Bas ...
- 《sort命令的k选项大讨论》-linux命令五分钟系列之二十七
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- WORDPRESS插件开发(二)HELLO WORLD改进版
在上一篇文章中WORDPRESS插件开发(一)HELLO WORLD,演示了Hello World的最简单实现,只是在每篇文章的后面加入Hello World字符,而且字符也是写死的. 如果用户需要自 ...
- linux命令之chown命令
发布:JB01 来源:脚本学堂 [大 中 小] 本文介绍下,linux系统中用于文件与目录权限管理的命令 chown命令的用法,chown将指定文件的拥有者改为指定的用户或组.有需要的朋友 ...
- php操作memcache的用法、详解和方法介绍
1.简介 memcache模块是一个高效的守护进程,提供用于内存缓存的过程式程序和面向对象的方便的接口,特别是对于设计动态web程序时减少对数据库的访问. memcache也提供用于通信对话(sess ...
- Echart..js插件渲染报错 data.length<1?
问题 getJSON提交 返回数据正常,在传入参数进行序列化,渲染报表时报错 option.data.length < 1. 分析 1.可能情况一: . 可自己明明是getJSON()把渲染放 ...
- HTML 中<style>中</style>里面<!-- -->标签是干嘛的
baidu:没什么用,这个主要是针对低版本的浏览器<!-- -->是html的注释标签,高版本的浏览器会识别<style>标签是样式表,并忽略里面的html注释标签,会解析它, ...
- 【C语言】37个关键字
C语言37个关键字 一.相关基础知识 年. 关键字:是由系统定义的,不能重新做其他定义的字符,且每个关键字已经赋予了不同的意义,让编程者能够使用来告诉编译器完成不同的工作PS:C语言严格区分大小写,i ...
- [swift]可选类型
可选类型 <Swift权威指南>第2章千里之行始于足下——Swift语言基础,本章挑选了Swift语言的最基本特性加以介绍.尽管这些特性只占Swift全部特性的很少一部分,但却是所有的Sw ...
- C# 在SQLite数据库中存储图像 z
C# 在SQLite数据库中存储图像 更多 0 C# SQLite 建表语句 CREATE TABLE [ImageStore]([ImageStore_Id] INTEGER NOT NULL ...