| 120 | * - Both runs compute the same output |
| 121 | */ |
| 122 | TEST_CASE(MemoryInjection, framework::DatasetMode::ALL) |
| 123 | { |
| 124 | auto fc = std::make_unique<cpu::CpuFullyConnected>(); |
| 125 | const auto src_info = TensorInfo(TensorShape(8U), 1, DataType::F32, DataLayout::NHWC); |
| 126 | const auto weight_info = TensorInfo(TensorShape(8U, 4U), 1, DataType::F32, DataLayout::NHWC); |
| 127 | const auto bias_info = TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC); |
| 128 | auto dst_info = TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC); |
| 129 | const auto fc_info = FullyConnectedLayerInfo{}; |
| 130 | fc->configure(&src_info, &weight_info, &bias_info, &dst_info, fc_info); |
| 131 | |
| 132 | // telhs are newly created every call of this lambda function |
| 133 | auto src = create_tensor<Tensor>(src_info); |
| 134 | auto weight = create_tensor<Tensor>(weight_info); |
| 135 | auto bias = create_tensor<Tensor>(bias_info); |
| 136 | src.allocator()->allocate(); |
| 137 | weight.allocator()->allocate(); |
| 138 | bias.allocator()->allocate(); |
| 139 | |
| 140 | ITensorPack run_pack{ |
| 141 | {TensorType::ACL_SRC_0, &src}, {TensorType::ACL_SRC_1, &weight}, {TensorType::ACL_SRC_2, &bias}}; |
| 142 | ITensorPack prep_pack{{TensorType::ACL_SRC_1, &weight}, {TensorType::ACL_SRC_2, &bias}}; |
| 143 | |
| 144 | auto mg = MemoryGroup{}; |
| 145 | auto ws = manage_workspace<Tensor>(fc->workspace(), mg, run_pack, prep_pack); |
| 146 | |
| 147 | auto run_conv = [&]() -> Tensor |
| 148 | { |
| 149 | auto dst = create_tensor<Tensor>(dst_info); |
| 150 | dst.allocator()->allocate(); |
| 151 | run_pack.add_tensor(TensorType::ACL_DST, &dst); |
| 152 | |
| 153 | library->fill_tensor_value(Accessor(src), 1.f); |
| 154 | library->fill_tensor_value(Accessor(weight), 2.f); |
| 155 | library->fill_tensor_value(Accessor(bias), 3.f); |
| 156 | // This operator is configured once and captured by this lambda. |
| 157 | fc->prepare(prep_pack); |
| 158 | fc->run(run_pack); |
| 159 | return dst; |
| 160 | }; |
| 161 | auto result_0 = run_conv(); |
| 162 | auto result_1 = run_conv(); |
| 163 | for (size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 164 | { |
| 165 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], |
| 166 | framework::LogLevel::ERRORS); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** Test case for memory injection in @ref NEFullyConnectedLayer. |
| 171 | * |
nothing calls this directly
no test coverage detected