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

Function readScalesFromCalibrationCache

samples/common/sampleEngines.cpp:68–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66};
67
68std::map<std::string, float> readScalesFromCalibrationCache(std::string const& calibrationFile)
69{
70 std::map<std::string, float> tensorScales;
71 std::ifstream cache{calibrationFile};
72 if (!cache.is_open())
73 {
74 sample::gLogError << "[TRT] Can not open provided calibration cache file" << std::endl;
75 return tensorScales;
76 }
77 std::string line;
78 while (std::getline(cache, line))
79 {
80 auto colonPos = line.find_last_of(':');
81 if (colonPos != std::string::npos)
82 {
83 // Scales should be stored in calibration cache as 32-bit floating numbers encoded as 32-bit integers
84 int32_t scalesAsInt = std::stoi(line.substr(colonPos + 2, 8), nullptr, 16);
85 auto const tensorName = line.substr(0, colonPos);
86 tensorScales[tensorName] = *reinterpret_cast<float*>(&scalesAsInt);
87 }
88 }
89 cache.close();
90 return tensorScales;
91}
92} // namespace
93
94nvinfer1::ICudaEngine* LazilyDeserializedEngine::get()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected