-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy patht2s_graph_cli_parser.cpp
More file actions
92 lines (81 loc) · 3.63 KB
/
t2s_graph_cli_parser.cpp
File metadata and controls
92 lines (81 loc) · 3.63 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
//*****************************************************************************
// Copyright 2025 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include "t2s_graph_cli_parser.hpp"
#include <algorithm>
#include <iostream>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include "../capi_frontend/server_settings.hpp"
#include "../ovms_exit_codes.hpp"
#include "../status.hpp"
#include "graph_queue_cli_options.hpp"
namespace ovms {
TextToSpeechGraphSettingsImpl& TextToSpeechGraphCLIParser::defaultGraphSettings() {
static TextToSpeechGraphSettingsImpl instance;
return instance;
}
void TextToSpeechGraphCLIParser::createOptions() {
this->options = std::make_unique<cxxopts::Options>("ovms --pull [PULL OPTIONS ... ]", "-pull --task text2speech graph options");
options->allow_unrecognised_options();
// clang-format off
options->add_options("TextToSpeech")
("num_streams",
"The number of parallel execution streams to use for the model. Use at least 2 on 2 socket CPU systems.",
cxxopts::value<uint32_t>()->default_value("1"),
"NUM_STREAMS");
addGraphQueueOptions(*options, "TextToSpeech");
}
void TextToSpeechGraphCLIParser::printHelp() {
if (!this->options) {
this->createOptions();
}
std::cout << options->help({"TextToSpeech"}) << std::endl;
}
std::vector<std::string> TextToSpeechGraphCLIParser::parse(const std::vector<std::string>& unmatchedOptions) {
if (!this->options) {
this->createOptions();
}
std::vector<const char*> cStrArray;
cStrArray.reserve(unmatchedOptions.size() + 1);
cStrArray.push_back("ovms graph");
std::transform(unmatchedOptions.begin(), unmatchedOptions.end(), std::back_inserter(cStrArray), [](const std::string& str) { return str.c_str(); });
const char* const* args = cStrArray.data();
result = std::make_unique<cxxopts::ParseResult>(options->parse(cStrArray.size(), args));
return result->unmatched();
}
void TextToSpeechGraphCLIParser::prepare(OvmsServerMode serverMode, HFSettingsImpl& hfSettings, const std::string& modelName) {
TextToSpeechGraphSettingsImpl textToSpeechGraphSettings = TextToSpeechGraphCLIParser::defaultGraphSettings();
hfSettings.exportSettings.targetDevice = hfSettings.exportSettings.targetDevice;
if (modelName != "") {
hfSettings.exportSettings.modelName = modelName;
} else {
hfSettings.exportSettings.modelName = hfSettings.sourceModel;
}
if (nullptr == result) {
// Pull with default arguments - no arguments from user
if (serverMode != HF_PULL_MODE && serverMode != HF_PULL_AND_START_MODE) {
throw std::logic_error("Tried to prepare server and model settings without graph parse result");
}
} else {
hfSettings.exportSettings.pluginConfig.numStreams = result->operator[]("num_streams").as<uint32_t>();
extractGraphQueueOptions(*result, hfSettings);
}
hfSettings.graphSettings = std::move(textToSpeechGraphSettings);
}
} // namespace ovms