common : add common_print_available_devices() (#26170)
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
This commit is contained in:
+26
-14
@@ -1061,6 +1061,31 @@ static std::vector<ggml_backend_dev_t> parse_device_list(const std::string & val
|
|||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void common_print_available_devices() {
|
||||||
|
constexpr size_t MiB = 1024 * 1024;
|
||||||
|
std::vector<ggml_backend_dev_t> devices;
|
||||||
|
|
||||||
|
ggml_backend_load_all();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
|
||||||
|
auto * dev = ggml_backend_dev_get(i);
|
||||||
|
if (ggml_backend_dev_type(dev) != GGML_BACKEND_DEVICE_TYPE_CPU) {
|
||||||
|
devices.push_back(dev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Available devices:\n");
|
||||||
|
|
||||||
|
if (devices.empty()) {
|
||||||
|
printf(" (none)\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto * dev : devices) {
|
||||||
|
size_t free, total;
|
||||||
|
ggml_backend_dev_memory(dev, &free, &total);
|
||||||
|
printf(" %s: %s (%zu MiB, %zu MiB free)\n", ggml_backend_dev_name(dev), ggml_backend_dev_description(dev), total / MiB, free / MiB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void add_rpc_devices(const std::string & servers) {
|
static void add_rpc_devices(const std::string & servers) {
|
||||||
auto rpc_servers = string_split<std::string>(servers, ',');
|
auto rpc_servers = string_split<std::string>(servers, ',');
|
||||||
if (rpc_servers.empty()) {
|
if (rpc_servers.empty()) {
|
||||||
@@ -2588,20 +2613,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
|||||||
{"--list-devices"},
|
{"--list-devices"},
|
||||||
"print list of available devices and exit",
|
"print list of available devices and exit",
|
||||||
[](common_params &) {
|
[](common_params &) {
|
||||||
ggml_backend_load_all();
|
common_print_available_devices();
|
||||||
std::vector<ggml_backend_dev_t> devices;
|
|
||||||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
|
|
||||||
auto * dev = ggml_backend_dev_get(i);
|
|
||||||
if (ggml_backend_dev_type(dev) != GGML_BACKEND_DEVICE_TYPE_CPU) {
|
|
||||||
devices.push_back(dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("Available devices:\n");
|
|
||||||
for (auto * dev : devices) {
|
|
||||||
size_t free, total;
|
|
||||||
ggml_backend_dev_memory(dev, &free, &total);
|
|
||||||
printf(" %s: %s (%zu MiB, %zu MiB free)\n", ggml_backend_dev_name(dev), ggml_backend_dev_description(dev), total / 1024 / 1024, free / 1024 / 1024);
|
|
||||||
}
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ struct common_params_context {
|
|||||||
// if one argument has invalid value, it will automatically display usage of the specific argument (and not the full usage message)
|
// if one argument has invalid value, it will automatically display usage of the specific argument (and not the full usage message)
|
||||||
bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
|
bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
|
||||||
|
|
||||||
|
// load all backends and print the list of available (non-CPU) devices to stdout
|
||||||
|
void common_print_available_devices();
|
||||||
|
|
||||||
// parse input arguments from CLI into a map
|
// parse input arguments from CLI into a map
|
||||||
bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map);
|
bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map);
|
||||||
|
|
||||||
|
|||||||
@@ -670,22 +670,7 @@ static cmd_params parse_cmd_params(int argc, char ** argv) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (arg == "--list-devices") {
|
} else if (arg == "--list-devices") {
|
||||||
std::vector<ggml_backend_dev_t> devices;
|
common_print_available_devices();
|
||||||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
|
|
||||||
auto * dev = ggml_backend_dev_get(i);
|
|
||||||
if (ggml_backend_dev_type(dev) != GGML_BACKEND_DEVICE_TYPE_CPU) {
|
|
||||||
devices.push_back(dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("Available devices:\n");
|
|
||||||
if (devices.empty()) {
|
|
||||||
printf(" (none)\n");
|
|
||||||
}
|
|
||||||
for (auto * dev : devices) {
|
|
||||||
size_t free, total;
|
|
||||||
ggml_backend_dev_memory(dev, &free, &total);
|
|
||||||
printf(" %s: %s (%zu MiB, %zu MiB free)\n", ggml_backend_dev_name(dev), ggml_backend_dev_description(dev), total / 1024 / 1024, free / 1024 / 1024);
|
|
||||||
}
|
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (arg == "-t" || arg == "--threads") {
|
} else if (arg == "-t" || arg == "--threads") {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user