|
81 | 81 |
|
82 | 82 | #include "ggml-cuda.h"
|
83 | 83 | #include "ggml.h"
|
| 84 | +#include "ggml-backend-impl.h" |
84 | 85 |
|
85 | 86 | #define MIN_CC_DP4A 610 // minimum compute capability for __dp4a, an intrinsic for byte-wise dot products
|
86 | 87 | #define CC_VOLTA 700
|
@@ -7649,11 +7650,11 @@ static size_t g_temp_tensor_extra_index = 0;
|
7649 | 7650 |
|
7650 | 7651 | static ggml_tensor_extra_gpu * ggml_cuda_alloc_temp_tensor_extra() {
|
7651 | 7652 | if (g_temp_tensor_extras == nullptr) {
|
7652 |
| - g_temp_tensor_extras = new ggml_tensor_extra_gpu[GGML_MAX_NODES]; |
| 7653 | + g_temp_tensor_extras = new ggml_tensor_extra_gpu[GGML_DEFAULT_GRAPH_SIZE]; |
7653 | 7654 | }
|
7654 | 7655 |
|
7655 | 7656 | size_t alloc_index = g_temp_tensor_extra_index;
|
7656 |
| - g_temp_tensor_extra_index = (g_temp_tensor_extra_index + 1) % GGML_MAX_NODES; |
| 7657 | + g_temp_tensor_extra_index = (g_temp_tensor_extra_index + 1) % GGML_DEFAULT_GRAPH_SIZE; |
7657 | 7658 | ggml_tensor_extra_gpu * extra = &g_temp_tensor_extras[alloc_index];
|
7658 | 7659 | memset(extra, 0, sizeof(*extra));
|
7659 | 7660 |
|
@@ -7960,11 +7961,11 @@ struct ggml_backend_buffer_context_cuda {
|
7960 | 7961 |
|
7961 | 7962 | ggml_tensor_extra_gpu * ggml_cuda_alloc_temp_tensor_extra() {
|
7962 | 7963 | if (temp_tensor_extras == nullptr) {
|
7963 |
| - temp_tensor_extras = new ggml_tensor_extra_gpu[GGML_MAX_NODES]; |
| 7964 | + temp_tensor_extras = new ggml_tensor_extra_gpu[GGML_DEFAULT_GRAPH_SIZE]; |
7964 | 7965 | }
|
7965 | 7966 |
|
7966 | 7967 | size_t alloc_index = temp_tensor_extra_index;
|
7967 |
| - temp_tensor_extra_index = (temp_tensor_extra_index + 1) % GGML_MAX_NODES; |
| 7968 | + temp_tensor_extra_index = (temp_tensor_extra_index + 1) % GGML_DEFAULT_GRAPH_SIZE; |
7968 | 7969 | ggml_tensor_extra_gpu * extra = &temp_tensor_extras[alloc_index];
|
7969 | 7970 | memset(extra, 0, sizeof(*extra));
|
7970 | 7971 |
|
@@ -8050,7 +8051,12 @@ static ggml_backend_buffer_t ggml_backend_cuda_alloc_buffer(ggml_backend_t backe
|
8050 | 8051 | ggml_cuda_set_device(g_main_device);
|
8051 | 8052 |
|
8052 | 8053 | ggml_backend_buffer_context_cuda * ctx = new ggml_backend_buffer_context_cuda;
|
| 8054 | + |
| 8055 | + size = std::max(size, (size_t)1); // cudaMalloc returns null for size 0 |
| 8056 | + |
| 8057 | + ggml_cuda_set_device(g_main_device); |
8053 | 8058 | CUDA_CHECK(cudaMalloc(&ctx->device, size));
|
| 8059 | + |
8054 | 8060 | return ggml_backend_buffer_init(backend, cuda_backend_buffer_interface, ctx, size);
|
8055 | 8061 | }
|
8056 | 8062 |
|
@@ -8117,6 +8123,8 @@ static void ggml_backend_cuda_graph_compute(ggml_backend_t backend, ggml_cgraph
|
8117 | 8123 | for (int i = 0; i < cgraph->n_nodes; i++) {
|
8118 | 8124 | ggml_tensor * node = cgraph->nodes[i];
|
8119 | 8125 |
|
| 8126 | + if (node->op == GGML_OP_RESHAPE || node->op == GGML_OP_TRANSPOSE || node->op == GGML_OP_VIEW || node->op == GGML_OP_PERMUTE) |
| 8127 | + continue; |
8120 | 8128 | assert(node->backend == GGML_BACKEND_GPU);
|
8121 | 8129 | for (int j = 0; j < GGML_MAX_SRC; j++) {
|
8122 | 8130 | if (node->src[j] != nullptr) {
|
|
0 commit comments