| 197 | } |
| 198 | |
| 199 | TensorValue ensure_backend_addressable_layout(ModuleBuildContext & ctx, const TensorValue & value) { |
| 200 | if (!value.valid()) { |
| 201 | throw std::runtime_error("Cannot materialize an invalid tensor"); |
| 202 | } |
| 203 | if (ctx.ggml == nullptr) { |
| 204 | throw std::runtime_error("ModuleBuildContext.ggml is null"); |
| 205 | } |
| 206 | if (has_backend_addressable_layout(value.tensor)) { |
| 207 | return value; |
| 208 | } |
| 209 | return wrap_tensor(ggml_cont(ctx.ggml, value.tensor), value.shape, value.type); |
| 210 | } |
| 211 | |
| 212 | void validate_shape(const TensorValue & value, const TensorShape & expected, const char * name) { |
| 213 | if (!value.valid()) { |
no test coverage detected