This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTSC Modules and Pragmas

I'm unsure of this is the correct place to post this question, but most of my RTSC and XDC questions seem to get answered here.

Is there a method to take a config parameter of an RTSC module, and place it into a pragma such as a MUST_ITERATE?

Thanks

  • Module configuration parameters are declared as constants in C code, which means you can't use them in pragmas. However, primitive values declared through Program.global are defined as macros, so you can assign the value of a particular config parameter (of a primitive type) to a Program.global value, and then use that value in a _Pragma operator. Would that work for you?

  • I have an RTSC module coded up for a particular algorithm, and now I am looking to start optimizing it. The loops I wish to optimize are in member functions of the module, and the bounds are set by config variables. So it appears that making certain parameters configurable with a configurable MUST_ITERATE won't be possible. To do that with the current XDC scheme would mean "regenerating" the function for each instance declared to provide an optimization tuned to its configuration, which is not how the tools implement it.

    To clarify the Program.global usage:

    in the .cfg:

    Program.global.loop_num = 20;

    Which translates to in C:

    #define Program_global_loop_num 20

    Is that correct?

  • Module functions are common for all instances of a module. That's common for object-oriented languages. But, there is some advanced RTSC functionality, where you can use templates to generate C functions based on a value of a configurable parameter. I haven't really thought about details, but you could have a function pointer config parameter to which you would assign a function name of a generated function for that specific instance. For example, the template would do this:
    %var Mod = xdc.module('pkg.Mod');
    %for (var i = 0; 
    i < Mod.$instances.length; i++) {
    %    var inst = Mod.$instances[i];
    %    var id = inst.id;
    %    var minLoop = inst.minLoop;

    Void loopFxn`id`() {
    ...
    #pragma MUST_ITERATE(`minLoop`)
    // loop
    ...
    }

    And then, the implementation of your module would invoke the generated function.

     

    /* The 'real' module function */
    Void Mod_loopFxn(Mod_Object *obj) {
        obj->ptrFxn();
    }

    I skipped over a lot of details here, but if you think the expense of an additional function call would be acceptable, and you want to try it, I can add more details later.

    As for the generated macro, what gets generated is

    #define loop_num 20

  • Since I am in the experimentation phase, I think I would like to try it. Additional details would be much appreciated.

    Thanks!

  • I am guessing you are creating all instances statically. Is that correct? If you want to create them at runtime, the proposed solution would not work. So, first you have to declare a function pointer parameter somewhere in your module spec (Mod.xdc). Let's say that function accepts UInt and then returns UInt, you can change it accordingly.

    ...
    instance:
       
    typedef UInt (*FuncPtr)(UInt);
       config FuncPtr ptrFxn;
    ...

    Then, in your config script, you assign the names of the instance-specific functions to that parameter. I created only two instances, but if you have many of them, you can create them in a loop.

    var Mod = xdc.module('pkg.Mod');
    var inst1 = Mod.create();
    inst1.ptrFxn = $externFxn("loopFxn1");
    var inst2 = Mod.create();
    inst2.ptrFxn = $externFxn("loopFxn2");

    $externFxn is an XDCscript global function that is not documented yet (there is a bug filed to document it). The function verifies that the type of the function parameter matches the type of the config parameter to which the $externFxn is assigned.
    Now, you need to create loopFxns. Check my previous post to see how to do that. The final step is to use an instance function that will delegate to loopFxns. You can also find that in my previous post, except that I didn't have any parameters or return values there.

    There will be some issues along the way until it all works, but this is a general direction. Let me know when you need more help.