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 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 7 | #include <CreateWorkload.hpp> |
| 8 | #include <armnnTestUtils/PredicateResult.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 9 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 10 | #include <armnn/backends/MemCopyWorkload.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 11 | #include <reference/RefWorkloadFactory.hpp> |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 12 | #include <reference/RefTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 14 | #if defined(ARMCOMPUTECL_ENABLED) |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 15 | #include <cl/ClTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 16 | #endif |
| 17 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 18 | #if defined(ARMCOMPUTENEON_ENABLED) |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 19 | #include <neon/NeonTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | #endif |
| 21 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 22 | #include <doctest/doctest.h> |
| 23 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | using namespace armnn; |
| 25 | |
| 26 | namespace |
| 27 | { |
| 28 | |
| 29 | using namespace std; |
| 30 | |
| 31 | template<typename IComputeTensorHandle> |
Colm Donelan | 25ab3a8 | 2021-05-17 13:01:52 +0100 | [diff] [blame] | 32 | PredicateResult CompareTensorHandleShape(IComputeTensorHandle* tensorHandle, |
| 33 | std::initializer_list<unsigned int> expectedDimensions) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 34 | { |
| 35 | arm_compute::ITensorInfo* info = tensorHandle->GetTensor().info(); |
| 36 | |
| 37 | auto infoNumDims = info->num_dimensions(); |
| 38 | auto numExpectedDims = expectedDimensions.size(); |
| 39 | if (infoNumDims != numExpectedDims) |
| 40 | { |
Colm Donelan | 25ab3a8 | 2021-05-17 13:01:52 +0100 | [diff] [blame] | 41 | PredicateResult res(false); |
| 42 | res.Message() << "Different number of dimensions [" << info->num_dimensions() |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 43 | << "!=" << expectedDimensions.size() << "]"; |
| 44 | return res; |
| 45 | } |
| 46 | |
| 47 | size_t i = info->num_dimensions() - 1; |
| 48 | |
| 49 | for (unsigned int expectedDimension : expectedDimensions) |
| 50 | { |
| 51 | if (info->dimension(i) != expectedDimension) |
| 52 | { |
Colm Donelan | 25ab3a8 | 2021-05-17 13:01:52 +0100 | [diff] [blame] | 53 | PredicateResult res(false); |
| 54 | res.Message() << "For dimension " << i << |
Matthew Bentham | 8910528 | 2018-11-20 14:33:33 +0000 | [diff] [blame] | 55 | " expected size " << expectedDimension << |
| 56 | " got " << info->dimension(i); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 57 | return res; |
| 58 | } |
| 59 | |
| 60 | i--; |
| 61 | } |
| 62 | |
Colm Donelan | 25ab3a8 | 2021-05-17 13:01:52 +0100 | [diff] [blame] | 63 | return PredicateResult(true); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 64 | } |
| 65 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 66 | template<typename IComputeTensorHandle> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 67 | void CreateMemCopyWorkloads(IWorkloadFactory& factory) |
| 68 | { |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 69 | TensorHandleFactoryRegistry registry; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 70 | Graph graph; |
| 71 | RefWorkloadFactory refFactory; |
| 72 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 73 | // Creates the layers we're testing. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | Layer* const layer1 = graph.AddLayer<MemCopyLayer>("layer1"); |
| 75 | Layer* const layer2 = graph.AddLayer<MemCopyLayer>("layer2"); |
| 76 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 77 | // Creates extra layers. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 78 | Layer* const input = graph.AddLayer<InputLayer>(0, "input"); |
| 79 | Layer* const output = graph.AddLayer<OutputLayer>(0, "output"); |
| 80 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 81 | // Connects up. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | TensorInfo tensorInfo({2, 3}, DataType::Float32); |
| 83 | Connect(input, layer1, tensorInfo); |
| 84 | Connect(layer1, layer2, tensorInfo); |
| 85 | Connect(layer2, output, tensorInfo); |
| 86 | |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 87 | input->CreateTensorHandles(registry, refFactory); |
| 88 | layer1->CreateTensorHandles(registry, factory); |
| 89 | layer2->CreateTensorHandles(registry, refFactory); |
| 90 | output->CreateTensorHandles(registry, refFactory); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | |
| 92 | // make the workloads and check them |
Derek Lamberti | 94a88d2 | 2019-12-10 21:12:59 +0000 | [diff] [blame] | 93 | auto workload1 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer1, factory); |
| 94 | auto workload2 = MakeAndCheckWorkload<CopyMemGenericWorkload>(*layer2, refFactory); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 95 | |
| 96 | MemCopyQueueDescriptor queueDescriptor1 = workload1->GetData(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 97 | CHECK(queueDescriptor1.m_Inputs.size() == 1); |
| 98 | CHECK(queueDescriptor1.m_Outputs.size() == 1); |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 99 | auto inputHandle1 = PolymorphicDowncast<RefTensorHandle*>(queueDescriptor1.m_Inputs[0]); |
| 100 | auto outputHandle1 = PolymorphicDowncast<IComputeTensorHandle*>(queueDescriptor1.m_Outputs[0]); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 101 | CHECK((inputHandle1->GetTensorInfo() == TensorInfo({2, 3}, DataType::Float32))); |
Colm Donelan | 25ab3a8 | 2021-05-17 13:01:52 +0100 | [diff] [blame] | 102 | auto result = CompareTensorHandleShape<IComputeTensorHandle>(outputHandle1, {2, 3}); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 103 | CHECK_MESSAGE(result.m_Result, result.m_Message.str()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 104 | |
| 105 | |
| 106 | MemCopyQueueDescriptor queueDescriptor2 = workload2->GetData(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 107 | CHECK(queueDescriptor2.m_Inputs.size() == 1); |
| 108 | CHECK(queueDescriptor2.m_Outputs.size() == 1); |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 109 | auto inputHandle2 = PolymorphicDowncast<IComputeTensorHandle*>(queueDescriptor2.m_Inputs[0]); |
| 110 | auto outputHandle2 = PolymorphicDowncast<RefTensorHandle*>(queueDescriptor2.m_Outputs[0]); |
Colm Donelan | 25ab3a8 | 2021-05-17 13:01:52 +0100 | [diff] [blame] | 111 | result = CompareTensorHandleShape<IComputeTensorHandle>(inputHandle2, {2, 3}); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 112 | CHECK_MESSAGE(result.m_Result, result.m_Message.str()); |
| 113 | CHECK((outputHandle2->GetTensorInfo() == TensorInfo({2, 3}, DataType::Float32))); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Matthew Bentham | 8910528 | 2018-11-20 14:33:33 +0000 | [diff] [blame] | 116 | } //namespace |