Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,20 @@ endif()
if (ENGINE_BUILD_TESTS)
enable_testing()

add_test(
NAME audiocpp_cli_list_devices
COMMAND audiocpp_cli --list-devices
)
add_test(
NAME audiocpp_server_list_devices
COMMAND audiocpp_server --list-devices
)
set_tests_properties(
audiocpp_cli_list_devices
audiocpp_server_list_devices
PROPERTIES PASS_REGULAR_EXPRESSION "available_devices=[0-9]+"
)

set(ENGINE_UNITTEST_ASSET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/tests/unittests/assets")

function(add_engine_unittest target source)
Expand Down
11 changes: 1 addition & 10 deletions app/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,16 +648,7 @@ int audiocpp_cli_main(int argc, char ** argv) {
return 0;
}
if (has_arg(argc, argv, "--list-devices")) {
const auto devices = engine::core::list_backend_devices();
std::cout << "available_devices=" << devices.size() << "\n";
for (const auto & device : devices) {
std::cout << device.backend << ":" << device.index;
if (!device.name.empty()) {
std::cout << " \"" << device.name << "\"";
}
std::cout << " [" << device.type << "]\n";
}
std::cout << "select with: --backend <cuda|hip|vulkan|metal|cpu> --device <index>\n";
engine::core::print_backend_devices(std::cout);
return 0;
}
if (has_arg(argc, argv, "--list-loaders")) {
Expand Down
9 changes: 8 additions & 1 deletion app/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "http.h"
#include "runtime.h"

#include "engine/framework/core/backend.h"
#include "engine/framework/debug/trace.h"

#include <csignal>
Expand Down Expand Up @@ -60,7 +61,8 @@ std::filesystem::path executable_directory(const char * argv0) {
void print_help() {
std::cout
<< "audiocpp_server [--config <server.json>] [--ui] [--host <ip>] [--port <port>] [--backend <backend>]\n"
<< " [--device <id>] [--threads <n>] [--busy-timeout-ms <ms>] [--max-loaded-models <n>]\n"
<< " [--device <id>] [--list-devices] [--threads <n>] [--busy-timeout-ms <ms>]\n"
<< " [--max-loaded-models <n>]\n"
<< " [--model-spec-override <json-or-directory>] [--voice-dir <directory>]\n"
<< " [--log] [--log-file <path>]\n"
<< " [--cors-origins <origins>]\n"
Expand All @@ -69,6 +71,7 @@ void print_help() {
<< " --ui-management allow WebUI model management and downloads; requires\n"
<< " AUDIOCPP_BUILD_NATIVE_MODEL_MANAGER=ON at build time\n"
<< " --backend cpu|cuda|hip|rocm|vulkan|metal default cuda (rocm is an alias for hip)\n"
<< " --list-devices list available backend devices and exit\n"
<< " --busy-timeout-ms <ms> fail a request with 503 when the model has been\n"
<< " busy this long; default 300000, 0 disables\n"
<< " --max-loaded-models <n> keep at most n models resident in memory, unloading\n"
Expand Down Expand Up @@ -110,6 +113,10 @@ void print_help() {

int main(int argc, char ** argv) {
try {
if (has_arg(argc, argv, "--list-devices")) {
engine::core::print_backend_devices(std::cout);
return 0;
}
if (has_arg(argc, argv, "--help") || has_arg(argc, argv, "-h")) {
print_help();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions include/engine/framework/core/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <string>
#include <vector>

Expand All @@ -29,6 +30,7 @@ struct BackendDeviceInfo {

// Enumerates every device of every loaded ggml backend registry, in registry order.
std::vector<BackendDeviceInfo> list_backend_devices();
void print_backend_devices(std::ostream & out);

struct BackendMemorySnapshot {
bool available = false;
Expand Down
14 changes: 14 additions & 0 deletions src/framework/core/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <ostream>
#include <stdexcept>
#include <string>

Expand Down Expand Up @@ -209,6 +210,19 @@ std::vector<BackendDeviceInfo> list_backend_devices() {
return devices;
}

void print_backend_devices(std::ostream & out) {
const auto devices = list_backend_devices();
out << "available_devices=" << devices.size() << "\n";
for (const auto & device : devices) {
out << device.backend << ":" << device.index;
if (!device.name.empty()) {
out << " \"" << device.name << "\"";
}
out << " [" << device.type << "]\n";
}
out << "select with: --backend <cuda|hip|vulkan|metal|cpu> --device <index>\n";
}

ggml_backend_t init_backend(const BackendConfig & config) {
ensure_backends_loaded();
switch (config.type) {
Expand Down
Loading