| 75 | |
| 76 | template<typename T> |
| 77 | void regions(Param out, Param in, const bool full_conn, |
| 78 | const int n_per_thread) { |
| 79 | using cl::Buffer; |
| 80 | using cl::EnqueueArgs; |
| 81 | using cl::NDRange; |
| 82 | |
| 83 | constexpr int THREADS_X = 16; |
| 84 | constexpr int THREADS_Y = 16; |
| 85 | |
| 86 | auto kernels = getRegionsKernels<T>(full_conn, n_per_thread); |
| 87 | |
| 88 | const NDRange local(THREADS_X, THREADS_Y); |
| 89 | |
| 90 | const int blk_x = divup(in.info.dims[0], THREADS_X * 2); |
| 91 | const int blk_y = divup(in.info.dims[1], THREADS_Y * 2); |
| 92 | |
| 93 | const NDRange global(blk_x * THREADS_X, blk_y * THREADS_Y); |
| 94 | |
| 95 | auto ilOp = kernels[0]; |
| 96 | auto ueOp = kernels[2]; |
| 97 | auto frOp = kernels[1]; |
| 98 | |
| 99 | ilOp(EnqueueArgs(getQueue(), global, local), *out.data, out.info, *in.data, |
| 100 | in.info); |
| 101 | CL_DEBUG_FINISH(getQueue()); |
| 102 | |
| 103 | int h_continue = 1; |
| 104 | Buffer* d_continue = bufferAlloc(sizeof(int)); |
| 105 | |
| 106 | while (h_continue) { |
| 107 | h_continue = 0; |
| 108 | getQueue().enqueueFillBuffer(*d_continue, h_continue, 0, sizeof(int)); |
| 109 | ueOp(EnqueueArgs(getQueue(), global, local), *out.data, out.info, |
| 110 | *d_continue); |
| 111 | CL_DEBUG_FINISH(getQueue()); |
| 112 | getQueue().enqueueReadBuffer(*d_continue, CL_TRUE, 0, sizeof(int), |
| 113 | &h_continue); |
| 114 | } |
| 115 | bufferFree(d_continue); |
| 116 | |
| 117 | // Now, perform the final relabeling. This converts the equivalency |
| 118 | // map from having unique labels based on the lowest pixel in the |
| 119 | // component to being sequentially numbered components starting at |
| 120 | // 1. |
| 121 | int size = in.info.dims[0] * in.info.dims[1]; |
| 122 | |
| 123 | compute::command_queue c_queue(getQueue()()); |
| 124 | |
| 125 | // Wrap raw device ptr |
| 126 | compute::context context(getContext()()); |
| 127 | compute::vector<T> tmp(size, context); |
| 128 | clEnqueueCopyBuffer(getQueue()(), (*out.data)(), tmp.get_buffer().get(), 0, |
| 129 | 0, size * sizeof(T), 0, NULL, NULL); |
| 130 | |
| 131 | // Sort the copy |
| 132 | compute::sort(tmp.begin(), tmp.end(), c_queue); |
| 133 | |
| 134 | // Take the max element which is the number |
nothing calls this directly
no test coverage detected