Changeset 2502 in CLRX


Ignore:
Timestamp:
Oct 29, 2016, 10:56:44 PM (4 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Tentative ROCmBinary constructor.

Location:
CLRadeonExtender/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdbin/ROCmBinaries.h

    r2501 r2502  
    4040
    4141enum : Flags {
    42     ROCMBIN_CREATE_KERNELDATA = 0x10,    ///< create kernel setup
    43     ROCMBIN_CREATE_KERNELDATAMAP = 0x20,    ///< create kernel setups map
     42    ROCMBIN_CREATE_KERNELMAP = 0x10,    ///< create kernel setups map
    4443   
    4544    ROCMBIN_CREATE_ALL = ELF_CREATE_ALL | 0xfff0 ///< all ROCm binaries flags
     
    5049{
    5150    CString kernelName; ///< kernel name
    52     size_t setupSize;   ///< setup size
    5351    cxbyte* setup;      ///< setup data
    54     size_t codeSize;    ///< size
    5552    cxbyte* code;     ///< data
    5653};
     
    6865    std::unique_ptr<ROCmKernel[]> kernels;  ///< AMD metadatas
    6966    KernelMap kernelsMap;
     67    size_t codeSize;
     68    cxbyte* code;
    7069public:
    7170    ROCmBinary(size_t binaryCodeSize, cxbyte* binaryCode,
     
    8281    /// get kernel by name
    8382    const ROCmKernel& getKernel(const char* name) const;
     83   
     84    /// get code size
     85    size_t getCodeSize() const
     86    { return codeSize; }
     87    /// get code
     88    const cxbyte* getCode() const
     89    { return code; }
     90   
     91    bool hasKernelMap() const
     92    { return (creationFlags & ROCMBIN_CREATE_KERNELMAP) != 0; };
    8493};
    8594
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r2501 r2502  
    3434
    3535ROCmBinary::ROCmBinary(size_t binaryCodeSize, cxbyte* binaryCode, Flags creationFlags)
    36         : ElfBinary64(binaryCodeSize, binaryCode, creationFlags)
     36        : ElfBinary64(binaryCodeSize, binaryCode, creationFlags),
     37          kernelsNum(0), codeSize(0), code(nullptr)
    3738{
     39    cxuint textIndex = SHN_UNDEF;
     40    try
     41    { textIndex = getSectionIndex(".text"); }
     42    catch(const Exception& ex)
     43    { } // ignore failed
     44    if (textIndex!=SHN_UNDEF)
     45    {
     46        code = getSectionContent(textIndex);
     47        codeSize = ULEV(getSectionHeader(textIndex).sh_size);
     48    }
     49   
     50    kernelsNum = 0;
     51    const size_t symbolsNum = getSymbolsNum();
     52    for (size_t i = 0; i < symbolsNum; i++)
     53    {
     54        const Elf64_Sym& sym = getSymbol(i);
     55        if (sym.st_shndx==textIndex)
     56            kernelsNum++;
     57    }
     58    if (code==nullptr && kernelsNum!=0)
     59        throw Exception("No code if kernels number is not zero");
     60    kernels.reset(new ROCmKernel[kernelsNum]);
     61    size_t j = 0;
     62    for (size_t i = 0; i < symbolsNum; i++)
     63    {
     64        const Elf64_Sym& sym = getSymbol(i);
     65        if (sym.st_shndx!=textIndex)
     66            continue;
     67        const size_t value = ULEV(sym.st_value);
     68        kernels[j++] = { getSymbolName(i), code+value, code+value+0x100 };
     69    }
     70    if (hasKernelMap())
     71    {   // create kernels map
     72        kernelsMap.resize(kernelsNum);
     73        for (size_t i = 0; i < kernelsNum; i++)
     74            kernelsMap[i] = std::make_pair(kernels[i].kernelName, i);
     75        mapSort(kernelsMap.begin(), kernelsMap.end());
     76    }
    3877}
    3978
     
    5190    if (!isElfBinary(binarySize, binary))
    5291        return false;
     92        return false;
    5393    if (binary[EI_CLASS] != ELFCLASS64)
    5494        return false;
Note: See TracChangeset for help on using the changeset viewer.