`clEnqueueNDRangeKernel` documentation says: "If local_work_size is specified, the values specified in global_work_size[0],... global_work_size[work_dim - 1] must be evenly **divisible** by the corresponding values specified in local_work_size[0],... local_work_size[work_dim - 1]"

So your `val` here should be `k[i] * _localSize[i]`. Value of k[i] != 1 are definitely useless, so `val = _localSize[i]` exactly.

Please look at `openCLExecuteKernel` implementation in ocl module. It is enough in the most cases.

P.S. Try to use this:

```
inline size_t roundUp(size_t sz, size_t n)
{
    // we don't assume that n is a power of 2 (see alignSize)
    // equal to divUp(sz, n) * n
    size_t t = sz + n - 1;
    size_t rem = t % n;
    size_t result = t - rem;
    return result;
}
```