MCPcopy Create free account
hub / github.com/alibaba/MNN / _init

Method _init

source/backend/vulkan/image/execution/VulkanConvolution.cpp:111–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109 return NO_ERROR;
110}
111bool VulkanConvolutionDepthwise::_init(const float* weightData, size_t weightSize, const Op* convOp, Backend* bn) {
112 auto extra = static_cast<VulkanBackend*>(bn);
113 auto common = convOp->main_as_Convolution2D()->common();
114 mSampler = extra->getCommonSampler();
115 // Create Pipeline
116 std::vector<VkDescriptorType> convTypes{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
117 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
118 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
119 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER};
120 MNN_ASSERT(OpType_ConvolutionDepthwise == convOp->type());
121 auto macroRelu = getPostTreatMacro(common);
122 bool useFP16 = (extra->gpuType() == VulkanRuntime::ADRENO || extra->gpuType() == VulkanRuntime::MALI) && extra->getMemoryPool().permitFp16();
123 std::string macroPrecision = (useFP16) ? "FP16_" : "FP32_";
124 std::string macro = macroRelu + macroPrecision;
125 if (common->strideX() == 1 && common->strideY() == 1 && common->dilateX() == 1 && common->dilateY() == 1 ) {
126 mConvPipeline = extra->getPrivatePipeline("glsl_convolutionDepthwise_s1d1_w2_" + macro + "comp", convTypes);
127 mUseS1D1W2 = true;
128 } else {
129 mConvPipeline = extra->getPrivatePipeline("glsl_convolutionDepthwise_" + macro + "comp", convTypes);
130 }
131
132 auto c4 = UP_DIV(common->outputCount(), 4);
133 mKernel = std::make_shared<VulkanImage>(extra->getMemoryPool(), false, common->kernelX() * common->kernelY(), c4);
134 if (nullptr != weightData){
135 auto tempBuffer = _createBufferForConvDepthwise(extra, common, weightData, weightSize);
136 extra->copyBufferToImage(tempBuffer.get(), mKernel.get());
137 }
138 auto convReal = convOp->main_as_Convolution2D();
139 mBias.reset(new VulkanImage(extra->getMemoryPool(), false, {c4, 1}));
140 auto biasBuffer = std::make_shared<VulkanBuffer>(extra->getMemoryPool(), false,
141 sizeof(float) * ALIGN_UP4(common->outputCount()));
142
143 auto bias = biasBuffer->map();
144 ::memset(bias, 0, ALIGN_UP4(common->outputCount()) * sizeof(float));
145 if (nullptr != convReal->bias()) {
146 // Create Buffer
147 ::memcpy(bias, convReal->bias()->data(), common->outputCount() * sizeof(float));
148 }
149 biasBuffer->unmap();
150 extra->copyBufferToImage(biasBuffer.get(), mBias.get());
151 return true;
152}
153
154
155VulkanConvolutionDepthwise::VulkanConvolutionDepthwise(const float* weightData, size_t weightSize, const Op* convOp, Backend* bn)

Callers

nothing calls this directly

Calls 13

permitFp16Method · 0.80
copyBufferToImageMethod · 0.80
biasMethod · 0.80
getCommonSamplerMethod · 0.45
typeMethod · 0.45
gpuTypeMethod · 0.45
getPrivatePipelineMethod · 0.45
getMethod · 0.45
resetMethod · 0.45
mapMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected