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); |
Matthew Bentham | 8910528 | 2018-11-20 14:33:33 +0000 | [diff] [blame] | 50 | res.message() << "For dimension " << i << |
| 51 | " expected size " << expectedDimension << |
| 52 | " got " << info->dimension(i); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | return res; |
| 54 | } |
| 55 | |
| 56 | i--; |
| 57 | } |
| 58 | |
| 59 | return true; |
| 60 | } |
| 61 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | template<typename IComputeTensorHandle> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 63 | void CreateMemCopyWorkloads(IWorkloadFactory& factory) |
| 64 | { |
| 65 | Graph graph; |
| 66 | RefWorkloadFactory refFactory; |
| 67 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 68 | // Creates the layers we're testing. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | Layer* const layer1 = graph.AddLayer<MemCopyLayer>("layer1"); |
| 70 | Layer* const layer2 = graph.AddLayer<MemCopyLayer>("layer2"); |
| 71 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 72 | // Creates extra layers. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 73 | Layer* const input = graph.AddLayer<InputLayer>(0, "input"); |
| 74 | Layer* const output = graph.AddLayer<OutputLayer>(0, "output"); |
| 75 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 76 | // Connects up. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 77 | 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 |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 88 | auto workload1 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer1, graph, factory); |
| 89 | auto workload2 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer2, graph, refFactory); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 90 | |
| 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 Bentham | 8910528 | 2018-11-20 14:33:33 +0000 | [diff] [blame] | 109 | } //namespace |