Changeset 2512 in CLRX


Ignore:
Timestamp:
Oct 30, 2016, 4:29:49 PM (4 years ago)
Author:
matszpk
Message:

CLRadeonExtender: ROCm: fixing determining kernel sizes (include symbols between/after kernels). Fixed obtaining kernels from symbols.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r2510 r2512  
    4747   
    4848    kernelsNum = 0;
     49    size_t symsNum = 0;
    4950    const size_t symbolsNum = getSymbolsNum();
    5051    for (size_t i = 0; i < symbolsNum; i++)
     
    5253        const Elf64_Sym& sym = getSymbol(i);
    5354        if (sym.st_shndx==textIndex)
    54             kernelsNum++;
     55        {
     56            if (ELF64_ST_TYPE(sym.st_info)==10)
     57                kernelsNum++;
     58            symsNum++;
     59        }
    5560    }
    5661    if (code==nullptr && kernelsNum!=0)
    5762        throw Exception("No code if kernels number is not zero");
    5863    kernels.reset(new ROCmKernel[kernelsNum]);
    59     size_t j = 0;
     64    size_t j = 0, k = 0;
     65    typedef std::pair<uint64_t, size_t> KernelOffsetEntry;
     66    std::unique_ptr<KernelOffsetEntry[]> symOffsets(new KernelOffsetEntry[symsNum]);
    6067   
    61     typedef std::pair<uint64_t, size_t> KernelOffsetEntry;
    62     std::unique_ptr<KernelOffsetEntry[]> kernelOffsets(new KernelOffsetEntry[kernelsNum]);
    6368    for (size_t i = 0; i < symbolsNum; i++)
    6469    {
     
    7075            throw Exception("Kernel offset is too small!");
    7176        const size_t size = ULEV(sym.st_size);
     77        if (ELF64_ST_TYPE(sym.st_info)!=10)
     78        {
     79            symOffsets[k++] = std::make_pair(value, SIZE_MAX);
     80            continue;
     81        }
     82        else // if kernel symbol
     83            symOffsets[k++] = std::make_pair(value, j);
     84       
    7285        if (value+0x100 > codeOffset+codeSize)
    7386            throw Exception("Kernel offset is too big!");
    74         kernelOffsets[j] = std::make_pair(value, j);
    7587        kernels[j++] = { getSymbolName(i), value, size, value+0x100 };
    7688    }
    77     std::sort(kernelOffsets.get(), kernelOffsets.get()+kernelsNum,
     89    std::sort(symOffsets.get(), symOffsets.get()+symsNum,
    7890            [](const KernelOffsetEntry& a, const KernelOffsetEntry& b)
    7991            { return a.first < b.first; });
    8092    // checking distance between kernels
    81     for (size_t i = 1; i < kernelsNum; i++)
     93    for (size_t i = 1; i <= symsNum; i++)
    8294    {
    83         if (kernelOffsets[i-1].first+0x100 > kernelOffsets[i].first)
     95        if (symOffsets[i-1].second==SIZE_MAX)
     96            continue;   // if not kernel symbol
     97        size_t end = (i<symsNum) ? symOffsets[i].first : codeOffset+codeSize;
     98        if (symOffsets[i-1].first+0x100 > end)
    8499            throw Exception("Kernel size is too small!");
    85         ROCmKernel& kernel = kernels[kernelOffsets[i-1].second];
    86         uint64_t kcodeSize = kernelOffsets[i].first - (kernelOffsets[i-1].first+0x100);
    87         if (kernel.codeSize==0 && kcodeSize>0)
     100        ROCmKernel& kernel = kernels[symOffsets[i-1].second];
     101        uint64_t kcodeSize = end - (symOffsets[i-1].first+0x100);
     102        if (kernel.codeSize==0)
    88103            kernel.codeSize = kcodeSize;
    89         if (kernel.codeSize > kcodeSize)
    90             throw Exception("Kernel code size out of range");
    91     }
    92     {   // last kernel in position
    93         if (kernelOffsets[kernelsNum-1].first+0x100 > codeOffset+codeSize)
    94             throw Exception("Kernel size is too small!");
    95         ROCmKernel& kernel = kernels[kernelOffsets[kernelsNum-1].second];
    96         uint64_t kcodeSize = codeSize -
    97                 (kernelOffsets[kernelsNum-1].first+0x100-codeOffset);
    98         if (kernel.codeSize==0 && kcodeSize>0)
    99             kernel.codeSize = kcodeSize;
    100         if (kernel.codeSize > kcodeSize)
    101             throw Exception("Kernel code size out of range");
     104        else
     105            kernel.codeSize = std::min(kcodeSize, kernel.codeSize);
    102106    }
    103107   
Note: See TracChangeset for help on using the changeset viewer.