1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file cm_task_internal.cpp
//! \brief Contains Class CmTaskInternal definitions
//!
#include "cm_task_internal.h"
#include "cm_kernel_rt.h"
#include "cm_mem.h"
#include "cm_event_rt.h"
#include "cm_device_rt.h"
#include "cm_kernel_data.h"
#include "cm_thread_space_rt.h"
#include "cm_group_space.h"
#include "cm_vebox_rt.h"
#include "cm_vebox_data.h"
#include "cm_queue_rt.h"
#include "cm_surface_manager.h"
#include "cm_surface_2d_rt.h"
namespace CMRT_UMD
{
//*-----------------------------------------------------------------------------
//| Purpose: Create Task internal
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Create(const uint32_t kernelCount, const uint32_t totalThreadCount,
CmKernelRT* kernelArray[], const CmThreadSpaceRT* threadSpace,
CmDeviceRT* device, const uint64_t syncBitmap, CmTaskInternal*& task,
const uint64_t conditionalEndBitmap,
PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo)
{
int32_t result = CM_SUCCESS;
task = new (std::nothrow) CmTaskInternal(kernelCount, totalThreadCount, kernelArray, device,
syncBitmap, conditionalEndBitmap, conditionalEndInfo,
nullptr);
if( task )
{
result = task->Initialize(threadSpace, false);
if( result != CM_SUCCESS )
{
CmTaskInternal::Destroy( task);
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create CmTaskInternal due to out of system memory.");
result = CM_OUT_OF_HOST_MEMORY;
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Task internal with Thread Group Space
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Create( const uint32_t kernelCount, const uint32_t totalThreadCount,
CmKernelRT* kernelArray[], const CmThreadGroupSpace* threadGroupSpace,
CmDeviceRT* device, const uint64_t syncBitmap, CmTaskInternal*& task,
const uint64_t conditionalEndBitmap,
PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo,
const CM_EXECUTION_CONFIG* krnExecCfg)
{
int32_t result = CM_SUCCESS;
task = new (std::nothrow) CmTaskInternal(kernelCount, totalThreadCount, kernelArray, device,
syncBitmap, conditionalEndBitmap, conditionalEndInfo,
krnExecCfg);
if( task )
{
result = task->Initialize(threadGroupSpace);
if( result != CM_SUCCESS )
{
CmTaskInternal::Destroy( task);
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create CmTaskInternal due to out of system memory.");
result = CM_OUT_OF_HOST_MEMORY;
}
return result;
}
int32_t CmTaskInternal::Create( CmDeviceRT* device, CmVeboxRT* vebox, CmTaskInternal*& task )
{
int32_t result = CM_SUCCESS;
task = new (std::nothrow) CmTaskInternal(0, 0, nullptr, device, CM_NO_KERNEL_SYNC,
CM_NO_CONDITIONAL_END, nullptr, nullptr);
if( task )
{
result = task->Initialize(vebox);
if( result != CM_SUCCESS )
{
CmTaskInternal::Destroy( task);
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create CmTaskInternal due to out of system memory.");
result = CM_OUT_OF_HOST_MEMORY;
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Task internal with hints
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Create(const uint32_t kernelCount, const uint32_t totalThreadCount,
CmKernelRT* kernelArray[], CmTaskInternal*& task,
uint32_t numGeneratedTasks, bool isLastTask, uint32_t hints,
CmDeviceRT* device)
{
int32_t result = CM_SUCCESS;
task = new (std::nothrow) CmTaskInternal(kernelCount, totalThreadCount, kernelArray, device,
CM_NO_KERNEL_SYNC, CM_NO_CONDITIONAL_END, nullptr, nullptr);
if ( task )
{
result = task->Initialize(hints, numGeneratedTasks, isLastTask);
if ( result != CM_SUCCESS )
{
CmTaskInternal::Destroy( task );
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create CmTaskInternal due to out of system memory.");
result = CM_OUT_OF_HOST_MEMORY;
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Task internal
//| Returns: None.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Destroy( CmTaskInternal* &task )
{
CmSafeDelete( task );
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Constructor of CmTaskInternal
//| Returns: None.
//*-----------------------------------------------------------------------------
CmTaskInternal::CmTaskInternal(const uint32_t kernelCount, const uint32_t totalThreadCount,
CmKernelRT* kernelArray[], CmDeviceRT* device,
const uint64_t syncBitmap, const uint64_t conditionalEndBitmap,
PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo,
const CM_EXECUTION_CONFIG* krnExecCfg) :
m_kernels( kernelCount ),
m_kernelData( kernelCount ),
m_kernelCount( kernelCount ),
m_totalThreadCount(totalThreadCount),
m_taskEvent( nullptr ),
m_isThreadSpaceCreated(false),
m_isThreadCoordinatesExisted(false),
m_threadSpaceWidth(0),
m_threadSpaceHeight(0),
m_threadSpaceDepth(0),
m_threadCoordinates(nullptr),
m_dependencyPattern(CM_NONE_DEPENDENCY),
m_walkingPattern(CM_WALK_DEFAULT),
m_mediaWalkerParamsSet( false ),
m_dependencyVectorsSet( false ),
m_dependencyMasks( nullptr ),
m_mediaWalkerGroupSelect(CM_MW_GROUP_NONE),
m_isThreadGroupSpaceCreated(false),
m_groupSpaceWidth(0),
m_groupSpaceHeight(0),
m_groupSpaceDepth(0),
m_slmSize(0),
m_spillMemUsed(0),
m_colorCountMinusOne( 0 ),
m_hints(0),
m_numTasksGenerated( 0 ),
m_isLastTask( false ),
m_ui64SyncBitmap (syncBitmap ),
m_ui64ConditionalEndBitmap(conditionalEndBitmap),
m_cmDevice( device ),
m_surfaceArray (nullptr),
m_isSurfaceUpdateDone(false),
m_taskType(CM_TASK_TYPE_DEFAULT),
m_mediaStatePtr( nullptr )
{
m_kernelSurfInfo.kernelNum = 0;
m_kernelSurfInfo.surfEntryInfosArray = nullptr;
m_kernelCurbeOffsetArray = MOS_NewArray(uint32_t, kernelCount);
CM_ASSERT(m_kernelCurbeOffsetArray != nullptr);
for( uint32_t i = 0 ; i < kernelCount; i ++ )
{
m_kernels.SetElement( i, kernelArray[ i ] );
m_kernelData.SetElement( i, nullptr );
}
CmSafeMemSet( &m_walkingParameters, 0, sizeof(m_walkingParameters));
CmSafeMemSet( &m_dependencyVectors, 0, sizeof(m_dependencyVectors));
CmSafeMemSet( &m_taskConfig, 0, sizeof(m_taskConfig));
if ( m_kernelCurbeOffsetArray != nullptr )
{
CmSafeMemSet( m_kernelCurbeOffsetArray, 0, sizeof(uint32_t) * kernelCount );
}
CmSafeMemSet(&m_taskProfilingInfo, 0, sizeof(m_taskProfilingInfo));
if (conditionalEndInfo != nullptr)
{
CmSafeMemCopy(&m_conditionalEndInfo, conditionalEndInfo, sizeof(m_conditionalEndInfo));
}
else
{
CmSafeMemSet(&m_conditionalEndInfo, 0, sizeof(m_conditionalEndInfo));
}
CmSafeMemSet(&m_veboxParam, 0, sizeof(m_veboxParam));
CmSafeMemSet(&m_veboxState, 0, sizeof(m_veboxState));
CmSafeMemSet(&m_veboxSurfaceData, 0, sizeof(m_veboxSurfaceData));
CmSafeMemSet(&m_powerOption, 0, sizeof(m_powerOption));
if (krnExecCfg != nullptr)
{
CmSafeMemCopy(&m_krnExecCfg, krnExecCfg, sizeof(m_krnExecCfg));
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Destructor of CmTaskInternal
//| Returns: None.
//*-----------------------------------------------------------------------------
CmTaskInternal::~CmTaskInternal( void )
{
//Write Event Infos
VtuneWriteEventInfo();
//Release Profiling Info
VtuneReleaseProfilingInfo();
for( uint32_t i = 0; i < m_kernelCount; i ++ )
{
CmKernelRT *kernel = (CmKernelRT*)m_kernels.GetElement(i);
CmKernelData* kernelData = (CmKernelData*)m_kernelData.GetElement( i );
if(kernel && kernelData)
{
kernel->ReleaseKernelData(kernelData);
CmKernel *kernelBase = kernel;
m_cmDevice->DestroyKernel(kernelBase);
}
}
m_kernelData.Delete();
m_kernels.Delete();
MosSafeDeleteArray(m_kernelCurbeOffsetArray);
if( m_taskEvent )
{
CmEvent *eventBase = m_taskEvent;
CmQueueRT *cmQueue = nullptr;
m_taskEvent->GetQueue(cmQueue);
cmQueue->DestroyEvent(eventBase); // need to update the m_EventArray
}
if(m_threadCoordinates){
for (uint32_t i=0; i<m_kernelCount; i++)
{
if (m_threadCoordinates[i])
{
MosSafeDeleteArray(m_threadCoordinates[i]);
}
}
MosSafeDeleteArray( m_threadCoordinates );
}
if( m_dependencyMasks )
{
for( uint32_t i = 0; i < m_kernelCount; ++i )
{
MosSafeDeleteArray(m_dependencyMasks[i]);
}
MosSafeDeleteArray( m_dependencyMasks );
}
if((m_kernelSurfInfo.kernelNum != 0)&&(m_kernelSurfInfo.surfEntryInfosArray != nullptr))
{
ClearKernelSurfInfo();
}
MosSafeDeleteArray(m_surfaceArray);
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Class CmTaskInternal
//| Returns: None.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Initialize(const CmThreadSpaceRT* threadSpace, bool isWithHints)
{
uint32_t totalCurbeSize = 0;
uint32_t surfacePoolSize = 0;
uint32_t totalKernelBinarySize = 0;
uint32_t kernelCurbeSize = 0;
uint32_t kernelPayloadSize = 0;
CmSurfaceManager* surfaceMgr = nullptr;
int32_t result = CM_SUCCESS;
CM_HAL_MAX_VALUES* halMaxValues = nullptr;
CM_HAL_MAX_VALUES_EX* halMaxValuesEx = nullptr;
m_cmDevice->GetHalMaxValues( halMaxValues, halMaxValuesEx );
if (m_cmDevice->IsPrintEnable())
{
SurfaceIndex *printBufferIndex = nullptr;
m_cmDevice->GetPrintBufferIndex(printBufferIndex);
CM_ASSERT(printBufferIndex);
for (uint32_t i = 0; i < m_kernelCount; i++)
{
CmKernelRT* kernel = (CmKernelRT*)m_kernels.GetElement(i);
if(kernel == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer.");
return CM_FAILURE;
}
if(FAILED(kernel->SetStaticBuffer(CM_PRINTF_STATIC_BUFFER_ID, printBufferIndex)))
{
CM_ASSERTMESSAGE("Error: Failed to set static buffer.");
return CM_FAILURE;
}
}
}
m_cmDevice->GetSurfaceManager( surfaceMgr );
surfacePoolSize = surfaceMgr->GetSurfacePoolSize();
m_surfaceArray = MOS_NewArray(bool, surfacePoolSize);
if (!m_surfaceArray)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_FAILURE;
}
CmSafeMemSet( m_surfaceArray, 0, surfacePoolSize * sizeof( bool ) );
for( uint32_t i = 0; i < m_kernelCount; i ++ )
{
CmKernelRT* kernel = (CmKernelRT*)m_kernels.GetElement( i );
if(kernel == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer.");
return CM_FAILURE;
}
uint32_t totalSize = 0;
CmKernelData* kernelData = nullptr;
if ( isWithHints )
{
CmThreadSpaceRT* kernelThreadSpace = nullptr;
kernel->GetThreadSpace(kernelThreadSpace);
if( kernelThreadSpace )
{
for(uint32_t j = i; j > 0; --j)
{
uint32_t width, height, myAdjY;
CmKernelRT* tmpKernel = (CmKernelRT*)m_kernels.GetElement( j-1 );
if( !tmpKernel )
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer.");
return CM_FAILURE;
}
tmpKernel->GetThreadSpace(kernelThreadSpace);
kernelThreadSpace->GetThreadSpaceSize(width, height);
myAdjY = kernel->GetAdjustedYCoord();
kernel->SetAdjustedYCoord(myAdjY + height);
}
}
}
if (threadSpace == nullptr)
{
CmThreadSpaceRT* kernelThreadSpace = nullptr;
kernel->GetThreadSpace(kernelThreadSpace);
if (kernelThreadSpace)
{
kernelThreadSpace->SetDependencyArgToKernel(kernel);
}
}
if (threadSpace != nullptr)
{
threadSpace->SetDependencyArgToKernel(kernel);
}
kernel->CollectKernelSurface();
result = kernel->CreateKernelData( kernelData, totalSize, threadSpace );
if( (kernelData == nullptr) || (result != CM_SUCCESS))
{
CM_ASSERTMESSAGE("Error: Failed to create kernel data.");
CmKernelData::Destroy( kernelData );
return result;
}
kernel->GetSizeInPayload( kernelPayloadSize );
kernel->GetSizeInCurbe( kernelCurbeSize );
if ( ( kernelCurbeSize + kernelPayloadSize ) > halMaxValues->maxArgByteSizePerKernel )
{ //Failed, exceed the maximum of inline data
CM_ASSERTMESSAGE("Error: Invalid kernel arg size.");
return CM_EXCEED_KERNEL_ARG_SIZE_IN_BYTE;
}
else
{
kernelCurbeSize = kernel->GetAlignedCurbeSize( kernelCurbeSize );
totalCurbeSize += kernelCurbeSize;
}
m_kernelCurbeOffsetArray[ i ] = totalCurbeSize - kernelCurbeSize;
m_kernelData.SetElement( i, kernelData );
totalKernelBinarySize += kernel->GetKernelGenxBinarySize();
totalKernelBinarySize += CM_KERNEL_BINARY_PADDING_SIZE; //Padding is necessary after kernel binary to avoid page fault issue
bool *surfArray = nullptr;
kernel->GetKernelSurfaces(surfArray);
for (uint32_t j = 0; j < surfacePoolSize; j ++)
{
m_surfaceArray[j] |= surfArray[j];
}
kernel->ResetKernelSurfaces();
PCM_CONTEXT_DATA cmData = ( PCM_CONTEXT_DATA )m_cmDevice->GetAccelData();
PCM_HAL_STATE state = cmData->cmHalState;
PRENDERHAL_MEDIA_STATE mediaStatePtr = state->pfnGetMediaStatePtrForKernel( state, kernel );
if ( ( mediaStatePtr != nullptr ) && ( m_mediaStatePtr == nullptr ) )
{
m_mediaStatePtr = mediaStatePtr;
}
else if ( ( mediaStatePtr != nullptr ) && ( m_mediaStatePtr != nullptr ) )
{
CM_ASSERTMESSAGE( "Error: More than one media state heap are used in one task! User-provided state heap error.\n" );
return CM_INVALID_ARG_VALUE;
}
}
if (totalKernelBinarySize > halMaxValues->maxKernelBinarySize * halMaxValues->maxKernelsPerTask)
{
CM_ASSERTMESSAGE("Error: Invalid kernel arg size.");
return CM_EXCEED_MAX_KERNEL_SIZE_IN_BYTE;
}
if (threadSpace)
{
if(FAILED(this->CreateThreadSpaceData(threadSpace)))
{
CM_ASSERTMESSAGE("Error: Failed to create thread space data.");
return CM_FAILURE;
}
m_isThreadSpaceCreated = true;
}
UpdateSurfaceStateOnTaskCreation();
m_taskType = CM_INTERNAL_TASK_WITH_THREADSPACE;
if ( m_cmDevice->CheckGTPinEnabled())
{
AllocateKernelSurfInfo();
}
this->VtuneInitProfilingInfo(threadSpace);
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Class CmTaskInternal with thread group space
//| Returns: None.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Initialize(const CmThreadGroupSpace* threadGroupSpace)
{
uint32_t totalCurbeSize = 0;
uint32_t surfacePoolSize = 0;
uint32_t totalKernelBinarySize = 0;
uint32_t kernelCurbeSize = 0;
uint32_t kernelPayloadSize = 0;
CmSurfaceManager* surfaceMgr = nullptr;
CM_HAL_MAX_VALUES* halMaxValues = nullptr;
CM_HAL_MAX_VALUES_EX* halMaxValuesEx = nullptr;
m_cmDevice->GetHalMaxValues( halMaxValues, halMaxValuesEx );
m_cmDevice->GetSurfaceManager( surfaceMgr );
CM_ASSERT( surfaceMgr );
surfacePoolSize = surfaceMgr->GetSurfacePoolSize();
m_surfaceArray = MOS_NewArray(bool, surfacePoolSize);
if (!m_surfaceArray)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_OUT_OF_HOST_MEMORY;
}
CmSafeMemSet( m_surfaceArray, 0, surfacePoolSize * sizeof( bool ) );
if (m_cmDevice->IsPrintEnable())
{
SurfaceIndex *printBufferIndex = nullptr;
m_cmDevice->GetPrintBufferIndex(printBufferIndex);
CM_ASSERT(printBufferIndex);
for (uint32_t i = 0; i < m_kernelCount; i++)
{
CmKernelRT* kernel = (CmKernelRT*)m_kernels.GetElement(i);
if(kernel == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer.");
return CM_FAILURE;
}
if(FAILED(kernel->SetStaticBuffer(CM_PRINTF_STATIC_BUFFER_ID, printBufferIndex)))
{
CM_ASSERTMESSAGE("Error: Failed to set static buffer.");
return CM_FAILURE;
}
}
}
for( uint32_t i = 0; i < m_kernelCount; i ++ )
{
CmKernelRT* kernel = (CmKernelRT*)m_kernels.GetElement( i );
if(kernel == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer.");
return CM_FAILURE;
}
kernel->CollectKernelSurface();
uint32_t totalSize = 0;
CmKernelData* kernelData = nullptr;
int32_t result = kernel->CreateKernelData( kernelData, totalSize, threadGroupSpace );
if(result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Failed to create kernel data.");
CmKernelData::Destroy( kernelData );
return result;
}
kernelData->SetKernelDataSize(totalSize);
kernel->GetSizeInPayload(kernelPayloadSize);
PCM_HAL_KERNEL_PARAM halKernelParam = kernelData->GetHalCmKernelData();
if (halKernelParam->crossThreadConstDataLen + halKernelParam->curbeSizePerThread + kernelPayloadSize
> halMaxValues->maxArgByteSizePerKernel)
{ //Failed, exceed the maximum of inline data
CM_ASSERTMESSAGE("Error: Invalid kernel arg size.");
return CM_EXCEED_KERNEL_ARG_SIZE_IN_BYTE;
}
else
{
kernel->GetSizeInCurbe(kernelCurbeSize);
kernelCurbeSize = kernel->GetAlignedCurbeSize(kernelCurbeSize);
totalCurbeSize += kernelCurbeSize;
}
m_kernelCurbeOffsetArray[ i ] = totalCurbeSize - kernelCurbeSize;
m_kernelData.SetElement( i, kernelData );
m_slmSize = kernel->GetSLMSize();
m_spillMemUsed = kernel->GetSpillMemUsed();
totalKernelBinarySize += kernel->GetKernelGenxBinarySize();
totalKernelBinarySize += CM_KERNEL_BINARY_PADDING_SIZE;
bool *surfArray = nullptr;
kernel->GetKernelSurfaces(surfArray);
for (uint32_t j = 0; j < surfacePoolSize; j ++)
{
m_surfaceArray[j] |= surfArray[j];
}
kernel->ResetKernelSurfaces();
PCM_CONTEXT_DATA cmData = ( PCM_CONTEXT_DATA )m_cmDevice->GetAccelData();
PCM_HAL_STATE state = cmData->cmHalState;
PRENDERHAL_MEDIA_STATE mediaStatePtr = state->pfnGetMediaStatePtrForKernel( state, kernel );
if ( ( mediaStatePtr != nullptr ) && ( m_mediaStatePtr == nullptr ) )
{
m_mediaStatePtr = mediaStatePtr;
}
else if ( ( mediaStatePtr != nullptr ) && ( m_mediaStatePtr != nullptr ) )
{
CM_ASSERTMESSAGE("Error: More than one media state heap are used in one task! User-provided state heap error.\n" );
return CM_INVALID_ARG_VALUE;
}
}
if( totalKernelBinarySize > halMaxValues->maxKernelBinarySize * halMaxValues->maxKernelsPerTask)
{
CM_ASSERTMESSAGE("Error: Invalid kernel arg size.");
return CM_EXCEED_MAX_KERNEL_SIZE_IN_BYTE;
}
UpdateSurfaceStateOnTaskCreation();
m_taskType = CM_INTERNAL_TASK_WITH_THREADGROUPSPACE;
if (threadGroupSpace)
{
threadGroupSpace->GetThreadGroupSpaceSize(m_threadSpaceWidth, m_threadSpaceHeight,
m_threadSpaceDepth, m_groupSpaceWidth,
m_groupSpaceHeight, m_groupSpaceDepth);
m_isThreadGroupSpaceCreated = true;
}
if ( m_cmDevice->CheckGTPinEnabled())
{
AllocateKernelSurfInfo();
}
this->VtuneInitProfilingInfo(threadGroupSpace);
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Class CmTaskInternal
//| Returns: None.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Initialize(CmVeboxRT* vebox)
{
int32_t result = CM_SUCCESS;
CmSurfaceManager* surfaceMgr = nullptr;
uint32_t surfacePoolSize = 0;
m_cmDevice->GetSurfaceManager( surfaceMgr );
CM_ASSERT( surfaceMgr );
surfacePoolSize = surfaceMgr->GetSurfacePoolSize();
m_surfaceArray = MOS_NewArray(bool, surfacePoolSize);
if (!m_surfaceArray)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_FAILURE;
}
CmSafeMemSet( m_surfaceArray, 0, surfacePoolSize * sizeof( bool ) );
CmBufferUP *paramBuffer = nullptr;
paramBuffer = vebox->GetParam();
m_veboxState = vebox->GetState();
m_veboxParam = paramBuffer;
m_taskType = CM_INTERNAL_TASK_VEBOX;
//Update used surfaces
for (int i = 0; i < VEBOX_SURFACE_NUMBER; i++)
{
CmSurface2DRT* surf = nullptr;
vebox->GetSurface(i, surf);
if (surf)
{
uint32_t surfaceHandle = 0;
SurfaceIndex* surfIndex = nullptr;
surf->GetIndex(surfIndex);
surf->GetHandle(surfaceHandle);
m_surfaceArray[surfIndex->get_data()] = true;
m_veboxSurfaceData.surfaceEntry[i].surfaceIndex = (uint16_t)surfaceHandle;
m_veboxSurfaceData.surfaceEntry[i].surfaceCtrlBits = vebox->GetSurfaceControlBits(i);
}
else
{
m_veboxSurfaceData.surfaceEntry[i].surfaceIndex = CM_INVALID_INDEX;
m_veboxSurfaceData.surfaceEntry[i].surfaceCtrlBits = CM_INVALID_INDEX;
}
}
UpdateSurfaceStateOnTaskCreation();
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Class CmTaskInternal with hints
//| Returns: Result of the operation
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::Initialize(uint32_t hints, uint32_t numTasksGenerated, bool isLastTask)
{
CmThreadSpaceRT* threadSpace = nullptr;
int32_t result = CM_SUCCESS;
// use ThreadSpace Initialize function to create kernel data
result = this->Initialize(threadSpace, true);
// set hints in task
m_hints = hints;
m_numTasksGenerated = numTasksGenerated;
m_isLastTask = isLastTask;
// set task type to be EnqueueWithHints
m_taskType = CM_INTERNAL_TASK_ENQUEUEWITHHINTS;
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Kernel Count
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetKernelCount( uint32_t& count )
{
count = m_kernelCount;
return CM_SUCCESS;
}
int32_t CmTaskInternal::GetTaskSurfaces( bool *&surfArray )
{
surfArray = m_surfaceArray;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Geth Kernel from the Kernel array
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetKernel( const uint32_t index, CmKernelRT* & kernel )
{
kernel = nullptr;
if( index < m_kernels.GetSize() )
{
kernel = (CmKernelRT*)m_kernels.GetElement( index );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Geth Kernel data by kernel's index
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetKernelData( const uint32_t index, CmKernelData* & kernelData )
{
kernelData = nullptr;
if( index < m_kernelData.GetSize() )
{
kernelData = (CmKernelData*)m_kernelData.GetElement( index );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Geth Kernel data size by kernel's index
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetKernelDataSize( const uint32_t index, uint32_t & size )
{
size = 0;
CmKernelData* kernelData = nullptr;
if( index < m_kernelData.GetSize() )
{
kernelData = (CmKernelData*)m_kernelData.GetElement( index );
if (kernelData == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel data.");
return CM_FAILURE;
}
size = kernelData->GetKernelDataSize();
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Get kernel's curbe offset
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
uint32_t CmTaskInternal::GetKernelCurbeOffset( const uint32_t index )
{
return ( uint32_t ) m_kernelCurbeOffsetArray[ index ];
}
//*-----------------------------------------------------------------------------
//| Purpose: Set task event, need add refcount hehe.
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::SetTaskEvent( CmEventRT* event )
{
m_taskEvent = event;
// add refCount
m_taskEvent->Acquire();
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the task event
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetTaskEvent( CmEventRT* & event )
{
event = m_taskEvent;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the task's status
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetTaskStatus(CM_STATUS & taskStatus)
{
if(m_taskEvent == nullptr)
{
return CM_FAILURE;
}
return m_taskEvent->GetStatusNoFlush(taskStatus);
}
//*-----------------------------------------------------------------------------
//| Purpose: Record CPU ticks for Flush Time
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::VtuneSetFlushTime()
{
if(!m_cmDevice->IsVtuneLogOn())
{ // return directly if ETW log is off
return CM_SUCCESS;
}
MOS_QueryPerformanceCounter((uint64_t*)&m_taskProfilingInfo.flushTime.QuadPart);
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Profiling Information for Media Pipeline
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::VtuneInitProfilingInfo(const CmThreadSpaceRT *perTaskThreadSpace)
{
CmKernelRT *cmKernel = nullptr;
CmThreadSpaceRT *perKernelThreadSpace = nullptr;
uint32_t threadSpaceWidth = 0;
uint32_t threadSpaceHeight = 0;
int32_t hr = CM_SUCCESS;
if(!m_cmDevice->IsVtuneLogOn())
{ // return directly if ETW log is off
return CM_SUCCESS;
}
CmSafeMemSet(&m_taskProfilingInfo, 0, sizeof(m_taskProfilingInfo));
m_taskProfilingInfo.kernelCount = m_kernelCount;
m_taskProfilingInfo.threadID = CmGetCurThreadId(); // Get Thread ID
MOS_QueryPerformanceCounter((uint64_t*)&m_taskProfilingInfo.enqueueTime.QuadPart); // Get Enqueue Time
// Currently, the Kernel/ThreadSpace/ThreadGroupSpace could not be deleted before task finished.
m_taskProfilingInfo.kernelNames = MOS_NewArray(char, (CM_MAX_KERNEL_NAME_SIZE_IN_BYTE * m_kernelCount));
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.kernelNames);
m_taskProfilingInfo.localWorkWidth = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.localWorkWidth);
m_taskProfilingInfo.localWorkHeight = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.localWorkHeight);
m_taskProfilingInfo.globalWorkWidth = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.globalWorkWidth);
m_taskProfilingInfo.globalWorkHeight = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.globalWorkHeight);
for (uint32_t i = 0; i < m_kernelCount; i++)
{
CM_CHK_CMSTATUS_GOTOFINISH(GetKernel(i, cmKernel));
CM_CHK_NULL_GOTOFINISH_CMERROR(cmKernel);
//Copy Kernel Name
MOS_SecureStrcpy(m_taskProfilingInfo.kernelNames + m_taskProfilingInfo.kernelNameLen,
CM_MAX_KERNEL_NAME_SIZE_IN_BYTE, cmKernel->GetName());
//Add Kernel Name Length
m_taskProfilingInfo.kernelNameLen += strlen(cmKernel->GetName()) + 1;
CM_CHK_CMSTATUS_GOTOFINISH(cmKernel->GetThreadSpace(perKernelThreadSpace));
if (perTaskThreadSpace)
{
//Per Task Thread Space Exists
m_taskProfilingInfo.localWorkWidth[i] = m_threadSpaceWidth;
m_taskProfilingInfo.localWorkHeight[i] = m_threadSpaceHeight;
m_taskProfilingInfo.globalWorkWidth[i] = m_threadSpaceWidth;
m_taskProfilingInfo.globalWorkHeight[i] = m_threadSpaceHeight;
}
else if (perKernelThreadSpace)
{
//Fill each threads Space's info
perKernelThreadSpace->GetThreadSpaceSize(threadSpaceWidth, threadSpaceHeight);
m_taskProfilingInfo.localWorkWidth[i] = threadSpaceWidth;
m_taskProfilingInfo.localWorkHeight[i] = threadSpaceHeight;
m_taskProfilingInfo.globalWorkWidth[i] = threadSpaceWidth;
m_taskProfilingInfo.globalWorkHeight[i] = threadSpaceHeight;
}
else
{
//Fill the thread count
uint32_t threadCount = 0;
cmKernel->GetThreadCount(threadCount);
m_taskProfilingInfo.localWorkWidth[i] = threadCount;
m_taskProfilingInfo.localWorkHeight[i] = 1;
m_taskProfilingInfo.globalWorkWidth[i] = threadCount;
m_taskProfilingInfo.globalWorkHeight[i] = 1;
}
}
finish:
if (hr != CM_SUCCESS)
{
MosSafeDeleteArray(m_taskProfilingInfo.kernelNames);
MosSafeDeleteArray(m_taskProfilingInfo.localWorkWidth);
MosSafeDeleteArray(m_taskProfilingInfo.localWorkHeight);
MosSafeDeleteArray(m_taskProfilingInfo.globalWorkWidth);
MosSafeDeleteArray(m_taskProfilingInfo.globalWorkHeight);
}
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Profiling Information
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::VtuneInitProfilingInfo(const CmThreadGroupSpace *perTaskThreadGroupSpace)
{
CmKernelRT *cmKernel = nullptr;
CmThreadGroupSpace *perKernelGroupSpace = nullptr;
uint32_t threadSpaceWidth = 0;
uint32_t threadSpaceHeight = 0;
uint32_t threadSpaceDepth = 0;
uint32_t threadGroupSpaceWidth = 0;
uint32_t threadGroupSpaceHeight = 0;
uint32_t threadGroupSpaceDepth = 0;
int32_t hr = CM_SUCCESS;
if(!m_cmDevice->IsVtuneLogOn())
{ // return directly if ETW log is off
return CM_SUCCESS;
}
CmSafeMemSet(&m_taskProfilingInfo, 0, sizeof(m_taskProfilingInfo));
m_taskProfilingInfo.kernelCount = m_kernelCount;
m_taskProfilingInfo.threadID = CmGetCurThreadId(); // Get Thread ID
MOS_QueryPerformanceCounter((uint64_t*)&m_taskProfilingInfo.enqueueTime.QuadPart); // Get Enqueue Time
m_taskProfilingInfo.kernelNames = MOS_NewArray(char, (CM_MAX_KERNEL_NAME_SIZE_IN_BYTE * m_kernelCount));
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.kernelNames);
m_taskProfilingInfo.localWorkWidth = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.localWorkWidth);
m_taskProfilingInfo.localWorkHeight = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.localWorkHeight);
m_taskProfilingInfo.globalWorkWidth = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.globalWorkWidth);
m_taskProfilingInfo.globalWorkHeight = MOS_NewArray(uint32_t, m_kernelCount);
CM_CHK_NULL_GOTOFINISH_CMERROR(m_taskProfilingInfo.globalWorkHeight);
for (uint32_t i = 0; i < m_kernelCount; i++)
{
CM_CHK_CMSTATUS_GOTOFINISH(GetKernel(i, cmKernel));
CM_CHK_NULL_GOTOFINISH_CMERROR(cmKernel);
//Copy Kernel Name
MOS_SecureStrcpy(m_taskProfilingInfo.kernelNames + m_taskProfilingInfo.kernelNameLen,
CM_MAX_KERNEL_NAME_SIZE_IN_BYTE, cmKernel->GetName());
//Add Kernel Name Length
m_taskProfilingInfo.kernelNameLen += strlen(cmKernel->GetName()) + 1;
CM_CHK_CMSTATUS_GOTOFINISH(cmKernel->GetThreadGroupSpace(perKernelGroupSpace));
if (perTaskThreadGroupSpace)
{ // Per Thread Group Space
perTaskThreadGroupSpace->GetThreadGroupSpaceSize(threadSpaceWidth, threadSpaceHeight,
threadSpaceDepth, threadGroupSpaceWidth,
threadGroupSpaceHeight, threadGroupSpaceDepth);
m_taskProfilingInfo.localWorkWidth[i] = threadSpaceWidth;
m_taskProfilingInfo.localWorkHeight[i] = threadSpaceHeight;
m_taskProfilingInfo.globalWorkWidth[i] = threadSpaceWidth*threadGroupSpaceWidth;
m_taskProfilingInfo.globalWorkHeight[i] = threadSpaceHeight*threadGroupSpaceHeight;
}
else if (perKernelGroupSpace)
{
//Fill each threads group space's info
perKernelGroupSpace->GetThreadGroupSpaceSize(threadSpaceWidth, threadSpaceHeight,
threadSpaceDepth, threadGroupSpaceWidth,
threadGroupSpaceHeight, threadGroupSpaceDepth);
m_taskProfilingInfo.localWorkWidth[i] = threadSpaceWidth;
m_taskProfilingInfo.localWorkHeight[i] = threadSpaceHeight;
m_taskProfilingInfo.globalWorkWidth[i] = threadSpaceWidth*threadGroupSpaceWidth;
m_taskProfilingInfo.globalWorkHeight[i] = threadSpaceHeight*threadGroupSpaceHeight; //Yi need to rethink
}
}
finish:
if (hr != CM_SUCCESS)
{
MosSafeDeleteArray(m_taskProfilingInfo.kernelNames);
MosSafeDeleteArray(m_taskProfilingInfo.localWorkWidth);
MosSafeDeleteArray(m_taskProfilingInfo.localWorkHeight);
MosSafeDeleteArray(m_taskProfilingInfo.globalWorkWidth);
MosSafeDeleteArray(m_taskProfilingInfo.globalWorkHeight);
}
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Release Profiling information
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::VtuneReleaseProfilingInfo()
{
if(!m_cmDevice->IsVtuneLogOn())
{ // return directly if ETW log is off
return CM_SUCCESS;
}
MosSafeDeleteArray(m_taskProfilingInfo.kernelNames);
MosSafeDeleteArray(m_taskProfilingInfo.localWorkWidth);
MosSafeDeleteArray(m_taskProfilingInfo.localWorkHeight);
MosSafeDeleteArray(m_taskProfilingInfo.globalWorkWidth);
MosSafeDeleteArray(m_taskProfilingInfo.globalWorkHeight);
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Reset KernelData status from IN_USE to IDLE.
// It is called immediately after the task being flushed.
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::ResetKernelDataStatus()
{
int32_t hr = CM_SUCCESS;
for(uint32_t krnDataIndex =0 ; krnDataIndex < m_kernelCount; krnDataIndex++ )
{
CmKernelData *kernelData;
CM_CHK_CMSTATUS_GOTOFINISH(GetKernelData(krnDataIndex, kernelData));
CM_CHK_NULL_GOTOFINISH_CMERROR(kernelData);
CM_CHK_CMSTATUS_GOTOFINISH(kernelData->ResetStatus());
}
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create thread space data
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::CreateThreadSpaceData(const CmThreadSpaceRT* threadSpace)
{
uint32_t i;
uint32_t width, height;
uint32_t *kernelCoordinateIndex = nullptr;
int hr = CM_SUCCESS;
CmThreadSpaceRT *threadSpaceRT = const_cast<CmThreadSpaceRT*>(threadSpace);
CmKernelRT* kernelInThreadSpace = nullptr;
CmKernelRT* kernelInTask = nullptr;
CM_CHK_NULL_GOTOFINISH(threadSpaceRT, CM_NULL_POINTER);
threadSpaceRT->GetThreadSpaceSize(m_threadSpaceWidth, m_threadSpaceHeight);
if (threadSpaceRT->IsThreadAssociated())
{
m_threadCoordinates = MOS_NewArray(PCM_HAL_SCOREBOARD, m_kernelCount);
CM_CHK_NULL_GOTOFINISH(m_threadCoordinates, CM_FAILURE);
CmSafeMemSet(m_threadCoordinates, 0, m_kernelCount*sizeof(PCM_HAL_SCOREBOARD));
m_dependencyMasks = MOS_NewArray(PCM_HAL_MASK_AND_RESET, m_kernelCount);
CM_CHK_NULL_GOTOFINISH(m_dependencyMasks, CM_FAILURE);
CmSafeMemSet(m_dependencyMasks, 0, m_kernelCount*sizeof(PCM_HAL_MASK_AND_RESET));
kernelCoordinateIndex = MOS_NewArray(uint32_t, m_kernelCount);
if(m_threadCoordinates && kernelCoordinateIndex && m_dependencyMasks)
{
CmSafeMemSet(kernelCoordinateIndex, 0, m_kernelCount*sizeof(uint32_t));
for (i = 0; i< m_kernelCount; i++)
{
kernelCoordinateIndex[i] = 0;
uint32_t threadCount;
this->GetKernel(i, kernelInTask);
if(kernelInTask == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer in task.");
hr = CM_NULL_POINTER;
goto finish;
}
kernelInTask->GetThreadCount(threadCount);
if (threadCount == 0)
{
threadCount = m_threadSpaceWidth*m_threadSpaceHeight;
}
m_threadCoordinates[i] = MOS_NewArray(CM_HAL_SCOREBOARD, threadCount);
if (m_threadCoordinates[i])
{
CmSafeMemSet(m_threadCoordinates[i], 0, sizeof(CM_HAL_SCOREBOARD)* threadCount);
}
else
{
CM_ASSERTMESSAGE("Error: Pointer to thread coordinates is null.");
hr = CM_NULL_POINTER;
goto finish;
}
m_dependencyMasks[i] = MOS_NewArray(CM_HAL_MASK_AND_RESET, threadCount);
if( m_dependencyMasks[i] )
{
CmSafeMemSet(m_dependencyMasks[i], 0, sizeof(CM_HAL_MASK_AND_RESET) * threadCount);
}
else
{
CM_ASSERTMESSAGE("Error: Pointer to dependency masks is null.");
hr = CM_NULL_POINTER;
goto finish;
}
}
CM_THREAD_SPACE_UNIT *threadSpaceUnit = nullptr;
threadSpaceRT->GetThreadSpaceSize(width, height);
threadSpaceRT->GetThreadSpaceUnit(threadSpaceUnit);
uint32_t *boardOrder = nullptr;
threadSpaceRT->GetBoardOrder(boardOrder);
for (uint32_t tIndex=0; tIndex < height*width; tIndex ++)
{
kernelInThreadSpace = static_cast<CmKernelRT *>(threadSpaceUnit[boardOrder[tIndex]].kernel);
if (kernelInThreadSpace == nullptr)
{
if (threadSpaceRT->GetNeedSetKernelPointer())
{
kernelInThreadSpace = threadSpaceRT->GetKernelPointer();
}
if (kernelInThreadSpace == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer in task.");
hr = CM_NULL_POINTER;
goto finish;
}
}
uint32_t kIndex = kernelInThreadSpace->GetIndexInTask();
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].x
= threadSpaceUnit[boardOrder[tIndex]].scoreboardCoordinates.x;
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].y
= threadSpaceUnit[boardOrder[tIndex]].scoreboardCoordinates.y;
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].mask
= threadSpaceUnit[boardOrder[tIndex]].dependencyMask;
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].resetMask
= threadSpaceUnit[boardOrder[tIndex]].reset;
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].color
= threadSpaceUnit[boardOrder[tIndex]].scoreboardColor;
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].sliceSelect
= threadSpaceUnit[boardOrder[tIndex]].sliceDestinationSelect;
m_threadCoordinates[kIndex][kernelCoordinateIndex[kIndex]].subSliceSelect
= threadSpaceUnit[boardOrder[tIndex]].subSliceDestinationSelect;
m_dependencyMasks[kIndex][kernelCoordinateIndex[kIndex]].mask
= threadSpaceUnit[boardOrder[tIndex]].dependencyMask;
m_dependencyMasks[kIndex][kernelCoordinateIndex[kIndex]].resetMask
= threadSpaceUnit[boardOrder[tIndex]].reset;
kernelCoordinateIndex[kIndex] ++;
}
MosSafeDeleteArray(kernelCoordinateIndex);
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create thread space data.");
hr = CM_FAILURE;
goto finish;
}
m_isThreadCoordinatesExisted = true;
}
else
{
m_threadCoordinates = nullptr;
m_dependencyMasks = nullptr;
m_isThreadCoordinatesExisted = false;
}
if (threadSpaceRT->IsDependencySet())
{
threadSpaceRT->GetDependencyPatternType(m_dependencyPattern);
}
threadSpaceRT->GetColorCountMinusOne(m_colorCountMinusOne);
threadSpaceRT->GetMediaWalkerGroupSelect(m_mediaWalkerGroupSelect);
threadSpaceRT->GetWalkingPattern(m_walkingPattern);
m_mediaWalkerParamsSet = threadSpaceRT->CheckWalkingParametersSet();
if( m_mediaWalkerParamsSet )
{
CM_WALKING_PARAMETERS tmpMWParams;
CM_CHK_CMSTATUS_GOTOFINISH(threadSpaceRT->GetWalkingParameters(tmpMWParams));
CmSafeMemCopy(&m_walkingParameters, &tmpMWParams, sizeof(tmpMWParams));
}
m_dependencyVectorsSet = threadSpaceRT->CheckDependencyVectorsSet();
if( m_dependencyVectorsSet )
{
CM_HAL_DEPENDENCY tmpDepVectors;
CM_CHK_CMSTATUS_GOTOFINISH(threadSpaceRT->GetDependencyVectors(tmpDepVectors));
CmSafeMemCopy(&m_dependencyVectors, &tmpDepVectors, sizeof(tmpDepVectors));
}
finish:
if(hr != CM_SUCCESS)
{
if(m_threadCoordinates )
{
for (i = 0; i< m_kernelCount; i++)
{
MosSafeDeleteArray(m_threadCoordinates[i]);
}
}
if(m_dependencyMasks)
{
for (i = 0; i< m_kernelCount; i++)
{
MosSafeDeleteArray(m_dependencyMasks[i]);
}
}
MosSafeDeleteArray(m_threadCoordinates);
MosSafeDeleteArray(m_dependencyMasks);
MosSafeDeleteArray(kernelCoordinateIndex);
}
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get thread space's coordinates
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetKernelCoordinates(const uint32_t index, void *&kernelCoordinates)
{
if (m_threadCoordinates != nullptr)
{
kernelCoordinates = (void *)m_threadCoordinates[index];
}
else
{
kernelCoordinates = nullptr;
}
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get thread space's dependency masks
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetKernelDependencyMasks(const uint32_t index, void *&kernelDependencyMasks)
{
if (m_dependencyMasks != nullptr)
{
kernelDependencyMasks = (void *)m_dependencyMasks[index];
}
else
{
kernelDependencyMasks = nullptr;
}
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get dependency pattern
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetDependencyPattern(CM_DEPENDENCY_PATTERN &dependencyPattern)
{
dependencyPattern = m_dependencyPattern;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get media walking pattern
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetWalkingPattern(CM_WALKING_PATTERN &walkingPattern)
{
walkingPattern = m_walkingPattern;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get media walking parameters
//| Returns: CM_FAILURE if dest ptr is nullptr, CM_SUCCESS otherwise
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetWalkingParameters(CM_WALKING_PARAMETERS &walkingParameters)
{
CmSafeMemCopy(&walkingParameters, &m_walkingParameters, sizeof(m_walkingParameters));
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Check to see if media walking parameters have been set
//| Returns: true if media walking parameters set, false otherwise
//*-----------------------------------------------------------------------------
bool CmTaskInternal::CheckWalkingParametersSet( )
{
return m_mediaWalkerParamsSet;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get dependency vectors
//| Returns: CM_FAILURE if dest ptr is nullptr, CM_SUCCESS otherwise
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetDependencyVectors(CM_HAL_DEPENDENCY &dependencyVectors)
{
CmSafeMemCopy(&dependencyVectors, &m_dependencyVectors, sizeof(m_dependencyVectors));
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Check to see if dependency vectors have been set
//| Returns: true if dependency vectors are set, false otherwise
//*-----------------------------------------------------------------------------
bool CmTaskInternal::CheckDependencyVectorsSet( )
{
return m_dependencyVectorsSet;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the total thread count
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetTotalThreadCount( uint32_t& totalThreadCount )
{
totalThreadCount = m_totalThreadCount;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the width,height of thread space
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetThreadSpaceSize(uint32_t& width, uint32_t& height )
{
width = m_threadSpaceWidth;
height = m_threadSpaceHeight;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the color count minus one of the thread space
//| Used to dispatch multiple sets of dependency threads
//| for media walker
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetColorCountMinusOne( uint32_t& colorCount )
{
colorCount = m_colorCountMinusOne;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Whether thread space is created
//| Returns: Boolean.
//*-----------------------------------------------------------------------------
bool CmTaskInternal::IsThreadSpaceCreated(void )
{
return m_isThreadSpaceCreated;
}
//*-----------------------------------------------------------------------------
//| Purpose: Whether thread coordinates are existed
//| Returns: Boolean.
//*-----------------------------------------------------------------------------
bool CmTaskInternal::IsThreadCoordinatesExisted(void)
{
return m_isThreadCoordinatesExisted;
}
//*-----------------------------------------------------------------------------
//| Purpose: Whether thread coordinates are existed
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetThreadGroupSpaceSize(uint32_t& threadSpaceWidth, uint32_t& threadSpaceHeight,
uint32_t& threadSpaceDepth, uint32_t& groupSpaceWidth,
uint32_t& groupSpaceHeight, uint32_t& groupSpaceDepth)
{
threadSpaceWidth = m_threadSpaceWidth;
threadSpaceHeight = m_threadSpaceHeight;
threadSpaceDepth = m_threadSpaceDepth;
groupSpaceWidth = m_groupSpaceWidth;
groupSpaceHeight = m_groupSpaceHeight;
groupSpaceDepth = m_groupSpaceDepth;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the size of sharedlocalmemory
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetSLMSize(uint32_t& slmSize)
{
slmSize = m_slmSize;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the size of spill memory used
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetSpillMemUsed(uint32_t& spillMemUsed)
{
spillMemUsed = m_spillMemUsed;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the hints for EnqueueWithHints
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetHints(uint32_t& hints)
{
hints = m_hints;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Gets the number of tasks generated for EnqueueWithHints
//| Used when splitting large task to smaller tasks
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetNumTasksGenerated(uint32_t& numTasksGenerated)
{
numTasksGenerated = m_numTasksGenerated;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Gets whether or not this task is the last task for EnqueueWithHints
//| Used to identify last smaller task when splitting large task
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetLastTask(bool& isLastTask)
{
isLastTask = m_isLastTask;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Whether thread group space is created
//| Returns: Value.
//*-----------------------------------------------------------------------------
bool CmTaskInternal::IsThreadGroupSpaceCreated(void)
{
return m_isThreadGroupSpaceCreated;
}
//*-----------------------------------------------------------------------------
//| Purpose: Allocate Space to record kernel surface's information
//| Returns: result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::AllocateKernelSurfInfo()
{
//Allocate Surf info array
m_kernelSurfInfo.kernelNum = m_kernelCount;
m_kernelSurfInfo.surfEntryInfosArray
= (CM_HAL_SURFACE_ENTRY_INFO_ARRAY*)MOS_AllocAndZeroMemory(m_kernelCount *
sizeof(CM_HAL_SURFACE_ENTRY_INFO_ARRAY));
if(m_kernelSurfInfo.surfEntryInfosArray == nullptr)
{
CM_ASSERTMESSAGE("Error: Mem allocation fail.");
return CM_OUT_OF_HOST_MEMORY;
}
for( uint32_t i = 0; i < m_kernelCount; i ++ )
{
CmKernelRT * tempCmKernel = nullptr;
this->GetKernel(i, tempCmKernel);
if(tempCmKernel == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid kernel pointer.");
return CM_FAILURE;
}
CM_ARG* arg=NULL;
tempCmKernel->GetArgs( arg );
uint32_t argCount = 0;
tempCmKernel->GetArgCount( argCount);
//allocate memory for non_static buffer&2D&3D
uint32_t surfEntryNum = 0;
for( uint32_t j = 0; j < argCount; j ++ )
{
switch(arg[ j ].unitKind)
{
case ARG_KIND_SURFACE_1D:
surfEntryNum = surfEntryNum + arg[ j ].unitCount * arg[j].unitSize/sizeof(int);
break;
case ARG_KIND_SURFACE_2D:
case ARG_KIND_SURFACE_2D_UP:
case ARG_KIND_SURFACE_3D:
case ARG_KIND_SURFACE_SAMPLER8X8_AVS:
case ARG_KIND_SURFACE_SAMPLER8X8_VA:
surfEntryNum = surfEntryNum + 3 * arg[ j ].unitCount * arg[j].unitSize/sizeof(int);//one 2D or 3D can have upto 3 planes
break;
case ARG_KIND_SURFACE_VME:
surfEntryNum = surfEntryNum + 24 * arg[ j ].unitCount;//surfaceVME will use upto 8 surfaces, each one can have upto 3 planes
break;
default:
break;
}
}
CM_HAL_SURFACE_ENTRY_INFO_ARRAY* tempArray = m_kernelSurfInfo.surfEntryInfosArray;
if(surfEntryNum>0)
{
tempArray[i].maxEntryNum = surfEntryNum;
tempArray[i].surfEntryInfos = (CM_SURFACE_DETAILS*)MOS_AllocAndZeroMemory(surfEntryNum*sizeof(CM_SURFACE_DETAILS));
if(tempArray[i].surfEntryInfos == nullptr)
{
CM_ASSERTMESSAGE("Error: Mem allocation fail.");
return CM_OUT_OF_HOST_MEMORY;
}
}
//allocate memory for those 7 static buffers
uint32_t globalBufNum=CM_GLOBAL_SURFACE_NUMBER + CM_GTPIN_BUFFER_NUM;
tempArray[i].globalSurfNum=globalBufNum;
tempArray[i].globalSurfInfos = (CM_SURFACE_DETAILS*)MOS_AllocAndZeroMemory(
globalBufNum*sizeof(CM_SURFACE_DETAILS));
if(tempArray[i].globalSurfInfos == nullptr)
{
CM_ASSERTMESSAGE("Mem allocation fail.");
return CM_OUT_OF_HOST_MEMORY;
}
}
return CM_SUCCESS;
}
int32_t CmTaskInternal::GetKernelSurfInfo(CM_HAL_SURFACE_ENTRY_INFO_ARRAYS & surfEntryInfoArray)
{
surfEntryInfoArray = m_kernelSurfInfo;
return CM_SUCCESS;
}
int32_t CmTaskInternal::ClearKernelSurfInfo()
{
if (m_kernelSurfInfo.surfEntryInfosArray == nullptr)
{ // if surfEntryInfosArray is empty, return directly
return CM_SUCCESS;
}
//free memory
for( uint32_t i = 0; i < m_kernelCount; i ++ )
{
if (m_kernelSurfInfo.surfEntryInfosArray[i].surfEntryInfos != nullptr)
{
MosSafeDelete(m_kernelSurfInfo.surfEntryInfosArray[i].surfEntryInfos);
}
if (m_kernelSurfInfo.surfEntryInfosArray[i].globalSurfInfos!= nullptr)
{
MosSafeDelete(m_kernelSurfInfo.surfEntryInfosArray[i].globalSurfInfos);
}
}
MosSafeDelete(m_kernelSurfInfo.surfEntryInfosArray);
m_kernelSurfInfo.kernelNum = 0 ;
m_kernelSurfInfo.surfEntryInfosArray = nullptr;
return CM_SUCCESS;
}
int32_t CmTaskInternal::GetTaskType(uint32_t& taskType)
{
taskType = m_taskType;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get vebox state
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::GetVeboxState(CM_VEBOX_STATE &veboxState)
{
veboxState = m_veboxState;
return CM_SUCCESS;
}
int32_t CmTaskInternal::GetVeboxParam(CmBufferUP * &veboxParam)
{
veboxParam = m_veboxParam;
return CM_SUCCESS;
}
int32_t CmTaskInternal::GetVeboxSurfaceData(CM_VEBOX_SURFACE_DATA &veboxSurfaceData)
{
veboxSurfaceData = m_veboxSurfaceData;
return CM_SUCCESS;
}
uint64_t CmTaskInternal::GetSyncBitmap()
{
return m_ui64SyncBitmap;
}
uint64_t CmTaskInternal::GetConditionalEndBitmap()
{
return m_ui64ConditionalEndBitmap;
}
CM_HAL_CONDITIONAL_BB_END_INFO* CmTaskInternal::GetConditionalEndInfo()
{
return m_conditionalEndInfo;
}
//*-----------------------------------------------------------------------------
//| Purpose: Set power option for this task
//| Returns: Result of operation.
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::SetPowerOption( PCM_POWER_OPTION powerOption )
{
if (powerOption == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to power option is null.");
return CM_NULL_POINTER;
}
CmSafeMemCopy( &m_powerOption, powerOption, sizeof( m_powerOption ) );
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get power option for this task
//| Returns: Pointer to power option.
//*-----------------------------------------------------------------------------
PCM_POWER_OPTION CmTaskInternal::GetPowerOption()
{
return &m_powerOption;
}
#if _DEBUG
const char *gDependencyPatternString[] =
{
"DEPENDENCY_NONE",
"DEPENDENCY_WAVEFRONT45",
"DEPENDENCY_WAVEFRONT26"
};
//Only for debugging
int32_t CmTaskInternal::DisplayThreadSpaceData(uint32_t width, uint32_t height)
{
if (m_threadCoordinates != nullptr)
{
CM_NORMALMESSAGE("Score board[Kernel x: (x1, y1), (x2, y2)...]:");
for (uint32_t i = 0; i < m_kernelCount; i ++)
{
CmKernelRT *kernelRT = nullptr;
GetKernel(i, kernelRT);
if(nullptr == kernelRT)
{
return CM_FAILURE;
}
uint32_t threadCount;
kernelRT->GetThreadCount(threadCount);
if (threadCount == 0)
{
threadCount = m_threadSpaceWidth*m_threadSpaceHeight;
}
CM_NORMALMESSAGE("Kernel %d: ", i);
for (uint32_t j=0; j<threadCount; j++)
{
CM_NORMALMESSAGE("(%d, %d) ", m_threadCoordinates[i][j].x, m_threadCoordinates[i][j].y);
}
}
}
else
{
CM_NORMALMESSAGE("Score Board is NULL.");
}
if (m_dependencyPattern <= CM_WAVEFRONT26)
{
CM_NORMALMESSAGE("Dependency Pattern: %s.", gDependencyPatternString[m_dependencyPattern]);
}
else
{
CM_NORMALMESSAGE("Dependency Pattern: UNASSIGNED.");
}
return CM_SUCCESS;
}
#endif
int32_t CmTaskInternal::GetMediaWalkerGroupSelect(CM_MW_GROUP_SELECT& groupSelect)
{
groupSelect = m_mediaWalkerGroupSelect;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Update surface state on task destroy stage
//*-----------------------------------------------------------------------------
int32_t CmTaskInternal::UpdateSurfaceStateOnTaskCreation()
{
CmSurfaceManager* surfaceMgr = nullptr;
int32_t *surfState = nullptr;
m_cmDevice->GetSurfaceManager(surfaceMgr);
if (surfaceMgr == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to surface manager is null.");
return CM_NULL_POINTER;
}
uint32_t poolSize = surfaceMgr->GetSurfacePoolSize();
CSync* surfaceLock = m_cmDevice->GetSurfaceCreationLock();
if (surfaceLock == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to surface creation lock is null.");
return CM_NULL_POINTER;
}
surfaceLock->Acquire();
// get the last tracker
PCM_CONTEXT_DATA cmData = ( PCM_CONTEXT_DATA )m_cmDevice->GetAccelData();
PCM_HAL_STATE state = cmData->cmHalState;
if (!m_isSurfaceUpdateDone)
{
for (uint32_t i = 0; i < poolSize; i++)
{
if (m_surfaceArray[i])
{
CmSurface *surface = NULL;
CM_CHK_CMSTATUS_RETURN(surfaceMgr->GetSurface(i, surface));
if (surface == nullptr) // surface destroyed but not updated in kernel
{
continue;
}
if (m_taskType == CM_INTERNAL_TASK_VEBOX)
{
surface->SetVeboxTracker(state->renderHal->veBoxTrackerRes.currentTrackerId);
}
else
{
surface->SetRenderTracker(state->renderHal->trackerResource.currentTrackerId);
}
}
}
m_isSurfaceUpdateDone = true;
}
surfaceLock->Release();
return CM_SUCCESS;
}
#if CM_LOG_ON
std::string CmTaskInternal::Log()
{
std::ostringstream oss;
oss << "Enqueue Task Type:" << m_taskType
<< " Kernel Count:" << m_kernelCount
<< " Total Thread Count:" << m_totalThreadCount
<< " Sync Bit:"<<m_ui64SyncBitmap
<< " Conditional End Bit:" << m_ui64ConditionalEndBitmap
<< std::endl;
switch(m_taskType)
{
case CM_INTERNAL_TASK_WITH_THREADSPACE:
if ( m_isThreadSpaceCreated )
{
oss << "Thread Space Width :" << m_threadSpaceWidth << " Height :" << m_threadSpaceHeight
<< "Walker Patten :" << (int)m_walkingPattern << std::endl;
}
break;
case CM_INTERNAL_TASK_WITH_THREADGROUPSPACE:
if(m_isThreadGroupSpaceCreated)
{
oss << "Thread Group Space Width:" << m_groupSpaceWidth << " Height:" << m_groupSpaceHeight
<< "SLM Size:" <<m_slmSize << std::endl;
}
break;
case CM_INTERNAL_TASK_VEBOX:
break;
case CM_INTERNAL_TASK_ENQUEUEWITHHINTS:
oss << " Hints :" << m_hints
<< " Thread Space Width :" << m_threadSpaceWidth
<< " Height :" << m_threadSpaceHeight
<< " Walker Patten :" << (int)m_walkingPattern
<< std::endl;
break;
default: // by default, assume the task is considered as general task: CM_INTERNAL_TASK_WITH_THREADSPACE
break;
}
for (uint32_t i=0 ; i< m_kernelCount; i++)
{
CmKernelRT* kernel = (CmKernelRT*)m_kernels.GetElement( i );
oss << kernel->Log(); // log each kernel
}
return oss.str();
}
#endif
void CmTaskInternal::SurfaceDump(int32_t taskId)
{
#if MDF_SURFACE_CONTENT_DUMP
for (uint32_t i=0 ; i< m_kernelCount; i++)
{
CmKernelRT* kernel = (CmKernelRT*)m_kernels.GetElement( i );
kernel->SurfaceDump(i, taskId);
}
#endif
}
int32_t CmTaskInternal::SetProperty(CM_TASK_CONFIG * taskConfig)
{
if (taskConfig == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to task config is null.");
return CM_NULL_POINTER;
}
CmSafeMemCopy(&m_taskConfig, taskConfig, sizeof(m_taskConfig));
return CM_SUCCESS;
}
PCM_TASK_CONFIG CmTaskInternal::GetTaskConfig()
{
return &m_taskConfig;
}
void *CMRT_UMD::CmTaskInternal::GetMediaStatePtr()
{
return m_mediaStatePtr;
}
}
|