From 611c7fb97412230d5cefee047081455fb60db06c Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Fri, 7 Jan 2022 09:47:29 +0000 Subject: IVGCVSW-6641 Stabilize the IWorkloadFactory interface with unified strategy Signed-off-by: Teresa Charlin Change-Id: Ia941be9bf2c15fe56e49a9b9a2bbe943a8152438 --- src/backends/cl/ClWorkloadFactory.cpp | 445 ++++++++++++++++++++++++++++++++++ 1 file changed, 445 insertions(+) (limited to 'src/backends/cl/ClWorkloadFactory.cpp') diff --git a/src/backends/cl/ClWorkloadFactory.cpp b/src/backends/cl/ClWorkloadFactory.cpp index 4bdb84a5a5..0632787db0 100644 --- a/src/backends/cl/ClWorkloadFactory.cpp +++ b/src/backends/cl/ClWorkloadFactory.cpp @@ -244,6 +244,451 @@ std::unique_ptr ClWorkloadFactory::CreateSubTensorHandle(ITensorH PolymorphicDowncast(&parent), shape, coords); } +std::unique_ptr ClWorkloadFactory::CreateWorkload(LayerType type, + const QueueDescriptor& descriptor, + const WorkloadInfo& info) const +{ + switch(type) + { + case LayerType::Activation : + { + auto activationQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*activationQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Addition : + { + auto additionQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*additionQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::ArgMinMax : + { + auto argMinMaxQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*argMinMaxQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::BatchNormalization : + { + auto batchNormalizationQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload + (*batchNormalizationQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::BatchToSpaceNd : + { + auto batchToSpaceNdQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*batchToSpaceNdQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Cast : + { + auto castQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*castQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::ChannelShuffle : + { + auto channelShuffleQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*channelShuffleQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Comparison : + { + auto comparisonQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*comparisonQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Concat : + { + auto concatQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*concatQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Constant : + { + auto constantQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*constantQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::ConvertFp16ToFp32 : + { + auto convertFp16ToFp32QueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*convertFp16ToFp32QueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::ConvertFp32ToFp16 : + { + auto convertFp32ToFp16QueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*convertFp32ToFp16QueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::Convolution2d : + { + auto convolution2dQueueDescriptor = PolymorphicDowncast(&descriptor); + + bool isFastMathEnabled = false; + if (m_ModelContextPtr) + { + if (m_ModelContextPtr.get() != nullptr) + { + auto modelOptions = dynamic_cast(m_ModelContextPtr.get()); + if (modelOptions) + { + isFastMathEnabled = modelOptions->IsFastMathEnabled(); + } + } + } + return MakeWorkload(*convolution2dQueueDescriptor, + info, + m_MemoryManager->GetIntraLayerManager(), + m_CLCompileContext, + isFastMathEnabled); + } + case LayerType::Convolution3d : + { + auto convolution3dQueueDescriptor = PolymorphicDowncast(&descriptor); + + bool isFastMathEnabled = false; + if (m_ModelContextPtr) + { + if (m_ModelContextPtr.get() != nullptr) + { + auto modelOptions = dynamic_cast(m_ModelContextPtr.get()); + if (modelOptions) + { + isFastMathEnabled = modelOptions->IsFastMathEnabled(); + } + } + } + return MakeWorkload(*convolution3dQueueDescriptor, + info, + m_MemoryManager->GetIntraLayerManager(), + m_CLCompileContext, + isFastMathEnabled); + } + case LayerType::Debug : + { + auto debugQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*debugQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::DepthToSpace : + { + auto depthToSpaceQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*depthToSpaceQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::DepthwiseConvolution2d : + { + auto depthwiseConvolution2dQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*depthwiseConvolution2dQueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::Dequantize : + { + auto dequantizeQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*dequantizeQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::DetectionPostProcess : + { + auto detectionPostProcessQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*detectionPostProcessQueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::Division : + { + auto divisionQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*divisionQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::ElementwiseUnary : + { + auto elementwiseUnaryQueueDescriptor + = PolymorphicDowncast(&descriptor); + + switch(elementwiseUnaryQueueDescriptor->m_Parameters.m_Operation) + { + case UnaryOperation::Abs: + { + AbsQueueDescriptor absQueueDescriptor; + absQueueDescriptor.m_Inputs = elementwiseUnaryQueueDescriptor->m_Inputs; + absQueueDescriptor.m_Outputs = elementwiseUnaryQueueDescriptor->m_Outputs; + + return std::make_unique(absQueueDescriptor, info, m_CLCompileContext); + } + case UnaryOperation::Exp: + return std::make_unique(*elementwiseUnaryQueueDescriptor, info, m_CLCompileContext); + case UnaryOperation::Log: + return std::make_unique(*elementwiseUnaryQueueDescriptor, info, m_CLCompileContext); + case UnaryOperation::LogicalNot: + return std::make_unique(*elementwiseUnaryQueueDescriptor, + info, + m_CLCompileContext); + case UnaryOperation::Neg: + return std::make_unique(*elementwiseUnaryQueueDescriptor, info, m_CLCompileContext); + case UnaryOperation::Rsqrt: + { + RsqrtQueueDescriptor rsqrtQueueDescriptor; + rsqrtQueueDescriptor.m_Inputs = elementwiseUnaryQueueDescriptor->m_Inputs; + rsqrtQueueDescriptor.m_Outputs = elementwiseUnaryQueueDescriptor->m_Outputs; + + return std::make_unique(rsqrtQueueDescriptor, info, m_CLCompileContext); + } + case UnaryOperation::Sin: + return std::make_unique(*elementwiseUnaryQueueDescriptor, info, m_CLCompileContext); + default: + return nullptr; + } + } + case LayerType::Fill : + { + auto fillQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*fillQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Floor : + { + auto floorQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*floorQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::FullyConnected : + { + auto fullyConnectedQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*fullyConnectedQueueDescriptor, + info, + m_MemoryManager->GetIntraLayerManager(), + m_CLCompileContext); + } + case LayerType::Gather : + { + auto gatherQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*gatherQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Input : + { + auto inputQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*inputQueueDescriptor, info); + } + case LayerType::InstanceNormalization : + { + auto instanceNormalizationQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*instanceNormalizationQueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::L2Normalization : + { + auto l2NormalizationQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*l2NormalizationQueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::LogicalBinary : + { + auto logicalBinaryQueueDescriptor = PolymorphicDowncast(&descriptor); + + switch(logicalBinaryQueueDescriptor->m_Parameters.m_Operation) + { + case LogicalBinaryOperation::LogicalAnd: + return std::make_unique(*logicalBinaryQueueDescriptor, + info, + m_CLCompileContext); + case LogicalBinaryOperation::LogicalOr: + return std::make_unique(*logicalBinaryQueueDescriptor, + info, + m_CLCompileContext); + default: + return nullptr; + } + } + case LayerType::LogSoftmax : + { + auto logSoftmaxQueueDescriptor = PolymorphicDowncast(&descriptor); + + return MakeWorkload(*logSoftmaxQueueDescriptor, + info, + m_MemoryManager->GetIntraLayerManager(), + m_CLCompileContext); + } + case LayerType::Lstm : + { + auto lstmQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*lstmQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Maximum : + { + auto maximumQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*maximumQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Mean : + { + auto meanQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*meanQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::MemCopy : + { + auto memCopyQueueDescriptor = PolymorphicDowncast(&descriptor); + if (memCopyQueueDescriptor->m_Inputs.empty() || !memCopyQueueDescriptor->m_Inputs[0]) + { + throw InvalidArgumentException("ClWorkloadFactory: Invalid null input for MemCopy workload"); + } + return MakeWorkload(*memCopyQueueDescriptor, info); + } + case LayerType::MemImport : + { + auto memImportQueueDescriptor = PolymorphicDowncast(&descriptor); + if (memImportQueueDescriptor->m_Inputs.empty() || !memImportQueueDescriptor->m_Inputs[0]) + { + throw InvalidArgumentException("ClWorkloadFactory: Invalid null input for MemImport workload"); + } + return std::make_unique(*memImportQueueDescriptor, info); + } + case LayerType::Minimum : + { + auto minimumQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*minimumQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Multiplication : + { + auto multiplicationQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*multiplicationQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Normalization : + { + auto normalizationQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*normalizationQueueDescriptor, + info, + m_CLCompileContext); + } + case LayerType::Output : + { + auto outputQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*outputQueueDescriptor, info); + } + case LayerType::Pad : + { + auto padQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*padQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Permute : + { + auto permuteQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*permuteQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Pooling2d : + { + auto pooling2dQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*pooling2dQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::PreCompiled : + { + auto preCompiledQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*preCompiledQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Prelu : + { + auto preluQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*preluQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::QLstm : + { + auto qLstmQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*qLstmQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Quantize : + { + auto quantizeQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*quantizeQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::QuantizedLstm : + { + auto quantizedLstmQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*quantizedLstmQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Rank : + { + auto rankQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*rankQueueDescriptor, info); + } + case LayerType::Reduce : + { + auto reduceQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*reduceQueueDescriptor, info); + } + case LayerType::Reshape : + { + auto reshapeQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*reshapeQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Resize : + { + auto resizeQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*resizeQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Slice : + { + auto sliceQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*sliceQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Softmax : + { + auto softmaxQueueDescriptor = PolymorphicDowncast(&descriptor); + return std::make_unique(*softmaxQueueDescriptor, + info, + m_MemoryManager->GetIntraLayerManager(), + m_CLCompileContext); + } + case LayerType::SpaceToBatchNd : + { + auto spaceToBatchNdQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*spaceToBatchNdQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::SpaceToDepth : + { + auto spaceToDepthQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*spaceToDepthQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Splitter : + { + auto splitterQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*splitterQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Stack : + { + auto stackQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*stackQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::StridedSlice : + { + auto stridedSliceQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*stridedSliceQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Subtraction : + { + auto subtractionQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*subtractionQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::Transpose : + { + auto transposeQueueDescriptor = PolymorphicDowncast(&descriptor); + return MakeWorkload(*transposeQueueDescriptor, info, m_CLCompileContext); + } + case LayerType::TransposeConvolution2d : + { + auto transposeConvolution2dQueueDescriptor + = PolymorphicDowncast(&descriptor); + return MakeWorkload(*transposeConvolution2dQueueDescriptor, + info, + m_MemoryManager->GetIntraLayerManager(), + m_CLCompileContext); + } + default: + return nullptr; + } +} + std::unique_ptr ClWorkloadFactory::CreateActivation(const ActivationQueueDescriptor& descriptor, const WorkloadInfo& info) const { -- cgit v1.2.1