| 27 | |
| 28 | template<typename T> |
| 29 | void fast(const unsigned arc_length, unsigned *out_feat, Param &x_out, |
| 30 | Param &y_out, Param &score_out, Param in, const float thr, |
| 31 | const float feature_ratio, const unsigned edge, const bool nonmax) { |
| 32 | constexpr int FAST_THREADS_X = 16; |
| 33 | constexpr int FAST_THREADS_Y = 16; |
| 34 | constexpr int FAST_THREADS_NONMAX_X = 32; |
| 35 | constexpr int FAST_THREADS_NONMAX_Y = 8; |
| 36 | |
| 37 | std::array<TemplateArg, 3> targs = { |
| 38 | TemplateTypename<T>(), |
| 39 | TemplateArg(arc_length), |
| 40 | TemplateArg(nonmax), |
| 41 | }; |
| 42 | std::array<std::string, 4> options = { |
| 43 | DefineKeyValue(T, dtype_traits<T>::getName()), |
| 44 | DefineKeyValue(ARC_LENGTH, arc_length), |
| 45 | DefineKeyValue(NONMAX, static_cast<unsigned>(nonmax)), |
| 46 | getTypeBuildDefinition<T>()}; |
| 47 | |
| 48 | auto locate = |
| 49 | common::getKernel("locate_features", {{fast_cl_src}}, targs, options); |
| 50 | auto nonMax = |
| 51 | common::getKernel("non_max_counts", {{fast_cl_src}}, targs, options); |
| 52 | auto getFeat = |
| 53 | common::getKernel("get_features", {{fast_cl_src}}, targs, options); |
| 54 | |
| 55 | const unsigned max_feat = |
| 56 | ceil(in.info.dims[0] * in.info.dims[1] * feature_ratio); |
| 57 | |
| 58 | // Matrix containing scores for detected features, scores are stored in the |
| 59 | // same coordinates as features, dimensions should be equal to in. |
| 60 | cl::Buffer *d_score = |
| 61 | bufferAlloc(in.info.dims[0] * in.info.dims[1] * sizeof(float)); |
| 62 | getQueue().enqueueFillBuffer( |
| 63 | *d_score, 0.0F, 0, in.info.dims[0] * in.info.dims[1] * sizeof(float)); |
| 64 | |
| 65 | cl::Buffer *d_flags = d_score; |
| 66 | if (nonmax) { |
| 67 | d_flags = |
| 68 | bufferAlloc(in.info.dims[0] * in.info.dims[1] * sizeof(float)); |
| 69 | } |
| 70 | |
| 71 | const int blk_x = divup(in.info.dims[0] - edge * 2, FAST_THREADS_X); |
| 72 | const int blk_y = divup(in.info.dims[1] - edge * 2, FAST_THREADS_Y); |
| 73 | |
| 74 | // Locate features kernel sizes |
| 75 | const cl::NDRange local(FAST_THREADS_X, FAST_THREADS_Y); |
| 76 | const cl::NDRange global(blk_x * FAST_THREADS_X, blk_y * FAST_THREADS_Y); |
| 77 | |
| 78 | locate(cl::EnqueueArgs(getQueue(), global, local), *in.data, in.info, |
| 79 | *d_score, thr, edge, |
| 80 | cl::Local((FAST_THREADS_X + 6) * (FAST_THREADS_Y + 6) * sizeof(T))); |
| 81 | CL_DEBUG_FINISH(getQueue()); |
| 82 | |
| 83 | const int blk_nonmax_x = divup(in.info.dims[0], 64); |
| 84 | const int blk_nonmax_y = divup(in.info.dims[1], 64); |
| 85 | |
| 86 | // Nonmax kernel sizes |
nothing calls this directly
no test coverage detected