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

GPU acceleration #96

Open
Drakula44 opened this issue Aug 9, 2024 · 3 comments
Open

GPU acceleration #96

Drakula44 opened this issue Aug 9, 2024 · 3 comments

Comments

@Drakula44
Copy link

Hi. I have working on my project when I wanted to use compute_svd_entropy but it was taking too much time.
I stumbled upon a library cupy that is replacement for numpy for running on cuda.
I modified locally compute_svd_entropy like this:

def compute_svd_entropy(data, tau=2, emb=10, n_jobs=1):
...
    import numpy as np
    if n_jobs == "cuda":
        import cupy as cp
        np = cp
        data = cp.asarray(data)
    _, sv, _ = np.linalg.svd(_embed(data, d=emb, tau=tau, n_jobs=n_jobs))
    m = np.sum(sv, axis=-1)
    sv_norm = np.divide(sv, m[:, None])
    out = -np.sum(np.multiply(sv_norm, np.log2(sv_norm)), axis=-1)
    if n_jobs == "cuda":
        out = cp.asnumpy(out)
    return out

And for my case it speeded up from 37s per chunk that I was passing to 3-4s per chunk.
I can create PR for that for every function that is applicable will you be willing to merge something like that. I know that it introduces one more dependency (it can be optional) so I wanted just to check first before submitting PR. Thanks in advance.

PS. n_jobs was motivated by the mne that is using n_jobs in that way.

@agramfort
Copy link
Member

agramfort commented Aug 10, 2024 via email

@Drakula44
Copy link
Author

Thank you for suggestion.

I looked into it a bit and dont think that there is much currently to do.
I looked into other functions and saw that they are not that straight forward as this one (I got quite lucky).
So in my opinion sklearn array API should mature a bit before it could be implemented here as I saw mne_features relays on sklern.

I still can make PR for this function or if some similar but dont think there is currently need for that?

@agramfort
Copy link
Member

agramfort commented Aug 13, 2024 via email

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

No branches or pull requests

2 participants