Changeset 3726 in CLRX


Ignore:
Timestamp:
Feb 6, 2018, 3:54:23 PM (15 months ago)
Author:
matszpk
Message:

CLRadeonExtender: DisasmAmd?&DisasmROCm: Check arg types and other fields before printing.
ROCmMetadata: Check arg types and other fields before generating. Escape number in string fields.
AsmROCm: Add additional pseudo-ops (only names) to set metadata info.

Location:
CLRadeonExtender/trunk
Files:
7 edited

Legend:

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

    r3724 r3726  
    8383    HIDDEN_PRINTF_BUFFER,   ///< buffer for printf calls
    8484    HIDDEN_DEFAULT_QUEUE,   ///< OpenCL default queue
    85     HIDDEN_COMPLETION_ACTION    ///< ???
     85    HIDDEN_COMPLETION_ACTION,    ///< ???
     86    MAX_VALUE = HIDDEN_COMPLETION_ACTION
    8687};
    8788
     
    100101    INT64,      ///< 64-bit signed integer
    101102    UINT64,     ///< 64-bit unsigned integer
    102     FLOAT64     ///< double floating point
     103    FLOAT64,     ///< double floating point
     104    MAX_VALUE = FLOAT64
    103105};
    104106
     
    112114    LOCAL,
    113115    GENERIC,
    114     REGION
     116    REGION,
     117    MAX_VALUE = REGION
    115118};
    116119
     
    122125    WRITE_ONLY,
    123126    READ_WRITE,
     127    MAX_VALUE = READ_WRITE
    124128};
    125129
  • CLRadeonExtender/trunk/amdasm/AsmAmdCL2Internals.h

    r3712 r3726  
    177177    static void setCWS(AsmAmdCL2Handler& handler, const char* pseudoOpPlace,
    178178                      const char* linePtr);
    179     // .cws (set reqd_work_group_size or workgroupsizehint)
     179    // .work_group_size_hint
    180180    static void setWorkGroupSizeHint(AsmAmdCL2Handler& handler, const char* pseudoOpPlace,
    181181                      const char* linePtr);
  • CLRadeonExtender/trunk/amdasm/AsmROCmFormat.cpp

    r3671 r3726  
    3636static const char* rocmPseudoOpNamesTbl[] =
    3737{
    38     "arch_minor", "arch_stepping",
     38    "arch_minor", "arch_stepping", "arg",
    3939    "call_convention", "codeversion", "config",
    40     "control_directive", "debug_private_segment_buffer_sgpr",
     40    "control_directive", "cws", "debug_private_segment_buffer_sgpr",
    4141    "debug_wavefront_private_segment_offset_sgpr",
    4242    "debugmode", "default_hsa_features", "dims", "dx10clamp",
    43     "eflags", "exceptions", "fkernel", "floatmode", "gds_segment_size",
     43    "eflags", "exceptions", "fixed_work_group_size",
     44    "fkernel", "floatmode", "gds_segment_size",
    4445    "globaldata", "group_segment_align", "ieeemode", "kcode",
    4546    "kcodeend", "kernarg_segment_align",
    4647    "kernarg_segment_size", "kernel_code_entry_offset",
    4748    "kernel_code_prefetch_offset", "kernel_code_prefetch_size",
    48     "localsize", "machine", "max_scratch_backing_memory",
    49     "metadata", "newbinfmt", "pgmrsrc1", "pgmrsrc2", "priority",
     49    "localsize", "machine",
     50    "max_flat_work_group_size", "max_scratch_backing_memory",
     51    "md_group_segment_fixed_size", "md_kernarg_segment_align",
     52    "md_kernarg_segment_size", "md_language","md_private_segment_fixed_size",
     53    "md_spilledsgprs", "md_spilledvgprs", "md_sgprsnum",
     54    "md_symname", "md_version", "md_vgprsnum", "md_wavefront_size",
     55    "metadata", "newbinfmt", "pgmrsrc1", "pgmrsrc2", "printf", "priority",
    5056    "private_elem_size", "private_segment_align",
    51     "privmode", "reserved_sgprs", "reserved_vgprs",
    52     "runtime_loader_kernel_symbol",
     57    "privmode", "reqd_work_group_size",
     58    "reserved_sgprs", "reserved_vgprs",
     59    "runtime_handle", "runtime_loader_kernel_symbol",
    5360    "scratchbuffer", "sgprsnum", "target", "tgsize", "tripple",
    5461    "use_debug_enabled", "use_dispatch_id",
     
    5865    "use_private_segment_buffer", "use_private_segment_size",
    5966    "use_ptr64", "use_queue_ptr", "use_xnack_enabled",
    60     "userdatanum", "vgprsnum", "wavefront_sgpr_count",
    61     "wavefront_size", "workgroup_fbarrier_count",
     67    "userdatanum", "vectypehint", "vgprsnum", "wavefront_sgpr_count",
     68    "wavefront_size", "work_group_size_hint", "workgroup_fbarrier_count",
    6269    "workgroup_group_segment_size", "workitem_private_segment_size",
    6370    "workitem_vgpr_count"
     
    6774enum
    6875{
    69     ROCMOP_ARCH_MINOR, ROCMOP_ARCH_STEPPING,
     76    ROCMOP_ARCH_MINOR, ROCMOP_ARCH_STEPPING, ROCMOP_ARG,
    7077    ROCMOP_CALL_CONVENTION, ROCMOP_CODEVERSION, ROCMOP_CONFIG,
    71     ROCMOP_CONTROL_DIRECTIVE, ROCMOP_DEBUG_PRIVATE_SEGMENT_BUFFER_SGPR,
     78    ROCMOP_CONTROL_DIRECTIVE, ROCMOP_CWS, ROCMOP_DEBUG_PRIVATE_SEGMENT_BUFFER_SGPR,
    7279    ROCMOP_DEBUG_WAVEFRONT_PRIVATE_SEGMENT_OFFSET_SGPR,
    7380    ROCMOP_DEBUGMODE, ROCMOP_DEFAULT_HSA_FEATURES, ROCMOP_DIMS, ROCMOP_DX10CLAMP,
    74     ROCMOP_EFLAGS, ROCMOP_EXCEPTIONS, ROCMOP_FKERNEL,
     81    ROCMOP_EFLAGS, ROCMOP_EXCEPTIONS, ROCMOP_FIXED_WORK_GROUP_SIZE, ROCMOP_FKERNEL,
    7582    ROCMOP_FLOATMODE, ROCMOP_GDS_SEGMENT_SIZE, ROCMOP_GLOBALDATA,
    7683    ROCMOP_GROUP_SEGMENT_ALIGN, ROCMOP_IEEEMODE, ROCMOP_KCODE,
     
    7885    ROCMOP_KERNARG_SEGMENT_SIZE, ROCMOP_KERNEL_CODE_ENTRY_OFFSET,
    7986    ROCMOP_KERNEL_CODE_PREFETCH_OFFSET, ROCMOP_KERNEL_CODE_PREFETCH_SIZE,
    80     ROCMOP_LOCALSIZE, ROCMOP_MACHINE, ROCMOP_MAX_SCRATCH_BACKING_MEMORY,
    81     ROCMOP_METADATA, ROCMOP_NEWBINFMT, ROCMOP_PGMRSRC1, ROCMOP_PGMRSRC2, ROCMOP_PRIORITY,
    82     ROCMOP_PRIVATE_ELEM_SIZE, ROCMOP_PRIVATE_SEGMENT_ALIGN,
    83     ROCMOP_PRIVMODE, ROCMOP_RESERVED_SGPRS, ROCMOP_RESERVED_VGPRS,
    84     ROCMOP_RUNTIME_LOADER_KERNEL_SYMBOL,
     87    ROCMOP_LOCALSIZE, ROCMOP_MACHINE,
     88    ROCMOP_MAX_FLAT_WORK_GROUP_SIZE, ROCMOP_MAX_SCRATCH_BACKING_MEMORY,
     89    ROCMOP_MD_GROUP_SEGMENT_FIXED_SIZE, ROCMOP_MD_KERNARG_SEGMENT_ALIGN,
     90    ROCMOP_MD_KERNARG_SEGMENT_SIZE, ROCMOP_MD_LANGUAGE, ROCMOP_MD_PRIVATE_SEGMENT_FIXED_SIZE,
     91    ROCMOP_MD_SPILLEDSGPRS, ROCMOP_MD_SPILLEDVGPRS, ROCMOP_MD_SGPRSNUM,
     92    ROCMOP_MD_SYMNAME, ROCMOP_MD_VERSION, ROCMOP_MD_VGPRSNUM, ROCMOP_MD_WAVEFRONT_SIZE,
     93    ROCMOP_METADATA, ROCMOP_NEWBINFMT, ROCMOP_PGMRSRC1, ROCMOP_PGMRSRC2, ROCMOP_PRINTF,
     94    ROCMOP_PRIORITY, ROCMOP_PRIVATE_ELEM_SIZE, ROCMOP_PRIVATE_SEGMENT_ALIGN,
     95    ROCMOP_PRIVMODE, ROCMOP_REQD_WORK_GROUP_SIZE,
     96    ROCMOP_RESERVED_SGPRS, ROCMOP_RESERVED_VGPRS,
     97    ROCMOP_RUNTIME_HANDLE, ROCMOP_RUNTIME_LOADER_KERNEL_SYMBOL,
    8598    ROCMOP_SCRATCHBUFFER, ROCMOP_SGPRSNUM,
    8699    ROCMOP_TARGET, ROCMOP_TGSIZE, ROCMOP_TRIPPLE,
     
    91104    ROCMOP_USE_PRIVATE_SEGMENT_BUFFER, ROCMOP_USE_PRIVATE_SEGMENT_SIZE,
    92105    ROCMOP_USE_PTR64, ROCMOP_USE_QUEUE_PTR, ROCMOP_USE_XNACK_ENABLED,
    93     ROCMOP_USERDATANUM, ROCMOP_VGPRSNUM, ROCMOP_WAVEFRONT_SGPR_COUNT,
    94     ROCMOP_WAVEFRONT_SIZE, ROCMOP_WORKGROUP_FBARRIER_COUNT,
     106    ROCMOP_USERDATANUM, ROCMOP_VECTYPEHINT, ROCMOP_VGPRSNUM, ROCMOP_WAVEFRONT_SGPR_COUNT,
     107    ROCMOP_WAVEFRONT_SIZE, ROCM_WORK_GROUP_SIZE_HINT, ROCMOP_WORKGROUP_FBARRIER_COUNT,
    95108    ROCMOP_WORKGROUP_GROUP_SEGMENT_SIZE, ROCMOP_WORKITEM_PRIVATE_SEGMENT_SIZE,
    96109    ROCMOP_WORKITEM_VGPR_COUNT
     
    11951208            AsmROCmPseudoOps::setArchStepping(*this, linePtr);
    11961209            break;
     1210        case ROCMOP_ARG:
     1211            break;
    11971212        case ROCMOP_CALL_CONVENTION:
    11981213            AsmROCmPseudoOps::setConfigValue(*this, stmtPlace, linePtr,
     
    12071222        case ROCMOP_CONTROL_DIRECTIVE:
    12081223            AsmROCmPseudoOps::doControlDirective(*this, stmtPlace, linePtr);
     1224            break;
     1225        case ROCMOP_CWS:
    12091226            break;
    12101227        case ROCMOP_DEBUG_PRIVATE_SEGMENT_BUFFER_SGPR:
     
    12341251                             ROCMCVAL_EXCEPTIONS);
    12351252            break;
     1253        case ROCMOP_FIXED_WORK_GROUP_SIZE:
     1254            break;
    12361255        case ROCMOP_FKERNEL:
    12371256            AsmROCmPseudoOps::doFKernel(*this, stmtPlace, linePtr);
     
    12921311            AsmROCmPseudoOps::setMachine(*this, stmtPlace, linePtr);
    12931312            break;
     1313        case ROCMOP_MAX_FLAT_WORK_GROUP_SIZE:
     1314            break;
    12941315        case ROCMOP_MAX_SCRATCH_BACKING_MEMORY:
    12951316            AsmROCmPseudoOps::setConfigValue(*this, stmtPlace, linePtr,
     
    12991320            AsmROCmPseudoOps::addMetadata(*this, stmtPlace, linePtr);
    13001321            break;
     1322        case ROCMOP_MD_GROUP_SEGMENT_FIXED_SIZE:
     1323            break;
     1324        case ROCMOP_MD_KERNARG_SEGMENT_ALIGN:
     1325            break;
     1326        case ROCMOP_MD_KERNARG_SEGMENT_SIZE:
     1327            break;
     1328        case ROCMOP_MD_LANGUAGE:
     1329            break;
     1330        case ROCMOP_MD_PRIVATE_SEGMENT_FIXED_SIZE:
     1331            break;
     1332        case ROCMOP_MD_SPILLEDSGPRS:
     1333            break;
     1334        case ROCMOP_MD_SPILLEDVGPRS:
     1335            break;
     1336        case ROCMOP_MD_SGPRSNUM:
     1337            break;
     1338        case ROCMOP_MD_SYMNAME:
     1339            break;
     1340        case ROCMOP_MD_VERSION:
     1341            break;
     1342        case ROCMOP_MD_VGPRSNUM:
     1343            break;
     1344        case ROCMOP_MD_WAVEFRONT_SIZE:
     1345            break;
    13011346        case ROCMOP_NEWBINFMT:
    13021347            AsmROCmPseudoOps::setNewBinFormat(*this, linePtr);
     
    13071352        case ROCMOP_PGMRSRC2:
    13081353            AsmROCmPseudoOps::setConfigValue(*this, stmtPlace, linePtr, ROCMCVAL_PGMRSRC2);
     1354            break;
     1355        case ROCMOP_PRINTF:
    13091356            break;
    13101357        case ROCMOP_PRIORITY:
     
    13231370                             ROCMCVAL_PRIVMODE);
    13241371            break;
     1372        case ROCMOP_REQD_WORK_GROUP_SIZE:
     1373            break;
    13251374        case ROCMOP_RESERVED_SGPRS:
    13261375            AsmROCmPseudoOps::setReservedXgprs(*this, stmtPlace, linePtr, false);
     
    13281377        case ROCMOP_RESERVED_VGPRS:
    13291378            AsmROCmPseudoOps::setReservedXgprs(*this, stmtPlace, linePtr, true);
     1379            break;
     1380        case ROCMOP_RUNTIME_HANDLE:
    13301381            break;
    13311382        case ROCMOP_RUNTIME_LOADER_KERNEL_SYMBOL:
     
    14201471            AsmROCmPseudoOps::setConfigValue(*this, stmtPlace, linePtr,
    14211472                             ROCMCVAL_WORKITEM_VGPR_COUNT);
     1473            break;
     1474        case ROCM_WORK_GROUP_SIZE_HINT:
    14221475            break;
    14231476        case ROCMOP_WORKGROUP_FBARRIER_COUNT:
  • CLRadeonExtender/trunk/amdasm/AsmROCmInternals.h

    r3671 r3726  
    8181    ROCMCVAL_WAVEFRONT_SIZE,
    8282    ROCMCVAL_CALL_CONVENTION,
    83     ROCMCVAL_RUNTIME_LOADER_KERNEL_SYMBOL
     83    ROCMCVAL_RUNTIME_LOADER_KERNEL_SYMBOL,
     84   
     85    // metadata info
     86    ROCMCVAL_MD_WAVEFRONT_SIZE,
     87    ROCMCVAL_MD_KERNARG_SEGMENT_ALIGN,
     88    ROCMCVAL_MD_KERNARG_SEGMENT_SIZE,
     89    ROCMCVAL_MD_GROUP_SEGMENT_FIXED_SIZE,
     90    ROCMCVAL_MD_PRIVATE_SEGMENT_FIXED_SIZE,
     91    ROCMCVAL_MD_SGPRSNUM,
     92    ROCMCVAL_MD_VGPRSNUM,
     93    ROCMCVAL_MD_SPILLEDSGPRS,
     94    ROCMCVAL_MD_SPILLEDVGPRS,
     95    ROCMCVAL_MAX_FLAT_WORK_GROUP_SIZE
    8496};
    8597
     
    107119    static void addMetadata(AsmROCmHandler& handler, const char* pseudoOpPlace,
    108120                      const char* linePtr);
    109    
     121    // .md_version
     122    static void setMetadataVersion(AsmROCmHandler& handler, const char* pseudoOpPlace,
     123                      const char* linePtr);
     124    // .cws (set reqd_work_group_size or workgroupsizehint)
     125    static void setCWS(AsmROCmHandler& handler, const char* pseudoOpPlace,
     126                      const char* linePtr);
     127    // .work_group_size_hint
     128    static void setWorkGroupSizeHint(AsmROCmHandler& handler, const char* pseudoOpPlace,
     129                      const char* linePtr);
     130    // .fixed_work_group_size
     131    static void setFixedWorkGroupSize(AsmROCmHandler& handler, const char* pseudoOpPlace,
     132                      const char* linePtr);
     133    // .vectypehint
     134    static void setVecTypeHint(AsmROCmHandler& handler, const char* pseudoOpPlace,
     135                      const char* linePtr);
     136    // .md_symname
     137    static void setKernelSymName(AsmROCmHandler& handler, const char* pseudoOpPlace,
     138                      const char* linePtr);
     139    // .md_language
     140    static void setKernelLanguage(AsmROCmHandler& handler, const char* pseudoOpPlace,
     141                      const char* linePtr);
     142    // .printf (add printf)
     143    static void addPrintf(AsmROCmHandler& handler, const char* pseudoOpPlace,
     144                      const char* linePtr);
    110145    // .fkernel (define kernel as function kernel)
    111146    static void doFKernel(AsmROCmHandler& handler, const char* pseudoOpPlace,
  • CLRadeonExtender/trunk/amdasm/DisasmAmd.cpp

    r3716 r3726  
    12871287    if (arg.argType != KernelArgType::POINTER)
    12881288    {
     1289        if (arg.argType > KernelArgType::MAX_VALUE_CL2)
     1290            throw DisasmException("Unknown argument type");
    12891291        bufSize = snprintf(buf, 100, "\", %s",
    12901292                   kernelArgTypeNamesTbl[cxuint(arg.argType)]);
     
    13221324    else
    13231325    {
     1326        if (arg.pointerType > KernelArgType::MAX_VALUE_CL2)
     1327            throw DisasmException("Unknown argument pointer type");
    13241328        // pointer
    13251329        bufSize = snprintf(buf, 100, "\", %s*",
  • CLRadeonExtender/trunk/amdasm/DisasmROCm.cpp

    r3723 r3726  
    679679                           argInfo.size, argInfo.align);
    680680        output.write(buf, bufSize);
     681       
     682        if (argInfo.valueKind > ROCmValueKind::MAX_VALUE)
     683            throw DisasmException("Unknown argument value kind");
     684        if (argInfo.valueType > ROCmValueType::MAX_VALUE)
     685            throw DisasmException("Unknown argument value type");
     686       
    681687        bufSize = snprintf(buf, 100, ", %s, %s",
    682688                    disasmROCmValueKindNames[cxuint(argInfo.valueKind)],
     
    693699            argInfo.valueKind == ROCmValueKind::GLOBAL_BUFFER)
    694700        {
     701            if (argInfo.addressSpace > ROCmAddressSpace::MAX_VALUE)
     702                throw DisasmException("Unknown address space");
    695703            buf[0] = ','; buf[1] = ' ';
    696704            const char* name = disasmROCmAddressSpaces[cxuint(argInfo.addressSpace)];
     
    703711            argInfo.valueKind == ROCmValueKind::PIPE)
    704712        {
     713            if (argInfo.accessQual > ROCmAccessQual::MAX_VALUE)
     714                throw DisasmException("Unknown access qualifier");
    705715            buf[0] = ','; buf[1] = ' ';
    706716            const char* name = disasmROCmAccessQuals[cxuint(argInfo.accessQual)];
     
    713723            argInfo.valueKind == ROCmValueKind::PIPE)
    714724        {
     725            if (argInfo.actualAccessQual > ROCmAccessQual::MAX_VALUE)
     726                throw DisasmException("Unknown actual access qualifier");
    715727            buf[0] = ','; buf[1] = ' ';
    716728            const char* name = disasmROCmAccessQuals[cxuint(argInfo.actualAccessQual)];
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r3725 r3726  
    15241524    bool toEscape = false;
    15251525    const char* s;
     1526    bool nonDigit = false;
    15261527    for (s = input.c_str(); *s!=0; s++)
    15271528    {
     
    15331534            break;
    15341535        }
     1536        nonDigit |= isDigit(c);
    15351537    }
    15361538    // if spaces in begin and end
    1537     if (isSpace(input[0]) || (!input.empty() && isSpace(s[-1])))
     1539    if (!nonDigit || isSpace(input[0]) || isDigit(input[0]) ||
     1540        (!input.empty() && isSpace(s[-1])))
    15381541        toEscape = true;
    15391542   
     
    15481551}
    15491552
    1550 void generateROCmMetadata(const ROCmMetadata& mdInfo, const ROCmKernelConfig** kconfigs,
    1551                     std::string& output)
     1553static void generateROCmMetadata(const ROCmMetadata& mdInfo,
     1554                    const ROCmKernelConfig** kconfigs, std::string& output)
    15521555{
    15531556    output.clear();
     
    16601663            output += numBuf;
    16611664            output += "\n        ValueKind:       ";
     1665           
     1666            if (argInfo.valueKind > ROCmValueKind::MAX_VALUE)
     1667                throw BinGenException("Unknown ValueKind");
    16621668            output += rocmValueKindNames[cxuint(argInfo.valueKind)];
     1669           
     1670            if (argInfo.valueType > ROCmValueType::MAX_VALUE)
     1671                throw BinGenException("Unknown ValueType");
    16631672            output += "\n        ValueType:       ";
    16641673            output += rocmValueTypeNames[cxuint(argInfo.valueType)];
     
    16751684                argInfo.valueKind == ROCmValueKind::GLOBAL_BUFFER)
    16761685            {
     1686                if (argInfo.addressSpace > ROCmAddressSpace::MAX_VALUE)
     1687                    throw BinGenException("Unknown AddressSpace");
    16771688                output += "        AddrSpaceQual:   ";
    16781689                output += rocmAddrSpaceTypesTbl[cxuint(argInfo.addressSpace)];
     
    16821693                argInfo.valueKind == ROCmValueKind::PIPE)
    16831694            {
     1695                if (argInfo.accessQual> ROCmAccessQual::MAX_VALUE)
     1696                    throw BinGenException("Unknown AccessQualifier");
    16841697                output += "        AccQual:         ";
    16851698                output += rocmAccessQualifierTbl[cxuint(argInfo.accessQual)];
     
    16901703                argInfo.valueKind == ROCmValueKind::PIPE)
    16911704            {
     1705                if (argInfo.actualAccessQual> ROCmAccessQual::MAX_VALUE)
     1706                    throw BinGenException("Unknown ActualAccessQualifier");
    16921707                output += "        ActualAccQual:   ";
    16931708                output += rocmAccessQualifierTbl[cxuint(argInfo.actualAccessQual)];
     
    19882003        std::unique_ptr<const ROCmKernelConfig*[]> kernelConfigPtrs(
    19892004                new const ROCmKernelConfig*[mdKernelsNum]);
     2005        // generate ROCm kernel config pointers
    19902006        for (size_t k = 0; k < mdKernelsNum; k++)
    19912007        {
    19922008            auto it = binaryMapFind(symbolIndices.begin(), symbolIndices.end(),
    19932009                        input->metadataInfo.kernels[k].name);
    1994             if (it == symbolIndices.end())
     2010            if (it == symbolIndices.end() ||
     2011                (input->symbols[it->second].type != ROCmRegionType::FKERNEL &&
     2012                 input->symbols[it->second].type != ROCmRegionType::KERNEL))
    19952013                throw BinGenException("Kernel in metadata doesn't exists in code");
    19962014            kernelConfigPtrs[k] = reinterpret_cast<const ROCmKernelConfig*>(
    19972015                        input->code + input->symbols[it->second].offset);
    19982016        }
    1999        
     2017        // just generate ROCm metadata from info
    20002018        generateROCmMetadata(input->metadataInfo, kernelConfigPtrs.get(), metadataStr);
    20012019        metadataSize = metadataStr.size();
Note: See TracChangeset for help on using the changeset viewer.