Ignore:
Timestamp:
Nov 4, 2016, 8:26:00 PM (3 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Add first code for ROCm binary generator.

File:
1 edited

Legend:

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

    r2533 r2534  
    2020#include <CLRX/Config.h>
    2121#include <cstdint>
     22#include <algorithm>
    2223#include <utility>
    23 #include <CLRX/amdbin/Elf.h>
     24#include <CLRX/amdbin/ElfBinaries.h>
    2425#include <CLRX/utils/Utilities.h>
    2526#include <CLRX/utils/MemAccess.h>
     27#include <CLRX/utils/InputOutput.h>
     28#include <CLRX/utils/Containers.h>
    2629#include <CLRX/amdbin/ROCmBinaries.h>
    2730
     
    132135    return true;
    133136}
     137
     138/*
     139 * ROCm Binary Generator
     140 */
     141
     142ROCmBinGenerator::ROCmBinGenerator() : manageable(false), input(nullptr)
     143{ }
     144
     145ROCmBinGenerator::ROCmBinGenerator(const ROCmInput* rocmInput)
     146        : manageable(false), input(rocmInput)
     147{ }
     148
     149ROCmBinGenerator::ROCmBinGenerator(GPUDeviceType deviceType,
     150        uint32_t archMinor, uint32_t archStepping, size_t codeSize, const cxbyte* code,
     151        const std::vector<ROCmSymbolInput>& symbols)
     152{
     153    input = new ROCmInput{ deviceType, archMinor, archStepping, symbols, codeSize, code };
     154}
     155
     156ROCmBinGenerator::ROCmBinGenerator(GPUDeviceType deviceType,
     157        uint32_t archMinor, uint32_t archStepping, size_t codeSize, const cxbyte* code,
     158        std::vector<ROCmSymbolInput>&& symbols)
     159{
     160    input = new ROCmInput{ deviceType, archMinor, archStepping, std::move(symbols),
     161                codeSize, code };
     162}
     163
     164ROCmBinGenerator::~ROCmBinGenerator()
     165{
     166    if (manageable)
     167        delete input;
     168}
     169
     170void ROCmBinGenerator::setInput(const ROCmInput* input)
     171{
     172    if (manageable)
     173        delete input;
     174    manageable = false;
     175    this->input = input;
     176}
     177
     178void ROCmBinGenerator::generateInternal(std::ostream* osPtr, std::vector<char>* vPtr,
     179             Array<cxbyte>* aPtr) const
     180{
     181    ElfBinaryGen64 elfBinGen64;
     182    elfBinGen64.addRegion(ElfRegion64(0, (const cxbyte*)nullptr, 8,
     183                ".dynsym", SHT_DYNSYM, SHF_ALLOC, 3, 1));
     184   
     185    size_t binarySize;
     186    /****
     187     * prepare for write binary to output
     188     ****/
     189    std::unique_ptr<std::ostream> outStreamHolder;
     190    std::ostream* os = nullptr;
     191    if (aPtr != nullptr)
     192    {
     193        aPtr->resize(binarySize);
     194        outStreamHolder.reset(
     195                new ArrayOStream(binarySize, reinterpret_cast<char*>(aPtr->data())));
     196        os = outStreamHolder.get();
     197    }
     198    else if (vPtr != nullptr)
     199    {
     200        vPtr->resize(binarySize);
     201        outStreamHolder.reset(new VectorOStream(*vPtr));
     202        os = outStreamHolder.get();
     203    }
     204    else // from argument
     205        os = osPtr;
     206   
     207    const std::ios::iostate oldExceptions = os->exceptions();
     208    try
     209    {
     210    os->exceptions(std::ios::failbit | std::ios::badbit);
     211    /****
     212     * write binary to output
     213     ****/
     214    //elfBinGen64->generate(bos);
     215    //assert(bos.getWritten() == binarySize);
     216    }
     217    catch(...)
     218    {
     219        os->exceptions(oldExceptions);
     220        throw;
     221    }
     222    os->exceptions(oldExceptions);
     223}
     224
     225void ROCmBinGenerator::generate(Array<cxbyte>& array) const
     226{
     227    generateInternal(nullptr, nullptr, &array);
     228}
     229
     230void ROCmBinGenerator::generate(std::ostream& os) const
     231{
     232    generateInternal(&os, nullptr, nullptr);
     233}
     234
     235void ROCmBinGenerator::generate(std::vector<char>& v) const
     236{
     237    generateInternal(nullptr, &v, nullptr);
     238}
Note: See TracChangeset for help on using the changeset viewer.