mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 1 | // |
Tracy Narine | bc5a5d5 | 2024-02-06 15:22:41 +0000 | [diff] [blame] | 2 | // Copyright © 2021, 2024 Arm Ltd and Contributors. All rights reserved. |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Tracy Narine | bc5a5d5 | 2024-02-06 15:22:41 +0000 | [diff] [blame] | 8 | #include <backendsCommon/test/EndToEndTestImpl.hpp> |
| 9 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 10 | #include <armnnTestUtils/LayerTestResult.hpp> |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 11 | |
| 12 | #include <ResolveType.hpp> |
| 13 | |
| 14 | #include <armnn/backends/IBackendInternal.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 15 | #include <armnn/backends/WorkloadFactory.hpp> |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 16 | #include <Half.hpp> |
| 17 | |
| 18 | template<armnn::DataType inputDataType, armnn::DataType outputDataType, |
| 19 | typename TInput=armnn::ResolveType<inputDataType>, |
| 20 | typename TOutput=armnn::ResolveType<outputDataType>> |
| 21 | LayerTestResult<TOutput, 4> CastTest(armnn::IWorkloadFactory& workloadFactory, |
| 22 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 23 | const armnn::ITensorHandleFactory& tensorHandleFactory, |
| 24 | const std::vector<TInput>& inputTensor, |
| 25 | const std::vector<TOutput>& outputTensor); |
| 26 | |
| 27 | |
| 28 | LayerTestResult<float, 4> CastInt32ToFloat2dTest( |
| 29 | armnn::IWorkloadFactory& workloadFactory, |
| 30 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 31 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 32 | |
| 33 | LayerTestResult<float, 4> CastInt16ToFloat2dTest( |
| 34 | armnn::IWorkloadFactory& workloadFactory, |
| 35 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 36 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 37 | |
| 38 | LayerTestResult<float, 4> CastInt8ToFloat2dTest( |
| 39 | armnn::IWorkloadFactory& workloadFactory, |
| 40 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 41 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 42 | |
| 43 | LayerTestResult<float, 4> CastInt8AsymmToFloat2dTest( |
| 44 | armnn::IWorkloadFactory& workloadFactory, |
| 45 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 46 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 47 | |
| 48 | LayerTestResult<float, 4> CastUInt8ToFloat2dTest( |
| 49 | armnn::IWorkloadFactory& workloadFactory, |
| 50 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 51 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 52 | |
| 53 | LayerTestResult<uint8_t, 4> CastInt8ToUInt82dTest( |
| 54 | armnn::IWorkloadFactory& workloadFactory, |
| 55 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 56 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 57 | |
| 58 | LayerTestResult<uint8_t, 4> CastInt8AsymmToUInt82dTest( |
| 59 | armnn::IWorkloadFactory& workloadFactory, |
| 60 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 61 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 62 | |
| 63 | LayerTestResult<float, 4> CastFloat16ToFloat322dTest( |
| 64 | armnn::IWorkloadFactory& workloadFactory, |
| 65 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 66 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 67 | |
| 68 | LayerTestResult<float, 4> CastBFloat16ToFloat322dTest( |
| 69 | armnn::IWorkloadFactory& workloadFactory, |
| 70 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 71 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 72 | |
| 73 | LayerTestResult<armnn::Half, 4> CastFloat32ToFloat162dTest( |
| 74 | armnn::IWorkloadFactory& workloadFactory, |
| 75 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 76 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 77 | |
| 78 | LayerTestResult<int8_t , 4> CastFloat32ToInt82dTest( |
| 79 | armnn::IWorkloadFactory& workloadFactory, |
| 80 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 81 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
| 82 | |
| 83 | LayerTestResult<uint8_t , 4> CastFloat32ToUInt82dTest( |
| 84 | armnn::IWorkloadFactory& workloadFactory, |
| 85 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 86 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
Tracy Narine | bc5a5d5 | 2024-02-06 15:22:41 +0000 | [diff] [blame] | 87 | |
| 88 | template<armnn::DataType inputDataType, armnn::DataType outputDataType, typename TInput, typename TOutput> |
| 89 | void CastSimpleTest(const std::vector<armnn::BackendId>& backends, |
| 90 | const std::vector<unsigned int>& shape, |
| 91 | const std::vector<TInput>& inputValues, |
| 92 | const std::vector<TOutput>& outputValues, |
| 93 | float qScale = 1.0f, |
| 94 | int32_t qOffset = 0) |
| 95 | { |
| 96 | using namespace armnn; |
| 97 | |
| 98 | const TensorShape inputShape(static_cast<unsigned int>(shape.size()), shape.data()); |
| 99 | const TensorShape outputShape(static_cast<unsigned int>(shape.size()), shape.data()); |
| 100 | |
| 101 | TensorInfo inputTensorInfo(inputShape, inputDataType, qScale, qOffset, true); |
| 102 | TensorInfo outputTensorInfo(outputShape, outputDataType, qScale, qOffset); |
| 103 | |
| 104 | IRuntime::CreationOptions options; |
| 105 | IRuntimePtr runtime(IRuntime::Create(options)); |
| 106 | INetworkPtr network(INetwork::Create()); |
| 107 | |
| 108 | IConnectableLayer* input = network->AddInputLayer(0, "input"); |
| 109 | IConnectableLayer* castLayer = network->AddCastLayer("cast"); |
| 110 | IConnectableLayer* output = network->AddOutputLayer(0, "output"); |
| 111 | |
| 112 | Connect(input, castLayer, inputTensorInfo, 0, 0); |
| 113 | Connect(castLayer, output, outputTensorInfo, 0, 0); |
| 114 | |
| 115 | std::map<int, std::vector<TInput>> inputTensorData = {{ 0, inputValues }}; |
| 116 | std::map<int, std::vector<TOutput>> expectedOutputData = {{ 0, outputValues }}; |
| 117 | |
| 118 | EndToEndLayerTestImpl<inputDataType, outputDataType>(std::move(network), |
| 119 | inputTensorData, |
| 120 | expectedOutputData, |
| 121 | backends); |
| 122 | } |