Ami*_*mir 5 kernel generic-programming memory-access opencl stencils
我是OpenCL的新手.
我想编写一个通用内核,以后我可以将其用途扩展到其他内存非合并模式,并将其与Rectangular stencil pattern简单配对(也避免了越界访问).
该内核控制本地内存(__local float ?lmem)的使用.
截至目前,我的.cl文件结构如下:
__kernel void kmain (
__global float ?in ,
__global float ?out ,
__global float ?in2 ,
__local float ?lmem)
{
int wg_x = get group id(0);
int wg_y = get group id(1);
int wi_x = get local id(0);
int wi_y = get local id(1);
// number of work units each work-item processes
for (int iter_x = 0; iter_x< NUM_WUS_X-1, iter_x++ ) {
for (int iter_y = 0; iter_y< NUM_WUS_Y-1; iter_x++) {
int wu_x, wu_y;
// The current work unit coordinate (wu_x, wu_y) is computed based on work group ID (wg_x, wg_y), work item ID (wi_x, wi_y) and work unit ID (iter_x, iter_y) :
(wu_x, wu_y) = func(wg_x, wg_y
wi_x, wi_y,
iter_x ,iter_y);
// This is where to cooperatively load
// a region of <in> to the local memory.
// barrier (...);
for (int i = 0; i < N-1, i++) {
for (int j = 0; j< M-1, j++) {
// (fo, fi) detemines the home access pattern centered around (idx_o, idx_i). WI(*,*) defines the memory access pattern i.e: (wi_x) = (wi_y) :
int idx_o = fo(wu_x, wu_y, i, j);
int idx_i = fi(wu_x, wu_y, i, j);
// offsets CO's and CI's determine stencil pattern within each work-item
... = in[idx_o + CO_1][idx_i + CI_1];
... // context (inner loop body)
... = in[idx_o + CO_k][idx_i + CI_k];
... // context (inner loop body)
}
}
// barrier (...);
... // context (epilogue)
out[y][x] = ...;
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道用相应的通用主机实现这种模式?
您可以通过 OpenCL 绑定开发主机端封装,以便:
[]针对不同内存类型和数据模式的不同访问模式的运算符实现那么您可以简单地更改参数列表中的标志,以根据本地与全局内存性能对其进行测试,或者为其提供不同的内核字符串,但这并不比简单地编写不同的 cl 文件更容易。如果您只有几种不同的实现,那么看起来工作量太大了。当您不知道结果内核字符串时,调试也会变得更加困难。
抱歉迟了回应。