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 | #include <boost/test/unit_test.hpp> |
| 6 | #include <boost/multi_array.hpp> |
| 7 | |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 8 | #include <armnn/ArmNN.hpp> |
David Beck | b4540be | 2018-09-24 13:18:27 +0100 | [diff] [blame] | 9 | #include <backends/reference/RefWorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #if ARMCOMPUTECL_ENABLED |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 11 | #include <backends/ClWorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | #endif |
| 13 | #if ARMCOMPUTENEON_ENABLED |
David Beck | 0dbe0ee | 2018-09-24 15:59:27 +0100 | [diff] [blame] | 14 | #include <backends/neon/NeonWorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | #endif |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 16 | #include <backends/CpuTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | #include "test/TensorHelpers.hpp" |
| 18 | |
| 19 | #include "TensorCopyUtils.hpp" |
| 20 | #include "WorkloadTestUtils.hpp" |
| 21 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 22 | #if ARMCOMPUTECL_ENABLED || ARMCOMPUTENEON_ENABLED |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 23 | #include <backends/aclCommon/ArmComputeTensorUtils.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | #endif |
| 25 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 26 | BOOST_AUTO_TEST_SUITE(MemCopyTestSuite) |
| 27 | |
| 28 | void MemCopyTest(armnn::IWorkloadFactory& srcWorkloadFactory, armnn::IWorkloadFactory& dstWorkloadFactory, |
| 29 | bool withSubtensors) |
| 30 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 31 | const std::array<unsigned int, 4> shapeData = { { 1u, 1u, 6u, 5u } }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | const armnn::TensorShape tensorShape(4, shapeData.data()); |
| 33 | const armnn::TensorInfo tensorInfo(tensorShape, armnn::DataType::Float32); |
| 34 | boost::multi_array<float, 4> inputData = MakeTensor<float, 4>(tensorInfo, std::vector<float>( |
| 35 | { |
| 36 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, |
| 37 | |
| 38 | 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
| 39 | |
| 40 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, |
| 41 | |
| 42 | 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
| 43 | |
| 44 | 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, |
| 45 | |
| 46 | 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, |
| 47 | }) |
| 48 | ); |
| 49 | |
| 50 | boost::multi_array<float, 4> outputData(shapeData); |
| 51 | |
| 52 | auto inputTensorHandle = srcWorkloadFactory.CreateTensorHandle(tensorInfo); |
| 53 | auto outputTensorHandle = dstWorkloadFactory.CreateTensorHandle(tensorInfo); |
| 54 | |
| 55 | AllocateAndCopyDataToITensorHandle(inputTensorHandle.get(), inputData.data()); |
| 56 | outputTensorHandle->Allocate(); |
| 57 | |
| 58 | armnn::MemCopyQueueDescriptor memCopyQueueDesc; |
| 59 | armnn::WorkloadInfo workloadInfo; |
| 60 | |
| 61 | const unsigned int origin[4] = {}; |
| 62 | |
| 63 | auto workloadInput = (withSubtensors && srcWorkloadFactory.SupportsSubTensors()) |
| 64 | ? srcWorkloadFactory.CreateSubTensorHandle(*inputTensorHandle, tensorShape, origin) |
| 65 | : std::move(inputTensorHandle); |
| 66 | auto workloadOutput = (withSubtensors && dstWorkloadFactory.SupportsSubTensors()) |
| 67 | ? dstWorkloadFactory.CreateSubTensorHandle(*outputTensorHandle, tensorShape, origin) |
| 68 | : std::move(outputTensorHandle); |
| 69 | |
| 70 | AddInputToWorkload(memCopyQueueDesc, workloadInfo, tensorInfo, workloadInput.get()); |
| 71 | AddOutputToWorkload(memCopyQueueDesc, workloadInfo, tensorInfo, workloadOutput.get()); |
| 72 | |
| 73 | dstWorkloadFactory.CreateMemCopy(memCopyQueueDesc, workloadInfo)->Execute(); |
| 74 | |
| 75 | CopyDataFromITensorHandle(outputData.data(), workloadOutput.get()); |
| 76 | |
| 77 | BOOST_TEST(CompareTensors(inputData, outputData)); |
| 78 | } |
| 79 | |
| 80 | template <typename SrcWorkloadFactory, typename DstWorkloadFactory> |
| 81 | void MemCopyTest(bool withSubtensors) |
| 82 | { |
| 83 | SrcWorkloadFactory srcWorkloadFactory; |
| 84 | DstWorkloadFactory dstWorkloadFactory; |
| 85 | MemCopyTest(srcWorkloadFactory, dstWorkloadFactory, withSubtensors); |
| 86 | } |
| 87 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 88 | #if ARMCOMPUTECL_ENABLED || ARMCOMPUTENEON_ENABLED |
| 89 | |
| 90 | BOOST_AUTO_TEST_CASE(AclTypeConversions) |
| 91 | { |
| 92 | arm_compute::Strides strides(1,2,3,4); |
| 93 | armnn::TensorShape convertedStrides = armnn::armcomputetensorutils::GetStrides(strides); |
| 94 | BOOST_TEST(convertedStrides[0] == 4); |
| 95 | BOOST_TEST(convertedStrides[1] == 3); |
| 96 | BOOST_TEST(convertedStrides[2] == 2); |
| 97 | BOOST_TEST(convertedStrides[3] == 1); |
| 98 | |
| 99 | arm_compute::TensorShape shape(5,6,7,8); |
| 100 | armnn::TensorShape convertedshape = armnn::armcomputetensorutils::GetShape(shape); |
| 101 | BOOST_TEST(convertedshape[0] == 8); |
| 102 | BOOST_TEST(convertedshape[1] == 7); |
| 103 | BOOST_TEST(convertedshape[2] == 6); |
| 104 | BOOST_TEST(convertedshape[3] == 5); |
| 105 | } |
| 106 | #endif |
| 107 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 108 | #if ARMCOMPUTECL_ENABLED |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(CopyBetweenCpuAndGpu) |
| 111 | { |
| 112 | MemCopyTest<armnn::RefWorkloadFactory, armnn::ClWorkloadFactory>(false); |
| 113 | } |
| 114 | |
| 115 | BOOST_AUTO_TEST_CASE(CopyBetweenGpuAndCpu) |
| 116 | { |
| 117 | MemCopyTest<armnn::ClWorkloadFactory, armnn::RefWorkloadFactory>(false); |
| 118 | } |
| 119 | |
| 120 | BOOST_AUTO_TEST_CASE(CopyBetweenCpuAndGpuWithSubtensors) |
| 121 | { |
| 122 | MemCopyTest<armnn::RefWorkloadFactory, armnn::ClWorkloadFactory>(true); |
| 123 | } |
| 124 | |
| 125 | BOOST_AUTO_TEST_CASE(CopyBetweenGpuAndCpuWithSubtensors) |
| 126 | { |
| 127 | MemCopyTest<armnn::ClWorkloadFactory, armnn::RefWorkloadFactory>(true); |
| 128 | } |
| 129 | |
| 130 | #endif // ARMCOMPUTECL_ENABLED |
| 131 | |
| 132 | #if ARMCOMPUTENEON_ENABLED |
| 133 | |
| 134 | BOOST_AUTO_TEST_CASE(CopyBetweenCpuAndNeon) |
| 135 | { |
| 136 | MemCopyTest<armnn::RefWorkloadFactory, armnn::NeonWorkloadFactory>(false); |
| 137 | } |
| 138 | |
| 139 | BOOST_AUTO_TEST_CASE(CopyBetweenNeonAndCpu) |
| 140 | { |
| 141 | MemCopyTest<armnn::NeonWorkloadFactory, armnn::RefWorkloadFactory>(false); |
| 142 | } |
| 143 | |
| 144 | BOOST_AUTO_TEST_CASE(CopyBetweenCpuAndNeonWithSubtensors) |
| 145 | { |
| 146 | MemCopyTest<armnn::RefWorkloadFactory, armnn::NeonWorkloadFactory>(true); |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(CopyBetweenNeonAndCpuWithSubtensors) |
| 150 | { |
| 151 | MemCopyTest<armnn::NeonWorkloadFactory, armnn::RefWorkloadFactory>(true); |
| 152 | } |
| 153 | |
| 154 | #endif // ARMCOMPUTENEON_ENABLED |
| 155 | |
| 156 | #if ARMCOMPUTECL_ENABLED && ARMCOMPUTENEON_ENABLED |
| 157 | |
| 158 | BOOST_AUTO_TEST_CASE(CopyBetweenNeonAndGpu) |
| 159 | { |
| 160 | MemCopyTest<armnn::NeonWorkloadFactory, armnn::ClWorkloadFactory>(false); |
| 161 | } |
| 162 | |
| 163 | BOOST_AUTO_TEST_CASE(CopyBetweenGpuAndNeon) |
| 164 | { |
| 165 | MemCopyTest<armnn::ClWorkloadFactory, armnn::NeonWorkloadFactory>(false); |
| 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_CASE(CopyBetweenNeonAndGpuWithSubtensors) |
| 169 | { |
| 170 | MemCopyTest<armnn::NeonWorkloadFactory, armnn::ClWorkloadFactory>(true); |
| 171 | } |
| 172 | |
| 173 | BOOST_AUTO_TEST_CASE(CopyBetweenGpuAndNeonWithSubtensors) |
| 174 | { |
| 175 | MemCopyTest<armnn::ClWorkloadFactory, armnn::NeonWorkloadFactory>(true); |
| 176 | } |
| 177 | |
| 178 | #endif |
| 179 | |
| 180 | BOOST_AUTO_TEST_SUITE_END() |