MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / vec2storage

Function vec2storage

imperative/python/src/tensor.cpp:197–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196template <typename ctype>
197auto vec2storage(Span<DTypeScalar> vec, CompNode cn, DType dtype) {
198 mgb_assert(vec.size() <= MEGDNN_MAX_NDIM);
199 // TODO: use storage cache and modify ConstTensorCache to return (Host, Device)
200 auto* raw_ptr = new ctype[MEGDNN_MAX_NDIM];
201 for (size_t i = 0; i < vec.size(); ++i) {
202 raw_ptr[i] = vec[i].get_cast<ctype>();
203 }
204 mgb_assert(sizeof(ctype) == dtype.size());
205 std::shared_ptr<dt_byte> raw_storage = {
206 reinterpret_cast<dt_byte*>(raw_ptr),
207 [](dt_byte* ptr) { delete[] reinterpret_cast<ctype*>(ptr); }};
208 HostTensorStorage storage(cn);
209 storage.only_reset_raw_storage(cn, sizeof(ctype) * vec.size(), raw_storage, 0);
210 return HostStorage::make(std::move(storage));
211}
212
213struct HostTensorArgs {
214 ValueShape shape;

Callers

nothing calls this directly

Calls 3

makeFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected