Shop OBEX P1 Docs P2 Docs Learn Events
Copy Cat Cog — Parallax Forums

Copy Cat Cog

HumanoidoHumanoido Posts: 5,770
edited 2012-08-24 23:37 in Propeller 1
Is it possible to read one entire 2K Cog risc processor
and copy it to another location
like a place in HUB ram or a 64K EEPROM
where it could be used to run a program?

Comments

  • kwinnkwinn Posts: 8,697
    edited 2012-08-21 20:28
    A cog cannot access the memory of any other cog directly. A cog could be programmed to transfer the contents of its own memory to hub ram for another cog to access it.
    If the DAT section of a spin program that started a cog has not been modified it could be used to start another cog.
  • Heater.Heater. Posts: 21,230
    edited 2012-08-22 01:15
    If you mean to copy the code inside a running COG into another COG and have it run there as well then it cannot be done because you cannot read a COGs memory from outside.

    What you could do is have some code in the running COG that would write out the contents of its own memory to a HUB buffer and then start a second COG to load and run that.
    The COG process would "clone" itself into a second COG.

    Such a clone code would be nice little exercise in PASM. I have not heard of anyone doing this yet.
  • SarielSariel Posts: 182
    edited 2012-08-22 03:41
    Propeller virus? :lol:

    I agree. It would be a great exercise. But wouldn't it just keep cloning to the other cogs if you dump from one to another... then another... then another....
  • Heater.Heater. Posts: 21,230
    edited 2012-08-22 03:58
    Clone wars!

    The cloning I suggested acts rather like a Unix "fork" which starts a second process running a copy of the code of the first. When allowed to run away this is known as a "fork bomb".

    I would anticipate that one would arrange to have the COG clone itself in response to some external command or other event.

    Either the clones themselves or some master program would have to manage how many copies are created and prevent runaway.

    Next challenge is to have a network of Propellers and have the clones "infect" all of the COGs on all of the Props.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-08-23 00:49
    Heater. wrote: »
    If you mean to copy the code inside a running COG into another COG and have it run there as well then it cannot be done because you cannot read a COGs memory from outside.

    I mean copy the cog, not the program it's running. I want to make a 9th cog in the HUB.
  • Heater.Heater. Posts: 21,230
    edited 2012-08-23 01:44
    In that case no.

    I guess one could write a COG simulation that runs on the Prop. But that simulation would have to be run by a COG so you have no gain in COG count.

    To make a gain the simulation would have to simulate two COGs thwn you have a 9th COG. But now you have 2 simulated virtual COG and they will both be horrible slow.

    You could probably compile spinsim to run on a COG and simulate a virtual Props 8 COGs. Then you would have 7 real COGs and 8 virtual COGs. Of course the spinsim code is big enough that it would have to run from external memory. Shall we say very slow and pointless.
  • Clock LoopClock Loop Posts: 2,069
    edited 2012-08-23 13:57
    Heater. wrote: »
    Shall we say very slow and pointless.

    You don't like ants do you?
  • Heater.Heater. Posts: 21,230
    edited 2012-08-23 14:20
    Ants are fascinating. What do you mean?
  • Clock LoopClock Loop Posts: 2,069
    edited 2012-08-23 15:02
    Heater. wrote: »
    Ants are fascinating. What do you mean?

    It is said that the processing power in an ant's brain and a Macintosh II computer might be similar.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-08-23 15:44
    You could convert a cog program into an LMM program, and then run it from an LMM interpreter in a cog. But then it would be 4 to 8 times slower and you still only have 8 cogs. However, you could have one cog execute many LMM programs, and now you have more than 8 things running, but still with a speed penalty. This is essentially how pthreads work in PropGCC. You can have as many pthreads running as the hub RAM allows. Of course, the Prop does not have an interrupt, so each thread must sleep periodically so that the other threads can run.
  • Heater.Heater. Posts: 21,230
    edited 2012-08-23 15:53
    Dave,

    Oh yes, I guess LMM is that COG simulator I was talking about.

    Loopy,
    It is said that the processing power in an ant's brain and a Macintosh II computer might be similar.

    I don't buy that idea.

    Given the trouble we humans have controlling 6 multi-jointed leg robots in real time with processors a lot more powerfull than a Mac II

    Never mind absorbing all the ant sensors and performing its other higher level behaviors.

    Counting neurons and equating to gates in a computer is not enough.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-08-23 19:49
    Heater. wrote: »
    Shall we say very slow and pointless.
    It just may be that your point of view about being very slow and pointless, is pointless because the speed may be completely acceptable for my experiments and applications. How slow is very slow?

    I like the idea of running eight cogs on a simulator in one cog so the prop chip has a total of 7 hard cogs and 8 soft cogs available, making a prop with 15 cogs, some faster, some slower.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-23 20:09
    Humanoido wrote: »
    It just may be that your point of view about being very slow and pointless, is pointless because the speed may be completely acceptable for my experiments and applications. How slow is very slow?

    I like the idea of running eight cogs on a simulator in one cog so the prop chip has a total of 7 hard cogs and 8 soft cogs available, making a prop with 15 cogs, some faster, some slower.

    How about running 2 cogs in a simulator on each of the 8 cogs so you could have 16 soft cogs available, or 3 simulated cogs/cog for 24 soft cogs, etc.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-08-23 21:29
    kwinn wrote: »
    How about running 2 cogs in a simulator on each of the 8 cogs so you could have 16 soft cogs available, or 3 simulated cogs/cog for 24 soft cogs, etc.

    Definitely yes. If possible, I would like to use each hard cog to run its version of Propeller sim to create 8 soft cogs (in each hard cog) for a total of 64 soft cogs per Propeller chip. Is this possible?
  • pik33pik33 Posts: 2,397
    edited 2012-08-23 23:25
    64 cogs=128k of RAM. Possible with external memory only.
  • Heater.Heater. Posts: 21,230
    edited 2012-08-23 23:41
    Hmm, So we can fit 16 simulated full COG images into the 32KHUB. Let's call it 15 or 14 because some HUB will be needed for housekeeping I guess.
    We have say one COG running the LMM for them leaving 7 others. For a sum of 14 virtual + 7 real COGS = 21 COGS.
    That's assuming you find a way to get all this loaded and started. For some definition of "works" this might just be doable.

    Humanoido,

    Sorry I said "slow and pointless", I should learn to stop throwing value judgements around.

    But in a conversation with someone who has hundreds of Props connected together I have to then ask what use for this do you have in mind given that you have thousands of COGs at your disposal?
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-08-24 08:23
    Simulating more than 1 cog with a cog could only be done provided that the cogs resources could be shared. By that I mean, you cannot use the A counter in more than one way. So, if you are not using counters or the video, then it could be done, but would be slower. Effectively the cog would be running multiple LMM programs, time sharing between the threads running. I/O pins would be another problem that may have to be catered for. Also, each thread would need to be careful to save and restore its flags between task switches.

    This is how some minis and mainframes used to work, using of course just one cpu.
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-08-24 20:20
    Heater. wrote: »
    But in a conversation with someone who has hundreds of Props connected together I have to then ask what use for this do you have in mind given that you have thousands of COGs at your disposal?
    The objective in this experiment is to increase the number of Cogs thereby creating a new machine to be studied and explored with capabilities, configurations and methods unlike previous machines.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-08-24 20:35
    Humanoido: Then I would implement a time sharing LMM machine (ie each cog could become one). Run a predetermined number of LMM instructions, then save the cpu state, and run another LMM machine.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-24 23:37
    pik33 wrote: »
    64 cogs=128k of RAM. Possible with external memory only.

    While available cog and hub memory will impose some limits, those limits may not be as constrained as it seems at first glance. With re-entrant programs and each simulated cog executing the program on it's own data set it might be possible to have 64 simulated cogs. A very sharp programmer I met years ago ran a data entry business and had 8 terminals entering data to 8" floppy disk using a single 8080 S100 computer with 64K of ram. Essentially each terminal program consisted of a data area and a few lines of code that read the characters from the keyboard, called the main re-entrant program to process the character, and output any data returned to the terminal screen.
Sign In or Register to comment.