| 53 | } |
| 54 | |
| 55 | auto CreateTensor::parse(Span<ValueRef> inputs) const -> Args { |
| 56 | Args result; |
| 57 | for (auto&& input : inputs) { |
| 58 | if (auto host_storage = input.as_ref<HostStorage>()) { |
| 59 | mgb_assert(!result.host, "duplicated host value"); |
| 60 | result.host.emplace(); |
| 61 | result.host->reset(*host_storage, {shape().as_tensor_shape(), dtype()}); |
| 62 | mgb_assert(result.host->layout().ndim, "invalid shape"); |
| 63 | } else if (auto device_storage = input.as_ref<DeviceStorage>()) { |
| 64 | mgb_assert(!result.device, "duplicated device value"); |
| 65 | result.device.emplace(device(), shape().as_tensor_shape(), dtype()); |
| 66 | result.device->reset(*device_storage, {shape().as_tensor_shape(), dtype()}); |
| 67 | mgb_assert(result.device->layout().ndim, "invalid shape"); |
| 68 | } else { |
| 69 | mgb_throw( |
| 70 | MegBrainError, |
| 71 | "unknown input type, expects HostStorage or DeviceStorage, got " |
| 72 | "%s", |
| 73 | input.to_string().c_str()); |
| 74 | } |
| 75 | } |
| 76 | mgb_assert( |
| 77 | result.host || result.device, "require at least one of host/device value"); |
| 78 | result.kind = kind(); |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | std::string CreateTensor::to_string() const { |
| 83 | return ssprintf( |
no test coverage detected