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

Method onEncode

source/backend/vulkan/buffer/render/VulkanTexture.cpp:85–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83 }
84 }
85 virtual ErrorCode onEncode(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
86 const VulkanCommandPool::Buffer* cmdBuffer) override {
87 Tensor* inputTensor;
88 Tensor* gridTensor;
89 Tensor* outputTensor;
90 if (mGrad) {
91 inputTensor = outputs[0];
92 gridTensor = inputs[1];
93 outputTensor = inputs[0];
94 } else {
95 inputTensor = inputs[0];
96 gridTensor = inputs[1];
97 outputTensor = outputs[0];
98 }
99 auto batches = inputTensor->length(0);
100 auto unit = outputTensor->length(3);
101 int ih, iw;
102 if (mIsCube) {
103 ih = inputTensor->length(2);
104 iw = inputTensor->length(3);
105 } else {
106 ih = inputTensor->length(1);
107 iw = inputTensor->length(2);
108 }
109 auto oh = outputTensor->length(1);
110 auto ow = outputTensor->length(2);
111 // gpu param
112 {
113 auto parm = reinterpret_cast<ConstBuffer*>(mConstBuffer->map());
114 parm->inShape[0] = iw;
115 parm->inShape[1] = ih;
116 parm->inShape[2] = unit;
117 parm->inShape[3] = gridTensor->length(3);
118 parm->outShape[0] = ow;
119 parm->outShape[1] = oh;
120 parm->outShape[2] = unit;
121 parm->outShape[3] = batches;
122 parm->alignCorners = false;
123 mConstBuffer->unmap();
124 }
125 auto vkBn = static_cast<VulkanBackend*>(backend());
126 mDescriptorSet->writeBuffer(vkBn->getBuffer(outputTensor), 0);
127 mDescriptorSet->writeBuffer(vkBn->getBuffer(gridTensor), 2);
128 mDescriptorSet->writeBuffer(mConstBuffer->buffer(), 3, mConstBuffer->size());
129 MemChunk tempMem;
130 VulkanBuffer* midBuffer = nullptr;
131 if (mGrad) {
132 auto memalloc = vkBn->getDynamicMemoryPool();
133 tempMem = memalloc->alloc(inputTensor->size());
134 if (tempMem.first == nullptr) {
135 return OUT_OF_MEMORY;
136 }
137 midBuffer = (VulkanBuffer*)tempMem.first;
138 mDescriptorSet->writeBuffer(midBuffer->buffer(), 1, midBuffer->size(), tempMem.second);
139 memalloc->free(tempMem);
140 vkCmdFillBuffer(cmdBuffer->get(), midBuffer->buffer(), tempMem.second, midBuffer->size(), 0);
141 cmdBuffer->barrierSource(midBuffer->buffer(), tempMem.second, midBuffer->size(), VulkanCommandPool::Buffer::WRITE_WRITE);
142 } else {

Callers

nothing calls this directly

Calls 14

backendFunction · 0.85
writeBufferMethod · 0.80
getDynamicMemoryPoolMethod · 0.80
barrierSourceMethod · 0.80
lengthMethod · 0.45
mapMethod · 0.45
unmapMethod · 0.45
getBufferMethod · 0.45
bufferMethod · 0.45
sizeMethod · 0.45
allocMethod · 0.45
freeMethod · 0.45

Tested by

no test coverage detected