| 23 | } |
| 24 | |
| 25 | ErrorCode RasterExecution::onEncode(const std::vector<Tensor *> &____inputs, const std::vector<Tensor *> &outputs) { |
| 26 | #ifdef LOG_VERBOSE |
| 27 | MNN_PRINT("start RasterExecution onResize !\n"); |
| 28 | #endif |
| 29 | mTempInput.clear(); |
| 30 | mTempOutput = nullptr; |
| 31 | MNN_ASSERT(outputs.size() == 1); |
| 32 | auto output = outputs[0]; |
| 33 | OpCommonUtils::rasterInputReset(____inputs, outputs[0]); |
| 34 | |
| 35 | auto des = TensorUtils::getDescribe(output); |
| 36 | auto outputDes = TensorUtils::getDescribe(output); |
| 37 | mNeedZero = !TensorUtils::regionIsFull(output); |
| 38 | auto regionNum = des->regions.size(); |
| 39 | auto runtime = ((OpenCLBackend *)backend())->getOpenCLRuntime(); |
| 40 | mFast = false; |
| 41 | if (outputDes->dimensionFormat == MNN_DATA_FORMAT_NC4HW4) { |
| 42 | mFast = true; |
| 43 | for (int i=0; i< des->regions.size(); ++i) { |
| 44 | auto& slice = des->regions[i]; |
| 45 | if (TensorUtils::getDescribe(slice.origin)->dimensionFormat != MNN_DATA_FORMAT_NC4HW4) { |
| 46 | mFast = false; |
| 47 | break; |
| 48 | } |
| 49 | if (!OpCommonUtils::canBlitFast(slice, output)) { |
| 50 | mFast = false; |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if(mFast) |
| 57 | { |
| 58 | mUnits.resize(regionNum); |
| 59 | int kernel_idx = 0; |
| 60 | |
| 61 | if(mNeedZero) |
| 62 | { |
| 63 | mUnits.resize(regionNum + 1); |
| 64 | auto outputShape = tensorShapeFormat(output); |
| 65 | int region[] = {outputShape[0], UP_DIV(outputShape[3], 4), outputShape[1], outputShape[2]};//nhwc |
| 66 | Unit &unit = mUnits[kernel_idx++]; |
| 67 | unit.kernel = runtime->buildKernel("raster", "image_set_zero", {}, mOpenCLBackend->getPrecision(), output, output); |
| 68 | unit.localWorkSize = {8, 8}; |
| 69 | unit.globalWorkSize = {(uint32_t)UP_DIV((region[1] * region[3]), 16)*16, |
| 70 | (uint32_t)UP_DIV((region[0] * region[2]), 16)*16}; |
| 71 | |
| 72 | int global_dim0 = region[1] * region[3]; |
| 73 | int global_dim1 = region[0] * region[2]; |
| 74 | |
| 75 | uint32_t idx = 0; |
| 76 | cl_int ret = CL_SUCCESS; |
| 77 | ret |= unit.kernel->get().setArg(idx++, global_dim0); |
| 78 | ret |= unit.kernel->get().setArg(idx++, global_dim1); |
| 79 | ret |= unit.kernel->get().setArg(idx++, openCLImage(output)); |
| 80 | if(ret != CL_SUCCESS) |
| 81 | { |
| 82 | MNN_PRINT("setArg err %d\n", (int)ret); |
nothing calls this directly
no test coverage detected