blob: adabed07f8a6ef117dfe2e12dbc62f968d47c787 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00007#include <test/CreateWorkload.hpp>
arovir0143095f32018-10-09 18:04:24 +01008
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00009#include <backendsCommon/MemCopyWorkload.hpp>
10#include <reference/RefWorkloadFactory.hpp>
telsoa014fcda012018-03-09 14:13:49 +000011
12#if ARMCOMPUTECL_ENABLED
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000013#include <cl/ClTensorHandle.hpp>
telsoa014fcda012018-03-09 14:13:49 +000014#endif
15
16#if ARMCOMPUTENEON_ENABLED
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000017#include <neon/NeonTensorHandle.hpp>
telsoa014fcda012018-03-09 14:13:49 +000018#endif
19
telsoa014fcda012018-03-09 14:13:49 +000020using namespace armnn;
21
22namespace
23{
24
25using namespace std;
26
27template<typename IComputeTensorHandle>
28boost::test_tools::predicate_result CompareTensorHandleShape(IComputeTensorHandle* tensorHandle,
29 std::initializer_list<unsigned int> expectedDimensions)
30{
31 arm_compute::ITensorInfo* info = tensorHandle->GetTensor().info();
32
33 auto infoNumDims = info->num_dimensions();
34 auto numExpectedDims = expectedDimensions.size();
35 if (infoNumDims != numExpectedDims)
36 {
37 boost::test_tools::predicate_result res(false);
38 res.message() << "Different number of dimensions [" << info->num_dimensions()
39 << "!=" << expectedDimensions.size() << "]";
40 return res;
41 }
42
43 size_t i = info->num_dimensions() - 1;
44
45 for (unsigned int expectedDimension : expectedDimensions)
46 {
47 if (info->dimension(i) != expectedDimension)
48 {
49 boost::test_tools::predicate_result res(false);
Matthew Bentham89105282018-11-20 14:33:33 +000050 res.message() << "For dimension " << i <<
51 " expected size " << expectedDimension <<
52 " got " << info->dimension(i);
telsoa014fcda012018-03-09 14:13:49 +000053 return res;
54 }
55
56 i--;
57 }
58
59 return true;
60}
61
telsoa01c577f2c2018-08-31 09:22:23 +010062template<typename IComputeTensorHandle>
telsoa014fcda012018-03-09 14:13:49 +000063void CreateMemCopyWorkloads(IWorkloadFactory& factory)
64{
65 Graph graph;
66 RefWorkloadFactory refFactory;
67
telsoa01c577f2c2018-08-31 09:22:23 +010068 // Creates the layers we're testing.
telsoa014fcda012018-03-09 14:13:49 +000069 Layer* const layer1 = graph.AddLayer<MemCopyLayer>("layer1");
70 Layer* const layer2 = graph.AddLayer<MemCopyLayer>("layer2");
71
telsoa01c577f2c2018-08-31 09:22:23 +010072 // Creates extra layers.
telsoa014fcda012018-03-09 14:13:49 +000073 Layer* const input = graph.AddLayer<InputLayer>(0, "input");
74 Layer* const output = graph.AddLayer<OutputLayer>(0, "output");
75
telsoa01c577f2c2018-08-31 09:22:23 +010076 // Connects up.
telsoa014fcda012018-03-09 14:13:49 +000077 TensorInfo tensorInfo({2, 3}, DataType::Float32);
78 Connect(input, layer1, tensorInfo);
79 Connect(layer1, layer2, tensorInfo);
80 Connect(layer2, output, tensorInfo);
81
82 input->CreateTensorHandles(graph, refFactory);
83 layer1->CreateTensorHandles(graph, factory);
84 layer2->CreateTensorHandles(graph, refFactory);
85 output->CreateTensorHandles(graph, refFactory);
86
87 // make the workloads and check them
telsoa01c577f2c2018-08-31 09:22:23 +010088 auto workload1 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer1, graph, factory);
89 auto workload2 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer2, graph, refFactory);
telsoa014fcda012018-03-09 14:13:49 +000090
91 MemCopyQueueDescriptor queueDescriptor1 = workload1->GetData();
92 BOOST_TEST(queueDescriptor1.m_Inputs.size() == 1);
93 BOOST_TEST(queueDescriptor1.m_Outputs.size() == 1);
94 auto inputHandle1 = boost::polymorphic_downcast<ConstCpuTensorHandle*>(queueDescriptor1.m_Inputs[0]);
95 auto outputHandle1 = boost::polymorphic_downcast<IComputeTensorHandle*>(queueDescriptor1.m_Outputs[0]);
96 BOOST_TEST((inputHandle1->GetTensorInfo() == TensorInfo({2, 3}, DataType::Float32)));
97 BOOST_TEST(CompareTensorHandleShape<IComputeTensorHandle>(outputHandle1, {2, 3}));
98
99
100 MemCopyQueueDescriptor queueDescriptor2 = workload2->GetData();
101 BOOST_TEST(queueDescriptor2.m_Inputs.size() == 1);
102 BOOST_TEST(queueDescriptor2.m_Outputs.size() == 1);
103 auto inputHandle2 = boost::polymorphic_downcast<IComputeTensorHandle*>(queueDescriptor2.m_Inputs[0]);
104 auto outputHandle2 = boost::polymorphic_downcast<CpuTensorHandle*>(queueDescriptor2.m_Outputs[0]);
105 BOOST_TEST(CompareTensorHandleShape<IComputeTensorHandle>(inputHandle2, {2, 3}));
106 BOOST_TEST((outputHandle2->GetTensorInfo() == TensorInfo({2, 3}, DataType::Float32)));
107}
108
Matthew Bentham89105282018-11-20 14:33:33 +0000109} //namespace