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.

Compiler/TMDSEVM6678: How to increase heap memory to be used for new/malloc for an openmp application?

Part Number: TMDSEVM6678Tool/software: TI C/C++ CompilerI have an openmp c/c++ code that apparently runs out of memory when c++ new operator is called ... i am using cfg file from an openmp exaple below: C:\ti\openmp_dsp_c667x_2_06_03_00\packages\examples\hello_with_makeI increased the heap size by changing the below two lines to increase the heap size but didn't work ... and I am still getting the same error ...       // Size of the heap shared by all the cores       var sharedHeapSize = 0x08000000;Please let me know how to change the cfg file as you mentioned below:
Other Parts Discussed in Thread: SYSBIOS

/*
 * Copyright (c) 2012-2015, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/***************************/
/* SECTION MAPPING         */
/***************************/
var program = xdc.useModule('xdc.cfg.Program');

program.sectMap[".args"]        = new Program.SectionSpec();
program.sectMap[".bss"]         = new Program.SectionSpec();
program.sectMap[".cinit"]       = new Program.SectionSpec();
program.sectMap[".cio"]         = new Program.SectionSpec();
program.sectMap[".const"]       = new Program.SectionSpec();
program.sectMap[".data"]        = new Program.SectionSpec();
program.sectMap[".far"]         = new Program.SectionSpec();
program.sectMap[".fardata"]     = new Program.SectionSpec();
program.sectMap[".neardata"]    = new Program.SectionSpec();
program.sectMap[".rodata"]      = new Program.SectionSpec();
program.sectMap[".stack"]       = new Program.SectionSpec();
program.sectMap[".switch"]      = new Program.SectionSpec();
program.sectMap[".sysmem"]      = new Program.SectionSpec();
program.sectMap[".text"]        = new Program.SectionSpec();
    
// Must place these sections in core local memory 
program.sectMap[".args"].loadSegment        = "L2SRAM";
program.sectMap[".cio"].loadSegment         = "L2SRAM";

// Variables in the following data sections can potentially be 'shared' in
// OpenMP. These sections must be placed in shared memory.
program.sectMap[".bss"].loadSegment         = "DDR3";
program.sectMap[".cinit"].loadSegment       = "DDR3";
program.sectMap[".const"].loadSegment       = "DDR3";
program.sectMap[".data"].loadSegment        = "DDR3";
program.sectMap[".far"].loadSegment         = "DDR3";
program.sectMap[".fardata"].loadSegment     = "DDR3";
program.sectMap[".neardata"].loadSegment    = "DDR3";
program.sectMap[".rodata"].loadSegment      = "DDR3";
program.sectMap[".sysmem"].loadSegment      = "DDR3";

// Code sections shared by cores - place in shared memory to avoid duplication
program.sectMap[".switch"].loadSegment      = program.platform.codeMemory;
program.sectMap[".text"].loadSegment        = program.platform.codeMemory;

// Size the default stack and place it in L2SRAM 
var deviceName = String(Program.cpu.deviceName);
if  (deviceName.search("DRA7XX") == -1) { program.stack = 0x20000; } 
else                                    { program.stack = 0x8000;  }
program.sectMap[".stack"].loadSegment       = "L2SRAM";

// Since there are no arguments passed to main, set .args size to 0
program.argSize = 0;


/********************************/
/* OPENMP RUNTIME CONFIGURATION */
/********************************/

// Include OMP runtime in the build
var ompSettings = xdc.useModule("ti.runtime.openmp.Settings");

// Set to true if the application uses or has dependencies on BIOS components
ompSettings.usingRtsc = true;

