Skip to content

Commit 231242e

Browse files
committed
examples: use -dev/--device and WHISPER_ARG_DEVICE
Align device selection naming with llama.cpp.
1 parent f53dc74 commit 231242e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

examples/cli/cli.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct whisper_params {
7777
bool log_score = false;
7878
bool use_gpu = true;
7979
bool flash_attn = true;
80+
int32_t gpu_device = 0;
8081
bool suppress_nst = false;
8182
bool carry_initial_prompt = false;
8283

@@ -129,6 +130,10 @@ static char * requires_value_error(const std::string & arg) {
129130
}
130131

131132
static bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
133+
if (const char * env_device = std::getenv("WHISPER_ARG_DEVICE")) {
134+
params.gpu_device = std::stoi(env_device);
135+
}
136+
132137
for (int i = 1; i < argc; i++) {
133138
std::string arg = argv[i];
134139

@@ -195,6 +200,7 @@ static bool whisper_params_parse(int argc, char ** argv, whisper_params & params
195200
else if (arg == "-dtw" || arg == "--dtw") { params.dtw = ARGV_NEXT; }
196201
else if (arg == "-ls" || arg == "--log-score") { params.log_score = true; }
197202
else if (arg == "-ng" || arg == "--no-gpu") { params.use_gpu = false; }
203+
else if (arg == "-dev" || arg == "--device") { params.gpu_device = std::stoi(ARGV_NEXT); }
198204
else if (arg == "-fa" || arg == "--flash-attn") { params.flash_attn = true; }
199205
else if (arg == "-nfa" || arg == "--no-flash-attn") { params.flash_attn = false; }
200206
else if (arg == "-sns" || arg == "--suppress-nst") { params.suppress_nst = true; }
@@ -276,6 +282,7 @@ static void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params
276282
fprintf(stderr, " -dtw MODEL --dtw MODEL [%-7s] compute token-level timestamps\n", params.dtw.c_str());
277283
fprintf(stderr, " -ls, --log-score [%-7s] log best decoder scores of tokens\n", params.log_score?"true":"false");
278284
fprintf(stderr, " -ng, --no-gpu [%-7s] disable GPU\n", params.use_gpu ? "false" : "true");
285+
fprintf(stderr, " -dev N, --device N [%-7d] GPU device ID (default: 0)\n", params.gpu_device);
279286
fprintf(stderr, " -fa, --flash-attn [%-7s] enable flash attention\n", params.flash_attn ? "true" : "false");
280287
fprintf(stderr, " -nfa, --no-flash-attn [%-7s] disable flash attention\n", params.flash_attn ? "false" : "true");
281288
fprintf(stderr, " -sns, --suppress-nst [%-7s] suppress non-speech tokens\n", params.suppress_nst ? "true" : "false");
@@ -1003,6 +1010,7 @@ int main(int argc, char ** argv) {
10031010
struct whisper_context_params cparams = whisper_context_default_params();
10041011

10051012
cparams.use_gpu = params.use_gpu;
1013+
cparams.gpu_device = params.gpu_device;
10061014
cparams.flash_attn = params.flash_attn;
10071015

10081016
if (!params.dtw.empty()) {

examples/server/server.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct whisper_params {
103103
bool no_timestamps = false;
104104
bool use_gpu = true;
105105
bool flash_attn = true;
106+
int32_t gpu_device = 0;
106107
bool suppress_nst = false;
107108
bool no_context = true;
108109
bool no_language_probabilities = false;
@@ -179,6 +180,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
179180
fprintf(stderr, " -sns, --suppress-nst [%-7s] suppress non-speech tokens\n", params.suppress_nst ? "true" : "false");
180181
fprintf(stderr, " -nth N, --no-speech-thold N [%-7.2f] no speech threshold\n", params.no_speech_thold);
181182
fprintf(stderr, " -ng, --no-gpu [%-7s] do not use gpu\n", params.use_gpu ? "false" : "true");
183+
fprintf(stderr, " -dev N, --device N [%-7d] GPU device ID (default: 0)\n", params.gpu_device);
182184
fprintf(stderr, " -fa, --flash-attn [%-7s] enable flash attention\n", params.flash_attn ? "true" : "false");
183185
fprintf(stderr, " -nfa, --no-flash-attn [%-7s] disable flash attention\n", params.flash_attn ? "false" : "true");
184186
fprintf(stderr, " -nlp, --no-language-probabilities [%-7s] exclude language probabilities from verbose_json output\n", params.no_language_probabilities ? "true" : "false");
@@ -198,6 +200,10 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
198200
}
199201

200202
bool whisper_params_parse(int argc, char ** argv, whisper_params & params, server_params & sparams) {
203+
if (const char * env_device = std::getenv("WHISPER_ARG_DEVICE")) {
204+
params.gpu_device = std::stoi(env_device);
205+
}
206+
201207
for (int i = 1; i < argc; i++) {
202208
std::string arg = argv[i];
203209

@@ -237,6 +243,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params, serve
237243
else if (arg == "-oved" || arg == "--ov-e-device") { params.openvino_encode_device = argv[++i]; }
238244
else if (arg == "-dtw" || arg == "--dtw") { params.dtw = argv[++i]; }
239245
else if (arg == "-ng" || arg == "--no-gpu") { params.use_gpu = false; }
246+
else if (arg == "-dev" || arg == "--device") { params.gpu_device = std::stoi(argv[++i]); }
240247
else if (arg == "-fa" || arg == "--flash-attn") { params.flash_attn = true; }
241248
else if (arg == "-nfa" || arg == "--no-flash-attn") { params.flash_attn = false; }
242249
else if (arg == "-sns" || arg == "--suppress-nst") { params.suppress_nst = true; }
@@ -643,6 +650,7 @@ int main(int argc, char ** argv) {
643650
struct whisper_context_params cparams = whisper_context_default_params();
644651

645652
cparams.use_gpu = params.use_gpu;
653+
cparams.gpu_device = params.gpu_device;
646654
cparams.flash_attn = params.flash_attn;
647655

648656
if (!params.dtw.empty()) {

0 commit comments

Comments
 (0)