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 TensorInfo inputTensorInfo = runtime->GetInputTensorInfo(networkId, it.first);
67 inputTensors.push_back({it.first,
71 outputTensors.reserve(expectedOutputData.size());
72 for (
auto&& it : expectedOutputData[i])
74 std::vector<TOutput> out(it.second.size());
75 outputStorageVec[i].emplace(it.first, out);
76 outputTensors.push_back({it.first,
77 Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
78 outputStorageVec[i].at(it.first).data())});
81 inputTensorsVec.push_back(inputTensors);
82 outputTensorsVec.push_back(outputTensors);
84 workingMemHandles.push_back(runtime->CreateWorkingMemHandle(networkId));
87 std::vector<std::thread> threads;
88 for (
unsigned int i = 0; i < numberOfInferences; ++i)
95 threads.emplace_back([&]()
98 runtime->Execute(workingMemHandle, inputTensors, outputTensors);
102 for (
unsigned int i = 0; i < numberOfInferences; ++i)
108 for (
unsigned int i = 0; i < numberOfInferences; ++i)
110 for (
auto &&it : expectedOutputData[i])
112 std::vector<TOutput> out = outputStorageVec[i].at(it.first);
113 for (
unsigned int j = 0; j < out.size(); ++j)
115 CHECK(Compare<ArmnnOType>(it.second[j], out[j], tolerance) ==
true);
125 const std::map<
int, std::vector<TInput>>& inputTensorData,
126 const std::map<
int, std::vector<TOutput>>& expectedOutputData,
127 std::vector<BackendId> backends,
128 float tolerance = 0.000001f,
129 size_t numThreads = 1)
141 std::string errorMessage;
145 runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
148 inputTensors.reserve(inputTensorData.size());
149 for (
auto&& it : inputTensorData)
151 TensorInfo inputTensorInfo = runtime->GetInputTensorInfo(networkId, it.first);
153 inputTensors.push_back({it.first,
158 outputTensors.reserve(expectedOutputData.size());
159 std::map<int, std::vector<TOutput>> outputStorage;
160 for (
auto&& it : expectedOutputData)
162 std::vector<TOutput> out(it.second.size());
163 outputStorage.emplace(it.first, out);
164 outputTensors.push_back({it.first,
165 Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
166 outputStorage.at(it.first).data())});
172 std::unique_ptr<IWorkingMemHandle> workingMemHandle = runtime->CreateWorkingMemHandle(networkId);
176 runtime->Execute(workingMemHandleRef, inputTensors, outputTensors);
180 std::vector<std::shared_ptr<IWorkingMemHandle>> memHandles;
182 for (
size_t i = 0; i < numThreads; ++i)
184 memHandles.emplace_back(runtime->CreateWorkingMemHandle(networkId));
187 Threadpool threadpool(numThreads, runtime.get(), memHandles);
192 for (
size_t i = 0; i < 1000; ++i)
194 threadpool.Schedule(networkId,
197 static_cast<QosExecPriority>(rand()%3),
198 callbackManager.GetNewCallback());
202 for (
size_t i = 0; i < 1000; ++i)
211 for (
auto&& it : expectedOutputData)
213 std::vector<TOutput> out = outputStorage.at(it.first);
215 for (
unsigned int i = 0; i < out.size(); ++i)
217 CHECK(Compare<ArmnnOType>(it.second[i], out[i], tolerance) ==
true);
222 template<
typename armnn::DataType DataType>
225 const std::vector<int>& beginData,
226 const std::vector<int>& endData,
227 const std::vector<int>& stridesData,
230 int shrinkAxisMask = 0,
231 int ellipsisMask = 0,
233 const float qScale = 1.0f,
234 const int32_t qOffset = 0)
236 using namespace armnn;
244 stridedSliceDescriptor.
m_Begin = beginData;
245 stridedSliceDescriptor.
m_End = endData;
246 stridedSliceDescriptor.
m_Stride = stridesData;
248 stridedSliceDescriptor.
m_EndMask = endMask;
254 IConnectableLayer* stridedSlice = net->AddStridedSliceLayer(stridedSliceDescriptor,
"splitter");
257 Connect(input, stridedSlice, inputTensorInfo, 0, 0);
258 Connect(stridedSlice, output, outputTensorInfo, 0, 0);
263 template<armnn::DataType ArmnnType>
266 using namespace armnn;
271 const std::vector<int>& beginData = {1, 0, 0, 0};
272 const std::vector<int>& endData = {2, 2, 3, 1};
273 const std::vector<int>& stridesData = {1, 1, 1, 1};
276 int shrinkAxisMask = 0;
277 int ellipsisMask = 0;
281 INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
294 std::vector<T> inputData{
295 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
297 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
299 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
302 std::vector<T> outputExpected{
303 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f
306 std::map<int, std::vector<T>> inputTensorData = {{0, inputData}};
307 std::map<int, std::vector<T>> expectedOutputData = {{0, outputExpected}};
309 AsyncEndToEndTestImpl<ArmnnType, ArmnnType>(move(net),
317 template<armnn::DataType ArmnnType>
320 using namespace armnn;
325 const std::vector<int>& beginData = {1, 0, 0, 0};
326 const std::vector<int>& endData = {2, 2, 3, 1};
327 const std::vector<int>& stridesData = {1, 1, 1, 1};
330 int shrinkAxisMask = 0;
331 int ellipsisMask = 0;
335 INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
349 std::vector<T> inputData1{
350 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
352 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
354 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
357 std::vector<T> outputExpected1{ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f };
360 std::vector<T> inputData2{
361 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
363 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f,
365 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
368 std::vector<T> outputExpected2{ 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f };
370 std::vector<std::map<int, std::vector<T>>> inputTensors;
371 std::vector<std::map<int, std::vector<T>>> outputTensors;
373 inputTensors.push_back(std::map<
int, std::vector<T>> {{0, inputData1}});
374 inputTensors.push_back(std::map<
int, std::vector<T>> {{0, inputData2}});
375 outputTensors.push_back(std::map<
int, std::vector<T>> {{0, outputExpected1}});
376 outputTensors.push_back(std::map<
int, std::vector<T>> {{0, outputExpected2}});
378 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.
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()