| 6938 | } |
| 6939 | |
| 6940 | static size_t ggml_graph_nbytes(size_t size, bool grads) { |
| 6941 | size_t hash_size = ggml_hash_size(size * 2); |
| 6942 | void * p = 0; |
| 6943 | incr_ptr_aligned(&p, sizeof(struct ggml_cgraph), 1); |
| 6944 | incr_ptr_aligned(&p, size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)); // nodes |
| 6945 | incr_ptr_aligned(&p, size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)); // leafs |
| 6946 | incr_ptr_aligned(&p, hash_size * sizeof(int32_t), sizeof(int32_t)); // use_counts |
| 6947 | incr_ptr_aligned(&p, hash_size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)); // hash keys |
| 6948 | if (grads) { |
| 6949 | incr_ptr_aligned(&p, hash_size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)); // grads |
| 6950 | incr_ptr_aligned(&p, hash_size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)); // grad_accs |
| 6951 | } |
| 6952 | incr_ptr_aligned(&p, ggml_bitset_size(hash_size) * sizeof(ggml_bitset_t), sizeof(ggml_bitset_t)); |
| 6953 | |
| 6954 | size_t nbytes = (size_t) p; |
| 6955 | return nbytes; |
| 6956 | } |
| 6957 | |
| 6958 | size_t ggml_graph_overhead_custom(size_t size, bool grads) { |
| 6959 | return GGML_OBJECT_SIZE + GGML_PAD(ggml_graph_nbytes(size, grads), GGML_MEM_ALIGN); |
no test coverage detected