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

Method onEncode

source/backend/vulkan/buffer/execution/VulkanRaster.cpp:116–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115
116ErrorCode VulkanRaster::onEncode(const std::vector<Tensor *> &____inputs, const std::vector<Tensor *> &outputs,
117 const VulkanCommandPool::Buffer *cmdBuffer) {
118 MNN_ASSERT(outputs.size() == 1);
119 if (____inputs.size() > 0) {
120 OpCommonUtils::rasterInputReset(____inputs, outputs[0]);
121 }
122 auto output = outputs[0];
123 auto des = TensorUtils::getDescribe(output);
124 bool needZero = !TensorUtils::regionIsFull(output);
125 _recycle();
126 auto vkBn = static_cast<VulkanBackend*>(backend());
127 auto bufferAlloc = vkBn->getDynamicMemoryPool();
128 auto vkRt = ((VulkanRuntime*)(vkBn->getRuntime()));
129 if (des->dimensionFormat == MNN_DATA_FORMAT_NC4HW4) {
130 bool fast = true;
131 for (int i=0; i< des->regions.size(); ++i) {
132 auto& slice = des->regions[i];
133 if (TensorUtils::getDescribe(slice.origin)->dimensionFormat != MNN_DATA_FORMAT_NC4HW4) {
134 fast = false;
135 break;
136 }
137 if (!OpCommonUtils::canBlitFast(slice, output, 4, true)) {
138 fast = false;
139 break;
140 }
141 }
142 if (fast) {
143 onEncodeFast(output, output, cmdBuffer, needZero);
144 return NO_ERROR;
145 }
146 }
147 // Single Convert Optimize
148 std::vector<VkDescriptorType> nchwConvertTypes{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
149 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER};
150 do {
151 if (des->regions.size() != 1) {
152 break;
153 }
154 OpCommonUtils::TensorConvertParameter convertParameter;
155 OpCommonUtils::turnRegion2Convert(des->regions[0], output, convertParameter);
156 if (convertParameter.type == 0) {
157 break;
158 }
159 const VulkanPipeline* convertPipeline = nullptr;
160 std::string pKey = "glsl_";
161 int srcIndex;
162 int dstIndex;
163 if (des->dimensionFormat == MNN_DATA_FORMAT_NC4HW4) {
164 pKey += "nchwTonc4hw4_";
165 srcIndex = 0;
166 dstIndex = 1;
167 } else {
168 pKey += "nc4hw4Tonchw_";
169 srcIndex = 1;
170 dstIndex = 0;
171 }
172 if (output->getType().code == halide_type_float && vkBn->useFP16()) {
173 pKey += "FP16_";

Callers

nothing calls this directly

Calls 15

backendFunction · 0.85
getDynamicMemoryPoolMethod · 0.80
useFP16Method · 0.80
createSetMethod · 0.80
writeBufferMethod · 0.80
getTensorBufferMethod · 0.80
barrierSourceMethod · 0.80
writeNCHWFunction · 0.70
writeSamplerInfoFunction · 0.70
sizeMethod · 0.45
getRuntimeMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected