| 222 | } |
| 223 | |
| 224 | TensorShape ptr2shape(const int64_t* ptr, size_t ndim) { |
| 225 | TensorShape shape; |
| 226 | mgb_assert( |
| 227 | ndim <= TensorShape::MAX_NDIM, "dim too large: %zd (max %zd)", ndim, |
| 228 | TensorShape::MAX_NDIM); |
| 229 | shape.ndim = ndim; |
| 230 | for (size_t i = 0; i < ndim; i++) { |
| 231 | if (ptr[i] < 0 || ptr[i] > std::numeric_limits<size_t>::max()) { |
| 232 | std::string error_msg = ""; |
| 233 | for (size_t idx = 0; idx < ndim; idx++) { |
| 234 | auto shape_i = " " + std::to_string(ptr[i]); |
| 235 | error_msg += shape_i; |
| 236 | } |
| 237 | mgb_throw( |
| 238 | MegBrainError, "unsupported dlpack input shape: %s", |
| 239 | error_msg.c_str()); |
| 240 | } |
| 241 | shape[i] = ptr[i]; |
| 242 | } |
| 243 | return shape; |
| 244 | } |
| 245 | |
| 246 | ValueRef mgb::imperative::from_dlpack(DLManagedTensor* dlMTensor, int stream = 0) { |
| 247 | std::function<void(void*)> deleter_dispatch = [dlMTensor](void*) { |
no test coverage detected