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)
46 std::string errorMessage;
48 runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
50 std::vector<InputTensors> inputTensorsVec;
51 std::vector<OutputTensors> outputTensorsVec;
52 std::vector<std::map<int, std::vector<TOutput>>> outputStorageVec;
53 std::vector<std::unique_ptr<IWorkingMemHandle>> workingMemHandles;
55 for (
unsigned int i = 0; i < numberOfInferences; ++i)
59 outputStorageVec.emplace_back(std::map<
int, std::vector<TOutput>>());
61 inputTensors.reserve(inputTensorData.size());
62 for (
auto&& it : inputTensorData[i])
64 TensorInfo inputTensorInfo = runtime->GetInputTensorInfo(networkId, it.first);
66 inputTensors.push_back({it.first,
70 outputTensors.reserve(expectedOutputData.size());
71 for (
auto&& it : expectedOutputData[i])
73 std::vector<TOutput> out(it.second.size());
74 outputStorageVec[i].emplace(it.first, out);
75 outputTensors.push_back({it.first,
76 Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
77 outputStorageVec[i].at(it.first).data())});
80 inputTensorsVec.push_back(inputTensors);
81 outputTensorsVec.push_back(outputTensors);
83 workingMemHandles.push_back(runtime->CreateWorkingMemHandle(networkId));
86 std::vector<std::thread> threads;
87 for (
unsigned int i = 0; i < numberOfInferences; ++i)
94 threads.emplace_back([&]()
97 runtime->Execute(workingMemHandle, inputTensors, outputTensors);
101 for (
unsigned int i = 0; i < numberOfInferences; ++i)
107 for (
unsigned int i = 0; i < numberOfInferences; ++i)
109 for (
auto &&it : expectedOutputData[i])
111 std::vector<TOutput> out = outputStorageVec[i].at(it.first);
112 for (
unsigned int j = 0; j < out.size(); ++j)
114 CHECK(Compare<ArmnnOType>(it.second[j], out[j], tolerance) ==
true);
124 const std::map<
int, std::vector<TInput>>& inputTensorData,
125 const std::map<
int, std::vector<TOutput>>& expectedOutputData,
126 std::vector<BackendId> backends,
127 float tolerance = 0.000001f,
128 size_t numThreads = 1)
131 const unsigned int numberOfInferences = numThreads == 1 ? 1 : 1000;
143 std::string errorMessage;
147 runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
150 inputTensors.reserve(inputTensorData.size());
151 for (
auto&& it : inputTensorData)
153 TensorInfo inputTensorInfo = runtime->GetInputTensorInfo(networkId, it.first);
155 inputTensors.push_back({it.first,
159 std::vector<OutputTensors> outputTensorsVec;
160 std::vector<std::map<int, std::vector<TOutput>>> outputStorageVec;
162 outputTensorsVec.reserve(numberOfInferences);
163 outputStorageVec.reserve(numberOfInferences);
164 for (
unsigned int i = 0; i < numberOfInferences; ++i)
167 outputStorageVec.emplace_back(std::map<
int, std::vector<TOutput>>());
169 outputTensors.reserve(expectedOutputData.size());
170 for (
auto&& it : expectedOutputData)
172 std::vector<TOutput> out(it.second.size());
173 outputStorageVec[i].emplace(it.first, out);
174 outputTensors.push_back({it.first,
175 Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
176 outputStorageVec[i].at(it.first).data())});
179 outputTensorsVec.push_back(outputTensors);
185 std::unique_ptr<IWorkingMemHandle> workingMemHandle = runtime->CreateWorkingMemHandle(networkId);
189 runtime->Execute(workingMemHandleRef, inputTensors, outputTensorsVec[0]);
193 std::vector<std::shared_ptr<IWorkingMemHandle>> memHandles;
195 for (
size_t i = 0; i < numThreads; ++i)
197 memHandles.emplace_back(runtime->CreateWorkingMemHandle(networkId));
200 Threadpool threadpool(numThreads, runtime.get(), memHandles);
205 for (
size_t i = 0; i < numberOfInferences; ++i)
207 threadpool.Schedule(networkId,
210 static_cast<QosExecPriority>(rand()%3),
211 callbackManager.GetNewCallback());
215 for (
size_t i = 0; i < numberOfInferences; ++i)
224 for (
auto&& outputStorage : outputStorageVec)
226 for (
auto&& it : expectedOutputData)
228 std::vector<TOutput> out = outputStorage.at(it.first);
230 for (
unsigned int i = 0; i < out.size(); ++i)
233 CHECK(it.second[i] == doctest::Approx(out[i]).epsilon(tolerance));
239 template<
typename armnn::DataType DataType>
242 const std::vector<int>& beginData,
243 const std::vector<int>& endData,
244 const std::vector<int>& stridesData,
247 int shrinkAxisMask = 0,
248 int ellipsisMask = 0,
250 const float qScale = 1.0f,
251 const int32_t qOffset = 0)
253 using namespace armnn;
261 stridedSliceDescriptor.
m_Begin = beginData;
262 stridedSliceDescriptor.
m_End = endData;
263 stridedSliceDescriptor.
m_Stride = stridesData;
265 stridedSliceDescriptor.
m_EndMask = endMask;
271 IConnectableLayer* stridedSlice = net->AddStridedSliceLayer(stridedSliceDescriptor,
"splitter");
274 Connect(input, stridedSlice, inputTensorInfo, 0, 0);
275 Connect(stridedSlice, output, outputTensorInfo, 0, 0);
280 template<armnn::DataType ArmnnType>
283 using namespace armnn;
288 const std::vector<int>& beginData = {1, 0, 0, 0};
289 const std::vector<int>& endData = {2, 2, 3, 1};
290 const std::vector<int>& stridesData = {1, 1, 1, 1};
293 int shrinkAxisMask = 0;
294 int ellipsisMask = 0;
298 INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
311 std::vector<T> inputData{
312 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
314 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
316 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
319 std::vector<T> outputExpected{
320 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f
323 std::map<int, std::vector<T>> inputTensorData = {{0, inputData}};
324 std::map<int, std::vector<T>> expectedOutputData = {{0, outputExpected}};
326 AsyncEndToEndTestImpl<ArmnnType, ArmnnType>(move(net),
334 template<armnn::DataType ArmnnType>
337 using namespace armnn;
342 const std::vector<int>& beginData = {1, 0, 0, 0};
343 const std::vector<int>& endData = {2, 2, 3, 1};
344 const std::vector<int>& stridesData = {1, 1, 1, 1};
347 int shrinkAxisMask = 0;
348 int ellipsisMask = 0;
352 INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
366 std::vector<T> inputData1{
367 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
369 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
371 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
374 std::vector<T> outputExpected1{ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f };
377 std::vector<T> inputData2{
378 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
380 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f,
382 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
385 std::vector<T> outputExpected2{ 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f };
387 std::vector<std::map<int, std::vector<T>>> inputTensors;
388 std::vector<std::map<int, std::vector<T>>> outputTensors;
390 inputTensors.push_back(std::map<
int, std::vector<T>> {{0, inputData1}});
391 inputTensors.push_back(std::map<
int, std::vector<T>> {{0, inputData2}});
392 outputTensors.push_back(std::map<
int, std::vector<T>> {{0, outputExpected1}});
393 outputTensors.push_back(std::map<
int, std::vector<T>> {{0, outputExpected2}});
395 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
#define ARMNN_ASSERT(COND)
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.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
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()