Speedup through better multithreading
* Fixed excessive locking * Using more threads for voice recognition
This commit is contained in:
parent
1cb41b8309
commit
6888dadd04
|
@ -361,13 +361,15 @@ BoundedTimeline<Phone> detectPhones(
|
||||||
std::stack<lambda_unique_ptr<ps_decoder_t>> decoderPool;
|
std::stack<lambda_unique_ptr<ps_decoder_t>> decoderPool;
|
||||||
std::mutex decoderPoolMutex;
|
std::mutex decoderPoolMutex;
|
||||||
auto getDecoder = [&] {
|
auto getDecoder = [&] {
|
||||||
|
{
|
||||||
std::lock_guard<std::mutex> lock(decoderPoolMutex);
|
std::lock_guard<std::mutex> lock(decoderPoolMutex);
|
||||||
if (decoderPool.empty()) {
|
if (!decoderPool.empty()) {
|
||||||
decoderPool.push(createDecoder(dialog));
|
|
||||||
}
|
|
||||||
auto decoder = std::move(decoderPool.top());
|
auto decoder = std::move(decoderPool.top());
|
||||||
decoderPool.pop();
|
decoderPool.pop();
|
||||||
return std::move(decoder);
|
return std::move(decoder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return createDecoder(dialog);
|
||||||
};
|
};
|
||||||
auto returnDecoder = [&](lambda_unique_ptr<ps_decoder_t> decoder) {
|
auto returnDecoder = [&](lambda_unique_ptr<ps_decoder_t> decoder) {
|
||||||
std::lock_guard<std::mutex> lock(decoderPoolMutex);
|
std::lock_guard<std::mutex> lock(decoderPoolMutex);
|
||||||
|
@ -408,7 +410,7 @@ BoundedTimeline<Phone> detectPhones(
|
||||||
// Don't use more threads than there are utterances to be processed
|
// Don't use more threads than there are utterances to be processed
|
||||||
static_cast<int>(utterances.size()),
|
static_cast<int>(utterances.size()),
|
||||||
// Don't waste time creating additional threads (and decoders!) if the recording is short
|
// Don't waste time creating additional threads (and decoders!) if the recording is short
|
||||||
static_cast<int>(duration_cast<std::chrono::seconds>(audioClip->getTruncatedRange().getLength()).count() / 10)
|
static_cast<int>(duration_cast<std::chrono::seconds>(audioClip->getTruncatedRange().getLength()).count() / 5)
|
||||||
});
|
});
|
||||||
logging::debug("Speech recognition -- start");
|
logging::debug("Speech recognition -- start");
|
||||||
runParallel(processUtterance, utterances, threadCount, dialogProgressSink, getUtteranceProgressWeight);
|
runParallel(processUtterance, utterances, threadCount, dialogProgressSink, getUtteranceProgressWeight);
|
||||||
|
|
Loading…
Reference in New Issue