blob: ec2072d243c50d431a347c01ac1c670ec2a1e27f [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);
50 res.message() << "Different dimension [" << info->dimension(i) << "!=" << expectedDimension << "]";
51 return res;
52 }
53
54 i--;
55 }
56
57 return true;
58}
59
telsoa01c577f2c2018-08-31 09:22:23 +010060template<typename IComputeTensorHandle>
telsoa014fcda012018-03-09 14:13:49 +000061void CreateMemCopyWorkloads(IWorkloadFactory& factory)
62{
63 Graph graph;
64 RefWorkloadFactory refFactory;
65
telsoa01c577f2c2018-08-31 09:22:23 +010066 // Creates the layers we're testing.
telsoa014fcda012018-03-09 14:13:49 +000067 Layer* const layer1 = graph.AddLayer<MemCopyLayer>("layer1");
68 Layer* const layer2 = graph.AddLayer<MemCopyLayer>("layer2");
69
telsoa01c577f2c2018-08-31 09:22:23 +010070 // Creates extra layers.
telsoa014fcda012018-03-09 14:13:49 +000071 Layer* const input = graph.AddLayer<InputLayer>(0, "input");
72 Layer* const output = graph.AddLayer<OutputLayer>(0, "output");
73
telsoa01c577f2c2018-08-31 09:22:23 +010074 // Connects up.
telsoa014fcda012018-03-09 14:13:49 +000075 TensorInfo tensorInfo({2, 3}, DataType::Float32);
76 Connect(input, layer1, tensorInfo);
77 Connect(layer1, layer2, tensorInfo);
78 Connect(layer2, output, tensorInfo);
79
80 input->CreateTensorHandles(graph, refFactory);
81 layer1->CreateTensorHandles(graph, factory);
82 layer2->CreateTensorHandles(graph, refFactory);
83 output->CreateTensorHandles(graph, refFactory);
84
85 // make the workloads and check them
telsoa01c577f2c2018-08-31 09:22:23 +010086 auto workload1 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer1, graph, factory);
87 auto workload2 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer2, graph, refFactory);
telsoa014fcda012018-03-09 14:13:49 +000088
89 MemCopyQueueDescriptor queueDescriptor1 = workload1->GetData();
90 BOOST_TEST(queueDescriptor1.m_Inputs.size() == 1);
91 BOOST_TEST(queueDescriptor1.m_Outputs.size() == 1);
92 auto inputHandle1 = boost::polymorphic_downcast<ConstCpuTensorHandle*>(queueDescriptor1.m_Inputs[0]);
93 auto outputHandle1 = boost::polymorphic_downcast<IComputeTensorHandle*>(queueDescriptor1.m_Outputs[0]);
94 BOOST_TEST((inputHandle1->GetTensorInfo() == TensorInfo({2, 3}, DataType::Float32)));
95 BOOST_TEST(CompareTensorHandleShape<IComputeTensorHandle>(outputHandle1, {2, 3}));
96
97
98 MemCopyQueueDescriptor queueDescriptor2 = workload2->GetData();
99 BOOST_TEST(queueDescriptor2.m_Inputs.size() == 1);
100 BOOST_TEST(queueDescriptor2.m_Outputs.size() == 1);
101 auto inputHandle2 = boost::polymorphic_downcast<IComputeTensorHandle*>(queueDescriptor2.m_Inputs[0]);
102 auto outputHandle2 = boost::polymorphic_downcast<CpuTensorHandle*>(queueDescriptor2.m_Outputs[0]);
103 BOOST_TEST(CompareTensorHandleShape<IComputeTensorHandle>(inputHandle2, {2, 3}));
104 BOOST_TEST((outputHandle2->GetTensorInfo() == TensorInfo({2, 3}, DataType::Float32)));
105}
106
telsoa01c577f2c2018-08-31 09:22:23 +0100107} //namespace