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

How to feed array into multithread sequence? #12

Open
Sciroccogti opened this issue Mar 10, 2024 · 0 comments · May be fixed by #13
Open

How to feed array into multithread sequence? #12

Sciroccogti opened this issue Mar 10, 2024 · 0 comments · May be fixed by #13

Comments

@Sciroccogti
Copy link

I have an upstream array which contains thousands of codewords to be decoded.

So I write a feeder like this:

class Feeder(Py_Module):
    def __init__(self, N: int, batch_size: int, dtype):
        Py_Module.__init__(self)
        self.name = "py_Feeder"
        self.N = N
        self.batch_size = batch_size
        self.cnt = 0

        step = self.create_task("step")
        inpt = self.create_socket_in(step, "input", batch_size * N, dtype)
        out = self.create_socket_out(step, "output", N, dtype)
        self.create_codelet(step, lambda slf, lsk, fid: slf.step(lsk[inpt], lsk[out]))

    def step(self, x: ndarray, y: ndarray):
        if self.cnt >= self.batch_size:
            print("Feeder overflow")
            self.toggle_done()
            return 0
        y[:] = x[:, self.cnt * self.N: (self.cnt + 1) * self.N]
        self.cnt += 1
        if self.cnt >= self.batch_size:
            self.toggle_done()
        return 0

It works well when sequence is run with 1 thread, but when it comes to multithreading, the code just keeps
running into overflow.

Mutex lock seems not to be supported either.

Is there a proper way to implement it?

@Sciroccogti Sciroccogti linked a pull request Mar 19, 2024 that will close this issue
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 a pull request may close this issue.

1 participant