How many cogs run
Ray0665
Posts: 231
I have a program lets call it main, it uses the F32 object which runs in
another cog. Now lets say I have another object lets call it mod1 which also uses F32
Mod1 runs as part of main, that is, main does not start mod1 in another cog
As I understand it there is only one copy of F32 in hub ram but how many cogs are running F32?
If main starts mod1 in another cog what happens with F32?
another cog. Now lets say I have another object lets call it mod1 which also uses F32
Mod1 runs as part of main, that is, main does not start mod1 in another cog
As I understand it there is only one copy of F32 in hub ram but how many cogs are running F32?
If main starts mod1 in another cog what happens with F32?
Comments
The accepted practice is to use a PUB Start method if an object starts a COG. Otherwise use PUB Init. F32 documents the following.
It looks like each object the has an OBJ reference to F32 and invokes the F32.Start method causes a new COG to start. If that's what you're asking.
Is it defined in VAR or in DAT section?
If it is in VAR it means that the variable is only known in an instance of the object. Another instance of the same object has it's own version. This means that you have to "start" the object twice to function properly. (That is how I'd expect it to work)
If the buffer is in a DAT section, there is only one copy used by all instances of the object. This means that only one COG has to run F32.
But in that case multiple other COGs might have the idea to use it simultaneously. This is no problem if these COGs use Locks.
If it is like I expect, you should be fine moving all variables into the DAT section and both parts (main and mod1 ) would then use the same F32.
If you use an object like F32 from different cogs, you have two options:
1) start the object only once (in Main) and use locks to make sure that not 2 cogs call an F32 methode at the same time.
2) start another instance of the object for every cog that needs F32 (call the F32 start methode at begin of "mod1" which is started in a new cog). This needs more cogs, but you can run different F32 functions at the same time, one per cog.
Not all objects allow both options, some are made to run as a single instance and implement the locking scheme right in the Spin interface methodes. There are for example versions of the FullDuplexSerial which can be called from several cogs but send and receive only thru one RX and TX pin.
If this is the begin of a bigger project, you should be careful with resources like cogs and memory, so it may be the best to structure your code so that only one cog makes all the floating point calculations with the help of one F32 cog.
Andy