if (ompSettings.usingRtsc)
{
    /* Configure OpenMP for BIOS
     * - OpenMP.configureCores(masterCoreId, numberofCoresInRuntime)
     *       Configures the id of the master core and the number of cores
     *       available to the runtime.
     */

    var OpenMP = xdc.useModule('ti.runtime.ompbios.OpenMP');

    // Configure the index of the master core and the number of cores available
    // to the runtime. The cores are contiguous.
    OpenMP.masterCoreIdx = 0;

    // Setup number of cores based on the device
    if      (deviceName.search("DRA7XX") != -1) { OpenMP.numCores = 2; }
    else if (deviceName.search("6670")   != -1) { OpenMP.numCores = 4; }
    else if (deviceName.search("6657")   != -1) { OpenMP.numCores = 2; }
    else if (deviceName.search("K2L")    != -1) { OpenMP.numCores = 4; }
    else                                        { OpenMP.numCores = 8; }

    // Pull in memory ranges described in Platform.xdc to configure the runtime
    var ddr3       = Program.cpu.memoryMap["DDR3"];
    var ddr3_nc    = Program.cpu.memoryMap["DDR3_NC"];
    var msmc       = Program.cpu.memoryMap["MSMCSRAM"];
    var msmcNcVirt = Program.cpu.memoryMap["OMP_MSMC_NC_VIRT"];
    var msmcNcPhy  = Program.cpu.memoryMap["OMP_MSMC_NC_PHY"];

    // Initialize the runtime with memory range information
    if (deviceName.search("DRA7XX") == -1) {
       OpenMP.msmcBase = msmc.base
       OpenMP.msmcSize = msmc.len;

       OpenMP.msmcNoCacheVirtualBase  = msmcNcVirt.base;
       OpenMP.msmcNoCacheVirtualSize  = msmcNcVirt.len;

       OpenMP.msmcNoCachePhysicalBase  = msmcNcPhy.base;
    }
    else
    {
       OpenMP.allocateStackFromHeap = true;
       OpenMP.allocateStackFromHeapSize = 0x010000;

       OpenMP.hasMsmc = false;
       OpenMP.ddrNoCacheBase = ddr3_nc.base;
       OpenMP.ddrNoCacheSize = ddr3_nc.len;
    }

    OpenMP.ddrBase          = ddr3.base;
    OpenMP.ddrSize          = ddr3.len;

    // Configure memory allocation using HeapOMP
    // HeapOMP handles 
    // - Memory allocation requests from BIOS components (core local memory)
    // - Shared memory allocation by utilizing the IPC module to enable 
    //   multiple cores to allocate memory out of the same heap - used by malloc
    if (deviceName.search("DRA7XX") == -1) {
       var HeapOMP = xdc.useModule('ti.runtime.ompbios.HeapOMP');

       // Shared Region 0 must be initialized for IPC 
       var sharedRegionId = 0;

       // Size of the core local heap
       var localHeapSize  = 0x8000;

       // Size of the heap shared by all the cores
       var sharedHeapSize = 0x08000000;

       // Initialize a Shared Region & create a heap in the DDR3 memory region
       var SharedRegion   = xdc.useModule('ti.sdo.ipc.SharedRegion');
       SharedRegion.setEntryMeta( sharedRegionId,
                                  {   base: ddr3.base,
                                      len:  sharedHeapSize,
                                      ownerProcId: OpenMP.masterCoreIdx,
                                      cacheEnable: true,
                                      createHeap: true,
                                      isValid: true,
                                      name: "DDR3_SR0",
                                  });

       // Configure and setup HeapOMP
       HeapOMP.configure(sharedRegionId, localHeapSize);
    }
    else
    {
       OpenMP.useIpcSharedHeap = false;
       OpenMP.allocateLocalHeapSize = 0x8000
       OpenMP.allocateSharedHeapSize = 0x00800000
    }

    
    var Startup = xdc.useModule('xdc.runtime.Startup');
    Startup.lastFxns.$add('&__TI_omp_initialize_rtsc_mode');
}
else
{
    /* Size the heap. It must be placed in shared memory */
    program.heap = sharedHeapSize;
}

One thing, is that if I change the shared heap size, the start address for other stuff in the DDR3 segment don't change ...

Regards

  • Unfortunately, TI's OpenMP solution does not support C++.  See the note at the end of the TI OpenMP Documentation introduction page.

    Thanks and regards,

    -George

  • I understand but I compile the cpp files with out the--openmp flag, though for c files I set omp flag ... isn't that supposed to work that way? because the code compiles and link just fine.

    What if I use malloc? Let me try and update...

  • But, I am changing the right place in the cfg file to increase the heap size to be used by malloc function ?

  • Mike ITGeek said:
    I understand but I compile the cpp files with out the--openmp flag, though for c files I set omp flag ... isn't that supposed to work that way?

    Yes, that should work.

    Thanks and regards,

    -George

  • Mike ITGeek said:
    But, I am changing the right place in the cfg file to increase the heap size to be used by malloc function ?

    I don't know.  I'll notify the TI-RTOS experts about this thread.

    Thanks and regards,

    -George

  • Hi Mike,

    malloc() is provided by SYS/BIOS. It uses the kernel's default system heap (not the compilers heap). I'm not familiar with the OpenMP code, so I'm not sure what the above configuration is doing in regards to heaps. If you need information about this, we can move this thread to the processors forum.

    Todd

  • Hi Todd,

    Thanks for the input ... I agree the malloc() is taken care by SYS/BIOS; and OpenMP, however offers two other types of heap as per Heap Management API.

    1. Heaps in Shared Memory (DDR or MSMC)

    2. Heap in Local Memory (L2SRAM)

    which is NOT my concern at the moment ...

    I guess since I do all memory allocations in C++ via malloc/new, I only need to know how to adjust the size of malloc(SYS/BIOS) heap via the .cfg file. If you could let me know how I can adjust the SYS/BIOS/malloc heap size in *.cfg (an cfg example from openmp example is provided above) that would be very helpful and much appreciated.

    Also, if you show me a reference on details of *.cfg files, that would be of great help too.

    Also, need to know if I oversize the malloc heap, would linker throw an error or some sort of warning?

    If you think processor team can help better, please feel free to forward the thread to them. But, It seems to be more TI-RTOS related ... because I get to see the below thread discussed in TI-RTOS ... anyway you guys know better :)

    https://e2e.ti.com/support/legacy_forums/embedded/tirtos/f/355/t/108589

    Regards,

    UPDATE

     

    I think it is described in detail under ...  SYS/BIOS (TI-RTOS Kernel) User's Guide (Rev. U)

    I will try and let you know if any thing .... Stay safe while self-isolating from pandemic

    Cheers

     

  • I seem to be able to figure that out by looking at : SYS/BIOS (TI-RTOS Kernel) User's Guide (Rev. U)

    var BIOS = xdc.useModule('ti.sysbios.BIOS');

    Program.sectMap["systemHeap"]    = new Program.SectionSpec();
    Program.sectMap["systemHeap"].loadSegment    = "DDR3";

    BIOS.heapSize = 0x12000000;                  
    BIOS.heapSection = "systemHeap";

    But, I would like an SYS/BIOS/TI-RTOS guy to comment on that too please .... (it can be helpful for future newbies too)

    And I have one more question .... how would I be able to find out the default value BIOS.heapSize?

    Thank you