ggml: allow reserving scratch memory in graph_optimize (#31898)
* ggml: allow reserving scratch memory in graph_optimize
Add add_scratch to ggml_backend_graph_optimize_params. A backend can
reserve compute buffer memory that is allocated before a node `first`
and kept until a node `last` has been computed, e.g. for data that
several nodes share. The scheduler adds the scratch tensor to the graph
copy right before `first` and frees it with an alloc dep at `last`.
* ggml: clarify the lifetime of add_scratch memory
* ggml: build the pending scratch set from the scratch map