FLAMEGPU / FLAMEGPU2

FLAME GPU 2 is a GPU accelerated agent based modelling framework for CUDA C++ and Python
https://flamegpu.com
MIT License
105 stars 20 forks source link

Access/Check agent state inside an agent function #1108

Closed Robadob closed 1 year ago

Robadob commented 1 year ago

Discussed in https://github.com/FLAMEGPU/FLAMEGPU2/discussions/1107

Originally posted by **daniele-baccega** September 18, 2023 Hi, is it possible to access to the agent state inside an agent function? Thank you

Need to decide a suitable API, but otherwise should be a simple PR.

Can we make the agent state comparison compile time? aka free?

ptheywood commented 1 year ago

Within an invocation of a kernel, all agents participating will be in the same state.

So presumably the use-case here is where the same agent function is reused, and somethign different needs to occur?

Agent state strings are only known at runtime, so dont' think we could make it a template value / constexpr if (for non-RTC). RTC we could embed it within the kernel source, and hope the optimiser realises it can optimize out the branching, but would need to ensure the kernel is recompiled per agent fn launch, not just per agent fn source? (I'm not sure if this is the case or not). Would presumably still cost some registers though (or "local" memory)).

During execution, there would be no divergent branching atleast, so the string comparison(s) would be the only epxensive bit. So makeing state names that have different early characters would be a gross way to minimize the run time cost...

mondus commented 1 year ago

Seems sensible. Also add for agent name. Docs need to make sure that performance of this is mentioned for non RTC.