FLAMEGPU / FLAMEGPU2

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

On-device initialisaiton functions (or step/exit functions?) #329

Open ptheywood opened 4 years ago

ptheywood commented 4 years ago

Current init functions are sequential host methods.

In some cases, doing this on the device is probably worthwhile (although it adds complexity).

General idea is:

Longer term the layers would become a DAG as with the main layers.

Would need to make sure curand behaves as intended, and potentially provide simple methods for provided non-uniform distributions across the populations (i.e normal distributions) otherwise a sequential host method would still have to be used instead.

Robadob commented 4 years ago

Simulate then calls this method...

a public version of step is still required though which doesn't take a set of layers though surely? I.e. where you call step explicilty in the test suite?

And not for step functions. That would create unwanted recursion

I don't see how it would be recursion, Step functions are just methods executed after the agent function layers, so no reason why they can't also have their own set of layers (though arguably there shoulnt be agent functions in there, but certainly scope for device step functions in some very obscure cases)?

Argubaly we don't actually need explicit step functions anymore, as we have host-layer functions, so step functions are just host layer functions which are implicitly at the end of the iteration.

Robadob commented 4 years ago

a public version of step is still required though which doesn't take a set of layers though surely? I.e. where you call step explicilty in the test suite?

Yes, step() currently never calls init or exit fns, hence it should probably read: "simulate then calls this method for init, agent, step and exit layer sets etc." The old step() would call the new step, passing main model layers, and then call step functions and exit conditions afterwards.

I don't see how it would be recursion, Step functions are just methods executed after the agent function layers, so no reason why they can't also have their own set of layers (though arguably there shoulnt be agent functions in there, but certainly scope for device step functions in some very obscure cases)?

Yeah, I was mistaken on this point whilst reading and walking. I was thinking a vector of layers, representing a step would have step functions. Regardless, I'm not a huge fan of allow step functions to have layers. Exit layers has more of a case.

Argubaly we don't actually need explicit step functions anymore, as we have host-layer functions, so step functions are just host layer functions which are implicitly at the end of the iteration.

I agree, but they exist as backwards compatibility (and should exist outside of the new private step).

Robadob commented 3 years ago

This alludes to device-agent initialisation functions (and they don't have a separate issue).

The easiest way to handle this would be with the existing Device API and agent function wrapper used by regular agent functions. But that would leave unusable message in/out properties (they would be treated as MsgNone) and redundant? read access to agent variables. The alternative being to make a bespoke InitDeviceApi, which then leads to either duplicated code or double inheritance/similar.

Robadob commented 2 years ago

Init/step/exit layers seems like a priority for Primage initialisation performance, so this may get addressed soon.