| 16 | // Block and grid size calculators for kernel launches. |
| 17 | |
| 18 | dim3 getLaunchBlockSize(int maxWidth, int maxHeight, dim3 dims) |
| 19 | { |
| 20 | int maxThreads = maxWidth * maxHeight; |
| 21 | if (maxThreads <= 1 || (dims.x * dims.y) <= 1) |
| 22 | return dim3(1, 1, 1); // Degenerate. |
| 23 | |
| 24 | // Start from max size. |
| 25 | int bw = maxWidth; |
| 26 | int bh = maxHeight; |
| 27 | |
| 28 | // Optimizations for weirdly sized buffers. |
| 29 | if (dims.x < bw) |
| 30 | { |
| 31 | // Decrease block width to smallest power of two that covers the buffer width. |
| 32 | while ((bw >> 1) >= dims.x) |
| 33 | bw >>= 1; |
| 34 | |
| 35 | // Maximize height. |
| 36 | bh = maxThreads / bw; |
| 37 | if (bh > dims.y) |
| 38 | bh = dims.y; |
| 39 | } |
| 40 | else if (dims.y < bh) |
| 41 | { |
| 42 | // Halve height and double width until fits completely inside buffer vertically. |
| 43 | while (bh > dims.y) |
| 44 | { |
| 45 | bh >>= 1; |
| 46 | if (bw < dims.x) |
| 47 | bw <<= 1; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // Done. |
| 52 | return dim3(bw, bh, 1); |
| 53 | } |
| 54 | |
| 55 | // returns the size of a block that can be reduced using horizontal SIMD operations (e.g. __shfl_xor_sync) |
| 56 | dim3 getWarpSize(dim3 blockSize) |
no outgoing calls
no test coverage detected