|
21 | 21 | #include "ggml.h" |
22 | 22 | #include "llama.h" |
23 | 23 | #include "common.h" |
24 | | -#include "ggml-cuda.h" |
25 | | -#include "ggml-sycl.h" |
26 | | - |
27 | | -#ifdef GGML_USE_CANN |
28 | | -#include "ggml-cann.h" |
29 | | -#endif |
30 | 24 |
|
31 | 25 | #ifdef _WIN32 |
32 | 26 | #define WIN32_LEAN_AND_MEAN |
@@ -82,95 +76,27 @@ static T stdev(const std::vector<T> & v) { |
82 | 76 | } |
83 | 77 |
|
84 | 78 | static std::string get_cpu_info() { |
85 | | - std::string id; |
86 | | -#ifdef __linux__ |
87 | | - FILE * f = fopen("/proc/cpuinfo", "r"); |
88 | | - if (f) { |
89 | | - char buf[1024]; |
90 | | - while (fgets(buf, sizeof(buf), f)) { |
91 | | - if (strncmp(buf, "model name", 10) == 0) { |
92 | | - char * p = strchr(buf, ':'); |
93 | | - if (p) { |
94 | | - p++; |
95 | | - while (std::isspace(*p)) { |
96 | | - p++; |
97 | | - } |
98 | | - while (std::isspace(p[strlen(p) - 1])) { |
99 | | - p[strlen(p) - 1] = '\0'; |
100 | | - } |
101 | | - id = p; |
102 | | - break; |
103 | | - } |
104 | | - } |
| 79 | + std::vector<std::string> gpu_list; |
| 80 | + for (size_t i = 0; i < ggml_backend_dev_count(); i++) { |
| 81 | + auto * dev = ggml_backend_dev_get(i); |
| 82 | + auto dev_type = ggml_backend_dev_type(dev); |
| 83 | + if (dev_type == GGML_BACKEND_DEVICE_TYPE_CPU || dev_type == GGML_BACKEND_DEVICE_TYPE_ACCEL) { |
| 84 | + gpu_list.push_back(ggml_backend_dev_description(dev)); |
105 | 85 | } |
106 | | - fclose(f); |
107 | | - } |
108 | | -#elif defined(_WIN32) |
109 | | - HKEY hKey; |
110 | | - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, |
111 | | - TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), |
112 | | - 0, |
113 | | - KEY_READ, |
114 | | - &hKey) != ERROR_SUCCESS) { |
115 | | - // fail to open registry key |
116 | | - return ""; |
117 | 86 | } |
118 | | - char cpu_brand[256]; |
119 | | - DWORD cpu_brand_size = sizeof(cpu_brand); |
120 | | - if (RegQueryValueExA(hKey, |
121 | | - TEXT("ProcessorNameString"), |
122 | | - NULL, |
123 | | - NULL, |
124 | | - (LPBYTE)cpu_brand, |
125 | | - &cpu_brand_size) == ERROR_SUCCESS) { |
126 | | - id.assign(cpu_brand, cpu_brand_size); |
127 | | - if (id.find('\0') != std::string::npos) { |
128 | | - id.resize(id.find('\0')); |
129 | | - } |
130 | | - } |
131 | | - RegCloseKey(hKey); |
132 | | -#endif |
133 | | - // TODO: other platforms |
134 | | - return id; |
| 87 | + return join(gpu_list, ", "); |
135 | 88 | } |
136 | 89 |
|
137 | 90 | static std::string get_gpu_info() { |
138 | | - std::string id; |
139 | | -#ifdef GGML_USE_CUDA |
140 | | - int count = ggml_backend_cuda_get_device_count(); |
141 | | - for (int i = 0; i < count; i++) { |
142 | | - char buf[128]; |
143 | | - ggml_backend_cuda_get_device_description(i, buf, sizeof(buf)); |
144 | | - id += buf; |
145 | | - if (i < count - 1) { |
146 | | - id += "/"; |
| 91 | + std::vector<std::string> gpu_list; |
| 92 | + for (size_t i = 0; i < ggml_backend_dev_count(); i++) { |
| 93 | + auto * dev = ggml_backend_dev_get(i); |
| 94 | + auto dev_type = ggml_backend_dev_type(dev); |
| 95 | + if (dev_type == GGML_BACKEND_DEVICE_TYPE_GPU) { |
| 96 | + gpu_list.push_back(ggml_backend_dev_description(dev)); |
147 | 97 | } |
148 | 98 | } |
149 | | -#endif |
150 | | -#ifdef GGML_USE_SYCL |
151 | | - int count = ggml_backend_sycl_get_device_count(); |
152 | | - for (int i = 0; i < count; i++) { |
153 | | - char buf[128]; |
154 | | - ggml_backend_sycl_get_device_description(i, buf, sizeof(buf)); |
155 | | - id += buf; |
156 | | - if (i < count - 1) { |
157 | | - id += "/"; |
158 | | - } |
159 | | - } |
160 | | -#endif |
161 | | -#ifdef GGML_USE_CANN |
162 | | - uint32_t count = ggml_backend_cann_get_device_count(); |
163 | | - for (uint32_t i = 0; i < count; i++) { |
164 | | - char buf[128]; |
165 | | - ggml_backend_cann_get_device_description(i, buf, sizeof(buf)); |
166 | | - id += buf; |
167 | | - if (i < count - 1) { |
168 | | - id += "/"; |
169 | | - } |
170 | | - } |
171 | | -#endif |
172 | | - // TODO: other backends |
173 | | - return id; |
| 99 | + return join(gpu_list, ", "); |
174 | 100 | } |
175 | 101 |
|
176 | 102 | // command line params |
@@ -938,29 +864,15 @@ struct test { |
938 | 864 | } |
939 | 865 |
|
940 | 866 | static std::string get_backend() { |
941 | | - if (cuda) { |
942 | | - return GGML_CUDA_NAME; |
943 | | - } |
944 | | - if (vulkan) { |
945 | | - return "Vulkan"; |
946 | | - } |
947 | | - if (kompute) { |
948 | | - return "Kompute"; |
949 | | - } |
950 | | - if (metal) { |
951 | | - return "Metal"; |
952 | | - } |
953 | | - if (sycl) { |
954 | | - return GGML_SYCL_NAME; |
955 | | - } |
956 | | - if (gpu_blas) { |
957 | | - return "GPU BLAS"; |
958 | | - } |
959 | | - if (blas) { |
960 | | - return "BLAS"; |
| 867 | + std::vector<std::string> backends; |
| 868 | + for (size_t i = 0; i < ggml_backend_reg_count(); i++) { |
| 869 | + auto * reg = ggml_backend_reg_get(i); |
| 870 | + std::string name = ggml_backend_reg_name(reg); |
| 871 | + if (name != "CPU") { |
| 872 | + backends.push_back(ggml_backend_reg_name(reg)); |
| 873 | + } |
961 | 874 | } |
962 | | - |
963 | | - return "CPU"; |
| 875 | + return backends.empty() ? "CPU" : join(backends, ","); |
964 | 876 | } |
965 | 877 |
|
966 | 878 | static const std::vector<std::string> & get_fields() { |
|
0 commit comments