6 #include <CommonTestUtils.hpp> 8 #include <GraphUtils.hpp> 10 #include <doctest/doctest.h> 14 TEST_CASE(
"ClImportEnabledFallbackToNeon")
16 using namespace armnn;
82 std::string ignoredErrorMessage;
84 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
87 std::vector<float> inputValue0
89 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f, 6.0f, 1.0f, 1.0f, 2.0f, 2.0f
91 std::vector<float> inputValue1
93 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f, 0.0f, 1.0f, 1.0f, 2.0f
95 std::vector<float> inputData2
97 12.0f, 11.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f, 12.0f, 11.0f, 10.0f, 9.0f
100 std::vector<float> outputData(16);
102 std::vector<float> expectedOutput
104 11.0f, 9.0f, 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, -7.0f, -9.0f, -11.0f, 11.0f, 9.0f, 7.0f, 5.0f
109 size_t totalBytes = numElements *
sizeof(float);
110 const size_t alignment = 64;
111 size_t space = totalBytes + alignment + alignment;
112 auto inputData0 = std::make_unique<uint8_t[]>(space);
113 void* alignedInputPtr0 = inputData0.get();
114 CHECK(std::align(alignment, totalBytes, alignedInputPtr0, space));
116 auto* intputPtr0 =
reinterpret_cast<float*
>(alignedInputPtr0);
117 std::copy(inputValue0.begin(), inputValue0.end(), intputPtr0);
119 auto inputData1 = std::make_unique<uint8_t[]>(space);
120 void* alignedInputPtr1 = inputData1.get();
121 CHECK(std::align(alignment, totalBytes, alignedInputPtr1, space));
123 auto* intputPtr1 =
reinterpret_cast<float*
>(alignedInputPtr1);
124 std::copy(inputValue1.begin(), inputValue1.end(), intputPtr1);
134 { 0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data()) }
137 runtime->GetProfiler(netId)->EnableProfiling(
true);
140 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
144 std::stringstream ss;
146 std::string dump = ss.str();
149 std::size_t found = dump.find(
"NeonSubtractionWorkload_Execute");
150 CHECK(found != std::string::npos);
153 found = dump.find(
"CopyMemGeneric");
154 CHECK(found != std::string::npos);
157 CHECK(outputData == expectedOutput);
159 runtime->UnloadNetwork(netId);
162 TEST_CASE(
"ClImportDisabledFallbackToNeon")
164 using namespace armnn;
228 runtime->LoadNetwork(netId, std::move(optNet));
231 std::vector<float> inputData0
233 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f, 6.0f
235 std::vector<float> inputData1
237 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f
239 std::vector<float> inputData2
241 12.0f, 11.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f
244 std::vector<float> outputData(12);
246 std::vector<float> expectedOutput
248 11.0f, 9.0f, 7.0f, 5.0f, 3.0f, 1.0f, -1.0f, -3.0f, -5.0f, -7.0f, -9.0f, -11.0f
259 { 0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data()) }
262 runtime->GetProfiler(netId)->EnableProfiling(
true);
265 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
269 std::stringstream ss;
271 std::string dump = ss.str();
274 std::size_t found = dump.find(
"NeonSubtractionWorkload_Execute");
275 CHECK(found != std::string::npos);
278 found = dump.find(
"CopyMemGeneric");
279 CHECK(found != std::string::npos);
282 CHECK(outputData == expectedOutput);
285 TEST_CASE(
"ClImportEnabledFallbackSubgraphToNeon")
287 using namespace armnn;
368 std::string ignoredErrorMessage;
370 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
373 std::vector<float> inputValue0
375 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f, 6.0f, 1.0f, 1.0f, 2.0f, 2.0f
377 std::vector<float> inputValue1
379 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f, 0.0f, 1.0f, 1.0f, 2.0f
381 std::vector<float> inputData2
383 12.0f, 11.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f, 12.0f, 11.0f, 10.0f, 9.0f
386 std::vector<float> outputData(4);
388 std::vector<float> expectedOutput{ 11.0f, 3.0f, -5.0f, 11.0f };
391 size_t totalBytes = numElements *
sizeof(float);
392 const size_t alignment = 64;
393 size_t space = totalBytes + alignment + alignment;
394 auto inputData0 = std::make_unique<uint8_t[]>(space);
395 void* alignedInputPtr0 = inputData0.get();
396 CHECK(std::align(alignment, totalBytes, alignedInputPtr0, space));
398 auto* intputPtr0 =
reinterpret_cast<float*
>(alignedInputPtr0);
399 std::copy(inputValue0.begin(), inputValue0.end(), intputPtr0);
401 auto inputData1 = std::make_unique<uint8_t[]>(space);
402 void* alignedInputPtr1 = inputData1.get();
403 CHECK(std::align(alignment, totalBytes, alignedInputPtr1, space));
405 auto* intputPtr1 =
reinterpret_cast<float*
>(alignedInputPtr1);
406 std::copy(inputValue1.begin(), inputValue1.end(), intputPtr1);
416 { 0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data()) }
419 runtime->GetProfiler(netId)->EnableProfiling(
true);
422 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
426 std::stringstream ss;
428 std::string dump = ss.str();
431 std::size_t found = dump.find(
"NeonSubtractionWorkload_Execute");
432 CHECK(found != std::string::npos);
435 found = dump.find(
"ClPooling2dWorkload_Execute");
436 CHECK(found != std::string::npos);
439 found = dump.find(
"CopyMemGeneric");
440 CHECK(found != std::string::npos);
443 CHECK(outputData == expectedOutput);
445 runtime->UnloadNetwork(netId);
448 TEST_CASE(
"ClImportDisableFallbackSubgraphToNeon")
450 using namespace armnn;
525 runtime->LoadNetwork(netId, std::move(optNet));
528 std::vector<float> inputData0
530 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f, 6.0f
532 std::vector<float> inputData1
534 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 5.0f, 5.0f, 6.0f
536 std::vector<float> inputData2
538 12.0f, 11.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f
541 std::vector<float> outputData(2);
543 std::vector<float> expectedOutput{ 11.0f, -1.0f };
553 { 0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data()) }
556 runtime->GetProfiler(netId)->EnableProfiling(
true);
559 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
563 std::stringstream ss;
565 std::string dump = ss.str();
568 std::size_t found = dump.find(
"NeonSubtractionWorkload_Execute");
569 CHECK(found != std::string::npos);
572 found = dump.find(
"ClPooling2dWorkload_Execute");
573 CHECK(found != std::string::npos);
576 found = dump.find(
"CopyMemGeneric");
577 CHECK(found != std::string::npos);
580 CHECK(outputData == expectedOutput);
static IRuntimePtr Create(const CreationOptions &options)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
armnn::Layer * GetFirstLayerWithName(armnn::Graph &graph, const std::string &name)
static ProfilerManager & GetInstance()
bool CheckOrder(const armnn::Graph &graph, const armnn::Layer *first, const armnn::Layer *second)
Checks that first comes before second in the order.
virtual void BackendSelectionHint(Optional< BackendId > backend)=0
Provide a hint for the optimizer as to which backend to prefer for this layer.
uint32_t m_PoolWidth
Pooling width value.
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.
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Copyright (c) 2021 ARM Limited and Contributors.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IProfiler * GetProfiler()
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
uint32_t m_PoolHeight
Pooling height value.
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
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
GPU Execution: OpenCL: ArmCompute.
ArmNN performs an optimization on each model/network before it gets loaded for execution.
const BackendId & GetBackendId() const
Graph & GetGraphForTesting(IOptimizedNetwork *optNet)
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.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
A Pooling2dDescriptor for the Pooling2dLayer.
static INetworkPtr Create(NetworkOptions networkOptions={})
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
unsigned int GetNumElements() const