shacklettbp / madrona

MIT License
254 stars 23 forks source link

How to modify Madrona to support addressing read-write conflicts? #18

Closed ShawnshanksGui closed 7 months ago

ShawnshanksGui commented 7 months ago

Hello, I'm aiming to implement some specific systems that might run into read-write conflicts due to multiple-to-one situations. How can I adapt Madrona to support resolving these read-write conflicts? Where should I begin, like which parts of the code should I concentrate on (I've attempted to read the code, but the vast majority of it lacks comments, making it quite strenuous to understand)? Thanks!

shacklettbp commented 7 months ago

Hi, like I mentioned in the other issue, you should just use atomics: https://github.com/shacklettbp/madrona/blob/main/include/madrona/sync.hpp#L53

Bidipta's blog post talks about using atomics to get more performance in steps 4 and 5: https://bsarkar321.github.io/blog/overcooked_madrona/index.html

Basically you can just put an atomic in a component, and then manage the atomic read-modify-write operations yourself. Let me know if I'm not answering / misunderstanding your question here.

Internal Madrona support for handling this kind of multiple-to-one situation without relying on the user to use atomics is something we could discuss but it's definitely not trivial and not clear to me what the API should look like. I'm open to suggestions.

shacklettbp commented 7 months ago

Here's one place in the overcooked code that uses atomics: https://github.com/bsarkar321/madrona_rl_envs/blob/main/src/overcooked_env/sim.cpp#L208

ShawnshanksGui commented 7 months ago

Hi, like I mentioned in the other issue, you should just use atomics: https://github.com/shacklettbp/madrona/blob/main/include/madrona/sync.hpp#L53

Bidipta's blog post talks about using atomics to get more performance in steps 4 and 5: https://bsarkar321.github.io/blog/overcooked_madrona/index.html

Basically you can just put an atomic in a component, and then manage the atomic read-modify-write operations yourself. Let me know if I'm not answering / misunderstanding your question here.

Internal Madrona support for handling this kind of multiple-to-one situation without relying on the user to use atomics is something we could discuss but it's definitely not trivial and not clear to me what the API should look like. I'm open to suggestions.

Thanks for sending me this learning material. I appreciate your help and I will definitely take the time to go through it.

shacklettbp commented 7 months ago

Closing, this feel free to reopen if you have further questions.