Skip to content

Commit

Permalink
Merge pull request #2542 from alibaba/feature/bugfix
Browse files Browse the repository at this point in the history
fix bug for vulkan tensorconvert error for some case of nc4hw4
  • Loading branch information
jxt1234 authored Aug 16, 2023
2 parents de34525 + d82a349 commit 01aafde
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 14 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ option(MNN_INTERNAL "Build with MNN internal features, such as model authenticat
option(MNN_JNI "Build MNN Jni for java to use" OFF)

IF (NOT DEFINED MNN_USE_SPARSE_COMPUTE)
IF (TARGET_OS_IPHONE OR TARGET_OS_SIMULATOR)
set(MNN_USE_SPARSE_COMPUTE OFF)
ELSE()
set(MNN_USE_SPARSE_COMPUTE ON)
ENDIF()
set(MNN_USE_SPARSE_COMPUTE ON)
ENDIF()

IF(NOT MNN_BUILD_SHARED_LIBS AND MNN_SEP_BUILD)
Expand Down
2 changes: 1 addition & 1 deletion source/backend/cpu/compute/ConvolutionFloatFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ Execution* ConvolutionFloatFactory::create(const std::vector<Tensor*>& inputs, c
std::shared_ptr<ConvolutionCommon::Int8Common> quanCommon;
std::unique_ptr<Tensor> externalWeightTensor, externalBiasTensor;
bool supportSparse = false;
#ifdef MNN_USE_SPARSE_COMPUTE
auto core = static_cast<CPUBackend*>(backend)->functions();
int bytes = core->bytes;
#ifdef MNN_USE_SPARSE_COMPUTE
#ifdef MNN_USE_SSE
const bool onlySSENotAVX = core->pack == 4; // no backend of only sse without avx2 or avx512
#else
Expand Down
1 change: 0 additions & 1 deletion source/backend/vulkan/image/backend/VulkanTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ std::array<int, 4> VulkanTensor::tensorShapeFormat(const Tensor *input) {
iW = 1;
iC = input->buffer().dim[0].extent;
}

#ifdef LOG_VERBOSE
MNN_PRINT("tensorShapeFormat : [%d, %d, %d, %d] \n", iN, iH, iW, iC);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ void VulkanImageConverter::encodeTensorToBuffer(const Tensor* srcTensor, VkBuffe
const VulkanCommandPool::Buffer* cmdBuffer) {
auto sourceFormat = TensorUtils::getDescribe(srcTensor)->dimensionFormat;
auto destFormat = destBufferFormat;
if (sourceFormat == MNN_DATA_FORMAT_NC4HW4 && 1 >= srcTensor->width() && 1 >= srcTensor->height() &&
srcTensor->channel() % 4 == 0) {
destFormat = MNN_DATA_FORMAT_NC4HW4;
}

auto vkTensor = (VulkanTensor*)(srcTensor->deviceId());
auto tensor = srcTensor;
Expand Down
4 changes: 1 addition & 3 deletions source/backend/vulkan/image/execution/VulkanRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ ErrorCode VulkanRaster::onEncode(const std::vector<Tensor *> &___inputs, const s
for (int i=0; i<origin->dimensions(); ++i) {
bufferSize *= origin->length(i);
}
ivec4 dims;
writeNCHW(dims, origin);
ConvertInfo info;
info.buffer.reset(new VulkanBuffer(vkBn->getDynamicMemoryPool(),
false, bufferSize, nullptr, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT));
Expand Down Expand Up @@ -212,6 +210,7 @@ ErrorCode VulkanRaster::onEncode(const std::vector<Tensor *> &___inputs, const s
for (auto& iter : mInputBuffers) {
auto& info = iter.second;
info.convert->encodeTensorToBuffer(iter.first, info.buffer->buffer(), info.buffer->size(), 0, VulkanImageConverter::getTensorLinearFormat(iter.first), cmdBuffer);
cmdBuffer->barrierSource(info.buffer->buffer(), 0, info.buffer->size());
}
//Blit
if (needZero) {
Expand All @@ -223,7 +222,6 @@ ErrorCode VulkanRaster::onEncode(const std::vector<Tensor *> &___inputs, const s
info.describe->writeBuffer(info.srcBuffer, 1, info.srcBufferSize);
info.describe->writeBuffer(info.uniform->buffer(), 2, info.uniform->size());
info.pipeline->bind(cmdBuffer->get(), info.describe->get());
cmdBuffer->barrierSource(info.srcBuffer, 0, info.srcBufferSize);
vkCmdDispatch(cmdBuffer->get(), info.workGroup[0], info.workGroup[1], info.workGroup[2]);
}

Expand Down

0 comments on commit 01aafde

Please sign in to comment.