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

Function runInference

samples/common/sampleInference.cpp:1087–1122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1085} // namespace
1086
1087bool runInference(
1088 InferenceOptions const& inference, InferenceEnvironment& iEnv, int32_t device, std::vector<InferenceTrace>& trace)
1089{
1090 cudaCheck(cudaProfilerStart());
1091
1092 trace.resize(0);
1093
1094 SyncStruct sync;
1095 sync.sleep = inference.sleep;
1096 sync.mainStream.sleep(&sync.sleep);
1097 sync.cpuStart = getCurrentTime();
1098 sync.gpuStart.record(sync.mainStream);
1099
1100 // When multiple streams are used, trtexec can run inference in two modes:
1101 // (1) if inference.threads is true, then run each stream on each thread.
1102 // (2) if inference.threads is false, then run all streams on the same thread.
1103 int32_t const numThreads = inference.threads ? inference.infStreams : 1;
1104 int32_t const streamsPerThread = inference.threads ? 1 : inference.infStreams;
1105
1106 std::vector<std::thread> threads;
1107 for (int32_t threadIdx = 0; threadIdx < numThreads; ++threadIdx)
1108 {
1109 threads.emplace_back(makeThread(inference, iEnv, sync, threadIdx, streamsPerThread, device, trace));
1110 }
1111 for (auto& th : threads)
1112 {
1113 th.join();
1114 }
1115
1116 cudaCheck(cudaProfilerStop());
1117
1118 auto cmpTrace = [](InferenceTrace const& a, InferenceTrace const& b) { return a.h2dStart < b.h2dStart; };
1119 std::sort(trace.begin(), trace.end(), cmpTrace);
1120
1121 return !iEnv.error;
1122}
1123
1124bool runMultiTasksInference(std::vector<std::unique_ptr<TaskInferenceEnvironment>>& tEnvList)
1125{

Callers 1

mainFunction · 0.85

Calls 6

cudaCheckFunction · 0.85
getCurrentTimeFunction · 0.85
makeThreadFunction · 0.85
sleepMethod · 0.80
resizeMethod · 0.45
recordMethod · 0.45

Tested by

no test coverage detected