We just want to profile another tensorrt instance, and clone the Profiler C++ class in sampleGoogleNet.cpp file. It’s report time is strange, so I digged to the document and header file. It seems Profiler class should report time in second instead of millisecond, or just don’t divide time by TIMING_ITERATIONS(1000).
struct Profiler : public IProfiler
{
typedef std::pair<std::string, float> Record;
std::vector<Record> mProfile;
virtual void reportLayerTime(const char* layerName, float ms)
{
auto record = std::find_if(mProfile.begin(), mProfile.end(), [&](const Record& r){ return r.first == layerName; });
if (record == mProfile.end())
mProfile.push_back(std::make_pair(layerName, ms));
else
record->second += ms;
}
void printLayerTimes()
{
float totalTime = 0;
for (size_t i = 0; i < mProfile.size(); i++)
{
//the mProfile[i].second(according to first) is already in millisecond, why divide it by TIMING_ITERATIONS?
printf("%-40.40s %4.3f<b>ms</b>\n", mProfile[i].first.c_str(), mProfile[i].second / TIMING_ITERATIONS);
totalTime += mProfile[i].second;
}
printf("Time over all layers: %4.3f\n", totalTime / TIMING_ITERATIONS);
}
} gProfiler;
This is the reportLayerTime function declaration in NvInfer.h
virtual void nvinfer1::IProfiler::reportLayerTime ( const char * layerName,
float ms
)
pure virtual
layer time reporting callback
Parameters
layerName the name of the layer, set when constructing the network definition
ms the time in milliseconds to execute the layer
What’s wrong?