Changeset 2517 in CLRX


Ignore:
Timestamp:
Nov 1, 2016, 11:53:03 AM (3 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Add code to handle ROCm in Disassembler. simplify getROCmDisasmInputFromBinary declaration.

Location:
CLRadeonExtender/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdasm/Disassembler.h

    r2516 r2517  
    3333#include <CLRX/amdbin/AmdBinaries.h>
    3434#include <CLRX/amdbin/AmdCL2Binaries.h>
     35#include <CLRX/amdbin/ROCmBinaries.h>
    3536#include <CLRX/amdbin/GalliumBinaries.h>
    3637#include <CLRX/amdbin/AmdBinGen.h>
     
    257258};
    258259
     260struct ROCmDisasmRegion
     261{
     262    size_t size;
     263    size_t offset;
     264    size_t kernelIndex;
     265};
     266
    259267struct ROCmDisasmInput
    260268{
     
    263271    uint32_t archStepping;     ///< GPU arch stepping
    264272    std::vector<ROCmDisasmKernelInput> kernels;    ///< kernel inputs
     273    std::vector<ROCmDisasmRegion> regions;  ///< regions
     274    size_t codeSize;    ///< code size
     275    const cxbyte* code; ///< code
    265276};
    266277
     
    306317        const AmdCL2DisasmInput* amdCL2Input;
    307318        const GalliumDisasmInput* galliumInput;
     319        const ROCmDisasmInput* rocmInput;
    308320        const RawCodeInput* rawInput;
    309321    };
     
    336348    Disassembler(const AmdCL2MainGPUBinary& binary, std::ostream& output,
    337349                 Flags flags = 0);
     350    /// constructor for ROCm GPU binary
     351    /**
     352     * \param binary main GPU binary
     353     * \param output output stream
     354     * \param flags flags for disassembler
     355     */
     356    Disassembler(const ROCmBinary& binary, std::ostream& output, Flags flags = 0);
    338357    /// constructor for AMD disassembler input
    339358    /**
     
    351370     */
    352371    Disassembler(const AmdCL2DisasmInput* disasmInput, std::ostream& output,
     372                 Flags flags = 0);
     373    /// constructor for ROCMm disassembler input
     374    /**
     375     * \param disasmInput disassembler input object
     376     * \param output output stream
     377     * \param flags flags for disassembler
     378     */
     379    Disassembler(const ROCmDisasmInput* disasmInput, std::ostream& output,
    353380                 Flags flags = 0);
    354381   
  • CLRadeonExtender/trunk/amdasm/DisasmInternals.h

    r2516 r2517  
    7171
    7272extern CLRX_INTERNAL ROCmDisasmInput* getROCmDisasmInputFromBinary(
    73             GPUDeviceType deviceType, const ROCmBinary& binary, Flags flags);
     73            const ROCmBinary& binary);
    7474
    7575extern CLRX_INTERNAL GalliumDisasmInput* getGalliumDisasmInputFromBinary(
  • CLRadeonExtender/trunk/amdasm/DisasmROCm.cpp

    r2516 r2517  
    6767};
    6868
    69 ROCmDisasmInput* CLRX::getROCmDisasmInputFromBinary(GPUDeviceType deviceType,
    70            const ROCmBinary& binary, Flags flags)
     69ROCmDisasmInput* CLRX::getROCmDisasmInputFromBinary(const ROCmBinary& binary)
    7170{
    7271    std::unique_ptr<ROCmDisasmInput> input(new ROCmDisasmInput);
    7372    uint32_t archMajor = 0;
     73    const uint16_t textIndex = binary.getSectionIndex(".text");
     74   
    7475    {
    7576        const cxbyte* noteContent = binary.getSectionContent(".note");
     
    107108        throw Exception("Can't determine device type from arch values!");
    108109    input->deviceType = GPUDeviceType(deviceNumber);
     110   
     111    input->code = binary.getSectionContent(textIndex);
     112    input->codeSize = ULEV(binary.getSectionHeader(textIndex).sh_size);
    109113    return input.release();
    110114}
  • CLRadeonExtender/trunk/amdasm/Disassembler.cpp

    r2516 r2517  
    268268}
    269269
     270Disassembler::Disassembler(const ROCmBinary& binary, std::ostream& _output, Flags _flags)
     271         : fromBinary(true), binaryFormat(BinaryFormat::ROCM),
     272           rocmInput(nullptr), output(_output), flags(_flags), sectionCount(0)
     273{
     274    isaDisassembler.reset(new GCNDisassembler(*this));
     275    rocmInput = getROCmDisasmInputFromBinary(binary);
     276}
     277
    270278Disassembler::Disassembler(const AmdDisasmInput* disasmInput, std::ostream& _output,
    271279            Flags _flags) : fromBinary(false), binaryFormat(BinaryFormat::AMD),
     
    278286            Flags _flags) : fromBinary(false), binaryFormat(BinaryFormat::AMDCL2),
    279287            amdCL2Input(disasmInput), output(_output), flags(_flags), sectionCount(0)
     288{
     289    isaDisassembler.reset(new GCNDisassembler(*this));
     290}
     291
     292Disassembler::Disassembler(const ROCmDisasmInput* disasmInput, std::ostream& _output,
     293                 Flags _flags) : fromBinary(false), binaryFormat(BinaryFormat::ROCM),
     294            rocmInput(disasmInput), output(_output), flags(_flags), sectionCount(0)
    280295{
    281296    isaDisassembler.reset(new GCNDisassembler(*this));
     
    311326    if (fromBinary)
    312327    {
    313         if (binaryFormat == BinaryFormat::AMD)
    314             delete amdInput;
    315         else if (binaryFormat == BinaryFormat::GALLIUM)
    316             delete galliumInput;
    317         else if (binaryFormat == BinaryFormat::AMDCL2)
    318             delete amdCL2Input;
    319         else // raw code input
    320             delete rawInput;
     328        switch(binaryFormat)
     329        {
     330            case BinaryFormat::AMD:
     331                delete amdInput;
     332                break;
     333            case BinaryFormat::GALLIUM:
     334                delete galliumInput;
     335                break;
     336            case BinaryFormat::ROCM:
     337                delete rocmInput;
     338                break;
     339            case BinaryFormat::AMDCL2:
     340                delete amdCL2Input;
     341                break;
     342            default:
     343                delete rawInput;
     344        }
    321345    }
    322346}
     
    324348GPUDeviceType Disassembler::getDeviceType() const
    325349{
    326     if (binaryFormat == BinaryFormat::AMD)
    327         return amdInput->deviceType;
    328     else if (binaryFormat == BinaryFormat::AMDCL2)
    329         return amdCL2Input->deviceType;
    330     else if (binaryFormat == BinaryFormat::GALLIUM)
    331         return galliumInput->deviceType;
    332     else // rawcode
    333         return rawInput->deviceType;
     350    switch(binaryFormat)
     351    {
     352        case BinaryFormat::AMD:
     353            return amdInput->deviceType;
     354        case BinaryFormat::AMDCL2:
     355            return amdCL2Input->deviceType;
     356        case BinaryFormat::ROCM:
     357            return rocmInput->deviceType;
     358        case BinaryFormat::GALLIUM:
     359            return galliumInput->deviceType;
     360        default:
     361            return rawInput->deviceType;
     362    }
    334363}
    335364
     
    504533    try
    505534    {
    506     if (binaryFormat == BinaryFormat::AMD)
    507         output.write(".amd\n", 5);
    508     else if (binaryFormat == BinaryFormat::AMDCL2)
    509         output.write(".amdcl2\n", 8);
    510     else if (binaryFormat == BinaryFormat::GALLIUM) // Gallium
    511         output.write(".gallium\n", 9);
    512     else // raw code
    513         output.write(".rawcode\n", 9);
     535    switch(binaryFormat)
     536    {
     537        case BinaryFormat::AMD:
     538            output.write(".amd\n", 5);
     539            break;
     540        case BinaryFormat::AMDCL2:
     541            output.write(".amdcl2\n", 8);
     542            break;
     543        case BinaryFormat::ROCM:
     544            output.write(".rocm\n", 6);
     545            break;
     546        case BinaryFormat::GALLIUM: // Gallium
     547            output.write(".gallium\n", 9);
     548            break;
     549        default:
     550            output.write(".rawcode\n", 9);
     551    }
    514552   
    515553    const GPUDeviceType deviceType = getDeviceType();
     
    519557    output.put('\n');
    520558   
    521     if (binaryFormat == BinaryFormat::AMD)
    522         disassembleAmd(output, amdInput, isaDisassembler.get(), sectionCount, flags);
    523     else if (binaryFormat == BinaryFormat::AMDCL2)
    524         disassembleAmdCL2(output, amdCL2Input, isaDisassembler.get(), sectionCount, flags);
    525     else if (binaryFormat == BinaryFormat::GALLIUM) // Gallium
    526         disassembleGallium(output, galliumInput, isaDisassembler.get(),
    527                    sectionCount, flags);
    528     else // raw code input
    529         disassembleRawCode(output, rawInput, isaDisassembler.get(), sectionCount, flags);
     559    switch(binaryFormat)
     560    {
     561        case BinaryFormat::AMD:
     562            disassembleAmd(output, amdInput, isaDisassembler.get(), sectionCount, flags);
     563            break;
     564        case BinaryFormat::AMDCL2:
     565            disassembleAmdCL2(output, amdCL2Input, isaDisassembler.get(),
     566                              sectionCount, flags);
     567            break;
     568        case BinaryFormat::ROCM:
     569            disassembleROCm(output, rocmInput, isaDisassembler.get(),
     570                              sectionCount, flags);
     571            break;
     572        case BinaryFormat::GALLIUM: // Gallium
     573            disassembleGallium(output, galliumInput, isaDisassembler.get(),
     574                           sectionCount, flags);
     575            break;
     576        default:
     577            disassembleRawCode(output, rawInput, isaDisassembler.get(),
     578                           sectionCount, flags);
     579    }
    530580    output.flush();
    531581    } /* try catch */
Note: See TracChangeset for help on using the changeset viewer.