Changeset 2561 in CLRX


Ignore:
Timestamp:
Nov 11, 2016, 10:07:43 AM (3 years ago)
Author:
matszpk
Message:

CLRadeonExtender: ROCmBinGen: Add programheaders and elfheader. Add PHREGION_FILESTART (not supported yet).
Cosmetic changes.

Location:
CLRadeonExtender/trunk
Files:
4 edited

Legend:

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

    r2556 r2561  
    677677typedef ElfRegionTemplate<Elf64Types> ElfRegion64;
    678678
     679enum {
     680    PHREGION_FILESTART = UINT_MAX
     681};
    679682/// template of ELF program header
    680683template<typename Types>
     
    689692    typename Types::Word vaddrBase;  ///< vaddr base
    690693    typename Types::Word memSize;    ///< size in memory
     694    typename Types::Word align;      ///< alignment
    691695};
    692696
  • CLRadeonExtender/trunk/amdbin/AmdCL2BinGen.cpp

    r2556 r2561  
    19451945             * AMD - 5 - size=0x19 \x16\000-hsa_call_convention=\0\0
    19461946             */
    1947             innerBinGen->addNote(ElfNote{"AMD", sizeof noteDescType1, noteDescType1, 1U});
    1948             innerBinGen->addNote(ElfNote{"AMD", sizeof noteDescType2, noteDescType2, 2U});
     1947            innerBinGen->addNote({"AMD", sizeof noteDescType1, noteDescType1, 1U});
     1948            innerBinGen->addNote({"AMD", sizeof noteDescType2, noteDescType2, 2U});
    19491949            noteBuf.reset(new cxbyte[0x1a]);
    19501950            ::memcpy(noteBuf.get(), noteDescType3, 0x1a);
     
    19521952            SULEV(*(uint32_t*)(noteBuf.get()+8), amdGpuArchValues.minor);
    19531953            SULEV(*(uint32_t*)(noteBuf.get()+12), amdGpuArchValues.stepping);
    1954             innerBinGen->addNote(ElfNote{"AMD", 0x1a, noteBuf.get(), 3U});
    1955             innerBinGen->addNote(ElfNote{"AMD",
     1954            innerBinGen->addNote({"AMD", 0x1a, noteBuf.get(), 3U});
     1955            innerBinGen->addNote({"AMD",
    19561956                         sizeof noteDescType4_16_3, noteDescType4_16_3, 4U});
    19571957            if (!gpuProDriver)
    1958                 innerBinGen->addNote(ElfNote{"AMD",
     1958                innerBinGen->addNote({"AMD",
    19591959                             sizeof noteDescType5_16_3, noteDescType5_16_3, 5U});
    19601960            else
    1961                 innerBinGen->addNote(ElfNote{"AMD",
     1961                innerBinGen->addNote({"AMD",
    19621962                             sizeof noteDescType5_gpupro, noteDescType5_gpupro, 5U});
    19631963           
     
    20352035             * AMD - 4 - size=8 random values 0x7ffXXXXXXXX
    20362036             */
    2037             innerBinGen->addNote(ElfNote{"AMD", sizeof noteDescType1, noteDescType1, 1U});
    2038             innerBinGen->addNote(ElfNote{"AMD", sizeof noteDescType2, noteDescType2, 2U});
    2039             innerBinGen->addNote(ElfNote{"AMD", sizeof noteDescType5, noteDescType5, 5U});
     2037            innerBinGen->addNote({"AMD", sizeof noteDescType1, noteDescType1, 1U});
     2038            innerBinGen->addNote({"AMD", sizeof noteDescType2, noteDescType2, 2U});
     2039            innerBinGen->addNote({"AMD", sizeof noteDescType5, noteDescType5, 5U});
    20402040            noteBuf.reset(new cxbyte[0x1e]);
    20412041            ::memcpy(noteBuf.get(), noteDescType3, 0x1e);
     
    20432043            SULEV(*(uint32_t*)(noteBuf.get()+8), amdGpuArchValues.minor);
    20442044            SULEV(*(uint32_t*)(noteBuf.get()+12), amdGpuArchValues.stepping);
    2045             innerBinGen->addNote(ElfNote{"AMD", 0x1e, noteBuf.get(), 3U});
    2046             innerBinGen->addNote(ElfNote{"AMD", sizeof noteDescType4, noteDescType4, 4U});
     2045            innerBinGen->addNote({"AMD", 0x1e, noteBuf.get(), 3U});
     2046            innerBinGen->addNote({"AMD", sizeof noteDescType4, noteDescType4, 4U});
    20472047           
    20482048            innerBinGen->addRegion(ElfRegion64(0, (const cxbyte*)nullptr, 8,
  • CLRadeonExtender/trunk/amdbin/ElfBinaries.cpp

    r2557 r2561  
    850850                SLEV(phdr.p_offset, !zeroOffset ?
    851851                        regionOffsets[progHeader.regionStart] : 0);
    852                 typename Types::Word align = (sregion.type==ElfRegionType::SECTION) ?
    853                         sregion.section.align : 0;
    854                 align = std::max(sregion.align, align);
    855                 SLEV(phdr.p_align, align);
     852                if (progHeader.align==0)
     853                {
     854                    typename Types::Word align = (sregion.type==ElfRegionType::SECTION) ?
     855                            sregion.section.align : 0;
     856                    align = std::max(sregion.align, align);
     857                    SLEV(phdr.p_align, align);
     858                }
     859                else
     860                    SLEV(phdr.p_align, progHeader.align);
    856861               
    857862                /* paddrBase and vaddrBase is base to program header virtual and physical
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r2557 r2561  
    186186  'A', 'M', 'D', 0, 'A', 'M', 'D', 'G', 'P', 'U', 0 };
    187187
     188struct AMDGPUArchValues
     189{
     190    uint32_t major;
     191    uint32_t minor;
     192    uint32_t stepping;
     193};
     194
     195static const AMDGPUArchValues amdGpuArchValuesTbl[] =
     196{
     197    { 0, 0, 0 }, // GPUDeviceType::CAPE_VERDE
     198    { 0, 0, 0 }, // GPUDeviceType::PITCAIRN
     199    { 0, 0, 0 }, // GPUDeviceType::TAHITI
     200    { 0, 0, 0 }, // GPUDeviceType::OLAND
     201    { 7, 0, 0 }, // GPUDeviceType::BONAIRE
     202    { 7, 0, 0 }, // GPUDeviceType::SPECTRE
     203    { 7, 0, 0 }, // GPUDeviceType::SPOOKY
     204    { 7, 0, 0 }, // GPUDeviceType::KALINDI
     205    { 0, 0, 0 }, // GPUDeviceType::HAINAN
     206    { 7, 0, 1 }, // GPUDeviceType::HAWAII
     207    { 8, 0, 0 }, // GPUDeviceType::ICELAND
     208    { 8, 0, 0 }, // GPUDeviceType::TONGA
     209    { 7, 0, 0 }, // GPUDeviceType::MULLINS
     210    { 8, 0, 3 }, // GPUDeviceType::FIJI
     211    { 8, 0, 1 }, // GPUDeviceType::CARRIZO
     212    { 0, 0, 0 }, // GPUDeviceType::DUMMY
     213    { 0, 0, 0 }, // GPUDeviceType::GOOSE
     214    { 0, 0, 0 }, // GPUDeviceType::HORSE
     215    { 8, 0, 1 }, // GPUDeviceType::STONEY
     216    { 8, 0, 4 }, // GPUDeviceType::ELLESMERE
     217    { 8, 0, 4 } // GPUDeviceType::BAFFIN
     218};
     219
     220
    188221void ROCmBinGenerator::generateInternal(std::ostream* osPtr, std::vector<char>* vPtr,
    189222             Array<cxbyte>* aPtr) const
    190223{
     224    const GPUArchitecture arch = getGPUArchitectureFromDeviceType(input->deviceType);
     225    if (arch == GPUArchitecture::GCN1_0)
     226        throw Exception("OpenCL 2.0 supported only for GCN1.1 or later");
     227   
     228    AMDGPUArchValues amdGpuArchValues = amdGpuArchValuesTbl[cxuint(input->deviceType)];
     229    if (input->archMinor!=UINT32_MAX)
     230        amdGpuArchValues.minor = input->archMinor;
     231    if (input->archStepping!=UINT32_MAX)
     232        amdGpuArchValues.stepping = input->archStepping;
     233   
    191234    const char* comment = "CLRX ROCmBinGenerator " CLRX_VERSION;
    192235    uint32_t commentSize = ::strlen(comment);
     
    199242    }
    200243   
    201     ElfBinaryGen64 elfBinGen64;
     244    ElfBinaryGen64 elfBinGen64({ 0U, 0U, 0x40, EV_CURRENT, ET_DYN,
     245        0xe0, EV_CURRENT, 0, 0, 0 });
    202246    // add symbols
    203247    elfBinGen64.addDynSymbol(ElfSymbol64("_DYNAMIC", 5,
     
    221265        DT_SYMTAB, DT_SYMENT, DT_STRTAB, DT_STRSZ, DT_HASH };
    222266    elfBinGen64.addDynamics(sizeof(dynTags)/sizeof(int32_t), dynTags);
    223    
    224     elfBinGen64.addNote(ElfNote{"AMD", sizeof noteDescType1, noteDescType1, 1U});
     267    // elf program headers
     268    elfBinGen64.addProgramHeader({ PT_PHDR, PF_R, 0, 1, true, 0, 0, 0 });
     269    elfBinGen64.addProgramHeader({ PT_LOAD, PF_R, PHREGION_FILESTART, 4,
     270                    true, 0, 0, 0, 0x1000 });
     271    elfBinGen64.addProgramHeader({ PT_LOAD, PF_R|PF_X, 4, 1, true, 0, 0, 0 });
     272    elfBinGen64.addProgramHeader({ PT_LOAD, PF_R|PF_W, 5, 1, true, 0, 0, 0 });
     273    elfBinGen64.addProgramHeader({ PT_DYNAMIC, PF_R|PF_W, 5, 1, true, 0, 0, 0, 8 });
     274    elfBinGen64.addProgramHeader({ PT_GNU_RELRO, PF_R, 5, 1, true, 0, 0, 0, 1 });
     275    elfBinGen64.addProgramHeader({ PT_GNU_STACK, PF_R|PF_W, 0, 0, true, 0, 0, 0 });
     276   
     277    // elf notes
     278    elfBinGen64.addNote({"AMD", sizeof noteDescType1, noteDescType1, 1U});
    225279    std::unique_ptr<cxbyte[]> noteBuf(new cxbyte[0x1b]);
    226280    ::memcpy(noteBuf.get(), noteDescType3, 0x1b);
    227     //SULEV(*(uint32_t*)(noteBuf.get()+4), amdGpuArchValues.major);
    228     //SULEV(*(uint32_t*)(noteBuf.get()+8), amdGpuArchValues.minor);
    229     //SULEV(*(uint32_t*)(noteBuf.get()+12), amdGpuArchValues.stepping);
    230     elfBinGen64.addNote(ElfNote{"AMD", 0x1b, noteBuf.get(), 3U});
    231    
     281    SULEV(*(uint32_t*)(noteBuf.get()+4), amdGpuArchValues.major);
     282    SULEV(*(uint32_t*)(noteBuf.get()+8), amdGpuArchValues.minor);
     283    SULEV(*(uint32_t*)(noteBuf.get()+12), amdGpuArchValues.stepping);
     284    elfBinGen64.addNote({"AMD", 0x1b, noteBuf.get(), 3U});
     285   
     286    /// region and sections
    232287    elfBinGen64.addRegion(ElfRegion64::programHeaderTable());
    233288    elfBinGen64.addRegion(ElfRegion64::dynsymSection());
Note: See TracChangeset for help on using the changeset viewer.