Using two separate counters, like in OpenCL code. A bug may lie there.