| 161 | |
| 162 | namespace { |
| 163 | void test_basic_input_no_copy(bool record) { |
| 164 | auto test_graph = TestGraph(); |
| 165 | auto compute_graph = test_graph.m_network->graph; |
| 166 | compute_graph->options().comp_node_seq_record_level = record; |
| 167 | test_graph.create_graph(); |
| 168 | HostTensorND out, out_pre; |
| 169 | auto func = test_graph.compile_with_copy(out); |
| 170 | size_t times = 10; |
| 171 | for (size_t i = 0; i < times; i++) { |
| 172 | if (i % 2 == 0) { |
| 173 | auto input_tensor = test_graph.input_tensor; |
| 174 | auto layout = input_tensor->layout(); |
| 175 | size_t length = layout.total_nr_elems(); |
| 176 | auto storage = TensorStorage<HostTensorStorageTrait>(test_graph.m_cn); |
| 177 | storage.ensure_size(length * sizeof(float)); |
| 178 | float* ptr = storage.ptr()->as<float>(); |
| 179 | for (size_t d = 0; d < length; d++) { |
| 180 | ptr[d] = i; |
| 181 | } |
| 182 | if (record) { |
| 183 | input_tensor->only_reset_raw_storage(storage); |
| 184 | } else { |
| 185 | input_tensor->reset(storage, layout); |
| 186 | } |
| 187 | } |
| 188 | func->execute(); |
| 189 | func->wait(); |
| 190 | if (i % 2 != 0) { |
| 191 | MGB_ASSERT_TENSOR_EQ(out, out_pre); |
| 192 | } |
| 193 | out_pre.copy_from(out).sync(); |
| 194 | } |
| 195 | } |
| 196 | } // namespace |
| 197 | |
| 198 | TEST(TestNoCopy, InputNoCopyPtrEQ) { |
no test coverage detected