| 86 | |
| 87 | template<typename T> |
| 88 | void morph3d(Param out, const Param in, const Param mask, bool isDilation) { |
| 89 | using cl::Buffer; |
| 90 | using cl::EnqueueArgs; |
| 91 | using cl::NDRange; |
| 92 | using std::make_unique; |
| 93 | using std::string; |
| 94 | using std::vector; |
| 95 | |
| 96 | constexpr int CUBE_X = 8; |
| 97 | constexpr int CUBE_Y = 8; |
| 98 | constexpr int CUBE_Z = 4; |
| 99 | |
| 100 | ToNumStr<T> toNumStr; |
| 101 | const T DefaultVal = isDilation ? common::Binary<T, af_max_t>::init() |
| 102 | : common::Binary<T, af_min_t>::init(); |
| 103 | const int SeLength = mask.info.dims[0]; |
| 104 | |
| 105 | std::vector<TemplateArg> targs = { |
| 106 | TemplateTypename<T>(), |
| 107 | TemplateArg(isDilation), |
| 108 | TemplateArg(SeLength), |
| 109 | }; |
| 110 | vector<string> options = { |
| 111 | DefineKeyValue(T, dtype_traits<T>::getName()), |
| 112 | DefineValue(isDilation), |
| 113 | DefineValue(SeLength), |
| 114 | DefineKeyValue(init, toNumStr(DefaultVal)), |
| 115 | }; |
| 116 | options.emplace_back(getTypeBuildDefinition<T>()); |
| 117 | |
| 118 | auto morphOp = |
| 119 | common::getKernel("morph3d", {{morph_cl_src}}, targs, options); |
| 120 | |
| 121 | NDRange local(CUBE_X, CUBE_Y, CUBE_Z); |
| 122 | |
| 123 | int blk_x = divup(in.info.dims[0], CUBE_X); |
| 124 | int blk_y = divup(in.info.dims[1], CUBE_Y); |
| 125 | int blk_z = divup(in.info.dims[2], CUBE_Z); |
| 126 | |
| 127 | NDRange global(blk_x * CUBE_X * in.info.dims[3], blk_y * CUBE_Y, |
| 128 | blk_z * CUBE_Z); |
| 129 | |
| 130 | cl_int seBytes = sizeof(T) * SeLength * SeLength * SeLength; |
| 131 | auto mBuff = |
| 132 | make_unique<cl::Buffer>(getContext(), CL_MEM_READ_ONLY, seBytes); |
| 133 | morphOp.copyToReadOnly(mBuff.get(), mask.data, seBytes); |
| 134 | |
| 135 | // calculate shared memory size |
| 136 | const int padding = |
| 137 | (SeLength % 2 == 0 ? (SeLength - 1) : (2 * (SeLength / 2))); |
| 138 | const int locLen = CUBE_X + padding + 1; |
| 139 | const int locArea = locLen * (CUBE_Y + padding); |
| 140 | const int locSize = locArea * (CUBE_Z + padding); |
| 141 | |
| 142 | morphOp(EnqueueArgs(getQueue(), global, local), *out.data, out.info, |
| 143 | *in.data, in.info, *mBuff, cl::Local(locSize * sizeof(T)), blk_x); |
| 144 | CL_DEBUG_FINISH(getQueue()); |
| 145 | } |
nothing calls this directly
no test coverage detected