Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building Kaldi to WASM with OpenBLAS #4954

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

msqr1
Copy link

@msqr1 msqr1 commented Oct 15, 2024

Kaldi with OpenBLAS 0.3.28 with some mini hacks and performance increased by 20% (#4952)

@msqr1
Copy link
Author

msqr1 commented Oct 16, 2024

@jtrmal PTAL at the changes as well as the guide itself here: https://github.com/msqr1/kaldi-wasm2. I also have to force the number threads spawned by Kaldi to be 1 because WASM is quite complicated with multiple threads (we can support that later). I know g_num_threads control this, but is there any other place where kaldi spawn threads?

Thanks!

@jtrmal
Copy link
Contributor

jtrmal commented Oct 16, 2024 via email

@msqr1
Copy link
Author

msqr1 commented Oct 16, 2024

Could you answer my question so I can work on it?

@msqr1 msqr1 changed the title Support building Kaldi to WASM with OpenBLAS (#4952) Support building Kaldi to WASM with OpenBLAS Oct 16, 2024
@msqr1 msqr1 changed the title Support building Kaldi to WASM with OpenBLAS Support building Kaldi to WASM with OpenBLAS (#4952) Oct 16, 2024
@msqr1 msqr1 changed the title Support building Kaldi to WASM with OpenBLAS (#4952) Support building Kaldi to WASM with OpenBLAS Oct 16, 2024
@jtrmal
Copy link
Contributor

jtrmal commented Oct 16, 2024 via email

@msqr1
Copy link
Author

msqr1 commented Oct 16, 2024

Is there any other place where kaldi spawn threads other than the controlled g_num_threads in kaldi_thread.cc?

@danpovey
Copy link
Contributor

I think just from libraries e.g. some math libraries, like MKL, spawn their own threads. (This is usually not helpful and should be disabled by appopriate environment variables or liberary versions)

@msqr1
Copy link
Author

msqr1 commented Oct 17, 2024

OK, so I can force kaldi to spawn 1 thread by setting g_num_threads to 1. I will have to force all creations of std::thread to be 1 when building to WASM (except the CUDA ones), right?

Btw, what is the difference between g_num_threads =1 vs =0? @danpovey

@danpovey
Copy link
Contributor

The vast majority of Kaldi programs only use one thread anyway so you probably don't have to do anything in most cases.

@csukuangfj
Copy link
Contributor

By the way, sherpa-onnx also uses a single thread in its WebAssembly ASR and TTS APPs. And the speed also looks OK, e.g., it is able to do real-time speech recongition.

@msqr1
Copy link
Author

msqr1 commented Oct 17, 2024

Thanks! I will TAL at that later. For now, I'm just fixing the threading issue to get this donr!

@danpovey
Copy link
Contributor

I wouldn't attempt to complie the entirety of Kaldi to WASM because the binary size would be enormous. There are
lots of templates and many libraries. I'd compile a single binary at a time. IDK much about how WASM works though
and how the linking etc. is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants