| 2039 | } |
| 2040 | |
| 2041 | static void graph_copy_init_tensor(struct ggml_hash_set * hash_set, struct ggml_tensor ** node_copies, bool * node_init, struct ggml_tensor * src) { |
| 2042 | size_t id = ggml_hash_find(hash_set, src); |
| 2043 | if (node_init[id]) { |
| 2044 | return; |
| 2045 | } |
| 2046 | node_init[id] = true; |
| 2047 | |
| 2048 | struct ggml_tensor * dst = node_copies[id]; |
| 2049 | if (dst->view_src != NULL) { |
| 2050 | graph_copy_init_tensor(hash_set, node_copies, node_init, src->view_src); |
| 2051 | enum ggml_status status = ggml_backend_view_init(dst); |
| 2052 | GGML_ASSERT(status == GGML_STATUS_SUCCESS); |
| 2053 | } |
| 2054 | else { |
| 2055 | ggml_backend_tensor_copy(src, dst); |
| 2056 | } |
| 2057 | |
| 2058 | // init src |
| 2059 | for (int i = 0; i < GGML_MAX_SRC; i++) { |
| 2060 | struct ggml_tensor * s = src->src[i]; |
| 2061 | if (s == NULL) { |
| 2062 | continue; |
| 2063 | } |
| 2064 | graph_copy_init_tensor(hash_set, node_copies, node_init, s); |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | struct ggml_backend_graph_copy ggml_backend_graph_copy(ggml_backend_t backend, struct ggml_cgraph * graph) { |
| 2069 | GGML_ASSERT(graph); |
no test coverage detected