MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / createTensor

Method createTensor

tests/unittests/gtest_utils.h:199–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 4

TensorClass · 0.50
beginMethod · 0.45
endMethod · 0.45
mallocMethod · 0.45

Tested by

no test coverage detected