| 197 | // Utilities to easily handle tensor instances in test cases. |
| 198 | |
| 199 | ft::Tensor createTensor(const ft::MemoryType mtype, |
| 200 | const ft::DataType dtype, |
| 201 | const std::vector<size_t> shape) |
| 202 | { |
| 203 | size_t n_elmts = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<size_t>()); |
| 204 | size_t buf_size = ft::Tensor::getTypeSize(dtype) * n_elmts; |
| 205 | |
| 206 | void* data = nullptr; |
| 207 | if (mtype == ft::MEMORY_CPU || mtype == ft::MEMORY_CPU_PINNED) { |
| 208 | data = malloc(buf_size); |
| 209 | allocated_cpu_buffers.push_back(data); |
| 210 | } |
| 211 | else { |
| 212 | data = allocator->malloc(buf_size); |
| 213 | } |
| 214 | return ft::Tensor(mtype, dtype, shape, data); |
| 215 | }; |
| 216 | |
| 217 | template<typename T> |
| 218 | ft::Tensor toHost(ft::Tensor& device_tensor) |