Changeset 3721 in CLRX for CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp
 Timestamp:
 Feb 4, 2018, 2:07:32 PM (22 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp
r3716 r3721 766 766 sizeof(kernelArgInfosKeywords) / sizeof(const char*); 767 767 768 static const std::pair<const char*, ROCmValueKind> rocmValueKindNames [] =768 static const std::pair<const char*, ROCmValueKind> rocmValueKindNamesMap[] = 769 769 { 770 770 { "ByValue", ROCmValueKind::BY_VALUE }, … … 785 785 786 786 static const size_t rocmValueKindNamesNum = 787 sizeof(rocmValueKindNames ) / sizeof(std::pair<const char*, ROCmValueKind>);788 789 static const std::pair<const char*, ROCmValueType> rocmValueTypeNames [] =787 sizeof(rocmValueKindNamesMap) / sizeof(std::pair<const char*, ROCmValueKind>); 788 789 static const std::pair<const char*, ROCmValueType> rocmValueTypeNamesMap[] = 790 790 { 791 791 { "F16", ROCmValueType::FLOAT16 }, … … 804 804 805 805 static const size_t rocmValueTypeNamesNum = 806 sizeof(rocmValueTypeNames ) / sizeof(std::pair<const char*, ROCmValueType>);806 sizeof(rocmValueTypeNamesMap) / sizeof(std::pair<const char*, ROCmValueType>); 807 807 808 808 static const char* rocmAddrSpaceTypesTbl[] = … … 1196 1196 const std::string vkind = trimStrSpaces(parseYAMLStringValue( 1197 1197 ptr, end, lineNo, level, true)); 1198 const size_t vkindIndex = binaryMapFind(rocmValueKindNames ,1199 rocmValueKindNames + rocmValueKindNamesNum, vkind.c_str(),1200 CStringLess())  rocmValueKindNames ;1198 const size_t vkindIndex = binaryMapFind(rocmValueKindNamesMap, 1199 rocmValueKindNamesMap + rocmValueKindNamesNum, vkind.c_str(), 1200 CStringLess())  rocmValueKindNamesMap; 1201 1201 // if unknown kind 1202 1202 if (vkindIndex == rocmValueKindNamesNum) 1203 1203 throw ParseException(valLineNo, "Wrong argument value kind"); 1204 kernelArg.valueKind = rocmValueKindNames [vkindIndex].second;1204 kernelArg.valueKind = rocmValueKindNamesMap[vkindIndex].second; 1205 1205 break; 1206 1206 } … … 1209 1209 const std::string vtype = trimStrSpaces(parseYAMLStringValue( 1210 1210 ptr, end, lineNo, level, true)); 1211 const size_t vtypeIndex = binaryMapFind(rocmValueTypeNames ,1212 rocmValueTypeNames + rocmValueTypeNamesNum, vtype.c_str(),1213 CStringLess())  rocmValueTypeNames ;1211 const size_t vtypeIndex = binaryMapFind(rocmValueTypeNamesMap, 1212 rocmValueTypeNamesMap + rocmValueTypeNamesNum, vtype.c_str(), 1213 CStringLess())  rocmValueTypeNamesMap; 1214 1214 // if unknown type 1215 1215 if (vtypeIndex == rocmValueTypeNamesNum) 1216 1216 throw ParseException(valLineNo, "Wrong argument value type"); 1217 kernelArg.valueType = rocmValueTypeNames [vtypeIndex].second;1217 kernelArg.valueType = rocmValueTypeNamesMap[vtypeIndex].second; 1218 1218 break; 1219 1219 } … … 1482 1482 { 1483 1483 symbols.push_back({ kernelName, 0, 0, ROCmRegionType::KERNEL }); 1484 } 1485 1486 /* 1487 * ROCm YAML metadata generator 1488 */ 1489 1490 static const char* rocmValueKindNames[] = 1491 { 1492 "ByValue", "GlobalBuffer", "DynamicSharedPointer", "Sampler", "Image", "Pipe", "Queue", 1493 "HiddenGlobalOffsetX", "HiddenGlobalOffsetY", "HiddenGlobalOffsetZ", "HiddenNone", 1494 "HiddenPrintfBuffer", "HiddenDefaultQueue", "HiddenCompletionAction" 1495 }; 1496 1497 static const char* rocmValueTypeNames[] = 1498 { 1499 "Struct", "I8", "U8", "I16", "U16", "F16", "I32", "U32", "F32", "I64", "U64", "F64" 1500 }; 1501 1502 static void genArrayValue(cxuint n, const cxuint* values, std::string& output) 1503 { 1504 char numBuf[24]; 1505 output += "[ "; 1506 for (cxuint i = 0; i < n; i++) 1507 { 1508 itocstrCStyle(values[i], numBuf, 24); 1509 output += numBuf; 1510 output += (i+1<n) ? ", " : "]\n"; 1511 } 1512 } 1513 1514 // helper for checking wether value is supplied 1515 static inline bool hasValue(cxuint value) 1516 { return value!=BINGEN_NOTSUPPLIED && value!=BINGEN_DEFAULT; } 1517 1518 static inline bool hasValue(uint64_t value) 1519 { return value!=BINGEN64_NOTSUPPLIED && value!=BINGEN64_DEFAULT; } 1520 1521 void generateROCmMetadata(const ROCmMetadata& mdInfo, const ROCmKernelConfig& kconfig, 1522 std::string& output) 1523 { 1524 output.clear(); 1525 char numBuf[24]; 1526 output += "\n"; 1527 // version 1528 output += "Version: "; 1529 genArrayValue(2, mdInfo.version, output); 1530 if (!mdInfo.printfInfos.empty()) 1531 output += "Printf: \n"; 1532 // printfs 1533 for (const ROCmPrintfInfo& printfInfo: mdInfo.printfInfos) 1534 { 1535 output += "  '"; 1536 itocstrCStyle(printfInfo.id, numBuf, 24); 1537 output += numBuf; 1538 output += ':'; 1539 itocstrCStyle(printfInfo.argSizes.size(), numBuf, 24); 1540 output += numBuf; 1541 output += ':'; 1542 for (size_t argSize: printfInfo.argSizes) 1543 { 1544 itocstrCStyle(argSize, numBuf, 24); 1545 output += numBuf; 1546 output += ':'; 1547 } 1548 // printf format 1549 output += escapeStringCStyle(printfInfo.format); 1550 output += "'\n"; 1551 } 1552 1553 if (!mdInfo.printfInfos.empty()) 1554 output += "Kernels: \n"; 1555 // kernels 1556 for (const ROCmKernelMetadata& kernel: mdInfo.kernels) 1557 { 1558 output += "  Name: "; 1559 output.append(kernel.name.c_str(), kernel.name.size()); 1560 output += "\n SymbolName: '"; 1561 output += escapeStringCStyle(kernel.symbolName); 1562 output += "'\n"; 1563 if (!kernel.language.empty()) 1564 { 1565 output += " Language: "; 1566 output.append(kernel.language.c_str(), kernel.language.size()); 1567 output += "\n"; 1568 } 1569 if (kernel.langVersion[0] != BINGEN_NOTSUPPLIED) 1570 { 1571 output += " LanguageVersion: "; 1572 genArrayValue(2, kernel.langVersion, output); 1573 } 1574 // kernel attributes 1575 if (kernel.reqdWorkGroupSize[0] != 0  kernel.reqdWorkGroupSize[1] != 0  1576 kernel.reqdWorkGroupSize[2] != 0  1577 kernel.workGroupSizeHint[0] != 0  kernel.workGroupSizeHint[1] != 0  1578 kernel.workGroupSizeHint[2] != 0  1579 !kernel.vecTypeHint.empty()  !kernel.runtimeHandle.empty()) 1580 { 1581 output += " Attrs: \n"; 1582 if (kernel.workGroupSizeHint[0] != 0  kernel.workGroupSizeHint[1] != 0  1583 kernel.workGroupSizeHint[2] != 0) 1584 { 1585 output += " WorkGroupSizeHint: "; 1586 genArrayValue(3, kernel.workGroupSizeHint, output); 1587 } 1588 if (kernel.reqdWorkGroupSize[0] != 0  kernel.reqdWorkGroupSize[1] != 0  1589 kernel.reqdWorkGroupSize[2] != 0) 1590 { 1591 output += " ReqdWorkGroupSize: "; 1592 genArrayValue(3, kernel.reqdWorkGroupSize, output); 1593 } 1594 if (!kernel.vecTypeHint.empty()) 1595 { 1596 output += " VecTypeHint: "; 1597 output.append(kernel.vecTypeHint.c_str(), kernel.vecTypeHint.size()); 1598 output += "\n"; 1599 } 1600 if (!kernel.runtimeHandle.empty()) 1601 { 1602 output += " RuntimeHandle: "; 1603 output.append(kernel.runtimeHandle.c_str(), kernel.runtimeHandle.size()); 1604 output += "\n"; 1605 } 1606 } 1607 // kernel arguments 1608 if (!kernel.argInfos.empty()) 1609 output += " Args: \n"; 1610 for (const ROCmKernelArgInfo& argInfo: kernel.argInfos) 1611 { 1612 output += "  "; 1613 if (!argInfo.name.empty()) 1614 { 1615 output += "Name: "; 1616 output.append(argInfo.name.c_str(), argInfo.name.size()); 1617 output += "\n "; 1618 } 1619 if (!argInfo.typeName.empty()) 1620 { 1621 output += "TypeName: "; 1622 output.append(argInfo.typeName.c_str(), argInfo.typeName.size()); 1623 output += "\n "; 1624 } 1625 output += "Size: "; 1626 itocstrCStyle(argInfo.size, numBuf, 24); 1627 output += numBuf; 1628 output += "\n Align: "; 1629 itocstrCStyle(argInfo.align, numBuf, 24); 1630 output += numBuf; 1631 output += "\n ValueKind: "; 1632 output += rocmValueKindNames[cxuint(argInfo.valueKind)]; 1633 output += "\n ValueType: "; 1634 output += rocmValueTypeNames[cxuint(argInfo.valueType)]; 1635 output += "\n"; 1636 1637 if (argInfo.valueKind == ROCmValueKind::DYN_SHARED_PTR) 1638 { 1639 output += " PointeeAlign: "; 1640 itocstrCStyle(argInfo.pointeeAlign, numBuf, 24); 1641 output += numBuf; 1642 output += "\n"; 1643 } 1644 if (argInfo.valueKind == ROCmValueKind::DYN_SHARED_PTR  1645 argInfo.valueKind == ROCmValueKind::GLOBAL_BUFFER) 1646 { 1647 output += " AddrSpaceQual: "; 1648 output += rocmAddrSpaceTypesTbl[cxuint(argInfo.addressSpace)]; 1649 output += "\n"; 1650 } 1651 if (argInfo.valueKind == ROCmValueKind::IMAGE  1652 argInfo.valueKind == ROCmValueKind::PIPE) 1653 { 1654 output += " AccQual: "; 1655 output += rocmAccessQualifierTbl[cxuint(argInfo.accessQual)]; 1656 output += "\n"; 1657 } 1658 if (argInfo.valueKind == ROCmValueKind::GLOBAL_BUFFER  1659 argInfo.valueKind == ROCmValueKind::IMAGE  1660 argInfo.valueKind == ROCmValueKind::PIPE) 1661 { 1662 output += " ActualAccQual: "; 1663 output += rocmAccessQualifierTbl[cxuint(argInfo.actualAccessQual)]; 1664 output += "\n"; 1665 } 1666 if (argInfo.isConst) 1667 output += " IsConst: true\n"; 1668 if (argInfo.isRestrict) 1669 output += " IsRestrict: true\n"; 1670 if (argInfo.isVolatile) 1671 output += " IsVolatile: true\n"; 1672 if (argInfo.isPipe) 1673 output += " IsPipe: true\n"; 1674 } 1675 1676 // kernel code properties 1677 if (kernel.kernargSegmentSize != BINGEN64_NOTSUPPLIED  1678 kernel.kernargSegmentAlign != BINGEN64_NOTSUPPLIED  1679 kernel.privateSegmentFixedSize != BINGEN64_NOTSUPPLIED  1680 kernel.groupSegmentFixedSize != BINGEN64_NOTSUPPLIED  1681 kernel.wavefrontSize != BINGEN_NOTSUPPLIED  1682 kernel.sgprsNum != BINGEN_NOTSUPPLIED  1683 kernel.vgprsNum != BINGEN_NOTSUPPLIED  1684 kernel.maxFlatWorkGroupSize != BINGEN64_NOTSUPPLIED  1685 hasValue(kernel.spilledSgprs)  hasValue(kernel.spilledVgprs)  1686 kernel.fixedWorkGroupSize[0] != 0  kernel.fixedWorkGroupSize[1] != 0  1687 kernel.fixedWorkGroupSize[2] != 0) 1688 { 1689 output += " CodeProps: \n"; 1690 output += " KernargSegmentSize: "; 1691 itocstrCStyle(kernel.kernargSegmentSize != BINGEN64_DEFAULT ? 1692 kernel.kernargSegmentSize : ULEV(kconfig.kernargSegmentSize), 1693 numBuf, 24); 1694 output += numBuf; 1695 output += "\n GroupSegmentFixedSize: "; 1696 itocstrCStyle(kernel.groupSegmentFixedSize != BINGEN64_DEFAULT ? 1697 kernel.groupSegmentFixedSize : 1698 uint64_t(ULEV(kconfig.workgroupGroupSegmentSize)), 1699 numBuf, 24); 1700 output += numBuf; 1701 output += "\n PrivateSegmentFixedSize: "; 1702 itocstrCStyle(kernel.privateSegmentFixedSize != BINGEN64_DEFAULT ? 1703 kernel.privateSegmentFixedSize : 1704 uint64_t(ULEV(kconfig.workitemPrivateSegmentSize)), 1705 numBuf, 24); 1706 output += numBuf; 1707 output += "\n KernargSegmentAlign: "; 1708 itocstrCStyle(kernel.kernargSegmentAlign != BINGEN64_DEFAULT ? 1709 kernel.kernargSegmentAlign : 1710 uint64_t(1ULL<<kconfig.kernargSegmentAlignment), 1711 numBuf, 24); 1712 output += numBuf; 1713 output += "\n WavefrontSize: "; 1714 itocstrCStyle(kernel.wavefrontSize != BINGEN_DEFAULT ? 1715 kernel.wavefrontSize : cxuint(1U<<kconfig.wavefrontSize), numBuf, 24); 1716 output += numBuf; 1717 output += "\n NumSGPRs: "; 1718 itocstrCStyle(kernel.sgprsNum != BINGEN_DEFAULT ? 1719 kernel.sgprsNum : cxuint(ULEV(kconfig.wavefrontSgprCount)), 1720 numBuf, 24); 1721 output += numBuf; 1722 output += "\n NumVGPRs: "; 1723 itocstrCStyle(kernel.vgprsNum != BINGEN_DEFAULT ? 1724 kernel.vgprsNum : cxuint(ULEV(kconfig.workitemVgprCount)), 1725 numBuf, 24); 1726 output += numBuf; 1727 if (hasValue(kernel.spilledSgprs)) 1728 { 1729 output += "\n NumSpilledSGPRs: "; 1730 itocstrCStyle(kernel.spilledSgprs, numBuf, 24); 1731 output += numBuf; 1732 } 1733 if (hasValue(kernel.spilledVgprs)) 1734 { 1735 output += "\n NumSpilledVGPRs: "; 1736 itocstrCStyle(kernel.spilledVgprs, numBuf, 24); 1737 output += numBuf; 1738 } 1739 output += "\n MaxFlatWorkGroupSize: "; 1740 itocstrCStyle(kernel.maxFlatWorkGroupSize != BINGEN_DEFAULT ? 1741 kernel.maxFlatWorkGroupSize : uint64_t(256), numBuf, 24); 1742 output += numBuf; 1743 output += "\n"; 1744 if (kernel.fixedWorkGroupSize[0] != 0  kernel.fixedWorkGroupSize[1] != 0  1745 kernel.fixedWorkGroupSize[2] != 0) 1746 { 1747 output += " FixedWorkGroupSize: "; 1748 genArrayValue(3, kernel.fixedWorkGroupSize, output); 1749 } 1750 } 1751 } 1752 output += "...\n"; 1484 1753 } 1485 1754
Note: See TracChangeset
for help on using the changeset viewer.