| 210 | } |
| 211 | if (has_backend_addressable_layout(value.tensor)) { |
| 212 | return value; |
| 213 | } |
| 214 | return wrap_tensor(ggml_cont(ctx.ggml, value.tensor), value.shape, value.type); |
| 215 | } |
| 216 | |
| 217 | void validate_shape(const TensorValue & value, const TensorShape & expected, const char * name) { |
| 218 | if (!value.valid()) { |
| 219 | throw std::runtime_error(name_or_default(name) + " is invalid"); |
| 220 | } |
| 221 | if (value.shape.rank != expected.rank) { |
| 222 | throw std::runtime_error(name_or_default(name) + " rank mismatch: expected " + expected.to_string() + |
| 223 | ", got " + value.shape.to_string()); |
| 224 | } |
| 225 | for (size_t i = 0; i < expected.rank; ++i) { |
| 226 | if (value.shape.dims[i] != expected.dims[i]) { |
| 227 | throw std::runtime_error(name_or_default(name) + " shape mismatch: expected " + expected.to_string() + |
| 228 | ", got " + value.shape.to_string()); |
| 229 | } |
no test coverage detected