| 105 | } |
| 106 | |
| 107 | void GeneratedTests::executeWithCompilation(const Model* model, Compilation* compilation, |
| 108 | std::function<bool(int)> isIgnored, |
| 109 | std::vector<MixedTypedExample>& examples, |
| 110 | std::string dumpFile) { |
| 111 | bool dumpToFile = !dumpFile.empty(); |
| 112 | std::ofstream s; |
| 113 | if (dumpToFile) { |
| 114 | s.open(dumpFile, std::ofstream::trunc); |
| 115 | ASSERT_TRUE(s.is_open()); |
| 116 | } |
| 117 | |
| 118 | int exampleNo = 0; |
| 119 | float fpAtol = 1e-5f; |
| 120 | float fpRtol = 5.0f * 1.1920928955078125e-7f; |
| 121 | for (auto& example : examples) { |
| 122 | NNTRACE_APP(NNTRACE_PHASE_EXECUTION, "executeWithCompilation example"); |
| 123 | SCOPED_TRACE(exampleNo); |
| 124 | // TODO: We leave it as a copy here. |
| 125 | // Should verify if the input gets modified by the test later. |
| 126 | MixedTyped inputs = example.operands.first; |
| 127 | const MixedTyped& golden = example.operands.second; |
| 128 | |
| 129 | // NNFW Fix: comment out using hasFloat16Inputs |
| 130 | //const bool hasFloat16Inputs = !inputs.float16Operands.empty(); |
| 131 | if (model->isRelaxed()/* || hasFloat16Inputs*/) { |
| 132 | // TODO: Adjust the error limit based on testing. |
| 133 | // If in relaxed mode, set the absolute tolerance to be 5ULP of FP16. |
| 134 | fpAtol = 5.0f * 0.0009765625f; |
| 135 | // Set the relative tolerance to be 5ULP of the corresponding FP precision. |
| 136 | fpRtol = 5.0f * 0.0009765625f; |
| 137 | } |
| 138 | |
| 139 | Execution execution(compilation); |
| 140 | MixedTyped test; |
| 141 | { |
| 142 | NNTRACE_APP(NNTRACE_PHASE_INPUTS_AND_OUTPUTS, "executeWithCompilation example"); |
| 143 | // Set all inputs |
| 144 | for_all(inputs, [&execution](int idx, const void* p, size_t s) { |
| 145 | const void* buffer = s == 0 ? nullptr : p; |
| 146 | ASSERT_EQ(Result::NO_ERROR, execution.setInput(idx, buffer, s)); |
| 147 | }); |
| 148 | |
| 149 | // Go through all typed outputs |
| 150 | resize_accordingly(golden, test); |
| 151 | for_all(test, [&execution](int idx, void* p, size_t s) { |
| 152 | void* buffer = s == 0 ? nullptr : p; |
| 153 | ASSERT_EQ(Result::NO_ERROR, execution.setOutput(idx, buffer, s)); |
| 154 | }); |
| 155 | } |
| 156 | |
| 157 | Result r = execution.compute(); |
| 158 | ASSERT_EQ(Result::NO_ERROR, r); |
| 159 | { |
| 160 | NNTRACE_APP(NNTRACE_PHASE_RESULTS, "executeWithCompilation example"); |
| 161 | |
| 162 | // Get output dimensions |
| 163 | for_each<uint32_t>( |
| 164 | test.operandDimensions, [&execution](int idx, std::vector<uint32_t>& t) { |
nothing calls this directly
no test coverage detected