Hello, I hope you are doing well!
Following the multiprocessing Best Practices page, a best practice is stated to
…make it send the buffers back
User phizaz suggested this near the bottom of the second post:
def run(Qr, Qs): while True: b = Qr.get() torch.randn(..., out=b) # reusing the buffer tensor without re-allocating Qs.put(b) def main(): ... for i in range(buffer_size): # allocate buffers b = torch.empty(...) Qs.put(b) ... start processes ... while True: b = Qr.get() # main's Qr = run's Qs ... use b ... Qs.put(b) # main's Qs = run's Qr
Though he mentioned
Caveat: I see the cost of an additional queue to be huge. It might not be worth the benefit of not reallocating additional shared memory.
Which I think he is probably correct about. So what exactly was the best practices page alluding to?
Very interested in a response. Thank you!