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) {
auto rpc_servers = string_split<std::string>(servers, ',');
if (rpc_servers.empty()) {
{"--list-devices"},
"print list of available devices and exit",
[](common_params &) {
- ggml_backend_load_all();
- 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);
- }
+ common_print_available_devices();
exit(0);
}
));
// 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);
+// 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
bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map);
break;
}
} else if (arg == "--list-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");
- 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);
- }
+ common_print_available_devices();
exit(0);
} else if (arg == "-t" || arg == "--threads") {
if (++i >= argc) {