MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / dumpRawBindingToFiles

Method dumpRawBindingToFiles

samples/common/sampleInference.cpp:1562–1603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1560
1561template <typename ContextType>
1562void Bindings::dumpRawBindingToFiles(ContextType const& context, std::ostream& os) const
1563{
1564 os << "Dumping I/O Bindings to RAW Files:" << std::endl;
1565 for (auto const& n : mNames)
1566 {
1567 auto name = n.first;
1568 auto bIndex = n.second;
1569 auto const& binding = mBindings[bIndex];
1570 void* outputBuffer{};
1571 if (binding.outputAllocator != nullptr)
1572 {
1573 outputBuffer = binding.outputAllocator->getBuffer()->getHostBuffer();
1574 }
1575 else
1576 {
1577 outputBuffer = binding.buffer->getHostBuffer();
1578 }
1579
1580 Dims dims = getBindingDimensions(context, bIndex);
1581 std::string dimsStr;
1582 std::string dotStr;
1583
1584 for (int32_t i = 0; i < dims.nbDims; i++)
1585 {
1586 dimsStr += dotStr + std::to_string(dims.d[i]);
1587 dotStr = ".";
1588 }
1589
1590 std::string const bindingTypeStr = (binding.isInput ? "input" : "output");
1591
1592 std::stringstream fileName;
1593 fileName << genFilenameSafeString(name) << "." << bindingTypeStr << "." << dimsStr << "." << binding.dataType << ".raw";
1594
1595 os << "Writing file for " << bindingTypeStr << " binding " << name << " (with datatype " << binding.dataType
1596 << " and dimensions " << dimsStr << ") to " << fileName.str() << std::endl;
1597
1598 std::ofstream f(fileName.str(), std::ios::out | std::ios::binary);
1599 ASSERT(f && "Cannot open file for write");
1600 f.write(static_cast<char*>(outputBuffer), binding.volume * samplesCommon::elementSize(binding.dataType));
1601 f.close();
1602 }
1603}
1604
1605template
1606void Bindings::dumpRawBindingToFiles<nvinfer1::IExecutionContext>(nvinfer1::IExecutionContext const& context, std::ostream& os) const;

Callers 1

dumpRawBindingsToFilesFunction · 0.80

Calls 6

getBindingDimensionsFunction · 0.85
genFilenameSafeStringFunction · 0.85
writeMethod · 0.80
elementSizeFunction · 0.70
getHostBufferMethod · 0.45
getBufferMethod · 0.45

Tested by

no test coverage detected