Skip to content

Commit

Permalink
Merge b3187 + Cuda Unified Memory support from matteoserva/master
Browse files Browse the repository at this point in the history
b3187 + Cuda Unified Memory support
  • Loading branch information
Nexesenex authored Jun 20, 2024
2 parents 425c5a3 + fce75cc commit 1c307c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ struct server_context {
} else {
std::string prompt;
if (task.data.contains("prompt") && task.data.at("prompt").is_string()) {
json_value(task.data, "prompt", std::string());
prompt = json_value(task.data, "prompt", std::string());
}

slot = get_available_slot(prompt);
Expand Down
9 changes: 8 additions & 1 deletion ggml-cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,14 @@ GGML_CALL static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffe
size = std::max(size, (size_t)1); // cudaMalloc returns null for size 0

void * dev_ptr;
cudaError_t err = ggml_cuda_device_malloc(&dev_ptr, size, buft_ctx->device);
cudaError_t err;
if (getenv("GGML_CUDA_ENABLE_UNIFIED_MEMORY") != nullptr)
{
err = cudaMallocManaged(&dev_ptr, size);
}
else {
err = ggml_cuda_device_malloc(&dev_ptr, size, buft_ctx->device);
}
if (err != cudaSuccess) {
// clear the error
cudaGetLastError();
Expand Down
6 changes: 6 additions & 0 deletions ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@ static void ggml_metal_free(struct ggml_metal_context * ctx) {
}

static bool ggml_metal_supports_op(const struct ggml_metal_context * ctx, const struct ggml_tensor * op) {
for (size_t i = 0, n = 3; i < n; ++i) {
if (op->src[i] != NULL && op->src[i]->type == GGML_TYPE_BF16) {
return false;
}
}

switch (op->op) {
case GGML_OP_UNARY:
switch (ggml_get_unary_op(op)) {
Expand Down

0 comments on commit 1c307c6

Please sign in to comment.