17 #include <doctest/doctest.h> 24 using namespace armnn;
27 bool ConstantUsageTest(
const std::vector<BackendId>& computeDevice,
29 const std::vector<T>& inputData,
30 const std::vector<T>& constantData,
31 const std::vector<T>& expectedOutputData)
59 runtime->LoadNetwork(netId, std::move(optNet));
62 std::vector<T> outputData(inputData.size());
66 {0,
ConstTensor(runtime->GetInputTensorInfo(netId, 0), inputData.data())}
70 {0,
Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
74 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
77 return outputData == expectedOutputData;
80 inline bool ConstantUsageFloat32Test(
const std::vector<BackendId>& backends)
85 return ConstantUsageTest(backends,
87 std::vector<float>{ 1.f, 2.f, 3.f, 4.f, 5.f, 6.f },
88 std::vector<float>{ 6.f, 5.f, 4.f, 3.f, 2.f, 1.f },
89 std::vector<float>{ 7.f, 7.f, 7.f, 7.f, 7.f, 7.f }
93 inline bool ConstantUsageUint8Test(
const std::vector<BackendId>& backends)
97 const float scale = 0.023529f;
98 const int8_t offset = -43;
104 return ConstantUsageTest(backends,
106 armnnUtils::QuantizedVector<uint8_t>({ 1.f, 2.f, 3.f, 4.f, 5.f, 6.f }, scale, offset),
107 armnnUtils::QuantizedVector<uint8_t>({ 6.f, 5.f, 4.f, 3.f, 2.f, 1.f }, scale, offset),
108 armnnUtils::QuantizedVector<uint8_t>({ 7.f, 7.f, 7.f, 7.f, 7.f, 7.f }, scale, offset)
113 int SubStringCounter(std::string&
string, std::string&& substring)
115 std::size_t found = 0;
118 while((found =
string.find(substring, found)) != std::string::npos)
122 found += substring.length();
130 const std::map<
int, std::vector<TInput>>& inputTensorData,
131 const std::map<
int, std::vector<TOutput>>& expectedOutputData,
132 std::vector<BackendId> backends,
133 float tolerance = 0.000001f)
144 runtime->LoadNetwork(netId, std::move(optNet));
147 inputTensors.reserve(inputTensorData.size());
148 for (
auto&& it : inputTensorData)
150 inputTensors.push_back({it.first,
151 ConstTensor(runtime->GetInputTensorInfo(netId, it.first), it.second.data())});
154 outputTensors.reserve(expectedOutputData.size());
155 std::map<int, std::vector<TOutput>> outputStorage;
156 for (
auto&& it : expectedOutputData)
158 std::vector<TOutput> out(it.second.size());
159 outputStorage.emplace(it.first, out);
160 outputTensors.push_back({it.first,
161 Tensor(runtime->GetOutputTensorInfo(netId, it.first),
162 outputStorage.at(it.first).data())});
166 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
169 for (
auto&& it : expectedOutputData)
171 std::vector<TOutput> out = outputStorage.at(it.first);
172 for (
unsigned int i = 0; i < out.size(); ++i)
174 CHECK_MESSAGE(Compare<ArmnnOType>(it.second[i], out[i], tolerance) ==
true,
175 "Actual output: " << out[i] <<
". Expected output:" << it.second[i]);
181 inline void ImportNonAlignedInputPointerTest(std::vector<BackendId> backends)
183 using namespace armnn;
214 std::string ignoredErrorMessage;
217 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
220 std::vector<float> inputData
222 1.0f, 2.0f, 3.0f, 4.0f
226 float* misalignedInputData =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(inputData.data()) + 1);
228 std::vector<float> outputData(4);
231 float* alignedOutputData = outputData.data();
239 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), alignedOutputData)}
242 runtime->GetProfiler(netId)->EnableProfiling(
true);
245 CHECK_THROWS_AS(runtime->EnqueueWorkload(netId, inputTensors, outputTensors),
MemoryImportException);
248 inline void ExportNonAlignedOutputPointerTest(std::vector<BackendId> backends)
250 using namespace armnn;
282 std::string ignoredErrorMessage;
285 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
288 std::vector<float> inputData
290 1.0f, 2.0f, 3.0f, 4.0f, 5.0f
294 float* alignedInputData = inputData.data();
296 std::vector<float> outputData(5);
299 float* misalignedOutputData =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(outputData.data()) + 1);
307 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), misalignedOutputData)}
314 CHECK_THROWS_AS(runtime->EnqueueWorkload(netId, inputTensors, outputTensors),
MemoryImportException);
318 CHECK_THROWS_AS(runtime->EnqueueWorkload(netId, inputTensors, outputTensors),
MemoryExportException);
322 inline void ImportAlignedPointerTest(std::vector<BackendId> backends)
324 using namespace armnn;
356 std::string ignoredErrorMessage;
359 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
362 std::vector<float> inputData
364 1.0f, 2.0f, 3.0f, 4.0f
367 std::vector<float> outputData(4);
369 std::vector<float> expectedOutput
371 1.0f, 4.0f, 9.0f, 16.0f
380 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
383 runtime->GetProfiler(netId)->EnableProfiling(
true);
386 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
390 std::stringstream ss;
392 std::string dump = ss.str();
395 std::size_t found = dump.find(
"ActivationWorkload");
396 CHECK(found != std::string::npos);
399 found = dump.find(
"SyncMemGeneric");
400 CHECK(found != std::string::npos);
403 found = dump.find(
"CopyMemGeneric");
404 CHECK(found == std::string::npos);
407 CHECK(outputData == expectedOutput);
410 inline void ImportOnlyWorkload(std::vector<BackendId> backends)
412 using namespace armnn;
439 INFO(
"Load Network");
442 std::string ignoredErrorMessage;
446 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
449 INFO(
"Generate Data");
451 std::vector<float> inputData
453 1.0f, 2.0f, 3.0f, 4.0f
456 std::vector<float> outputData(4);
458 std::vector<float> expectedOutput
460 1.0f, 4.0f, 9.0f, 16.0f
463 INFO(
"Create Inference");
471 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
474 INFO(
"Get Profiler");
475 runtime->GetProfiler(netId)->EnableProfiling(
true);
477 INFO(
"Run Inference");
479 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
481 INFO(
"Print Profiler");
484 std::stringstream ss;
486 std::string dump = ss.str();
489 INFO(
"Find SyncMemGeneric");
490 int count = SubStringCounter(dump,
"SyncMemGeneric");
494 INFO(
"Find CopyMemGeneric");
495 count = SubStringCounter(dump,
"CopyMemGeneric");
499 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
502 inline void ExportOnlyWorkload(std::vector<BackendId> backends)
504 using namespace armnn;
531 INFO(
"Load Network");
534 std::string ignoredErrorMessage;
536 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
539 INFO(
"Generate Data");
541 std::vector<float> inputData
543 1.0f, 2.0f, 3.0f, 4.0f
546 std::vector<float> outputData(4);
548 std::vector<float> expectedOutput
550 1.0f, 4.0f, 9.0f, 16.0f
553 INFO(
"Create Inference");
561 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
564 INFO(
"Get Profiler");
565 runtime->GetProfiler(netId)->EnableProfiling(
true);
567 INFO(
"Run Inference");
569 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
571 INFO(
"Print Profiler");
574 std::stringstream ss;
576 std::string dump = ss.str();
579 INFO(
"Find SyncMemGeneric");
580 int count = SubStringCounter(dump,
"SyncMemGeneric");
584 INFO(
"Find CopyMemGeneric");
585 count = SubStringCounter(dump,
"CopyMemGeneric");
589 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
592 inline void ImportAndExportWorkload(std::vector<BackendId> backends)
594 using namespace armnn;
621 INFO(
"Load Network");
624 std::string ignoredErrorMessage;
628 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
631 INFO(
"Generate Data");
633 std::vector<float> inputData
635 1.0f, 2.0f, 3.0f, 4.0f
638 std::vector<float> outputData(4);
640 std::vector<float> expectedOutput
642 1.0f, 4.0f, 9.0f, 16.0f
645 INFO(
"Create inference");
653 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
656 INFO(
"Get Profiler");
657 runtime->GetProfiler(netId)->EnableProfiling(
true);
659 INFO(
"Run Inference");
661 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
663 INFO(
"Print Profiler");
666 std::stringstream ss;
668 std::string dump = ss.str();
671 INFO(
"Find SyncMemGeneric");
672 int count = SubStringCounter(dump,
"SyncMemGeneric");
676 INFO(
"Find CopyMemGeneric");
677 count = SubStringCounter(dump,
"CopyMemGeneric");
681 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
684 inline void ExportOutputWithSeveralOutputSlotConnectionsTest(std::vector<BackendId> backends)
686 using namespace armnn;
719 std::string ignoredErrorMessage;
722 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
725 std::vector<float> inputData
727 1.0f, 2.0f, 3.0f, 4.0f
730 std::vector<float> outputData0(4);
731 std::vector<float> outputData1(4);
733 std::vector<float> expectedOutput
735 1.0f, 4.0f, 9.0f, 16.0f
744 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData0.data())},
745 {1,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 1), outputData1.data())}
750 runtime->GetProfiler(netId)->EnableProfiling(
true);
753 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
757 std::stringstream ss;
759 std::string dump = ss.str();
761 std::size_t found = std::string::npos;
765 found = dump.find(
"RefActivationWorkload");
769 found = dump.find(
"NeonActivationWorkload");
773 found = dump.find(
"ClActivationWorkload");
776 CHECK(found != std::string::npos);
778 found = dump.find(
"SyncMemGeneric");
779 CHECK(found == std::string::npos);
781 found = dump.find(
"CopyMemGeneric");
782 CHECK(found != std::string::npos);
785 CHECK(std::equal(outputData0.begin(), outputData0.end(),
786 expectedOutput.begin(), expectedOutput.end()));
787 CHECK(std::equal(outputData1.begin(), outputData1.end(),
788 expectedOutput.begin(), expectedOutput.end()));
791 inline void StridedSliceInvalidSliceEndToEndTest(std::vector<BackendId> backends)
793 using namespace armnn;
808 descriptor.
m_End = {2, 3};
827 inline void ForceImportWithAlignedBuffersEndToEndTest(std::vector<BackendId> backends)
835 using namespace armnn;
851 INFO(
"Load Network");
855 std::string ignoredErrorMessage;
857 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
859 INFO(
"Generate Data");
862 std::vector<float> inputData
864 1.0f, 2.0f, 3.0f, 4.0f
866 std::vector<float> outputData(4);
867 std::vector<float> expectedOutput
869 1.0f, 4.0f, 9.0f, 16.0f
874 CHECK(!(reinterpret_cast<uintptr_t>(inputData.data()) % alignment));
875 CHECK(!(reinterpret_cast<uintptr_t>(outputData.data()) % alignment));
877 INFO(
"Create Inference");
884 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
887 runtime->GetProfiler(netId)->EnableProfiling(
true);
888 std::vector<ImportedInputId> importedInputIds =
890 CHECK(importedInputIds.size() == 1);
891 std::vector<ImportedOutputId> importedOutputIds =
893 CHECK(importedOutputIds.size() == 1);
899 std::stringstream ss;
901 std::string dump = ss.str();
907 int count = SubStringCounter(dump,
"SyncMemGeneric");
910 count = SubStringCounter(dump,
"CopyMemGeneric");
916 int count = SubStringCounter(dump,
"SyncMemGeneric");
919 count = SubStringCounter(dump,
"CopyMemGeneric");
923 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
926 inline void ForceImportWithMisalignedInputBuffersEndToEndTest(std::vector<BackendId> backends)
934 using namespace armnn;
955 INFO(
"Load Network");
958 std::string ignoredErrorMessage;
960 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
962 INFO(
"Generate Data");
966 auto memPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
968 float* misalignedMemPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(memPtr) + 1);
972 CHECK (reinterpret_cast<uintptr_t>(misalignedMemPtr) % alignment);
974 std::vector<float> inputData
976 1.0f, 2.0f, 3.0f, 4.0f
979 std::memcpy(misalignedMemPtr, inputData.data(), 4*
sizeof(float));
981 std::vector<float> outputData(4);
983 CHECK(!(reinterpret_cast<uintptr_t>(outputData.data()) % alignment));
985 std::vector<float> expectedOutput
987 1.0f, 4.0f, 9.0f, 16.0f
990 INFO(
"Create Inference");
997 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
999 runtime->GetProfiler(netId)->EnableProfiling(
true);
1000 std::vector<ImportedInputId> importedInputIds =
1003 CHECK(importedInputIds.size() == 0);
1004 std::vector<ImportedOutputId> importedOutputIds =
1006 CHECK(importedOutputIds.size() == 1);
1009 runtime->EnqueueWorkload(netId, inputTensors,
OutputTensors(), importedInputIds, importedOutputIds);
1013 std::stringstream ss;
1015 std::string dump = ss.str();
1027 int count = SubStringCounter(dump,
"SyncMemGeneric");
1030 count = SubStringCounter(dump,
"CopyMemGeneric");
1036 int count = SubStringCounter(dump,
"SyncMemGeneric");
1039 count = SubStringCounter(dump,
"CopyMemGeneric");
1044 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
1048 inline void ForceImportWithMisalignedOutputBuffersEndToEndTest(std::vector<BackendId> backends)
1056 using namespace armnn;
1077 INFO(
"Load Network");
1080 std::string ignoredErrorMessage;
1082 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
1084 INFO(
"Generate Data");
1088 auto memPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1090 float* misalignedMemPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(memPtr) + 1);
1094 CHECK (reinterpret_cast<uintptr_t>(misalignedMemPtr) % alignment);
1097 std::vector<float> inputData
1099 1.0f, 2.0f, 3.0f, 4.0f
1103 CHECK(!(reinterpret_cast<uintptr_t>(inputData.data()) % alignment));
1104 std::vector<float> expectedOutput
1106 1.0f, 4.0f, 9.0f, 16.0f
1109 INFO(
"Create Inference");
1116 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), misalignedMemPtr)}
1118 runtime->GetProfiler(netId)->EnableProfiling(
true);
1119 std::vector<ImportedInputId> importedInputIds =
1121 CHECK(importedInputIds.size() == 1);
1123 std::vector<ImportedOutputId> importedOutputIds =
1125 CHECK(importedOutputIds.size() == 0);
1128 runtime->EnqueueWorkload(netId,
InputTensors(), outputTensors, importedInputIds, importedOutputIds);
1132 std::stringstream ss;
1134 std::string dump = ss.str();
1142 int count = SubStringCounter(dump,
"SyncMemGeneric");
1145 count = SubStringCounter(dump,
"CopyMemGeneric");
1158 unsigned int index = 0;
1159 std::vector<float> outputData(expectedOutput.size(), 0);
1160 std::memcpy(outputData.data(), misalignedMemPtr, expectedOutput.size() *
sizeof(float));
1161 for (
auto outputValue : expectedOutput)
1163 CHECK(outputValue == outputData[index]);
1169 inline void ForceImportWithMisalignedInputAndOutputBuffersEndToEndTest(std::vector<BackendId> backends)
1177 using namespace armnn;
1198 INFO(
"Load Network");
1201 std::string ignoredErrorMessage;
1203 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
1205 INFO(
"Generate Data");
1209 auto inputMemPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1210 float* misalignedInputPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(inputMemPtr) + 1);
1214 CHECK (reinterpret_cast<uintptr_t>(misalignedInputPtr) % alignment);
1215 std::vector<float> inputData
1217 1.0f, 2.0f, 3.0f, 4.0f
1219 std::memcpy(misalignedInputPtr, inputData.data(), 4*
sizeof(float));
1221 auto outputMemPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1222 float* misalignedOutputPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(outputMemPtr) + 1);
1225 CHECK (reinterpret_cast<uintptr_t>(misalignedOutputPtr) % alignment);
1227 std::vector<float> expectedOutput
1229 1.0f, 4.0f, 9.0f, 16.0f
1232 INFO(
"Create Inference");
1239 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), misalignedOutputPtr)}
1241 runtime->GetProfiler(netId)->EnableProfiling(
true);
1242 std::vector<ImportedInputId> importedInputIds =
1245 CHECK(importedInputIds.size() == 0);
1246 std::vector<ImportedOutputId> importedOutputIds =
1249 CHECK(importedOutputIds.size() == 0);
1252 runtime->EnqueueWorkload(netId, inputTensors, outputTensors, importedInputIds, importedOutputIds);
1256 std::stringstream ss;
1258 std::string dump = ss.str();
1266 int count = SubStringCounter(dump,
"SyncMemGeneric");
1269 count = SubStringCounter(dump,
"CopyMemGeneric");
1273 unsigned int index = 0;
1274 std::vector<float> outputData(expectedOutput.size(), 0);
1275 std::memcpy(outputData.data(), misalignedOutputPtr, expectedOutput.size() *
sizeof(float));
1276 for (
auto expectedValue : expectedOutput)
1278 CHECK(expectedValue == outputData[index]);
1281 std::free(inputMemPtr);
1282 std::free(outputMemPtr);
1285 inline void ForceImportRepeatedInferencesEndToEndTest(std::vector<BackendId> backends)
1295 using namespace armnn;
1316 INFO(
"Load Network");
1319 std::string ignoredErrorMessage;
1321 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
1323 INFO(
"Generate Data");
1326 std::vector<float> inputData
1328 1.0f, 2.0f, 3.0f, 4.0f
1330 std::vector<float> outputData(4);
1331 std::vector<float> expectedOutput
1333 1.0f, 4.0f, 9.0f, 16.0f
1338 CHECK(!(reinterpret_cast<uintptr_t>(inputData.data()) % alignment));
1339 CHECK(!(reinterpret_cast<uintptr_t>(outputData.data()) % alignment));
1341 INFO(
"Create Inference");
1348 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
1351 runtime->GetProfiler(netId)->EnableProfiling(
true);
1352 std::vector<ImportedInputId> importedInputIds =
1354 CHECK(importedInputIds.size() == 1);
1355 std::vector<ImportedOutputId> importedOutputIds =
1357 CHECK(importedOutputIds.size() == 1);
1363 std::stringstream ss;
1365 std::string dump = ss.str();
1371 int count = SubStringCounter(dump,
"SyncMemGeneric");
1374 count = SubStringCounter(dump,
"CopyMemGeneric");
1380 int count = SubStringCounter(dump,
"SyncMemGeneric");
1383 count = SubStringCounter(dump,
"CopyMemGeneric");
1387 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
1391 auto inputMemPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1392 float* misalignedInputPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(inputMemPtr) + 1);
1395 CHECK (reinterpret_cast<uintptr_t>(misalignedInputPtr) % alignment);
1397 std::vector<float> inputValues
1399 2.0f, 3.0f, 4.0f, 5.0f
1402 std::memcpy(misalignedInputPtr, inputValues.data(), inputValues.size()*
sizeof(float));
1404 auto outputMemPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1405 float* misalignedOutputPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(outputMemPtr) + 1);
1408 CHECK (reinterpret_cast<uintptr_t>(misalignedOutputPtr) % alignment);
1410 std::vector<float> expectedMisalignedOutput
1412 4.0f, 9.0f, 16.0f, 25.0f
1415 INFO(
"Create Second Inference");
1422 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), misalignedOutputPtr)}
1426 CHECK(importedInputIds.size() == 0);
1427 importedOutputIds = runtime->ImportOutputs(netId, outputTensorsMisaligned,
MemorySource::Malloc);
1429 CHECK(importedOutputIds.size() == 0);
1432 runtime->EnqueueWorkload(netId,
1433 inputTensorsMisaligned,
1434 outputTensorsMisaligned,
1449 int count = SubStringCounter(dump,
"SyncMemGeneric");
1452 count = SubStringCounter(dump,
"CopyMemGeneric");
1456 unsigned int index = 0;
1457 std::vector<float> alignedOutputData(expectedMisalignedOutput.size(), 0);
1458 std::memcpy(alignedOutputData.data(), misalignedOutputPtr, expectedMisalignedOutput.size() *
sizeof(float));
1459 for (
auto outputValue : expectedMisalignedOutput)
1461 CHECK(outputValue == alignedOutputData[index]);
1465 runtime->UnloadNetwork(netId);
1466 std::free(inputMemPtr);
1467 std::free(outputMemPtr);
1471 inline void ForceImportRepeatedInferencesInvertedEndToEndTest(std::vector<BackendId> backends)
1481 using namespace armnn;
1502 INFO(
"Load Network");
1505 std::string ignoredErrorMessage;
1507 CHECK(runtime->LoadNetwork(netId, std::move(optNet),ignoredErrorMessage, networkProperties)
1509 INFO(
"Generate Data");
1513 auto inputMemPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1514 float* misalignedInputPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(inputMemPtr) + 1);
1518 CHECK (reinterpret_cast<uintptr_t>(misalignedInputPtr) % alignment);
1519 std::vector<float> inputValues
1521 2.0f, 3.0f, 4.0f, 5.0f
1523 std::memcpy(misalignedInputPtr, inputValues.data(), inputValues.size() *
sizeof(float));
1525 auto outputMemPtr = std::malloc(4 *
sizeof(
float) +
sizeof(
char));
1526 float* misalignedOutputPtr =
reinterpret_cast<float*
>(
reinterpret_cast<char*
>(outputMemPtr) + 1);
1529 CHECK (reinterpret_cast<uintptr_t>(misalignedOutputPtr) % alignment);
1531 std::vector<float> expectedMisalignedOutput
1533 4.0f, 9.0f, 16.0f, 25.0f
1536 INFO(
"Create Second Inference");
1543 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), misalignedOutputPtr)}
1545 runtime->GetProfiler(netId)->EnableProfiling(
true);
1546 std::vector<ImportedInputId> importedInputIds =
1549 CHECK(importedInputIds.size() == 0);
1550 std::vector<ImportedOutputId> importedOutputIds =
1553 CHECK(importedOutputIds.size() == 0);
1556 runtime->EnqueueWorkload(netId,
1557 inputTensorsMisaligned,
1558 outputTensorsMisaligned,
1564 std::stringstream ss;
1566 std::string dump = ss.str();
1574 int count = SubStringCounter(dump,
"SyncMemGeneric");
1577 count = SubStringCounter(dump,
"CopyMemGeneric");
1581 unsigned int index = 0;
1582 std::vector<float> alignedOutput(expectedMisalignedOutput.size());
1583 std::memcpy(alignedOutput.data(), misalignedOutputPtr, expectedMisalignedOutput.size()*
sizeof(float));
1584 for (
auto outputValue : expectedMisalignedOutput)
1586 CHECK(outputValue == alignedOutput[index]);
1589 std::free(inputMemPtr);
1590 std::free(outputMemPtr);
1593 std::vector<float> inputData
1595 1.0f, 2.0f, 3.0f, 4.0f
1597 std::vector<float> outputData(4);
1598 std::vector<float> expectedOutput
1600 1.0f, 4.0f, 9.0f, 16.0f
1604 CHECK(!(reinterpret_cast<uintptr_t>(inputData.data()) % alignment));
1605 CHECK(!(reinterpret_cast<uintptr_t>(outputData.data()) % alignment));
1607 INFO(
"Create Inference");
1614 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data())}
1618 CHECK(importedInputIds.size() == 1);
1620 CHECK(importedOutputIds.size() == 1);
1633 int count = SubStringCounter(dump,
"SyncMemGeneric");
1636 count = SubStringCounter(dump,
"CopyMemGeneric");
1643 int count = SubStringCounter(dump,
"SyncMemGeneric");
1646 count = SubStringCounter(dump,
"CopyMemGeneric");
1650 CHECK(std::equal(outputData.begin(), outputData.end(), expectedOutput.begin(), expectedOutput.end()));
1652 runtime->UnloadNetwork(netId);
static IRuntimePtr Create(const CreationOptions &options)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
CPU Execution: Reference C++ kernels.
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1...
static ProfilerManager & GetInstance()
std::vector< int > m_Begin
Begin values for the input that will be sliced.
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
void Print(std::ostream &outStream) const
Print stats for events in JSON Format to the given output stream.
typename ResolveTypeImpl< DT >::Type ResolveType
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
void AnalyzeEventsAndWriteResults(std::ostream &outStream) const
Analyzes the tracked events and writes the results to the given output stream.
Copyright (c) 2021 ARM Limited and Contributors.
int32_t m_BeginMask
Begin mask value.
int32_t m_EndMask
End mask value.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IProfiler * GetProfiler()
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
void SetQuantizationScale(float scale)
GPU Execution: OpenCL: ArmCompute.
ArmNN performs an optimization on each model/network before it gets loaded for execution.
std::vector< int > m_Stride
Stride values for the input that will be sliced.
An ActivationDescriptor for the ActivationLayer.
std::vector< int > m_End
End values for the input that will be sliced.
CPU Execution: NEON: ArmCompute.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
A StridedSliceDescriptor for the StridedSliceLayer.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
void SetQuantizationOffset(int32_t offset)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
static INetworkPtr Create(NetworkOptions networkOptions={})
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
constexpr unsigned int GetDataTypeSize(DataType dataType)