@@ -7,41 +7,41 @@ This enables matching up devices and information reported by the backend
77with tools (e.g. nvidia-smi) and system management libraries (e.g. nvml).
88---
99 ggml/include/ggml-backend.h | 1 +
10- ggml/src/ggml-cuda/ggml-cuda.cu | 33 ++++++++++++++++++++++++++++++++
10+ ggml/src/ggml-cuda/ggml-cuda.cu | 39 ++++++++++++++++++++++++++++++++
1111 ggml/src/ggml-metal/ggml-metal.m | 1 +
12- 3 files changed, 35 insertions(+)
12+ 3 files changed, 41 insertions(+)
1313
1414diff --git a/ggml/include/ggml-backend.h b/ggml/include/ggml-backend.h
15- index 74e46716..a880df33 100644
15+ index 74e46716..48839339 100644
1616--- a/ggml/include/ggml-backend.h
1717+++ b/ggml/include/ggml-backend.h
1818@@ -152,6 +152,7 @@ extern "C" {
1919 struct ggml_backend_dev_props {
2020 const char * name;
2121 const char * description;
22- + const char * uuid ;
22+ + const char * id ;
2323 size_t memory_free;
2424 size_t memory_total;
2525 enum ggml_backend_dev_type type;
2626diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
27- index cb0d8528..4c829153 100644
27+ index cb0d8528..d6960174 100644
2828--- a/ggml/src/ggml-cuda/ggml-cuda.cu
2929+++ b/ggml/src/ggml-cuda/ggml-cuda.cu
3030@@ -2884,6 +2884,7 @@ struct ggml_backend_cuda_device_context {
3131 int device;
3232 std::string name;
3333 std::string description;
34- + std::string uuid ;
34+ + std::string id ;
3535 };
3636
3737 static const char * ggml_backend_cuda_device_get_name(ggml_backend_dev_t dev) {
3838@@ -2896,6 +2897,11 @@ static const char * ggml_backend_cuda_device_get_description(ggml_backend_dev_t
3939 return ctx->description.c_str();
4040 }
4141
42- + static const char * ggml_backend_cuda_device_get_uuid (ggml_backend_dev_t dev) {
42+ + static const char * ggml_backend_cuda_device_get_id (ggml_backend_dev_t dev) {
4343+ ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;
44- + return ctx->uuid .c_str();
44+ + return ctx->id .c_str();
4545+ }
4646+
4747 static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {
@@ -51,17 +51,17 @@ index cb0d8528..4c829153 100644
5151 static void ggml_backend_cuda_device_get_props(ggml_backend_dev_t dev, ggml_backend_dev_props * props) {
5252 props->name = ggml_backend_cuda_device_get_name(dev);
5353 props->description = ggml_backend_cuda_device_get_description(dev);
54- + props->uuid = ggml_backend_cuda_device_get_uuid (dev);
54+ + props->id = ggml_backend_cuda_device_get_id (dev);
5555 props->type = ggml_backend_cuda_device_get_type(dev);
5656 ggml_backend_cuda_device_get_memory(dev, &props->memory_free, &props->memory_total);
5757
58- @@ -3458,6 +3465,32 @@ ggml_backend_reg_t ggml_backend_cuda_reg() {
58+ @@ -3458,6 +3465,38 @@ ggml_backend_reg_t ggml_backend_cuda_reg() {
5959 CUDA_CHECK(cudaGetDeviceProperties(&prop, i));
6060 dev_ctx->description = prop.name;
6161
6262+ #if !defined(GGML_USE_HIP)
63- + char uuid [64];
64- + snprintf(uuid , sizeof(uuid ),
63+ + char id [64];
64+ + snprintf(id , sizeof(id ),
6565+ "GPU-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
6666+ (unsigned char)prop.uuid.bytes[0],
6767+ (unsigned char)prop.uuid.bytes[1],
@@ -80,23 +80,29 @@ index cb0d8528..4c829153 100644
8080+ (unsigned char)prop.uuid.bytes[14],
8181+ (unsigned char)prop.uuid.bytes[15]
8282+ );
83- + dev_ctx->uuid = uuid ;
83+ + dev_ctx->id = id ;
8484+ #else
85- + dev_ctx->uuid = "GPU-" + std::string(prop.uuid.bytes, 16);
85+ + #ifdef _WIN32
86+ + char id[16];
87+ + snprintf(id, sizeof(id), "%d", i);
88+ + dev_ctx->id = id;
89+ + #else
90+ + dev_ctx->id = "GPU-" + std::string(prop.uuid.bytes, 16);
91+ + #endif
8692+ #endif
8793+
8894 ggml_backend_dev_t dev = new ggml_backend_device {
8995 /* .iface = */ ggml_backend_cuda_device_interface,
9096 /* .reg = */ ®,
9197diff --git a/ggml/src/ggml-metal/ggml-metal.m b/ggml/src/ggml-metal/ggml-metal.m
92- index 1b56f858..ee4f2dcb 100644
98+ index 1b56f858..a9eeebc6 100644
9399--- a/ggml/src/ggml-metal/ggml-metal.m
94100+++ b/ggml/src/ggml-metal/ggml-metal.m
95101@@ -5703,6 +5703,7 @@ static enum ggml_backend_dev_type ggml_backend_metal_device_get_type(ggml_backen
96102 static void ggml_backend_metal_device_get_props(ggml_backend_dev_t dev, struct ggml_backend_dev_props * props) {
97103 props->name = ggml_backend_metal_device_get_name(dev);
98104 props->description = ggml_backend_metal_device_get_description(dev);
99- + props->uuid = "0";
105+ + props->id = "0";
100106 props->type = ggml_backend_metal_device_get_type(dev);
101107 ggml_backend_metal_device_get_memory(dev, &props->memory_free, &props->memory_total);
102108 props->caps = (struct ggml_backend_dev_caps) {
0 commit comments