Topic
  • 4 replies
  • Latest Post - ‏2011-10-12T06:20:02Z by jk-
memstick
memstick
2 Posts

Pinned topic Initiating SPE with custom entry point

‏2011-10-10T08:55:05Z |
Hello!

I'm working on a project to adapt a video encoding program to the Cell Broadband architecture. During program execution I want to run the SPEs with a custom entry point with the function spe_context_run(spe context, entrypoint, ...), where entrypoint specifies the address of the function where the SPE starts executing. I've looked around a lot and I cannot seem to find any examples of this anywhere; seems all of them uses the SPE_DEFAULT_ENTRY for entrypoint which effectively starts the SPE in its main function.

The only way I can think of to make this work is to load the SPE program execution entrypoints at runtime (since the addresses cannot be found at compile time) using main(...). Or am I completely off here?

Anyway, can anyone provide me with an example of how to specify the entrypoint of an SPE context using spe_program_run(...)?
Updated on 2011-10-12T06:20:02Z at 2011-10-12T06:20:02Z by jk-
  • SystemAdmin
    SystemAdmin
    10114 Posts

    Re: Initiating SPE with custom entry point

    ‏2011-10-10T12:38:34Z  
    I'm not 100% positive (its been a long time since I have worked with the Cell SDK), but I think even obtaining alternate entry points at runtime may be problematic unless you are well versed in the inner workings of the spufs, runtime library, and the SPE ABI. The entry parameter is intended to either specify its main (SPE_DEFAULT_ENTRY) or resume execution at the next instruction following a SPE program stop. Any other usage will likely encountered issues relating to runtime stack and calling conventions.
  • memstick
    memstick
    2 Posts

    Re: Initiating SPE with custom entry point

    ‏2011-10-10T13:07:52Z  
    Right.. Actually it says so in the SPE runtime API as well now that I had another look. Thing is, we've got three separate tasks to assign the SPEs, and we figured it'd be faster to have three functions for these instead of loading three different contexts that had to be loaded for each task switch.

    I guess what we could do is have the SPE wait for a mailbox message after entering main, then switch to the appropriate function from there. But then again, the one should generally avoid program flow control on the SPE, right?

    Anyway, thanks.
  • SystemAdmin
    SystemAdmin
    10114 Posts

    Re: Initiating SPE with custom entry point

    ‏2011-10-10T13:24:28Z  
    • memstick
    • ‏2011-10-10T13:07:52Z
    Right.. Actually it says so in the SPE runtime API as well now that I had another look. Thing is, we've got three separate tasks to assign the SPEs, and we figured it'd be faster to have three functions for these instead of loading three different contexts that had to be loaded for each task switch.

    I guess what we could do is have the SPE wait for a mailbox message after entering main, then switch to the appropriate function from there. But then again, the one should generally avoid program flow control on the SPE, right?

    Anyway, thanks.
    Program flow in the SPE can hurt performance only if it is within a tight inner loop. Keeping the SPE's hot having them wait for work (on a mailbox, as example) is better (with respect to performance) than having the kernel manage the start and stopping of the SPE threads.
  • jk-
    jk-
    43 Posts

    Re: Initiating SPE with custom entry point

    ‏2011-10-12T06:20:02Z  
    Hi,

    You can pass any address (in the SPE's address space) to spe_context_run, and the SPE will start execution from that address. However, unless you use SPE_DEFAULT_ENTRY, initial setup (initialising the stack and registers) will not be performed. So, as brokensh says, you probably only want to either pass SPE_DEFAULT_ENTRY, or the instruction address from the previous invocation of spe_context_run.

    So, if you want to start from a non-default entry point, you will need to do this state setup manually. Alternatively, do the branching in you spe program's main() function. The latter will probably be a much better solution.

    Rather than sending a mailbox message though, you can use the argp and envp to arguments to spe_context_run to pass the necessary data.