MCPcopy Create free account
hub / github.com/alibaba/MNN / ditWorkerLoop

Method ditWorkerLoop

transformers/llm/engine/src/omni.cpp:1768–1830  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1766}
1767
1768void Talker::ditWorkerLoop() {
1769 BackendConfig backendConfig;
1770 auto forwardType = backend_type_convert(mConfig->backend_type(true));
1771 int numThread = mConfig->thread_num(true);
1772 auto executor = Express::Executor::newExecutor(forwardType, backendConfig, numThread);
1773 Express::ExecutorScope scope(executor);
1774 mPreDit_async.reset(Module::clone(mPreDit.get()));
1775 mDit_async.reset(Module::clone(mDit.get()));
1776 mSpk_async = _Clone(mSpk, true);
1777 mCond_async = _Clone(mCond, true);
1778
1779 while (true) {
1780 WavChunk chunk;
1781 {
1782 std::unique_lock<std::mutex> lock(mWavQueueMutex);
1783 mWavQueueCond.wait(lock, [this] {
1784 return !mWavQueue.empty() || !mWavWorkerRunning;
1785 });
1786
1787 if (!mWavWorkerRunning && mWavQueue.empty()) {
1788 break;
1789 }
1790
1791 if (mWavQueue.empty()) {
1792 continue;
1793 }
1794
1795 chunk = std::move(mWavQueue.front());
1796 mWavQueue.pop();
1797 }
1798
1799 if (!chunk.codec_tokens.empty()) {
1800 auto generated_mel = ditForwardAsync((int)chunk.codec_tokens.size(),
1801 chunk.codec_tokens.data(), chunk.noise.data());
1802 generated_mel = _Slice(generated_mel,
1803 _var<int>({0, 0, chunk.mel_slice_start}, {3}),
1804 _var<int>({-1, -1, chunk.mel_slice_size}, {3}));
1805 auto mel_info = generated_mel->getInfo();
1806 chunk.mel_dims = mel_info->dim;
1807 chunk.mel.assign(generated_mel->readMap<float>(),
1808 generated_mel->readMap<float>() + mel_info->size);
1809 }
1810
1811 {
1812 std::lock_guard<std::mutex> lock(mMelQueueMutex);
1813 mMelQueue.push(std::move(chunk));
1814 }
1815 mMelQueueCond.notify_one();
1816 }
1817
1818 {
1819 WavChunk sentinel;
1820 sentinel.is_last = true;
1821 std::lock_guard<std::mutex> lock(mMelQueueMutex);
1822 mMelQueue.push(std::move(sentinel));
1823 }
1824 mMelQueueCond.notify_one();
1825

Callers

nothing calls this directly

Calls 15

_CloneFunction · 0.85
_SliceFunction · 0.85
backend_typeMethod · 0.80
thread_numMethod · 0.80
backend_type_convertFunction · 0.70
cloneFunction · 0.50
resetMethod · 0.45
getMethod · 0.45
waitMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected