18 #include <doctest/doctest.h> 25 namespace experimental
29 typename TInput = ResolveType <ArmnnIType>,
typename TOutput = ResolveType <ArmnnOType>>
31 const std::vector<std::map<
int, std::vector<TInput>>>& inputTensorData,
32 const std::vector<std::map<
int, std::vector<TOutput>>>& expectedOutputData,
33 std::vector<BackendId> backends,
34 const size_t numberOfInferences,
35 float tolerance = 0.000001f)
47 std::string errorMessage;
49 runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
51 std::vector<InputTensors> inputTensorsVec;
52 std::vector<OutputTensors> outputTensorsVec;
53 std::vector<std::map<int, std::vector<TOutput>>> outputStorageVec;
54 std::vector<std::unique_ptr<IWorkingMemHandle>> workingMemHandles;
56 for (
unsigned int i = 0; i < numberOfInferences; ++i)
60 outputStorageVec.emplace_back(std::map<
int, std::vector<TOutput>>());
62 inputTensors.reserve(inputTensorData.size());
63 for (
auto&& it : inputTensorData[i])
65 inputTensors.push_back({it.first,
66 ConstTensor(runtime->GetInputTensorInfo(networkId, it.first), it.second.data())});
69 outputTensors.reserve(expectedOutputData.size());
70 for (
auto&& it : expectedOutputData[i])
72 std::vector<TOutput> out(it.second.size());
73 outputStorageVec[i].emplace(it.first, out);
74 outputTensors.push_back({it.first,
75 Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
76 outputStorageVec[i].at(it.first).data())});
79 inputTensorsVec.push_back(inputTensors);
80 outputTensorsVec.push_back(outputTensors);
82 workingMemHandles.push_back(runtime->CreateWorkingMemHandle(networkId));
85 std::vector<std::thread> threads;
86 for (
unsigned int i = 0; i < numberOfInferences; ++i)
93 threads.emplace_back([&]()
96 runtime->Execute(workingMemHandle, inputTensors, outputTensors);
100 for (
unsigned int i = 0; i < numberOfInferences; ++i)
106 for (
unsigned int i = 0; i < numberOfInferences; ++i)
108 for (
auto &&it : expectedOutputData[i])
110 std::vector<TOutput> out = outputStorageVec[i].at(it.first);
111 for (
unsigned int j = 0; j < out.size(); ++j)
113 CHECK(Compare<ArmnnOType>(it.second[j], out[j], tolerance) ==
true);
123 const std::map<
int, std::vector<TInput>>& inputTensorData,
124 const std::map<
int, std::vector<TOutput>>& expectedOutputData,
125 std::vector<BackendId> backends,
126 float tolerance = 0.000001f,
127 size_t numThreads = 1)
139 std::string errorMessage;
143 runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
146 inputTensors.reserve(inputTensorData.size());
147 for (
auto&& it : inputTensorData)
149 inputTensors.push_back({it.first,
150 ConstTensor(runtime->GetInputTensorInfo(networkId, 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(networkId, it.first),
162 outputStorage.at(it.first).data())});
168 std::unique_ptr<IWorkingMemHandle> workingMemHandle = runtime->CreateWorkingMemHandle(networkId);
172 runtime->Execute(workingMemHandleRef, inputTensors, outputTensors);
176 std::vector<std::shared_ptr<IWorkingMemHandle>> memHandles;
178 for (
size_t i = 0; i < numThreads; ++i)
180 memHandles.emplace_back(runtime->CreateWorkingMemHandle(networkId));
183 Threadpool threadpool(numThreads, runtime.get(), memHandles);
188 for (
size_t i = 0; i < 1000; ++i)
190 threadpool.Schedule(networkId,
193 static_cast<QosExecPriority>(rand()%3),
194 callbackManager.GetNewCallback());
198 for (
size_t i = 0; i < 1000; ++i)
207 for (
auto&& it : expectedOutputData)
209 std::vector<TOutput> out = outputStorage.at(it.first);
211 for (
unsigned int i = 0; i < out.size(); ++i)
213 CHECK(Compare<ArmnnOType>(it.second[i], out[i], tolerance) ==
true);
218 template<
typename armnn::DataType DataType>
221 const std::vector<int>& beginData,
222 const std::vector<int>& endData,
223 const std::vector<int>& stridesData,
226 int shrinkAxisMask = 0,
227 int ellipsisMask = 0,
229 const float qScale = 1.0f,
230 const int32_t qOffset = 0)
232 using namespace armnn;
240 stridedSliceDescriptor.
m_Begin = beginData;
241 stridedSliceDescriptor.
m_End = endData;
242 stridedSliceDescriptor.
m_Stride = stridesData;
244 stridedSliceDescriptor.
m_EndMask = endMask;
250 IConnectableLayer* stridedSlice = net->AddStridedSliceLayer(stridedSliceDescriptor,
"splitter");
253 Connect(input, stridedSlice, inputTensorInfo, 0, 0);
254 Connect(stridedSlice, output, outputTensorInfo, 0, 0);
259 template<armnn::DataType ArmnnType>
262 using namespace armnn;
267 const std::vector<int>& beginData = {1, 0, 0, 0};
268 const std::vector<int>& endData = {2, 2, 3, 1};
269 const std::vector<int>& stridesData = {1, 1, 1, 1};
272 int shrinkAxisMask = 0;
273 int ellipsisMask = 0;
277 INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
290 std::vector<T> inputData{
291 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
293 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
295 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
298 std::vector<T> outputExpected{
299 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f
302 std::map<int, std::vector<T>> inputTensorData = {{0, inputData}};
303 std::map<int, std::vector<T>> expectedOutputData = {{0, outputExpected}};
305 AsyncEndToEndTestImpl<ArmnnType, ArmnnType>(move(net),
313 template<armnn::DataType ArmnnType>
316 using namespace armnn;
321 const std::vector<int>& beginData = {1, 0, 0, 0};
322 const std::vector<int>& endData = {2, 2, 3, 1};
323 const std::vector<int>& stridesData = {1, 1, 1, 1};
326 int shrinkAxisMask = 0;
327 int ellipsisMask = 0;
331 INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
345 std::vector<T> inputData1{
346 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
348 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
350 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
353 std::vector<T> outputExpected1{ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f };
356 std::vector<T> inputData2{
357 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
359 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f,
361 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
364 std::vector<T> outputExpected2{ 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f };
366 std::vector<std::map<int, std::vector<T>>> inputTensors;
367 std::vector<std::map<int, std::vector<T>>> outputTensors;
369 inputTensors.push_back(std::map<
int, std::vector<T>> {{0, inputData1}});
370 inputTensors.push_back(std::map<
int, std::vector<T>> {{0, inputData2}});
371 outputTensors.push_back(std::map<
int, std::vector<T>> {{0, outputExpected1}});
372 outputTensors.push_back(std::map<
int, std::vector<T>> {{0, outputExpected2}});
374 AsyncThreadedEndToEndTestImpl<ArmnnType, ArmnnType>(move(net), inputTensors, outputTensors, backends, 2);
static IRuntimePtr Create(const CreationOptions &options)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1...
void AsyncThreadedEndToEndTestImpl(INetworkPtr network, const std::vector< std::map< int, std::vector< TInput >>> &inputTensorData, const std::vector< std::map< int, std::vector< TOutput >>> &expectedOutputData, std::vector< BackendId > backends, const size_t numberOfInferences, float tolerance=0.000001f)
std::vector< int > m_Begin
Begin values for the input that will be sliced.
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
typename ResolveTypeImpl< DT >::Type ResolveType
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Copyright (c) 2021 ARM Limited and Contributors.
int32_t m_BeginMask
Begin mask value.
int32_t m_EndMask
End mask value.
void StridedSlicedEndToEndTest(const std::vector< BackendId > &backends, size_t numThreads)
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
void StridedSlicedMultiThreadedEndToEndTest(const std::vector< BackendId > &backends)
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.
int32_t m_NewAxisMask
New axis mask value.
void AsyncEndToEndTestImpl(INetworkPtr network, const std::map< int, std::vector< TInput >> &inputTensorData, const std::map< int, std::vector< TOutput >> &expectedOutputData, std::vector< BackendId > backends, float tolerance=0.000001f, size_t numThreads=1)
int32_t m_EllipsisMask
Ellipsis mask value.
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
std::vector< int > m_Stride
Stride values for the input that will be sliced.
INetworkPtr CreateStridedSliceNetwork(const TensorShape &inputShape, const TensorShape &outputShape, const std::vector< int > &beginData, const std::vector< int > &endData, const std::vector< int > &stridesData, int beginMask=0, int endMask=0, int shrinkAxisMask=0, int ellipsisMask=0, int newAxisMask=0, const float qScale=1.0f, const int32_t qOffset=0)
std::vector< int > m_End
End values for the input that will be sliced.
A StridedSliceDescriptor for the StridedSliceLayer.
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
static INetworkPtr Create(NetworkOptions networkOptions={})
std::shared_ptr< AsyncExecutionCallback > GetNotifiedCallback()