January 2018
Intermediate to advanced
374 pages
9h 53m
English
We implement the per element box filter as a regular lambda function in C++, and the corresponding OpenCL kernel as a string. In order to see the resemblance, we've put them side by side:
|
C++ box filter kernel |
OpenCL box filter kernel |
auto box_filter = []( int x, int y, const auto& src, auto& odst, int w, int r) { float sum = 0.0f; for (int yp=y-r; yp<=y+r; ++yp) { for (int xp=x-r; xp<=(x+r);++xp){ sum += src[yp * w + xp]; } } float n = ((r*2 + 1) * (r*2 + 1)); float average = sum / n; odst[y*w + x] = average;}; |
auto src_code = std::string_view{"kernel void box_filter( "" global const float* src, "" global float* odst, "" int w, "" int r "") { "" int x = get_global_id(0); "" int y = get_global_id(1); ... |