Skip to content

Commit

Permalink
Fixed Driver Crash in DumpTensor
Browse files Browse the repository at this point in the history
 * When handling Tensors DumpTensor was automatically trying to turn
   them into ConstTensors but then threw an exceptions when IsConstant
   returned false

Signed-off-by: Mike Kelly <[email protected]>
Change-Id: I8681bb3dd41cfe19c60fbd1cc9394c8b6cca551e
  • Loading branch information
MikeJKelly authored and David Monahan committed Nov 9, 2021
1 parent ee6818b commit bc8caca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
35 changes: 24 additions & 11 deletions Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,27 @@ std::string GetOperandSummary(const V1_3::Operand& operand)

#endif

using DumpElementFunction = void (*)(const armnn::ConstTensor& tensor,
template <typename TensorType>
using DumpElementFunction = void (*)(const TensorType& tensor,
unsigned int elementIndex,
std::ofstream& fileStream);

namespace
{
template <typename ElementType, typename PrintableType = ElementType>
void DumpTensorElement(const armnn::ConstTensor& tensor, unsigned int elementIndex, std::ofstream& fileStream)
template <typename TensorType, typename ElementType, typename PrintableType = ElementType>
void DumpTensorElement(const TensorType& tensor, unsigned int elementIndex, std::ofstream& fileStream)
{
const ElementType* elements = reinterpret_cast<const ElementType*>(tensor.GetMemoryArea());
fileStream << static_cast<PrintableType>(elements[elementIndex]) << " ";
}

} // namespace

template <typename TensorType>
void DumpTensor(const std::string& dumpDir,
const std::string& requestName,
const std::string& tensorName,
const armnn::ConstTensor& tensor)
const TensorType& tensor)
{
// The dump directory must exist in advance.
fs::path dumpPath = dumpDir;
Expand All @@ -368,38 +370,38 @@ void DumpTensor(const std::string& dumpDir,
return;
}

DumpElementFunction dumpElementFunction = nullptr;
DumpElementFunction<TensorType> dumpElementFunction = nullptr;

switch (tensor.GetDataType())
{
case armnn::DataType::Float32:
{
dumpElementFunction = &DumpTensorElement<float>;
dumpElementFunction = &DumpTensorElement<TensorType, float>;
break;
}
case armnn::DataType::QAsymmU8:
{
dumpElementFunction = &DumpTensorElement<uint8_t, uint32_t>;
dumpElementFunction = &DumpTensorElement<TensorType, uint8_t, uint32_t>;
break;
}
case armnn::DataType::Signed32:
{
dumpElementFunction = &DumpTensorElement<int32_t>;
dumpElementFunction = &DumpTensorElement<TensorType, int32_t>;
break;
}
case armnn::DataType::Float16:
{
dumpElementFunction = &DumpTensorElement<armnn::Half>;
dumpElementFunction = &DumpTensorElement<TensorType, armnn::Half>;
break;
}
case armnn::DataType::QAsymmS8:
{
dumpElementFunction = &DumpTensorElement<int8_t, int32_t>;
dumpElementFunction = &DumpTensorElement<TensorType, int8_t, int32_t>;
break;
}
case armnn::DataType::Boolean:
{
dumpElementFunction = &DumpTensorElement<bool>;
dumpElementFunction = &DumpTensorElement<TensorType, bool>;
break;
}
default:
Expand Down Expand Up @@ -473,6 +475,17 @@ void DumpTensor(const std::string& dumpDir,
}
}


template void DumpTensor<armnn::ConstTensor>(const std::string& dumpDir,
const std::string& requestName,
const std::string& tensorName,
const armnn::ConstTensor& tensor);

template void DumpTensor<armnn::Tensor>(const std::string& dumpDir,
const std::string& requestName,
const std::string& tensorName,
const armnn::Tensor& tensor);

void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled,
const std::string& dumpDir,
armnn::NetworkId networkId,
Expand Down
3 changes: 2 additions & 1 deletion Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ std::string GetModelSummary(const HalModel& model)
return result.str();
}

template <typename TensorType>
void DumpTensor(const std::string& dumpDir,
const std::string& requestName,
const std::string& tensorName,
const armnn::ConstTensor& tensor);
const TensorType& tensor);

void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled,
const std::string& dumpDir,
Expand Down

0 comments on commit bc8caca

Please sign in to comment.