| 195 | |
| 196 | template <typename ctype> |
| 197 | auto 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 | |
| 213 | struct HostTensorArgs { |
| 214 | ValueShape shape; |
nothing calls this directly
no test coverage detected