File size: 2,714 Bytes
a57f260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
// SPDX-License-Identifier: Apache-2.0
//

#include "accelerator_core.hpp"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

void print_usage(const char* program_name) {
    std::cout << "Usage: " << program_name << " [options]" << std::endl;
    std::cout << std::endl;
    std::cout << "Options:" << std::endl;
    std::cout << "  --socket PATH     IPC socket path (default: /tmp/pocket_tts_accelerator.sock)" << std::endl;
    std::cout << "  --threads N       Number of worker threads (default: 2)" << std::endl;
    std::cout << "  --memory MB       Memory pool size in megabytes (default: 64)" << std::endl;
    std::cout << "  --quiet           Disable verbose logging" << std::endl;
    std::cout << "  --help            Show this help message" << std::endl;
}

int main(int argc, char* argv[]) {
    pocket_tts_accelerator::AcceleratorConfiguration configuration = 
        pocket_tts_accelerator::AcceleratorCore::get_default_configuration();
    
    for (int argument_index = 1; argument_index < argc; ++argument_index) {
        std::string argument(argv[argument_index]);
        
        if (argument == "--help" || argument == "-h") {
            print_usage(argv[0]);
            return 0;
        }
        
        if (argument == "--socket" && argument_index + 1 < argc) {
            configuration.ipc_socket_path = argv[++argument_index];
            continue;
        }
        
        if (argument == "--threads" && argument_index + 1 < argc) {
            configuration.number_of_worker_threads = std::stoul(argv[++argument_index]);
            continue;
        }
        
        if (argument == "--memory" && argument_index + 1 < argc) {
            std::size_t memory_mb = std::stoul(argv[++argument_index]);
            configuration.memory_pool_size_bytes = memory_mb * 1024 * 1024;
            continue;
        }
        
        if (argument == "--quiet" || argument == "-q") {
            configuration.enable_verbose_logging = false;
            continue;
        }
        
        std::cerr << "Unknown argument: " << argument << std::endl;
        print_usage(argv[0]);
        return 1;
    }
    
    if (configuration.number_of_worker_threads < 1) {
        configuration.number_of_worker_threads = 1;
    }
    
    if (configuration.number_of_worker_threads > 2) {
        configuration.number_of_worker_threads = 2;
    }
    
    pocket_tts_accelerator::AcceleratorCore accelerator(configuration);
    
    if (!accelerator.initialize()) {
        std::cerr << "Failed to initialize accelerator" << std::endl;
        return 1;
    }
    
    accelerator.run();
    
    return 0;
}