telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame^] | 7 | #include <test/CreateWorkload.hpp> |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 8 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame^] | 9 | #include <backendsCommon/MemCopyWorkload.hpp> |
| 10 | #include <reference/RefWorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | |
| 12 | #if ARMCOMPUTECL_ENABLED |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame^] | 13 | #include <cl/ClTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | #endif |
| 15 | |
| 16 | #if ARMCOMPUTENEON_ENABLED |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame^] | 17 | #include <neon/NeonTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | #endif |
| 19 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | using namespace armnn; |
| 21 | |
| 22 | namespace |
| 23 | { |
| 24 | |
| 25 | using namespace std; |
| 26 | |
| 27 | template<typename IComputeTensorHandle> |
| 28 | boost::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 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 60 | template<typename IComputeTensorHandle> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 61 | void CreateMemCopyWorkloads(IWorkloadFactory& factory) |
| 62 | { |
| 63 | Graph graph; |
| 64 | RefWorkloadFactory refFactory; |
| 65 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 66 | // Creates the layers we're testing. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 67 | Layer* const layer1 = graph.AddLayer<MemCopyLayer>("layer1"); |
| 68 | Layer* const layer2 = graph.AddLayer<MemCopyLayer>("layer2"); |
| 69 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 70 | // Creates extra layers. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 71 | Layer* const input = graph.AddLayer<InputLayer>(0, "input"); |
| 72 | Layer* const output = graph.AddLayer<OutputLayer>(0, "output"); |
| 73 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 74 | // Connects up. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | 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 |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 86 | auto workload1 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer1, graph, factory); |
| 87 | auto workload2 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer2, graph, refFactory); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 88 | |
| 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 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 107 | } //namespace |