| 110 | } |
| 111 | |
| 112 | bool InferenceTest(const InferenceTestOptions& params, |
| 113 | const std::vector<unsigned int>& defaultTestCaseIds, |
| 114 | IInferenceTestCaseProvider& testCaseProvider) |
| 115 | { |
| 116 | #if !defined (NDEBUG) |
| 117 | if (params.m_IterationCount > 0) // If just running a few select images then don't bother to warn. |
| 118 | { |
| 119 | ARMNN_LOG(warning) << "Performance test running in DEBUG build - results may be inaccurate."; |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | double totalTime = 0; |
| 124 | unsigned int nbProcessed = 0; |
| 125 | bool success = true; |
| 126 | |
| 127 | // Opens the file to write inference times too, if needed. |
| 128 | ofstream inferenceTimesFile; |
| 129 | const bool recordInferenceTimes = !params.m_InferenceTimesFile.empty(); |
| 130 | if (recordInferenceTimes) |
| 131 | { |
| 132 | inferenceTimesFile.open(params.m_InferenceTimesFile.c_str(), ios_base::trunc | ios_base::out); |
| 133 | if (!inferenceTimesFile.good()) |
| 134 | { |
| 135 | ARMNN_LOG(error) << "Failed to open inference times file for writing: " |
| 136 | << params.m_InferenceTimesFile; |
| 137 | return false; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // Create a profiler and register it for the current thread. |
| 142 | std::unique_ptr<IProfiler> profiler = std::make_unique<IProfiler>(); |
| 143 | ProfilerManager::GetInstance().RegisterProfiler(profiler.get()); |
| 144 | |
| 145 | // Enable profiling if requested. |
| 146 | profiler->EnableProfiling(params.m_EnableProfiling); |
| 147 | |
| 148 | // Run a single test case to 'warm-up' the model. The first one can sometimes take up to 10x longer |
| 149 | std::unique_ptr<IInferenceTestCase> warmupTestCase = testCaseProvider.GetTestCase(0); |
| 150 | if (warmupTestCase == nullptr) |
| 151 | { |
| 152 | ARMNN_LOG(error) << "Failed to load test case"; |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | try |
| 157 | { |
| 158 | warmupTestCase->Run(); |
| 159 | } |
| 160 | catch (const TestFrameworkException& testError) |
| 161 | { |
| 162 | ARMNN_LOG(error) << testError.what(); |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | const unsigned int nbTotalToProcess = params.m_IterationCount > 0 ? params.m_IterationCount |
| 167 | : static_cast<unsigned int>(defaultTestCaseIds.size()); |
| 168 | |
| 169 | for (; nbProcessed < nbTotalToProcess; nbProcessed++) |
nothing calls this directly
no test coverage detected