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

Method VulkanPrelu

source/backend/vulkan/image/execution/VulkanRelu.cpp:92–113  ·  view source on GitHub ↗

--------------------------Prelu--------------------------//

Source from the content-addressed store, hash-verified

90}
91//--------------------------Prelu--------------------------//
92VulkanPrelu::VulkanPrelu(Backend *bn, const Op *op) : VulkanBasicExecution(bn) {
93 std::vector<VkDescriptorType> types{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
94 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER};
95 auto vulkanBn = static_cast<VulkanBackend *>(bn);
96 mPreluPipeline = vulkanBn->getPipeline("glsl_preluWithChannel_comp",
97 /*glsl_preluWithChannel_comp, glsl_preluWithChannel_comp_len,*/ types);
98 const auto prelu = op->main_as_PRelu();
99 mGpuPreluParam.reset(new VulkanBuffer(vulkanBn->getMemoryPool(), false, sizeof(GpuReluParam), nullptr,
100 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT));
101 int count = ALIGN_UP4(prelu->slope()->size());
102
103 mSlope.reset(new VulkanImage(vulkanBn->getMemoryPool(), false, std::vector<int>{count / 4, 1}));
104 {
105 std::shared_ptr<VulkanBuffer> slopeBuffer(new VulkanBuffer(
106 vulkanBn->getMemoryPool(), false, sizeof(float) * count, nullptr, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT));
107 auto slope = slopeBuffer->map();
108 ::memset(slope, 0, count * sizeof(float));
109 ::memcpy(slope, prelu->slope()->data(), prelu->slope()->size() * sizeof(float));
110 slopeBuffer->unmap();
111 vulkanBn->copyBufferToImage(slopeBuffer.get(), mSlope.get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
112 }
113}
114
115VulkanPrelu::~VulkanPrelu() {
116}

Callers

nothing calls this directly

Calls 8

copyBufferToImageMethod · 0.80
getPipelineMethod · 0.45
resetMethod · 0.45
sizeMethod · 0.45
mapMethod · 0.45
dataMethod · 0.45
unmapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected