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 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583
|
/*
* Copyright (c) 2007-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_queue_rt.cpp
//! \brief Contains CmQueueRT implementations.
//!
#include "cm_queue_rt.h"
#include "cm_mem.h"
#include "cm_device_rt.h"
#include "cm_event_rt.h"
#include "cm_task_rt.h"
#include "cm_task_internal.h"
#include "cm_thread_space_rt.h"
#include "cm_kernel_rt.h"
#include "cm_kernel_data.h"
#include "cm_buffer_rt.h"
#include "cm_group_space.h"
#include "cm_vebox_data.h"
#include "cm_surface_manager.h"
#include "cm_surface_2d_rt.h"
#include "cm_vebox_rt.h"
#include "cm_execution_adv.h"
// Used by GPUCopy
#define BLOCK_PIXEL_WIDTH (32)
#define BLOCK_HEIGHT (8)
#define BLOCK_HEIGHT_NV12 (4)
#define SUB_BLOCK_PIXEL_WIDTH (8)
#define SUB_BLOCK_HEIGHT (8)
#define SUB_BLOCK_HEIGHT_NV12 (4)
#define INNER_LOOP (4)
#define BYTE_COPY_ONE_THREAD (1024*INNER_LOOP) //4K for each thread
#define THREAD_SPACE_WIDTH_INCREMENT (8)
//Used by unaligned copy
#define BLOCK_WIDTH (64)
#define PAGE_ALIGNED (0x1000)
#define GPUCOPY_KERNEL_LOCK(a) ((a)->locked = true)
#define GPUCOPY_KERNEL_UNLOCK(a) ((a)->locked = false)
namespace CMRT_UMD
{
//*-----------------------------------------------------------------------------
//| Purpose: Create Queue
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::Create(CmDeviceRT *device,
CmQueueRT* &queue,
CM_QUEUE_CREATE_OPTION queueCreateOption)
{
int32_t result = CM_SUCCESS;
queue = new (std::nothrow) CmQueueRT(device, queueCreateOption);
if( queue )
{
result = queue->Initialize( );
if( result != CM_SUCCESS )
{
CmQueueRT::Destroy( queue);
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create CmQueue due to out of system memory.");
result = CM_OUT_OF_HOST_MEMORY;
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Queue
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::Destroy(CmQueueRT* &queue )
{
if( queue == nullptr )
{
return CM_FAILURE;
}
uint32_t result = queue->CleanQueue();
CmSafeDelete( queue );
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Constructor of Cm Queue
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CmQueueRT::CmQueueRT(CmDeviceRT *device,
CM_QUEUE_CREATE_OPTION queueCreateOption):
m_device(device),
m_eventArray(CM_INIT_EVENT_COUNT),
m_eventCount(0),
m_halMaxValues(nullptr),
m_copyKernelParamArray(CM_INIT_GPUCOPY_KERNL_COUNT),
m_copyKernelParamArrayCount(0),
m_queueOption(queueCreateOption)
{
}
//*-----------------------------------------------------------------------------
//| Purpose: Destructor of Cm Queue
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CmQueueRT::~CmQueueRT()
{
uint32_t eventArrayUsedSize = m_eventArray.GetMaxSize();
for( uint32_t i = 0; i < eventArrayUsedSize; i ++ )
{
CmEventRT* event = (CmEventRT*)m_eventArray.GetElement( i );
uint32_t eventReleaseTimes = 0;
while( event )
{ // destroy the event no matter if it is released by user
if(eventReleaseTimes > 2)
{
// The max of event's reference cout is 2
// if the event is not released after 2 times, there is something wrong
CM_ASSERTMESSAGE("Error: The max of event's reference cout is 2.");
break;
}
CmEventRT::Destroy( event );
eventReleaseTimes ++;
}
}
m_eventArray.Delete();
// Do not destroy the kernel in m_copyKernelParamArray.
// They have been destoyed in ~CmDevice() before destroying Queue
for( uint32_t i = 0; i < m_copyKernelParamArrayCount; i ++ )
{
CM_GPUCOPY_KERNEL *gpuCopyParam = (CM_GPUCOPY_KERNEL*)m_copyKernelParamArray.GetElement( i );
CmSafeDelete(gpuCopyParam);
}
m_copyKernelParamArray.Delete();
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Cm Queue
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::Initialize()
{
PCM_HAL_STATE cmHalState = ((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
CM_HAL_MAX_VALUES_EX* halMaxValuesEx = nullptr;
CM_RETURN_CODE hr = CM_SUCCESS;
m_device->GetHalMaxValues(m_halMaxValues, halMaxValuesEx);
// Creates or gets GPU Context for the test
if (m_queueOption.UserGPUContext == true)
{
// Checks if it is the user-provided GPU context. If it is valid, we will create the queue with the existing Context
if (cmHalState->osInterface->pfnIsGpuContextValid(cmHalState->osInterface, (MOS_GPU_CONTEXT)m_queueOption.GPUContext) != MOS_STATUS_SUCCESS)
{
// Returns failure
CM_ASSERTMESSAGE("Error: The user passed in an GPU context which is not valid");
return CM_INVALID_USER_GPU_CONTEXT_FOR_QUEUE_EX;
}
}
else
{
MOS_GPUCTX_CREATOPTIONS ctxCreateOption;
ctxCreateOption.CmdBufferNumScale = cmHalState->cmDeviceParam.maxTasks;
// Create MDF preset GPU context, update GPUContext in m_queueOption
if (m_queueOption.QueueType == CM_QUEUE_TYPE_RENDER)
{
// command buffer number
ctxCreateOption.CmdBufferNumScale = HalCm_GetNumCmdBuffers(cmHalState->osInterface, cmHalState->cmDeviceParam.maxTasks);
MOS_GPU_CONTEXT tmpGpuCtx = cmHalState->requestCustomGpuContext? MOS_GPU_CONTEXT_RENDER4: MOS_GPU_CONTEXT_RENDER3;;
// check if context handle was specified by user.
if (m_queueOption.GPUContext != 0)
{
tmpGpuCtx = (MOS_GPU_CONTEXT)m_queueOption.GPUContext;
}
// sanity check of context handle for CM
if (HalCm_IsValidGpuContext(tmpGpuCtx) == false)
{
return CM_INVALID_USER_GPU_CONTEXT_FOR_QUEUE_EX;
}
// SSEU overriding
if (cmHalState->cmHalInterface->IsOverridePowerOptionPerGpuContext())
{
// checking if need shutdown sub-slices for VME usage
if (m_queueOption.SseuUsageHint == CM_QUEUE_SSEU_USAGE_HINT_VME
&& cmHalState->cmHalInterface->IsRequestShutdownSubslicesForVmeUsage())
{
MEDIA_SYSTEM_INFO *gtSystemInfo = cmHalState->osInterface->pfnGetGtSystemInfo(cmHalState->osInterface);
ctxCreateOption.packed.SliceCount = (uint8_t)gtSystemInfo->SliceCount;
ctxCreateOption.packed.SubSliceCount = (gtSystemInfo->SubSliceCount / gtSystemInfo->SliceCount) >> 1; // set to half
ctxCreateOption.packed.MaxEUcountPerSubSlice = gtSystemInfo->EUCount/gtSystemInfo->SubSliceCount;
ctxCreateOption.packed.MinEUcountPerSubSlice = gtSystemInfo->EUCount/gtSystemInfo->SubSliceCount;
}
#if (_DEBUG || _RELEASE_INTERNAL)
MOS_USER_FEATURE_VALUE_DATA UserFeatureData = {0};
MOS_UserFeature_ReadValue_ID(
nullptr,
__MEDIA_USER_FEATURE_VALUE_SSEU_SETTING_OVERRIDE_ID,
&UserFeatureData);
// +---------------+----------------+----------------+----------------+
// | EUCountMax | EUCountMin | SSCount | SliceCount |
// +-------------24+--------------16+---------------8+---------------0+
if (UserFeatureData.u32Data != 0xDEADC0DE)
{
ctxCreateOption.packed.SliceCount = UserFeatureData.u32Data & 0xFF; // Bits 0-7
ctxCreateOption.packed.SubSliceCount = (UserFeatureData.u32Data >> 8) & 0xFF; // Bits 8-15
ctxCreateOption.packed.MaxEUcountPerSubSlice = (UserFeatureData.u32Data >> 16) & 0xFF; // Bits 16-23
ctxCreateOption.packed.MinEUcountPerSubSlice = (UserFeatureData.u32Data >> 24) & 0xFF; // Bits 24-31
}
#endif
}
ctxCreateOption.runAloneMode = m_queueOption.RunAloneMode;
// Create Render GPU Context
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnCreateGPUContext(cmHalState, tmpGpuCtx, MOS_GPU_NODE_3D, &ctxCreateOption));
// Set current GPU context
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->osInterface->pfnSetGpuContext(cmHalState->osInterface, tmpGpuCtx));
#if (_RELEASE_INTERNAL || _DEBUG)
#if defined(CM_DIRECT_GUC_SUPPORT)
//init GuC
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->osInterface->pfnInitGuC(cmHalState->osInterface, MOS_GPU_NODE_3D));
#endif
#endif
m_queueOption.GPUContext = tmpGpuCtx;
}
else if (m_queueOption.QueueType == CM_QUEUE_TYPE_COMPUTE)
{
ctxCreateOption.runAloneMode = m_queueOption.RunAloneMode;
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(
cmHalState->pfnCreateGPUContext(cmHalState, MOS_GPU_CONTEXT_CM_COMPUTE,
MOS_GPU_NODE_COMPUTE, &ctxCreateOption));
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(
cmHalState->osInterface->pfnSetGpuContext(cmHalState->osInterface,
MOS_GPU_CONTEXT_CM_COMPUTE));
m_queueOption.GPUContext = MOS_GPU_CONTEXT_CM_COMPUTE;
}
else
{
// Returns failure
CM_ASSERTMESSAGE("Error: The QueueType is not supported by MDF.");
return CM_NOT_IMPLEMENTED;
}
}
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Checks whether any kernels in the task have a thread argument
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::GetTaskHasThreadArg(CmKernelRT* kernelArray[], uint32_t numKernels, bool& threadArgExists)
{
threadArgExists = false;
for(uint32_t krn = 0; krn < numKernels; krn++)
{
if( !kernelArray[krn] )
{
CM_ASSERTMESSAGE("Error: The kernel in the task have no thread argument.");
return CM_FAILURE;
}
if( kernelArray[krn]->IsThreadArgExisted( ) )
{
threadArgExists = true;
break;
}
}
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Enqueue Task
//| Arguments :
//| kernelArray [in] Pointer to kernel array
//| event [in] Reference to the pointer to Event
//| threadSpace [out] Pointer to thread space
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::Enqueue(
CmTask* kernelArray,
CmEvent* & event,
const CmThreadSpace* threadSpace)
{
INSERT_API_CALL_LOG();
if (kernelArray == nullptr)
{
CM_ASSERTMESSAGE("Error: Kernel array is null.");
return CM_INVALID_ARG_VALUE;
}
CmTaskRT *kernelArrayRT = static_cast<CmTaskRT *>(kernelArray);
uint32_t kernelCount = 0;
kernelCount = kernelArrayRT->GetKernelCount();
if (kernelCount == 0)
{
CM_ASSERTMESSAGE("Error: Invalid kernel count.");
return CM_FAILURE;
}
if (kernelCount > m_halMaxValues->maxKernelsPerTask)
{
CM_ASSERTMESSAGE("Error: Kernel count exceeds max kernel per enqueue.");
return CM_EXCEED_MAX_KERNEL_PER_ENQUEUE;
}
int32_t result;
const CmThreadSpaceRT *threadSpaceRTConst = static_cast<const CmThreadSpaceRT *>(threadSpace);
PCM_HAL_STATE cmHalState = ((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
if (cmHalState->cmHalInterface->CheckMediaModeAvailability() == false)
{
if (threadSpaceRTConst != nullptr)
{
result = EnqueueWithGroup(kernelArray, event, threadSpaceRTConst->GetThreadGroupSpace());
}
else
{
// If there isn't any shared thread space or associated thread space,
// create a temporary (maxThreadCount x 1) thread group space whose
// size equal to the max thread count of kernel who doesn't have a
// thread space associated.
uint32_t maxThreadCount = 1;
bool usedCommonTGS = false;
for (uint32_t i = 0; i < kernelCount; i++)
{
CmKernelRT *tmpKernel = kernelArrayRT->GetKernelPointer(i);
CmThreadGroupSpace *tmpTGS = nullptr;
tmpKernel->GetThreadGroupSpace(tmpTGS);
if (tmpTGS == nullptr)
{
usedCommonTGS = true;
uint32_t singleThreadCount = 0;
tmpKernel->GetThreadCount(singleThreadCount);
if (maxThreadCount < singleThreadCount)
{
maxThreadCount = singleThreadCount;
}
}
}
CmThreadGroupSpace *threadGroupSpaceTemp = nullptr;
if (usedCommonTGS == true)
{
result = m_device->CreateThreadGroupSpace(1, 1, maxThreadCount, 1, threadGroupSpaceTemp);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Creating temporary thread group space failure.");
return result;
}
}
result = EnqueueWithGroup(kernelArray, event, threadGroupSpaceTemp);
if (threadGroupSpaceTemp != nullptr)
{
m_device->DestroyThreadGroupSpace(threadGroupSpaceTemp);
}
}
return result;
}
if (threadSpaceRTConst && threadSpaceRTConst->IsThreadAssociated())
{
if (threadSpaceRTConst->GetNeedSetKernelPointer() && threadSpaceRTConst->KernelPointerIsNULL())
{
CmKernelRT* tmp = nullptr;
tmp = kernelArrayRT->GetKernelPointer(0);
threadSpaceRTConst->SetKernelPointer(tmp);
}
}
#if _DEBUG
if (threadSpaceRTConst)
{
CmThreadSpaceRT *threadSpaceRT = const_cast<CmThreadSpaceRT*>(threadSpaceRTConst);
if (!threadSpaceRT->IntegrityCheck(kernelArrayRT))
{
CM_ASSERTMESSAGE("Error: Invalid thread space.");
return CM_INVALID_THREAD_SPACE;
}
}
#endif
if(m_device->IsPrintEnable())
{
m_device->ClearPrintBuffer();
}
typedef CmKernelRT* pCmKernel;
CmKernelRT** tmp = MOS_NewArray(pCmKernel, (kernelCount + 1));
if(tmp == nullptr)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_OUT_OF_HOST_MEMORY;
}
uint32_t totalThreadNumber = 0;
for(uint32_t i = 0; i < kernelCount; i++)
{
tmp[ i ] = kernelArrayRT->GetKernelPointer(i);
uint32_t singleThreadNumber = 0;
tmp[i]->GetThreadCount(singleThreadNumber);
if (singleThreadNumber == 0)
{
CmThreadSpaceRT *threadSpaceRT = const_cast<CmThreadSpaceRT*>(threadSpaceRTConst);
if (threadSpaceRT)
{
uint32_t width, height;
threadSpaceRT->GetThreadSpaceSize(width, height);
singleThreadNumber = width*height;
}
}
totalThreadNumber += singleThreadNumber;
}
tmp[kernelCount ] = nullptr;
CmEventRT *eventRT = static_cast<CmEventRT *>(event);
result = Enqueue_RT(tmp, kernelCount, totalThreadNumber, eventRT, threadSpaceRTConst, kernelArrayRT->GetSyncBitmap(), kernelArrayRT->GetPowerOption(),
kernelArrayRT->GetConditionalEndBitmap(), kernelArrayRT->GetConditionalEndInfo(), kernelArrayRT->GetTaskConfig());
if (eventRT)
{
eventRT->SetKernelNames(kernelArrayRT, const_cast<CmThreadSpaceRT*>(threadSpaceRTConst), nullptr);
}
event = eventRT;
MosSafeDeleteArray( tmp );
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Enqueue Task
//| Arguments :
//| kernelArray [in] Pointer to kernel array
//| event [in] Reference to the pointer to Event
//| threadSpace [out] Pointer to thread space
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::Enqueue_RT(
CmKernelRT* kernelArray[],
const uint32_t kernelCount,
const uint32_t totalThreadCount,
CmEventRT* & event,
const CmThreadSpaceRT* threadSpace,
uint64_t syncBitmap,
PCM_POWER_OPTION powerOption,
uint64_t conditionalEndBitmap,
CM_HAL_CONDITIONAL_BB_END_INFO* conditionalEndInfo,
PCM_TASK_CONFIG taskConfig)
{
if(kernelArray == nullptr)
{
CM_ASSERTMESSAGE("Error: Kernel array is NULL.");
return CM_INVALID_ARG_VALUE;
}
if( kernelCount == 0 )
{
CM_ASSERTMESSAGE("Error: There are no valid kernels.");
return CM_INVALID_ARG_VALUE;
}
bool isEventVisible = (event == CM_NO_EVENT)? false:true;
CLock Locker(m_criticalSectionTaskInternal);
CmTaskInternal* task = nullptr;
int32_t result = CmTaskInternal::Create(kernelCount, totalThreadCount, kernelArray, threadSpace, m_device, syncBitmap, task, conditionalEndBitmap, conditionalEndInfo);
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Create CM task internal failure.");
return result;
}
LARGE_INTEGER nEnqueueTime;
if ( !(MOS_QueryPerformanceCounter( (uint64_t*)&nEnqueueTime.QuadPart )))
{
CM_ASSERTMESSAGE("Error: Query performance counter failure.");
return CM_FAILURE;
}
int32_t taskDriverId = -1;
result = CreateEvent(task, isEventVisible, taskDriverId, event);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Create event failure.");
return result;
}
if ( event != nullptr )
{
event->SetEnqueueTime( nEnqueueTime );
}
task->SetPowerOption( powerOption );
task->SetProperty(taskConfig);
if( !m_enqueuedTasks.Push( task ) )
{
CM_ASSERTMESSAGE("Error: Push enqueued tasks failure.");
return CM_FAILURE;
}
result = FlushTaskWithoutSync();
return result;
}
int32_t CmQueueRT::Enqueue_RT(CmKernelRT* kernelArray[],
const uint32_t kernelCount,
const uint32_t totalThreadCount,
CmEventRT* & event,
const CmThreadGroupSpace* threadGroupSpace,
uint64_t syncBitmap,
PCM_POWER_OPTION powerOption,
uint64_t conditionalEndBitmap,
CM_HAL_CONDITIONAL_BB_END_INFO* conditionalEndInfo,
PCM_TASK_CONFIG taskConfig,
const CM_EXECUTION_CONFIG* krnExecCfg)
{
if(kernelArray == nullptr)
{
CM_ASSERTMESSAGE("Error: Kernel array is NULL.");
return CM_INVALID_ARG_VALUE;
}
if( kernelCount == 0 )
{
CM_ASSERTMESSAGE("Error: There are no valid kernels.");
return CM_INVALID_ARG_VALUE;
}
CLock Locker(m_criticalSectionTaskInternal);
CmTaskInternal* task = nullptr;
int32_t result = CmTaskInternal::Create( kernelCount, totalThreadCount, kernelArray,
threadGroupSpace, m_device, syncBitmap, task,
conditionalEndBitmap, conditionalEndInfo, krnExecCfg);
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Create CmTaskInternal failure.");
return result;
}
LARGE_INTEGER nEnqueueTime;
if ( !(MOS_QueryPerformanceCounter( (uint64_t*)&nEnqueueTime.QuadPart )))
{
CM_ASSERTMESSAGE("Error: Query performance counter failure.");
return CM_FAILURE;
}
int32_t taskDriverId = -1;
result = CreateEvent(task, !(event == CM_NO_EVENT) , taskDriverId, event);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Create event failure.");
return result;
}
if ( event != nullptr )
{
event->SetEnqueueTime( nEnqueueTime );
}
task->SetPowerOption( powerOption );
task->SetProperty(taskConfig);
if( !m_enqueuedTasks.Push( task ) )
{
CM_ASSERTMESSAGE("Error: Push enqueued tasks failure.")
return CM_FAILURE;
}
result = FlushTaskWithoutSync();
return result;
}
int32_t CmQueueRT::Enqueue_RT( CmKernelRT* kernelArray[],
CmEventRT* & event,
uint32_t numTasksGenerated,
bool isLastTask,
uint32_t hints,
PCM_POWER_OPTION powerOption)
{
int32_t result = CM_FAILURE;
uint32_t kernelCount = 0;
CmTaskInternal* task = nullptr;
int32_t taskDriverId = -1;
bool isEventVisible = (event == CM_NO_EVENT) ? false:true;
bool threadArgExists = false;
if( kernelArray == nullptr)
{
CM_ASSERTMESSAGE("Error: Kernel array is NULL.");
return CM_INVALID_ARG_VALUE;
}
while( kernelArray[ kernelCount ] )
{
kernelCount++;
}
if( kernelCount < CM_MINIMUM_NUM_KERNELS_ENQWHINTS )
{
CM_ASSERTMESSAGE("Error: EnqueueWithHints requires at least 2 kernels.");
return CM_FAILURE;
}
uint32_t totalThreadCount = 0;
for( uint32_t i = 0; i < kernelCount; i ++ )
{
uint32_t threadCount = 0;
kernelArray[i]->GetThreadCount( threadCount );
totalThreadCount += threadCount;
}
if( GetTaskHasThreadArg(kernelArray, kernelCount, threadArgExists) != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Thread argument checking fails.");
return CM_FAILURE;
}
if( !threadArgExists )
{
if (totalThreadCount > m_halMaxValues->maxUserThreadsPerTaskNoThreadArg )
{
CM_ASSERTMESSAGE("Error: Maximum number of threads per task exceeded.");
return CM_EXCEED_MAX_THREAD_AMOUNT_PER_ENQUEUE;
}
}
else
{
if( totalThreadCount > m_halMaxValues->maxUserThreadsPerTask )
{
CM_ASSERTMESSAGE("Error: Maximum number of threads per task exceeded.");
return CM_EXCEED_MAX_THREAD_AMOUNT_PER_ENQUEUE;
}
}
CLock Locker(m_criticalSectionTaskInternal);
result = CmTaskInternal::Create( kernelCount, totalThreadCount, kernelArray, task, numTasksGenerated, isLastTask, hints, m_device );
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Create CM task internal failure.");
return result;
}
LARGE_INTEGER nEnqueueTime;
if ( !(MOS_QueryPerformanceCounter( (uint64_t*)&nEnqueueTime.QuadPart )) )
{
CM_ASSERTMESSAGE("Error: Query performance counter failure.");
return CM_FAILURE;
}
result = CreateEvent(task, isEventVisible, taskDriverId, event);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Create event failure.");
return result;
}
if ( event != nullptr )
{
event->SetEnqueueTime( nEnqueueTime );
}
for( uint32_t i = 0; i < kernelCount; ++i )
{
CmKernelRT* kernel = nullptr;
task->GetKernel(i, kernel);
if( kernel != nullptr )
{
kernel->SetAdjustedYCoord(0);
}
}
task->SetPowerOption( powerOption );
if (!m_enqueuedTasks.Push(task))
{
CM_ASSERTMESSAGE("Error: Push enqueued tasks failure.")
return CM_FAILURE;
}
result = FlushTaskWithoutSync();
return result;
}
//*-----------------------------------------------------------------------------
//! Function to enqueue task with thread group space pointer
//! Arguments:
//! 1. Pointer to CmTask, which can only contain one kernel.
//! 2. Reference to the pointer to CmEvent that is to be returned
//! 3. Pointer to a CmThreadGroupSpace.
//! Return Value:
//! CM_SUCCESS if the task is successfully enqueued and the CmEvent is generated
//! CM_OUT_OF_HOST_MEMORY if out of host memory
//! CM_FAILURE otherwise
//! Notes:
//! If the kernel has per thread arg, GPGPU object is to be used.
//! If the kernel has no per thread arg. GPGPU walker is used.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueWithGroup( CmTask* task, CmEvent* & event, const CmThreadGroupSpace* threadGroupSpace)
{
INSERT_API_CALL_LOG();
int32_t result;
if(task == nullptr)
{
CM_ASSERTMESSAGE("Error: Kernel array is NULL.");
return CM_INVALID_ARG_VALUE;
}
CmTaskRT *taskRT = static_cast<CmTaskRT *>(task);
uint32_t count = 0;
count = taskRT->GetKernelCount();
if( count == 0 )
{
CM_ASSERTMESSAGE("Error: There are no valid kernels.");
return CM_FAILURE;
}
if(m_device->IsPrintEnable())
{
m_device->ClearPrintBuffer();
}
typedef CmKernelRT* pCmKernel;
CmKernelRT** tmp = MOS_NewArray(pCmKernel, (count+1));
if(tmp == nullptr)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_OUT_OF_HOST_MEMORY;
}
uint32_t totalThreadNumber = 0;
for(uint32_t i = 0; i < count; i++)
{
uint32_t singleThreadNumber = 0;
tmp[ i ] = taskRT->GetKernelPointer(i);
//Thread arguments is not allowed in GPGPU_WALKER path
if(tmp[i]->IsThreadArgExisted())
{
CM_ASSERTMESSAGE("Error: No thread Args allowed when using group space");
MosSafeDeleteArray(tmp);
return CM_THREAD_ARG_NOT_ALLOWED;
}
tmp[i]->GetThreadCount(singleThreadNumber);
totalThreadNumber += singleThreadNumber;
}
tmp[count ] = nullptr;
CmEventRT *eventRT = static_cast<CmEventRT *>(event);
result = Enqueue_RT( tmp, count, totalThreadNumber, eventRT,
threadGroupSpace, taskRT->GetSyncBitmap(),
taskRT->GetPowerOption(),
taskRT->GetConditionalEndBitmap(), taskRT->GetConditionalEndInfo(),
taskRT->GetTaskConfig(), taskRT->GetKernelExecuteConfig());
if (eventRT)
{
eventRT->SetKernelNames(taskRT, nullptr, const_cast<CmThreadGroupSpace*>(threadGroupSpace));
}
event = eventRT;
MosSafeDeleteArray( tmp );
return result;
}
CM_RT_API int32_t CmQueueRT::EnqueueWithHints(
CmTask* kernelArray,
CmEvent* & event,
uint32_t hints)
{
INSERT_API_CALL_LOG();
int32_t hr = CM_FAILURE;
uint32_t count = 0;
uint32_t index = 0;
CmKernelRT** kernels = nullptr;
uint32_t numTasks = 0;
bool splitTask = false;
bool lastTask = false;
uint32_t numTasksGenerated = 0;
CmEventRT *eventRT = static_cast<CmEventRT *>(event);
if (kernelArray == nullptr)
{
return CM_INVALID_ARG_VALUE;
}
CmTaskRT *kernelArrayRT = static_cast<CmTaskRT *>(kernelArray);
count = kernelArrayRT->GetKernelCount();
if( count == 0 )
{
CM_ASSERTMESSAGE("Error: Invalid kernel count.");
hr = CM_FAILURE;
goto finish;
}
if( count > m_halMaxValues->maxKernelsPerTask )
{
CM_ASSERTMESSAGE("Error: Kernel count exceeds maximum kernel per enqueue.");
hr = CM_EXCEED_MAX_KERNEL_PER_ENQUEUE;
goto finish;
}
for (uint32_t i = 0; i < count; ++i)
{
CmKernelRT* kernelTmp = nullptr;
CmThreadSpaceRT* threadSpaceTmp = nullptr;
kernelTmp = kernelArrayRT->GetKernelPointer(i);
CM_CHK_NULL_GOTOFINISH_CMERROR(kernelTmp);
kernelTmp->GetThreadSpace(threadSpaceTmp);
CM_CHK_NULL_GOTOFINISH_CMERROR(threadSpaceTmp);
if (threadSpaceTmp->GetNeedSetKernelPointer() && threadSpaceTmp->KernelPointerIsNULL())
{
threadSpaceTmp->SetKernelPointer(kernelTmp);
}
}
#if _DEBUG
if( !kernelArrayRT->IntegrityCheckKernelThreadspace() )
{
CM_ASSERTMESSAGE("Error: Integrity check for kernel thread space failed.");
hr = CM_KERNEL_THREADSPACE_INTEGRITY_FAILED;
goto finish;
}
#endif
numTasks = ( hints & CM_HINTS_MASK_NUM_TASKS ) >> CM_HINTS_NUM_BITS_TASK_POS;
if( numTasks > 1 )
{
splitTask = true;
}
if( m_device->IsPrintEnable() )
{
m_device->ClearPrintBuffer();
}
kernels = MOS_NewArray(CmKernelRT*, (count + 1));
CM_CHK_NULL_GOTOFINISH_CMERROR(kernels);
do
{
for (index = 0; index < count; ++index)
{
kernels[ index ] = kernelArrayRT->GetKernelPointer( index );
}
kernels[ count ] = nullptr;
if(splitTask)
{
if( numTasksGenerated == (numTasks - 1 ) )
{
lastTask = true;
}
}
else
{
lastTask = true;
}
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue_RT( kernels, eventRT, numTasksGenerated, lastTask, hints, kernelArrayRT->GetPowerOption() ));
event = eventRT;
numTasksGenerated++;
}while(numTasksGenerated < numTasks);
finish:
MosSafeDeleteArray( kernels );
return hr;
}
//*-----------------------------------------------------------------------------
//! Enqueue an task, which contains one pre-defined kernel to
//! copy from host memory to surface
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of the task.
//! A CmEvent is generated each time a task is enqueued. The CmEvent can
//! be used to check if the task finishs.
//! INPUT:
//! 1) Pointer to the CmSurface2D_RT as copy destination
//! 2) Pointer to the host memory as copy source
//! 3) Reference to the pointer to CMEvent
//! 4) A boolean value to indicate if or not to flush the queue after enqueue the task
//! by default the boolean value is TRUE.
//! OUTPUT:
//! CM_SUCCESS if the task is successfully enqueued and the CmEvent is generated;
//! CM_OUT_OF_HOST_MEMORY if out of host memery;
//! CM_FAILURE otherwise.
//! More error code is coming.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueCopyCPUToGPU( CmSurface2D* surface, const unsigned char* sysMem, CmEvent* & event )
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuCopyKernel())
{
return CM_NOT_IMPLEMENTED;
}
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT *>(surface);
return EnqueueCopyInternal(surfaceRT, (unsigned char*)sysMem, 0, 0, CM_FASTCOPY_CPU2GPU, CM_FASTCOPY_OPTION_NONBLOCKING, event);
}
//*-----------------------------------------------------------------------------
//! Enqueue an task, which contains one pre-defined kernel to
//! copy from surface to host memory
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of the task.
//! A CmEvent is generated each time a task is enqueued. The CmEvent can
//! be used to check if the task finishs.
//! INPUT:
//! 1) Pointer to the CmSurface2D_RT as copy source
//! 2) Pointer to the host memory as copy destination
//! 3) Reference to the pointer to CMEvent
//! 4) A boolean value to indicate if or not to flush the queue after enqueue the task
//! by default the boolean value is TRUE.
//! OUTPUT:
//! CM_SUCCESS if the task is successfully enqueued and the CmEvent is generated;
//! CM_OUT_OF_HOST_MEMORY if out of host memery;
//! CM_FAILURE otherwise.
//! More error code is coming.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueCopyGPUToCPU( CmSurface2D* surface, unsigned char* sysMem, CmEvent* & event )
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuCopyKernel())
{
return CM_NOT_IMPLEMENTED;
}
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT *>(surface);
return EnqueueCopyInternal(surfaceRT, sysMem, 0, 0, CM_FASTCOPY_GPU2CPU, CM_FASTCOPY_OPTION_NONBLOCKING, event);
}
int32_t CmQueueRT::EnqueueUnalignedCopyInternal( CmSurface2DRT* surface, unsigned char* sysMem, const uint32_t widthStride, const uint32_t heightStride, CM_GPUCOPY_DIRECTION direction)
{
int32_t hr = CM_SUCCESS;
uint32_t bufferupSize = 0;
uint32_t dstAddShiftOffset = 0;
uint32_t threadWidth = 0;
uint32_t threadHeight = 0;
uint32_t threadNum = 0;
uint32_t auxiliaryBufferupSize = 0;
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizePerPixel = 0;
uint32_t widthByte = 0;
uint32_t copyWidthByte = 0;
uint32_t copyHeightRow = 0;
uint32_t strideInBytes = widthStride;
uint32_t heightStrideInRows = heightStride;
size_t linearAddress = (size_t)sysMem;
size_t linearAddressAligned = 0;
unsigned char* hybridCopyAuxSysMem = nullptr;
CmBufferUP *bufferUP = nullptr;
CmKernel *kernel = nullptr;
CmBufferUP *hybridCopyAuxBufferUP = nullptr;
SurfaceIndex *bufferIndexCM = nullptr;
SurfaceIndex *hybridCopyAuxIndexCM = nullptr;
SurfaceIndex *surf2DIndexCM = nullptr;
CmThreadSpace *threadSpace = nullptr;
CmTask *gpuCopyTask = nullptr;
CmProgram *gpuCopyProgram = nullptr;
CmEvent *event = nullptr;
CM_STATUS status;
CM_SURFACE_FORMAT format;
if ( surface )
{
CM_CHK_CMSTATUS_GOTOFINISH( surface->GetSurfaceDesc(width, height, format, sizePerPixel));
}
else
{
return CM_FAILURE;
}
widthByte = width * sizePerPixel;
// the actual copy region
copyWidthByte = MOS_MIN(strideInBytes, widthByte);
copyHeightRow = MOS_MIN(heightStrideInRows, height);
if(linearAddress == 0)
{
CM_ASSERTMESSAGE("Error: Pointer to system memory is null.");
return CM_INVALID_ARG_VALUE;
}
if( (copyWidthByte > CM_MAX_THREADSPACE_WIDTH_FOR_MW * BLOCK_WIDTH ) || ( copyHeightRow > CM_MAX_THREADSPACE_HEIGHT_FOR_MW * BLOCK_HEIGHT) )
{ // each thread handles 64x8 block data. This API will fail if it exceeds the max thread space's size
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_INVALID_ARG_SIZE;
}
if (sizeof (void *) == 8 ) //64-bit
{
linearAddressAligned = linearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X64;
}
else //32-bit
{
linearAddressAligned = linearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X86;
}
//Calculate Left Shift offset
dstAddShiftOffset = (uint32_t)(linearAddress - linearAddressAligned);
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
bufferupSize = MOS_ALIGN_CEIL(strideInBytes * (heightStrideInRows + copyHeightRow * 1/2) + (uint32_t)dstAddShiftOffset , 64);
}
else
{
bufferupSize = MOS_ALIGN_CEIL(strideInBytes * heightStrideInRows + (uint32_t)dstAddShiftOffset, 64);
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateBufferUP(bufferupSize, ( void * )linearAddressAligned, bufferUP));
CM_CHK_CMSTATUS_GOTOFINISH(bufferUP->GetIndex(bufferIndexCM));
CM_CHK_CMSTATUS_GOTOFINISH(surface->GetIndex(surf2DIndexCM));
CM_CHK_CMSTATUS_GOTOFINISH( m_device->LoadPredefinedCopyKernel(gpuCopyProgram));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyProgram);
if (direction == CM_FASTCOPY_CPU2GPU)
{
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(surfaceCopy_write_unaligned_NV12), kernel, "PredefinedGPUCopyKernel"));
}
else
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(surfaceCopy_write_unaligned), kernel, "PredefinedGPUCopyKernel"));
}
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 0, sizeof( SurfaceIndex ), bufferIndexCM ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 1, sizeof( SurfaceIndex ), surf2DIndexCM ));
}
else
{
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(surfaceCopy_read_unaligned_NV12), kernel, "PredefinedGPUCopyKernel"));
auxiliaryBufferupSize = BLOCK_WIDTH * 2 * (heightStrideInRows + copyHeightRow * 1/2);
}
else
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(surfaceCopy_read_unaligned), kernel, "PredefinedGPUCopyKernel"));
auxiliaryBufferupSize = BLOCK_WIDTH * 2 * heightStrideInRows;
}
hybridCopyAuxSysMem = (unsigned char*)MOS_AlignedAllocMemory(auxiliaryBufferupSize, PAGE_ALIGNED);
if(!hybridCopyAuxSysMem)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_OUT_OF_HOST_MEMORY;
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateBufferUP(auxiliaryBufferupSize, (void*)hybridCopyAuxSysMem, hybridCopyAuxBufferUP));
CM_CHK_CMSTATUS_GOTOFINISH(hybridCopyAuxBufferUP->GetIndex(hybridCopyAuxIndexCM));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 0, sizeof( SurfaceIndex ), surf2DIndexCM ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 1, sizeof( SurfaceIndex ), bufferIndexCM ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 5, sizeof( uint32_t ), ©WidthByte ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 6, sizeof( SurfaceIndex ), hybridCopyAuxIndexCM ));
}
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 2, sizeof( uint32_t ), &strideInBytes ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 3, sizeof( uint32_t ), &heightStrideInRows ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 4, sizeof( uint32_t ), &dstAddShiftOffset ));
threadWidth = ( uint32_t )ceil( ( double )copyWidthByte/BLOCK_WIDTH );
threadHeight = ( uint32_t )ceil( ( double )copyHeightRow/BLOCK_HEIGHT );
threadNum = threadWidth * threadHeight;
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetThreadCount( threadNum ));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateThreadSpace( threadWidth, threadHeight, threadSpace ));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateTask(gpuCopyTask));
CM_CHK_CMSTATUS_GOTOFINISH(gpuCopyTask->AddKernel( kernel ));
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue(gpuCopyTask, event, threadSpace));
if(event)
{
CM_CHK_CMSTATUS_GOTOFINISH(event->GetStatus(status));
while(status != CM_STATUS_FINISHED)
{
if (status == CM_STATUS_RESET)
{
hr = CM_TASK_MEDIA_RESET;
goto finish;
}
CM_CHK_CMSTATUS_GOTOFINISH(event->GetStatus(status));
}
}
// CPU copy unaligned data
if( direction == CM_FASTCOPY_GPU2CPU)
{
uint32_t readOffset = 0;
uint32_t copyLines = 0;
unsigned char* startBuffer = (unsigned char*)linearAddressAligned;
copyLines = (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016) ? heightStrideInRows + MOS_MIN(heightStrideInRows, height) * 1 / 2 : heightStrideInRows;
for(uint32_t i = 0; i < copyLines; ++i)
{
//copy begining of line
size_t beginLineWriteOffset = strideInBytes * i + dstAddShiftOffset;
uint32_t mod = ((uintptr_t)startBuffer + beginLineWriteOffset) < BLOCK_WIDTH ? ((uintptr_t)startBuffer + beginLineWriteOffset) : ((uintptr_t)startBuffer + beginLineWriteOffset) & (BLOCK_WIDTH - 1);
uint32_t beginLineCopySize = (mod == 0) ? 0:(BLOCK_WIDTH - mod);
//fix copy size for cases where the surface width is small
if((beginLineCopySize > widthByte) || ( beginLineCopySize == 0 && widthByte < BLOCK_WIDTH ) )
{
beginLineCopySize = widthByte;
}
if(beginLineCopySize > 0)
{
CmSafeMemCopy((void *)( (unsigned char *)startBuffer + beginLineWriteOffset), (void *)(hybridCopyAuxSysMem + readOffset), beginLineCopySize);
}
//copy end of line
uint32_t alignedWrites = (copyWidthByte - beginLineCopySize) &~ (BLOCK_WIDTH - 1);
uint32_t endLineWriteOffset = beginLineWriteOffset + alignedWrites + beginLineCopySize;
uint32_t endLineCopySize = dstAddShiftOffset+ i * strideInBytes + copyWidthByte - endLineWriteOffset;
if(endLineCopySize > 0 && endLineWriteOffset > beginLineWriteOffset)
{
CmSafeMemCopy((void *)((unsigned char *)startBuffer + endLineWriteOffset), (void *)(hybridCopyAuxSysMem + readOffset + BLOCK_WIDTH), endLineCopySize);
}
readOffset += (BLOCK_WIDTH * 2);
}
}
CM_CHK_CMSTATUS_GOTOFINISH(DestroyEvent(event));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyTask(gpuCopyTask));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyThreadSpace(threadSpace));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(bufferUP));
if (direction == CM_FASTCOPY_GPU2CPU)
{
if(hybridCopyAuxBufferUP)
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(hybridCopyAuxBufferUP));
}
if(hybridCopyAuxSysMem)
{
MOS_AlignedFreeMemory(hybridCopyAuxSysMem);
hybridCopyAuxSysMem = nullptr;
}
}
finish:
if(hr != CM_SUCCESS)
{
if(bufferUP == nullptr)
{
// user need to know whether the failure is caused by out of BufferUP.
hr = CM_GPUCOPY_OUT_OF_RESOURCE;
}
if(event) DestroyEvent(event);
if(kernel) m_device->DestroyKernel(kernel);
if(threadSpace) m_device->DestroyThreadSpace(threadSpace);
if(gpuCopyTask) m_device->DestroyTask(gpuCopyTask);
if(bufferUP) m_device->DestroyBufferUP(bufferUP);
if(hybridCopyAuxBufferUP) m_device->DestroyBufferUP(hybridCopyAuxBufferUP);
if(hybridCopyAuxSysMem) {MOS_AlignedFreeMemory(hybridCopyAuxSysMem); hybridCopyAuxSysMem = nullptr;}
}
return hr;
}
//*-----------------------------------------------------------------------------
//! Enqueue an task, which contains one pre-defined kernel to
//! copy from surface to host memory or from host memory to surface
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of the task.
//! A CmEvent is generated each time a task is enqueued. The CmEvent can
//! be used to check if the task finishes.
//! INPUT:
//! 1) Pointer to the CmSurface2D
//! 2) Pointer to the host memory
//! 3) Width stride in bytes, if there is no padding in system memroy, it is set to zero.
//! 4) Height stride in row, if there is no padding in system memroy, it is set to zero.
//! 4) Copy direction, cpu->gpu (linear->tiled) or gpu->cpu(tiled->linear)
//! 5) Reference to the pointer to CMEvent
//! OUTPUT:
//! CM_SUCCESS if the task is successfully enqueued and the CmEvent is generated;
//! CM_OUT_OF_HOST_MEMORY if out of host memery;
//! CM_FAILURE otherwise.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::EnqueueCopyInternal(CmSurface2DRT* surface,
unsigned char* sysMem,
const uint32_t widthStride,
const uint32_t heightStride,
CM_GPUCOPY_DIRECTION direction,
const uint32_t option,
CmEvent* & event)
{
int32_t hr = CM_FAILURE;
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizePerPixel = 0;
CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
if (surface)
{
CM_CHK_CMSTATUS_GOTOFINISH(surface->GetSurfaceDesc(width, height, format, sizePerPixel));
}
else
{
return CM_GPUCOPY_INVALID_SURFACES;
}
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
hr = EnqueueCopyInternal_2Planes(surface, (unsigned char*)sysMem, format, width, widthStride, height, heightStride, sizePerPixel, direction, option, event);
}
else
{
hr = EnqueueCopyInternal_1Plane(surface, (unsigned char*)sysMem, format, width, widthStride, height, heightStride, sizePerPixel, direction, option, event);
}
finish:
return hr;
}
int32_t CmQueueRT::EnqueueCopyInternal_1Plane(CmSurface2DRT* surface,
unsigned char* sysMem,
CM_SURFACE_FORMAT format,
const uint32_t widthInPixel,
const uint32_t widthStride,
const uint32_t heightInRow,
const uint32_t heightStride,
const uint32_t sizePerPixel,
CM_GPUCOPY_DIRECTION direction,
const uint32_t option,
CmEvent* & event )
{
int32_t hr = CM_SUCCESS;
uint32_t tempHeight = heightInRow;
uint32_t strideInBytes = widthStride;
uint32_t strideInDwords = 0;
uint32_t heightStrideInRows = heightStride;
uint32_t addedShiftLeftOffset = 0;
size_t linearAddress = (size_t)sysMem;
size_t linearAddressAligned = 0;
CmKernel *kernel = nullptr;
CmBufferUP *cmbufferUP = nullptr;
SurfaceIndex *bufferIndexCM = nullptr;
SurfaceIndex *surf2DIndexCM = nullptr;
CmThreadSpace *threadSpace = nullptr;
CmTask *gpuCopyTask = nullptr;
CmEvent *internalEvent = nullptr;
uint32_t threadWidth = 0;
uint32_t threadHeight = 0;
uint32_t threadNum = 0;
uint32_t widthDword = 0;
uint32_t widthByte = 0;
uint32_t copyWidthByte = 0;
uint32_t copyHeightRow = 0;
uint32_t sliceCopyHeightRow = 0;
uint32_t sliceCopyBufferUPSize = 0;
int32_t totalBufferUPSize = 0;
uint32_t startX = 0;
uint32_t startY = 0;
bool blSingleEnqueue = true;
CM_GPUCOPY_KERNEL *gpuCopyKernelParam = nullptr;
PCM_HAL_STATE cmHalState = \
((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
widthByte = widthInPixel * sizePerPixel;
//Align the width regarding stride
if(strideInBytes == 0)
{
strideInBytes = widthByte;
}
if(heightStrideInRows == 0)
{
heightStrideInRows = heightInRow;
}
// the actual copy region
copyWidthByte = MOS_MIN(strideInBytes, widthByte);
copyHeightRow = MOS_MIN(heightStrideInRows, heightInRow);
// Make sure stride and start address of system memory is 16-byte aligned.
// if no padding in system memory , strideInBytes = widthByte.
if(strideInBytes & 0xf)
{
CM_ASSERTMESSAGE("Error: Stride is not 16-byte aligned.");
return CM_GPUCOPY_INVALID_STRIDE;
}
if((linearAddress & 0xf) || (linearAddress == 0))
{
CM_ASSERTMESSAGE("Error: Start address of system memory is not 16-byte aligned.");
return CM_GPUCOPY_INVALID_SYSMEM;
}
//Calculate actual total size of system memory
totalBufferUPSize = strideInBytes * heightStrideInRows;
//Check thread space width here
if( copyWidthByte > CM_MAX_THREADSPACE_WIDTH_FOR_MW * BLOCK_PIXEL_WIDTH *4 )
{ // each thread handles 128x8 block data. This API will fail if it exceeds the max thread space's size
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_GPUCOPY_INVALID_SIZE;
}
while (totalBufferUPSize > 0)
{
if (sizeof (void *) == 8 ) //64-bit
{
linearAddressAligned = linearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X64;
}
else //32-bit
{
linearAddressAligned = linearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X86;
}
//Calculate Left Shift offset
addedShiftLeftOffset = (uint32_t)(linearAddress - linearAddressAligned);
totalBufferUPSize += addedShiftLeftOffset;
if (totalBufferUPSize > CM_MAX_1D_SURF_WIDTH)
{
blSingleEnqueue = false;
sliceCopyHeightRow = ((CM_MAX_1D_SURF_WIDTH - addedShiftLeftOffset)/(strideInBytes*(BLOCK_HEIGHT * INNER_LOOP))) * (BLOCK_HEIGHT * INNER_LOOP);
sliceCopyBufferUPSize = sliceCopyHeightRow * strideInBytes + addedShiftLeftOffset;
tempHeight = sliceCopyHeightRow;
}
else
{
sliceCopyHeightRow = copyHeightRow;
sliceCopyBufferUPSize = totalBufferUPSize;
if (!blSingleEnqueue)
{
tempHeight = sliceCopyHeightRow;
}
}
//Check thread space height here
if(sliceCopyHeightRow > CM_MAX_THREADSPACE_HEIGHT_FOR_MW * BLOCK_HEIGHT * INNER_LOOP )
{ // each thread handles 128x8 block data. This API will fail if it exceeds the max thread space's size
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_GPUCOPY_INVALID_SIZE;
}
kernel = nullptr;
CM_CHK_CMSTATUS_GOTOFINISH( m_device->CreateBufferUP( sliceCopyBufferUPSize, ( void * )linearAddressAligned, cmbufferUP ));
CM_CHK_NULL_GOTOFINISH_CMERROR(cmbufferUP);
//Configure memory object control for BufferUP to solve the cache-line issue.
if (cmHalState->cmHalInterface->IsGPUCopySurfaceNoCacheWARequired())
{
CM_CHK_CMSTATUS_GOTOFINISH(cmbufferUP->SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL_SKL_NO_LLC_L3));
}
CM_CHK_CMSTATUS_GOTOFINISH(CreateGPUCopyKernel(copyWidthByte, sliceCopyHeightRow, format, direction, gpuCopyKernelParam));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam);
kernel = gpuCopyKernelParam->kernel;
CM_CHK_NULL_GOTOFINISH_CMERROR(kernel);
CM_CHK_NULL_GOTOFINISH_CMERROR(cmbufferUP);
CM_CHK_CMSTATUS_GOTOFINISH(cmbufferUP->GetIndex( bufferIndexCM ));
CM_CHK_CMSTATUS_GOTOFINISH(surface->GetIndex( surf2DIndexCM ));
threadWidth = ( uint32_t )ceil( ( double )copyWidthByte/BLOCK_PIXEL_WIDTH/4 );
threadHeight = ( uint32_t )ceil( ( double )sliceCopyHeightRow/BLOCK_HEIGHT/INNER_LOOP );
threadNum = threadWidth * threadHeight;
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetThreadCount( threadNum ));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateThreadSpace( threadWidth, threadHeight, threadSpace ));
if( direction == CM_FASTCOPY_CPU2GPU)
{
if (cmHalState->cmHalInterface->IsSurfaceCompressionWARequired())
{
CM_CHK_CMSTATUS_GOTOFINISH(surface->SetCompressionMode(MEMCOMP_DISABLED));
}
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 0, sizeof( SurfaceIndex ), bufferIndexCM) );
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 1, sizeof( SurfaceIndex ), surf2DIndexCM ));
}
else
{
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 1, sizeof( SurfaceIndex ), bufferIndexCM ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 0, sizeof( SurfaceIndex ), surf2DIndexCM ));
}
if(direction == CM_FASTCOPY_GPU2CPU)
{
surface->SetReadSyncFlag(true, this); // GPU -> CPU, set surf2d as read sync flag
}
widthDword = (uint32_t)ceil((double)widthByte / 4);
strideInDwords = (uint32_t)ceil((double)strideInBytes / 4);
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 2, sizeof( uint32_t ), &strideInDwords ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 3, sizeof( uint32_t ), &heightStrideInRows ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 4, sizeof( uint32_t ), &addedShiftLeftOffset ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 5, sizeof( uint32_t ), &threadHeight ));
if (direction == CM_FASTCOPY_GPU2CPU) //GPU-->CPU, read
{
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 6, sizeof( uint32_t ), &widthDword ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 7, sizeof( uint32_t ), &tempHeight ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 8, sizeof(uint32_t), &startX));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 9, sizeof(uint32_t), &startY));
}
else //CPU-->GPU, write
{
//this only works for the kernel surfaceCopy_write_32x32
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 6, sizeof( uint32_t ), &startX ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 7, sizeof( uint32_t ), &startY ));
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateTask(gpuCopyTask));
CM_CHK_CMSTATUS_GOTOFINISH(gpuCopyTask->AddKernel( kernel ));
if (option & CM_FASTCOPY_OPTION_DISABLE_TURBO_BOOST)
{
// disable turbo
CM_TASK_CONFIG taskConfig;
CmSafeMemSet(&taskConfig, 0, sizeof(CM_TASK_CONFIG));
taskConfig.turboBoostFlag = CM_TURBO_BOOST_DISABLE;
gpuCopyTask->SetProperty(taskConfig);
}
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue(gpuCopyTask, internalEvent,
threadSpace));
GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
//update for next slice
linearAddress += sliceCopyBufferUPSize - addedShiftLeftOffset;
totalBufferUPSize -= sliceCopyBufferUPSize;
copyHeightRow -= sliceCopyHeightRow;
startX = 0;
startY += sliceCopyHeightRow;
if(totalBufferUPSize > 0) //Intermediate event, we don't need it
{
CM_CHK_CMSTATUS_GOTOFINISH(DestroyEvent(internalEvent));
}
else //Last one event, need keep or destroy it
{
if ((option & CM_FASTCOPY_OPTION_BLOCKING) && (internalEvent))
{
CM_CHK_CMSTATUS_GOTOFINISH(internalEvent->WaitForTaskFinished());
}
if(event == CM_NO_EVENT) //User doesn't need CmEvent for this copy
{
event = nullptr;
CM_CHK_CMSTATUS_GOTOFINISH(DestroyEvent(internalEvent));
}
else //User needs this CmEvent
{
event = internalEvent;
}
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyTask(gpuCopyTask));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyThreadSpace(threadSpace));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(cmbufferUP));
}
finish:
if(hr != CM_SUCCESS)
{
if(cmbufferUP == nullptr)
{
// user need to know whether the failure is caused by out of BufferUP.
hr = CM_GPUCOPY_OUT_OF_RESOURCE;
}
if(kernel && gpuCopyKernelParam) GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
if(threadSpace) m_device->DestroyThreadSpace(threadSpace);
if(gpuCopyTask) m_device->DestroyTask(gpuCopyTask);
if(cmbufferUP) m_device->DestroyBufferUP(cmbufferUP);
if(internalEvent) DestroyEvent(internalEvent);
// CM_FAILURE for all the other errors
// return CM_EXCEED_MAX_TIMEOUT to notify app that gpu reset happens
if( hr != CM_GPUCOPY_OUT_OF_RESOURCE && hr != CM_EXCEED_MAX_TIMEOUT)
{
hr = CM_FAILURE;
}
}
return hr;
}
int32_t CmQueueRT::EnqueueCopyInternal_2Planes(CmSurface2DRT* surface,
unsigned char* sysMem,
CM_SURFACE_FORMAT format,
const uint32_t widthInPixel,
const uint32_t widthStride,
const uint32_t heightInRow,
const uint32_t heightStride,
const uint32_t sizePerPixel,
CM_GPUCOPY_DIRECTION direction,
const uint32_t option,
CmEvent* & event)
{
int32_t hr = CM_SUCCESS;
uint32_t strideInBytes = widthStride;
uint32_t strideInDwords = 0;
uint32_t heightStrideInRows = heightStride;
size_t linearAddressY = 0;
size_t linearAddressUV = 0;
size_t linearAddressAlignedY = 0;
size_t linearAddressAlignedUV = 0;
uint32_t addedShiftLeftOffsetY = 0;
uint32_t addedShiftLeftOffsetUV = 0;
CmKernel *kernel = nullptr;
CmBufferUP *cmbufferUPY = nullptr;
CmBufferUP *cmbufferUPUV = nullptr;
SurfaceIndex *bufferUPIndexY = nullptr;
SurfaceIndex *bufferUPIndexUV = nullptr;
SurfaceIndex *surf2DIndexCM = nullptr;
CmThreadSpace *threadSpace = nullptr;
CmTask *gpuCopyTask = nullptr;
CmEvent *internalEvent = nullptr;
uint32_t threadWidth = 0;
uint32_t threadHeight = 0;
uint32_t threadNum = 0;
uint32_t widthDword = 0;
uint32_t widthByte = 0;
uint32_t copyWidthByte = 0;
uint32_t copyHeightRow = 0;
uint32_t bufferUPYSize = 0;
uint32_t bufferUPUVSize = 0;
CM_GPUCOPY_KERNEL *gpuCopyKernelParam = nullptr;
PCM_HAL_STATE cmHalState = \
((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
widthByte = widthInPixel * sizePerPixel;
//Align the width regarding stride
if (strideInBytes == 0)
{
strideInBytes = widthByte;
}
if (heightStrideInRows == 0)
{
heightStrideInRows = heightInRow;
}
// the actual copy region
copyWidthByte = MOS_MIN(strideInBytes, widthByte);
copyHeightRow = MOS_MIN(heightStrideInRows, heightInRow);
// Make sure stride and start address of system memory is 16-byte aligned.
// if no padding in system memory , strideInBytes = widthByte.
if (strideInBytes & 0xf)
{
CM_ASSERTMESSAGE("Error: Stride is not 16-byte aligned.");
return CM_GPUCOPY_INVALID_STRIDE;
}
//Check thread space width here
if (copyWidthByte > CM_MAX_THREADSPACE_WIDTH_FOR_MW * BLOCK_PIXEL_WIDTH * 4)
{ // each thread handles 128x8 block data. This API will fail if it exceeds the max thread space's size
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_GPUCOPY_INVALID_SIZE;
}
linearAddressY = (size_t)sysMem;
linearAddressUV = (size_t)((char*)sysMem + strideInBytes * heightStrideInRows);
if ((linearAddressY & 0xf) || (linearAddressY == 0) || (linearAddressAlignedUV & 0xf))
{
CM_ASSERTMESSAGE("Error: Start address of system memory is not 16-byte aligned.");
return CM_GPUCOPY_INVALID_SYSMEM;
}
if (sizeof (void *) == 8) //64-bit
{
linearAddressAlignedY = linearAddressY & ADDRESS_PAGE_ALIGNMENT_MASK_X64;
linearAddressAlignedUV = linearAddressUV & ADDRESS_PAGE_ALIGNMENT_MASK_X64;
}
else //32-bit
{
linearAddressAlignedY = linearAddressY & ADDRESS_PAGE_ALIGNMENT_MASK_X86;
linearAddressAlignedUV = linearAddressUV & ADDRESS_PAGE_ALIGNMENT_MASK_X86;
}
//Calculate Left Shift offset
addedShiftLeftOffsetY = (uint32_t)(linearAddressY - linearAddressAlignedY);
addedShiftLeftOffsetUV = (uint32_t)(linearAddressUV - linearAddressAlignedUV);
//Calculate actual total size of system memory, assume it's NV12/P010/P016 formats
bufferUPYSize = strideInBytes * heightStrideInRows + addedShiftLeftOffsetY;
bufferUPUVSize = strideInBytes * copyHeightRow * 1 / 2 + addedShiftLeftOffsetUV;
//Check thread space height here
if (copyHeightRow > CM_MAX_THREADSPACE_HEIGHT_FOR_MW * BLOCK_HEIGHT * INNER_LOOP)
{ // each thread handles 128x8 block data. This API will fail if it exceeds the max thread space's size
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_GPUCOPY_INVALID_SIZE;
}
kernel = nullptr;
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateBufferUP(bufferUPYSize, (void *)linearAddressAlignedY, cmbufferUPY));
CM_CHK_NULL_GOTOFINISH_CMERROR(cmbufferUPY);
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateBufferUP(bufferUPUVSize, (void *)linearAddressAlignedUV, cmbufferUPUV));
CM_CHK_NULL_GOTOFINISH_CMERROR(cmbufferUPUV);
//Configure memory object control for the two BufferUP to solve the same cache-line coherency issue.
if (cmHalState->cmHalInterface->IsGPUCopySurfaceNoCacheWARequired())
{
CM_CHK_CMSTATUS_GOTOFINISH(cmbufferUPY->SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL_SKL_NO_LLC_L3));
CM_CHK_CMSTATUS_GOTOFINISH(cmbufferUPUV->SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL_SKL_NO_LLC_L3));
}
else
{
CM_CHK_CMSTATUS_GOTOFINISH(static_cast< CmBuffer_RT* >(cmbufferUPY)->SetMemoryObjectControl(MEMORY_OBJECT_CONTROL_FROM_GTT_ENTRY, CM_WRITE_THROUGH, 0));
CM_CHK_CMSTATUS_GOTOFINISH(static_cast< CmBuffer_RT* >(cmbufferUPUV)->SetMemoryObjectControl(MEMORY_OBJECT_CONTROL_FROM_GTT_ENTRY, CM_WRITE_THROUGH, 0));
}
CM_CHK_CMSTATUS_GOTOFINISH(CreateGPUCopyKernel(copyWidthByte, copyHeightRow, format, direction, gpuCopyKernelParam));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam);
kernel = gpuCopyKernelParam->kernel;
CM_CHK_NULL_GOTOFINISH_CMERROR(kernel);
CM_CHK_NULL_GOTOFINISH_CMERROR(cmbufferUPY);
CM_CHK_NULL_GOTOFINISH_CMERROR(cmbufferUPUV);
CM_CHK_CMSTATUS_GOTOFINISH(cmbufferUPY->GetIndex(bufferUPIndexY));
CM_CHK_CMSTATUS_GOTOFINISH(cmbufferUPUV->GetIndex(bufferUPIndexUV));
CM_CHK_CMSTATUS_GOTOFINISH(surface->GetIndex(surf2DIndexCM));
threadWidth = (uint32_t)ceil((double)copyWidthByte / BLOCK_PIXEL_WIDTH / 4);
threadHeight = (uint32_t)ceil((double)copyHeightRow / BLOCK_HEIGHT / INNER_LOOP);
threadNum = threadWidth * threadHeight;
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetThreadCount(threadNum));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateThreadSpace(threadWidth, threadHeight, threadSpace));
widthDword = (uint32_t)ceil((double)widthByte / 4);
strideInDwords = (uint32_t)ceil((double)strideInBytes / 4);
if (direction == CM_FASTCOPY_CPU2GPU) //Write
{
//Input BufferUP_Y and BufferUP_UV
if (cmHalState->cmHalInterface->IsSurfaceCompressionWARequired())
{
CM_CHK_CMSTATUS_GOTOFINISH(surface->SetCompressionMode(MEMCOMP_DISABLED));
}
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(0, sizeof(SurfaceIndex), bufferUPIndexY));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(1, sizeof(SurfaceIndex), bufferUPIndexUV));
//Output Surface2D
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(2, sizeof(SurfaceIndex), surf2DIndexCM));
//Other parameters
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(3, sizeof(uint32_t), &strideInDwords));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(4, sizeof(uint32_t), &heightStrideInRows));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(5, sizeof(uint32_t), &addedShiftLeftOffsetY));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(6, sizeof(uint32_t), &addedShiftLeftOffsetUV));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(7, sizeof(uint32_t), &threadHeight));
}
else //Read
{
//Input Surface2D
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(0, sizeof(SurfaceIndex), surf2DIndexCM));
//Output BufferUP_Y and BufferUP_UV
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(1, sizeof(SurfaceIndex), bufferUPIndexY));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(2, sizeof(SurfaceIndex), bufferUPIndexUV));
//Other parameters
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(3, sizeof(uint32_t), &strideInDwords));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(4, sizeof(uint32_t), &heightStrideInRows));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(5, sizeof(uint32_t), &addedShiftLeftOffsetY));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(6, sizeof(uint32_t), &addedShiftLeftOffsetUV));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(7, sizeof(uint32_t), &threadHeight));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(8, sizeof(uint32_t), &widthDword));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(9, sizeof(uint32_t), &heightInRow));
surface->SetReadSyncFlag(true, this); // GPU -> CPU, set surf2d as read sync flag
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateTask(gpuCopyTask));
CM_CHK_CMSTATUS_GOTOFINISH(gpuCopyTask->AddKernel(kernel));
if (option & CM_FASTCOPY_OPTION_DISABLE_TURBO_BOOST)
{
// disable turbo
CM_TASK_CONFIG taskConfig;
CmSafeMemSet(&taskConfig, 0, sizeof(CM_TASK_CONFIG));
taskConfig.turboBoostFlag = CM_TURBO_BOOST_DISABLE;
gpuCopyTask->SetProperty(taskConfig);
}
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue(gpuCopyTask, internalEvent,
threadSpace));
GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
if ((option & CM_FASTCOPY_OPTION_BLOCKING) && (internalEvent))
{
CM_CHK_CMSTATUS_GOTOFINISH(internalEvent->WaitForTaskFinished());
}
if (event == CM_NO_EVENT) //User doesn't need CmEvent for this copy
{
event = nullptr;
CM_CHK_CMSTATUS_GOTOFINISH(DestroyEvent(internalEvent));
}
else //User needs this CmEvent
{
event = internalEvent;
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyTask(gpuCopyTask));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyThreadSpace(threadSpace));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(cmbufferUPY));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(cmbufferUPUV));
finish:
if (hr != CM_SUCCESS)
{
if ((cmbufferUPY == nullptr) || (cmbufferUPUV == nullptr))
{
// user need to know whether the failure is caused by out of BufferUP.
hr = CM_GPUCOPY_OUT_OF_RESOURCE;
}
if (kernel && gpuCopyKernelParam) GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
if (threadSpace) m_device->DestroyThreadSpace(threadSpace);
if (gpuCopyTask) m_device->DestroyTask(gpuCopyTask);
if (cmbufferUPY) m_device->DestroyBufferUP(cmbufferUPY);
if (cmbufferUPUV) m_device->DestroyBufferUP(cmbufferUPUV);
if (internalEvent) DestroyEvent(internalEvent);
// CM_FAILURE for all the other errors
// return CM_EXCEED_MAX_TIMEOUT to notify app that gpu reset happens
if( hr != CM_GPUCOPY_OUT_OF_RESOURCE && hr != CM_EXCEED_MAX_TIMEOUT)
{
hr = CM_FAILURE;
}
}
return hr;
}
//*-----------------------------------------------------------------------------
//! Enqueue an task, which contains one pre-defined kernel to copy from video memory to video memory
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of the task.
//! A CmEvent is generated each time a task is enqueued. The CmEvent can
//! be used to check if the task finishes.
//! INPUT:
//! 1) Pointer to the CmSurface2D as copy destination
//! 2) Pointer to the CmSurface2D as copy source
//! 3) Option passed from user, blocking copy, non-blocking copy or disable turbo boost
//! 4) Reference to the pointer to CMEvent
//! OUTPUT:
//! CM_SUCCESS if the task is successfully enqueued and the CmEvent is generated;
//! CM_OUT_OF_HOST_MEMORY if out of host memery;
//! CM_GPUCOPY_INVALID_SURFACES if input/output surfaces' width/format are different or
//! input surface's height is larger than output surface's
//! Restrictions:
//! 1) Surface's width should be 64-byte aligned.
//! 2) The input surface's width/height/format should be the same as output surface's.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueCopyGPUToGPU( CmSurface2D* outputSurface, CmSurface2D* inputSurface, uint32_t option, CmEvent* & event )
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuCopyKernel())
{
return CM_NOT_IMPLEMENTED;
}
uint32_t srcSurfaceWidth = 0;
uint32_t srcSurfaceHeight = 0;
uint32_t dstSurfaceWidth = 0;
uint32_t dstSurfaceHeight = 0;
CM_SURFACE_FORMAT srcSurfaceFormat = CM_SURFACE_FORMAT_INVALID;
CM_SURFACE_FORMAT dstSurfaceFormat = CM_SURFACE_FORMAT_INVALID;
int32_t hr = CM_SUCCESS;
uint32_t srcSizePerPixel = 0;
uint32_t dstSizePerPixel = 0;
uint32_t threadWidth = 0;
uint32_t threadHeight = 0;
CmKernel *kernel = nullptr;
SurfaceIndex *surfaceInputIndex = nullptr;
SurfaceIndex *surfaceOutputIndex = nullptr;
CmThreadSpace *threadSpace = nullptr;
CmTask *task = nullptr;
uint32_t srcSurfAlignedWidthInBytes = 0;
CM_GPUCOPY_KERNEL *gpuCopyKernelParam = nullptr;
if ((outputSurface == nullptr) || (inputSurface == nullptr))
{
CM_ASSERTMESSAGE("Error: Pointer to input surface or output surface is null.");
return CM_FAILURE;
}
PCM_HAL_STATE cmHalState = ((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
CmSurface2DRT *outputSurfaceRT = static_cast<CmSurface2DRT *>(outputSurface);
CmSurface2DRT *inputSurfaceRT = static_cast<CmSurface2DRT *>(inputSurface);
if (cmHalState->cmHalInterface->IsSurfaceCompressionWARequired())
{
CM_CHK_CMSTATUS_GOTOFINISH(outputSurfaceRT->SetCompressionMode(MEMCOMP_DISABLED));
}
CM_CHK_CMSTATUS_GOTOFINISH(outputSurfaceRT->GetSurfaceDesc(dstSurfaceWidth, dstSurfaceHeight, dstSurfaceFormat, dstSizePerPixel));
CM_CHK_CMSTATUS_GOTOFINISH(inputSurfaceRT->GetSurfaceDesc(srcSurfaceWidth, srcSurfaceHeight, srcSurfaceFormat, srcSizePerPixel));
if ((dstSurfaceWidth != srcSurfaceWidth) ||
(dstSurfaceHeight < srcSurfaceHeight) || //relax the restriction
(dstSizePerPixel != srcSizePerPixel))
{
CM_ASSERTMESSAGE("Error: Size of dest surface does not match src surface.");
return CM_GPUCOPY_INVALID_SURFACES;
}
//To support copy b/w Format_A8R8G8B8 and Format_A8B8G8R8
if (dstSurfaceFormat != srcSurfaceFormat)
{
if (!((dstSurfaceFormat == CM_SURFACE_FORMAT_A8R8G8B8) && (srcSurfaceFormat == CM_SURFACE_FORMAT_A8B8G8R8)) &&
!((dstSurfaceFormat == CM_SURFACE_FORMAT_A8R8G8B8) && (srcSurfaceFormat == CM_SURFACE_FORMAT_A8B8G8R8)))
{
CM_ASSERTMESSAGE("Error: Only support copy b/w Format_A8R8G8B8 and Format_A8B8G8R8 if src format is not matched with dst format.");
return CM_GPUCOPY_INVALID_SURFACES;
}
}
// 128Bytes aligned
srcSurfAlignedWidthInBytes = (uint32_t)(ceil((double)srcSurfaceWidth*srcSizePerPixel / BLOCK_PIXEL_WIDTH / 4) * (BLOCK_PIXEL_WIDTH * 4));
if (srcSurfaceHeight > CM_MAX_THREADSPACE_WIDTH_FOR_MW *BLOCK_HEIGHT *INNER_LOOP)
{
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_GPUCOPY_INVALID_SIZE;
}
CM_CHK_CMSTATUS_GOTOFINISH(CreateGPUCopyKernel(srcSurfaceWidth*srcSizePerPixel, srcSurfaceHeight, srcSurfaceFormat, CM_FASTCOPY_GPU2GPU, gpuCopyKernelParam));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam);
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam->kernel);
kernel = gpuCopyKernelParam->kernel;
CM_CHK_CMSTATUS_GOTOFINISH(inputSurface->GetIndex(surfaceInputIndex));
CM_CHK_CMSTATUS_GOTOFINISH(outputSurface->GetIndex(surfaceOutputIndex));
threadWidth = srcSurfAlignedWidthInBytes / (BLOCK_PIXEL_WIDTH * 4);
threadHeight = (uint32_t)ceil((double)srcSurfaceHeight / BLOCK_HEIGHT / INNER_LOOP);
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetThreadCount(threadWidth * threadHeight));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(0, sizeof(SurfaceIndex), surfaceInputIndex));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(1, sizeof(SurfaceIndex), surfaceOutputIndex));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg(2, sizeof(uint32_t), &threadHeight));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateThreadSpace(threadWidth, threadHeight, threadSpace));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateTask(task));
CM_CHK_NULL_GOTOFINISH_CMERROR(task);
CM_CHK_CMSTATUS_GOTOFINISH(task->AddKernel(kernel));
if (option & CM_FASTCOPY_OPTION_DISABLE_TURBO_BOOST)
{
// disable turbo
CM_TASK_CONFIG taskConfig;
CmSafeMemSet(&taskConfig, 0, sizeof(CM_TASK_CONFIG));
taskConfig.turboBoostFlag = CM_TURBO_BOOST_DISABLE;
task->SetProperty(taskConfig);
}
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue(task, event, threadSpace));
if ((option & CM_FASTCOPY_OPTION_BLOCKING) && (event))
{
CM_CHK_CMSTATUS_GOTOFINISH(event->WaitForTaskFinished());
}
finish:
if (kernel && gpuCopyKernelParam) GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
if (threadSpace) m_device->DestroyThreadSpace(threadSpace);
if (task) m_device->DestroyTask(task);
return hr;
}
//*-----------------------------------------------------------------------------
//! Enqueue an task, which contains one pre-defined kernel to copy from system memory to system memory
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of the task.
//! A CmEvent is generated each time a task is enqueued. The CmEvent can be used to check if the task finishs.
//! If the size is less than 1KB, CPU is used to do the copy and event will be set as nullptr .
//!
//! INPUT:
//! 1) Pointer to the system memory as copy destination
//! 2) Pointer to the system memory as copy source
//! 3) The size in bytes of memory be copied.
//! 4) Option passed from user, blocking copy, non-blocking copy or disable turbo boost
//! 5) Reference to the pointer to CMEvent
//! OUTPUT:
//! CM_SUCCESS if the task is successfully enqueued and the CmEvent is generated;
//! CM_OUT_OF_HOST_MEMORY if out of host memery;
//! CM_GPUCOPY_INVALID_SYSMEM if the sysMem is not 16-byte aligned or is NULL.
//! CM_GPUCOPY_OUT_OF_RESOURCE if runtime run out of BufferUP.
//! CM_GPUCOPY_INVALID_SIZE if its size plus shift-left offset large than CM_MAX_1D_SURF_WIDTH.
//! Restrictions:
//! 1) dstSysMem and srcSysMem should be 16-byte aligned.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueCopyCPUToCPU( unsigned char* dstSysMem, unsigned char* srcSysMem, uint32_t size, uint32_t option, CmEvent* & event )
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuCopyKernel())
{
return CM_NOT_IMPLEMENTED;
}
int hr = CM_SUCCESS;
size_t inputLinearAddress = (size_t )srcSysMem;
size_t outputLinearAddress = (size_t )dstSysMem;
size_t inputLinearAddressAligned = 0;
size_t outputLinearAddressAligned = 0;
CmBufferUP *surfaceInput = nullptr;
CmBufferUP *surfaceOutput = nullptr;
CmKernel *kernel = nullptr;
SurfaceIndex *surfaceInputIndex = nullptr;
SurfaceIndex *surfaceOutputIndex = nullptr;
CmThreadSpace *threadSpace = nullptr;
CmTask *task = nullptr;
int32_t srcLeftShiftOffset = 0;
int32_t dstLeftShiftOffset = 0;
uint32_t threadWidth = 0;
uint32_t threadHeight = 0;
uint32_t threadNum = 0;
uint32_t gpuMemcopySize = 0;
uint32_t cpuMemcopySize = 0;
CM_GPUCOPY_KERNEL *gpuCopyKernelParam = nullptr;
if((inputLinearAddress & 0xf) || (outputLinearAddress & 0xf) ||
(inputLinearAddress == 0) || (outputLinearAddress == 0))
{
CM_ASSERTMESSAGE("Error: Start address of system memory is not 16-byte aligned.");
return CM_GPUCOPY_INVALID_SYSMEM;
}
// Get page aligned address
if (sizeof (void *) == 8 ) //64-bit
{
inputLinearAddressAligned = inputLinearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X64; // make sure the address page aligned.
outputLinearAddressAligned = outputLinearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X64; // make sure the address page aligned.
}
else
{
inputLinearAddressAligned = inputLinearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X86; // make sure the address page aligned.
outputLinearAddressAligned = outputLinearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X86; // make sure the address page aligned.
}
srcLeftShiftOffset = (int32_t)(inputLinearAddress - inputLinearAddressAligned) ;
dstLeftShiftOffset = (int32_t)(outputLinearAddress - outputLinearAddressAligned) ;
if(((size + srcLeftShiftOffset) > CM_MAX_1D_SURF_WIDTH)||
((size + dstLeftShiftOffset) > CM_MAX_1D_SURF_WIDTH))
{
CM_ASSERTMESSAGE("Error: Invalid copy size.");
return CM_GPUCOPY_INVALID_SIZE;
}
threadWidth = 0;
threadHeight = 0;
threadNum = size / BYTE_COPY_ONE_THREAD; // each thread copys 32 x 4 x32 bytes = 1K
if( threadNum == 0)
{
//if the size of data is less than data copied per thread ( 4K), use CPU to copy it instead of GPU.
CmFastMemCopy((void *)(outputLinearAddress),
(void *)(inputLinearAddress),
size); //SSE copy used in CMRT.
event = nullptr;
return CM_SUCCESS;
}
//Calculate proper thread space's width and height
threadWidth = 1;
threadHeight = threadNum/threadWidth;
while((threadHeight > CM_MAX_THREADSPACE_HEIGHT_FOR_MW))
{
if(threadWidth > CM_MAX_THREADSPACE_WIDTH_FOR_MW)
{
hr = CM_GPUCOPY_INVALID_SIZE; // thread number exceed 511*511
goto finish;
}
else if (threadWidth == 1)
{
threadWidth = THREAD_SPACE_WIDTH_INCREMENT; // first time,
threadHeight = threadNum/threadWidth;
}
else
{
threadWidth += THREAD_SPACE_WIDTH_INCREMENT; // increase 8 per iteration
threadHeight = threadNum/threadWidth;
}
}
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateBufferUP(size + srcLeftShiftOffset, (void *)inputLinearAddressAligned,surfaceInput));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateBufferUP(size + dstLeftShiftOffset, (void *)outputLinearAddressAligned,surfaceOutput));
CM_CHK_CMSTATUS_GOTOFINISH(CreateGPUCopyKernel(size, 0, CM_SURFACE_FORMAT_INVALID, CM_FASTCOPY_CPU2CPU, gpuCopyKernelParam));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam);
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam->kernel);
kernel = gpuCopyKernelParam->kernel;
CM_CHK_NULL_GOTOFINISH_CMERROR(surfaceInput);
CM_CHK_CMSTATUS_GOTOFINISH(surfaceInput->GetIndex(surfaceInputIndex));
CM_CHK_NULL_GOTOFINISH_CMERROR(surfaceOutput);
CM_CHK_CMSTATUS_GOTOFINISH(surfaceOutput->GetIndex(surfaceOutputIndex));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetThreadCount(threadWidth * threadHeight));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 0, sizeof( SurfaceIndex ), surfaceInputIndex ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 1, sizeof( SurfaceIndex ), surfaceOutputIndex ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 2, sizeof( int ), &threadWidth ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 3, sizeof( int ), &threadHeight ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 4, sizeof( int ), &srcLeftShiftOffset ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 5, sizeof( int ), &dstLeftShiftOffset ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 6, sizeof( int ), &size ));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateThreadSpace(threadWidth, threadHeight, threadSpace));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateTask(task));
CM_CHK_NULL_GOTOFINISH_CMERROR(task);
CM_CHK_CMSTATUS_GOTOFINISH(task->AddKernel (kernel));
if (option & CM_FASTCOPY_OPTION_DISABLE_TURBO_BOOST)
{
// disable turbo
CM_TASK_CONFIG taskConfig;
CmSafeMemSet(&taskConfig, 0, sizeof(CM_TASK_CONFIG));
taskConfig.turboBoostFlag = CM_TURBO_BOOST_DISABLE;
task->SetProperty(taskConfig);
}
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue(task, event, threadSpace));
if ((option & CM_FASTCOPY_OPTION_BLOCKING) && (event))
{
CM_CHK_CMSTATUS_GOTOFINISH(event->WaitForTaskFinished());
}
//Copy the unaligned part by using CPU
gpuMemcopySize = threadHeight * threadWidth *BYTE_COPY_ONE_THREAD;
cpuMemcopySize = size - threadHeight * threadWidth *BYTE_COPY_ONE_THREAD;
CmFastMemCopy((void *)(outputLinearAddress+gpuMemcopySize),
(void *)(inputLinearAddress+gpuMemcopySize),
cpuMemcopySize); //SSE copy used in CMRT.
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyThreadSpace(threadSpace));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyTask(task));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(surfaceOutput)); // ref_cnf to guarantee task finish before BufferUP being really destroy.
CM_CHK_CMSTATUS_GOTOFINISH(m_device->DestroyBufferUP(surfaceInput));
GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
finish:
if(hr != CM_SUCCESS)
{ //Failed
if( surfaceInput == nullptr || surfaceOutput == nullptr)
{
hr = CM_GPUCOPY_OUT_OF_RESOURCE; // user need to know whether the failure is caused by out of BufferUP.
}
else
{
hr = CM_FAILURE;
}
if(surfaceInput) m_device->DestroyBufferUP(surfaceInput);
if(surfaceOutput) m_device->DestroyBufferUP(surfaceOutput);
if(kernel && gpuCopyKernelParam) GPUCOPY_KERNEL_UNLOCK(gpuCopyKernelParam);
if(threadSpace) m_device->DestroyThreadSpace(threadSpace);
if(task) m_device->DestroyTask(task);
}
return hr;
}
//*----------------------------------------------------------------------------------------
//| Purpose: Pop task from flushed Queue, Update surface state and Destroy the task
//| Notes:
//*----------------------------------------------------------------------------------------
void CmQueueRT::PopTaskFromFlushedQueue()
{
CmTaskInternal* topTask = (CmTaskInternal*)m_flushedTasks.Pop();
if ( topTask != nullptr )
{
CmEventRT *event = nullptr;
topTask->GetTaskEvent( event );
if ( event != nullptr )
{
LARGE_INTEGER nTime;
if ( !(MOS_QueryPerformanceCounter( (uint64_t*)&nTime.QuadPart )) )
{
CM_ASSERTMESSAGE("Error: Query performace counter failure.");
}
else
{
event->SetCompleteTime( nTime );
}
}
#if MDF_SURFACE_CONTENT_DUMP
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)m_device->GetAccelData();
if (cmData->cmHalState->dumpSurfaceContent)
{
int32_t taskId = 0;
if (event != nullptr)
{
event->GetTaskDriverId(taskId);
}
topTask->SurfaceDump(taskId);
}
#endif
CmTaskInternal::Destroy( topTask );
}
return;
}
int32_t CmQueueRT::TouchFlushedTasks( )
{
int32_t hr = CM_SUCCESS;
if (m_flushedTasks.IsEmpty())
{
if (!m_enqueuedTasks.IsEmpty())
{
// if FlushedQueue is empty and EnqueuedQueue is not empty
// try flush task to FlushedQueue
hr = FlushTaskWithoutSync();
if (FAILED(hr))
{
return hr;
}
}
else
{ // no task in flushedQueue and EnqueuedQueue
return CM_FAILURE;
}
}
// Flush FlushedQueue
hr = QueryFlushedTasks();
return hr;
}
//*-----------------------------------------------------------------------------
//! Flush the queue, i.e. submit all tasks in the queue to execute according
//! to their order in the the queue. The queue will be empty after flush,
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of tasks.
//! INPUT:
//! OUTPUT:
//! CM_SUCCESS if all tasks in the queue are submitted
//! CM_FAILURE otherwise.
//! More error code is coming.
//!
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::QueryFlushedTasks()
{
int32_t hr = CM_SUCCESS;
m_criticalSectionFlushedTask.Acquire();
while( !m_flushedTasks.IsEmpty() )
{
CmTaskInternal* task = (CmTaskInternal*)m_flushedTasks.Top();
CM_CHK_NULL_GOTOFINISH_CMERROR(task);
CM_STATUS status = CM_STATUS_FLUSHED ;
task->GetTaskStatus(status);
if( status == CM_STATUS_FINISHED )
{
PopTaskFromFlushedQueue();
}
else
{
// media reset
if (status == CM_STATUS_RESET)
{
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)m_device->GetAccelData();
// Clear task status table in Cm Hal State
int32_t taskId;
CmEventRT*pTopTaskEvent;
task->GetTaskEvent(pTopTaskEvent);
CM_CHK_NULL_GOTOFINISH_CMERROR(pTopTaskEvent);
pTopTaskEvent->GetTaskDriverId(taskId);
cmData->cmHalState->taskStatusTable[taskId] = CM_INVALID_INDEX;
//Pop task and Destroy it
PopTaskFromFlushedQueue();
}
// It is an in-order queue, if this one hasn't finshed,
// the following ones haven't finished either.
break;
}
}
finish:
m_criticalSectionFlushedTask.Release();
return hr;
}
//*-----------------------------------------------------------------------------
//! This is a blocking call. It will NOT return untill
//! all tasks in GPU and all tasks in queue finishes execution.
//! It will first flush the queue if the queue is not empty.
//! INPUT:
//! OUTPUT:
//! CM_SUCCESS if all tasks finish execution.
//! CM_FAILURE otherwise.
//! More error code is coming.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::DestroyEvent( CmEvent* & event )
{
CLock Lock(m_criticalSectionEvent);
if (event == nullptr)
{
return CM_FAILURE;
}
uint32_t index = 0;
CmEventRT *eventRT = static_cast<CmEventRT *>(event);
eventRT->GetIndex(index);
CM_ASSERT( m_eventArray.GetElement( index ) == eventRT );
int32_t status = CmEventRT::Destroy( eventRT );
if( status == CM_SUCCESS && eventRT == nullptr)
{
m_eventArray.SetElement(index, nullptr);
}
// Should return nullptr to application even the event is not destroyed
// since its reference count is not zero
event = nullptr;
return status;
}
//*-----------------------------------------------------------------------------
//| Purpose: Clean the Queue if its tasks time out
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::CleanQueue( )
{
int32_t status = CM_SUCCESS;
// Maybe not necessary since
// it is called by ~CmDevice only
// Update: necessary because it calls FlushBlockWithoutSync
if( !m_enqueuedTasks.IsEmpty() )
{
// If there are tasks not flushed (i.e. not send to driver )
// wait untill all such tasks are flushed
FlushTaskWithoutSync( true );
}
CM_ASSERT( m_enqueuedTasks.IsEmpty() );
//Used for timeout detection
LARGE_INTEGER freq;
MOS_QueryPerformanceFrequency((uint64_t*)&freq.QuadPart);
LARGE_INTEGER start;
MOS_QueryPerformanceCounter((uint64_t*)&start.QuadPart);
int64_t timeout = start.QuadPart + (CM_MAX_TIMEOUT * freq.QuadPart * m_flushedTasks.GetCount()); //Count to timeout at
while( !m_flushedTasks.IsEmpty() && status != CM_EXCEED_MAX_TIMEOUT )
{
QueryFlushedTasks();
LARGE_INTEGER current;
MOS_QueryPerformanceCounter((uint64_t*)¤t.QuadPart);
if( current.QuadPart > timeout )
status = CM_EXCEED_MAX_TIMEOUT;
}
return status;
}
CM_QUEUE_CREATE_OPTION &CmQueueRT::GetQueueOption()
{
return m_queueOption;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the count of task in queue
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::GetTaskCount( uint32_t& numTasks )
{
numTasks = m_enqueuedTasks.GetCount() + m_flushedTasks.GetCount();
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Use GPU to init Surface2D
//| Returns: result of operation
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueInitSurface2D( CmSurface2D* surf2D, const uint32_t initValue, CmEvent* &event)
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuInitKernel())
{
return CM_NOT_IMPLEMENTED;
}
int32_t hr = CM_SUCCESS;
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizePerPixel = 0;
CmProgram *gpuInitKernelProgram = nullptr;
CmKernel *kernel = nullptr;
SurfaceIndex *outputIndexCM = nullptr;
CmThreadSpace *threadSpace = nullptr;
CmTask *gpuCopyTask = nullptr;
uint32_t threadWidth = 0;
uint32_t threadHeight = 0;
uint32_t threadNum = 0;
CmSurfaceManager* surfaceMgr = nullptr;
CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
if(!surf2D)
{
CM_ASSERTMESSAGE("Error: Pointer to surface 2d is null.");
return CM_FAILURE;
}
CmSurface2DRT *surf2DRT = static_cast<CmSurface2DRT *>(surf2D);
CM_CHK_CMSTATUS_GOTOFINISH(m_device->LoadPredefinedInitKernel(gpuInitKernelProgram));
CM_CHK_CMSTATUS_GOTOFINISH(surf2DRT->GetSurfaceDesc(width, height, format,sizePerPixel));
m_device->GetSurfaceManager(surfaceMgr);
CM_CHK_NULL_GOTOFINISH_CMERROR(surfaceMgr);
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel( gpuInitKernelProgram, _NAME( surfaceCopy_set_NV12 ), kernel, "PredefinedGPUCopyKernel"));
}
else
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel( gpuInitKernelProgram, _NAME( surfaceCopy_set ), kernel, "PredefinedGPUCopyKernel" ));
}
CM_CHK_NULL_GOTOFINISH_CMERROR(kernel);
CM_CHK_CMSTATUS_GOTOFINISH(surf2D->GetIndex( outputIndexCM ));
threadWidth = ( uint32_t )ceil( ( double )width*sizePerPixel/BLOCK_PIXEL_WIDTH/4 );
threadHeight = ( uint32_t )ceil( ( double )height/BLOCK_HEIGHT );
threadNum = threadWidth * threadHeight;
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetThreadCount( threadNum ));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateThreadSpace( threadWidth, threadHeight, threadSpace ));
CM_CHK_NULL_GOTOFINISH_CMERROR(threadSpace);
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 0, sizeof( uint32_t ), &initValue ));
CM_CHK_CMSTATUS_GOTOFINISH(kernel->SetKernelArg( 1, sizeof( SurfaceIndex ), outputIndexCM ));
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateTask(gpuCopyTask));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyTask);
CM_CHK_CMSTATUS_GOTOFINISH(gpuCopyTask->AddKernel( kernel ));
CM_CHK_CMSTATUS_GOTOFINISH(Enqueue(gpuCopyTask, event, threadSpace));
finish:
if (kernel) m_device->DestroyKernel( kernel );
if (gpuCopyTask) m_device->DestroyTask(gpuCopyTask);
if (threadSpace) m_device->DestroyThreadSpace(threadSpace);
return hr;
}
//*-----------------------------------------------------------------------------
//! Flush a geneal task to HAL CM layer for execution.
//! This is a non-blocking call. i.e. it returs immediately without waiting for
//! GPU to finish the execution of tasks.
//! INPUT: task -- Pointer to CmTaskInternal object
//! OUTPUT:
//! CM_SUCCESS if all tasks in the queue are submitted
//! CM_FAILURE otherwise.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::FlushGeneralTask(CmTaskInternal* task)
{
CM_RETURN_CODE hr = CM_SUCCESS;
CM_HAL_EXEC_TASK_PARAM param;
PCM_HAL_KERNEL_PARAM kernelParam = nullptr;
CmKernelData* kernelData = nullptr;
uint32_t kernelDataSize = 0;
PCM_CONTEXT_DATA cmData = nullptr;
CmEventRT* event = nullptr;
uint32_t totalThreadCount= 0;
uint32_t count = 0;
PCM_HAL_KERNEL_PARAM tempData = nullptr;
uint32_t maxTSWidth = 0;
bool hasThreadArg = false;
CmSafeMemSet( ¶m, 0, sizeof( CM_HAL_EXEC_TASK_PARAM ) );
//GT-PIN
if(m_device->CheckGTPinEnabled())
{
CM_CHK_CMSTATUS_GOTOFINISH(task->GetKernelSurfInfo(param.surfEntryInfoArrays));
}
task->GetKernelCount( count );
param.numKernels = count;
param.kernels = MOS_NewArray(PCM_HAL_KERNEL_PARAM,count);
param.kernelSizes = MOS_NewArray(uint32_t,count);
param.kernelCurbeOffset = MOS_NewArray(uint32_t,count);
param.queueOption = m_queueOption;
CM_CHK_NULL_GOTOFINISH(param.kernels, CM_OUT_OF_HOST_MEMORY);
CM_CHK_NULL_GOTOFINISH(param.kernelSizes, CM_OUT_OF_HOST_MEMORY);
CM_CHK_NULL_GOTOFINISH(param.kernelCurbeOffset, CM_OUT_OF_HOST_MEMORY);
for( uint32_t i = 0; i < count; i ++ )
{
task->GetKernelData( i, kernelData );
CM_CHK_NULL_GOTOFINISH_CMERROR(kernelData);
kernelParam = kernelData->GetHalCmKernelData();
CM_CHK_NULL_GOTOFINISH_CMERROR(kernelParam);
hasThreadArg |= kernelParam->perThreadArgExisted;
task->GetKernelDataSize( i, kernelDataSize );
if(kernelDataSize == 0)
{
CM_ASSERTMESSAGE("Error: Invalid kernel data size.");
hr = CM_FAILURE;
goto finish;
}
tempData = kernelData->GetHalCmKernelData();
param.kernels[ i ] = tempData;
param.kernelSizes[ i ] = kernelDataSize;
param.kernelCurbeOffset[ i ] = task->GetKernelCurbeOffset(i);
param.globalSurfaceUsed |= tempData->globalSurfaceUsed;
param.kernelDebugEnabled |= tempData->kernelDebugEnabled;
}
/*
* Preset the default TS width/height/dependency:
* TS width = MOS_MIN(CM_MAX_THREADSPACE_WIDTH, threadcount)
* TS height = totalThreadCount/CM_MAX_THREADSPACE_WIDTH + 1
* dependency = CM_NONE_DEPENDENCY
* For threadSpace is nullptr case, we will pass the default TS width/height/dependency to driver
* For threadSpace is valid case, the TS width/height/dependency will be update according to thread space set by user.
*/
task->GetTotalThreadCount(totalThreadCount);
if (hasThreadArg)
{
maxTSWidth = CM_MAX_THREADSPACE_WIDTH_FOR_MW + 1; // 512 allowed for media object
}
else
{
maxTSWidth = CM_MAX_THREADSPACE_WIDTH_FOR_MW; // 511 for media walker
}
param.threadSpaceWidth = (totalThreadCount > maxTSWidth) ? maxTSWidth : totalThreadCount;
if(totalThreadCount%maxTSWidth)
{
param.threadSpaceHeight = totalThreadCount/maxTSWidth + 1;
}
else
{
param.threadSpaceHeight = totalThreadCount/maxTSWidth;
}
param.dependencyPattern = CM_NONE_DEPENDENCY;
if (task->IsThreadSpaceCreated()) //scoreboard data preparation
{
if(task->IsThreadCoordinatesExisted())
{
param.threadCoordinates = MOS_NewArray(PCM_HAL_SCOREBOARD, count);
param.dependencyMasks = MOS_NewArray(PCM_HAL_MASK_AND_RESET, count);
CM_CHK_NULL_GOTOFINISH(param.threadCoordinates, CM_OUT_OF_HOST_MEMORY);
CM_CHK_NULL_GOTOFINISH(param.dependencyMasks, CM_OUT_OF_HOST_MEMORY);
for(uint32_t i=0; i<count; i++)
{
void *kernelCoordinates = nullptr;
void *dependencyMasks = nullptr;
task->GetKernelCoordinates(i, kernelCoordinates);
task->GetKernelDependencyMasks(i, dependencyMasks);
param.threadCoordinates[i] = (PCM_HAL_SCOREBOARD)kernelCoordinates;
param.dependencyMasks[i] = (PCM_HAL_MASK_AND_RESET)dependencyMasks;
}
}
else
{
param.threadCoordinates = nullptr;
}
task->GetDependencyPattern(param.dependencyPattern);
task->GetThreadSpaceSize(param.threadSpaceWidth, param.threadSpaceHeight);
task->GetWalkingPattern(param.walkingPattern);
if( task->CheckWalkingParametersSet( ) )
{
param.walkingParamsValid = 1;
CM_CHK_CMSTATUS_GOTOFINISH(task->GetWalkingParameters(param.walkingParams));
}
else
{
param.walkingParamsValid = 0;
}
if( task->CheckDependencyVectorsSet( ) )
{
param.dependencyVectorsValid = 1;
CM_CHK_CMSTATUS_GOTOFINISH(task->GetDependencyVectors(param.dependencyVectors));
}
else
{
param.dependencyVectorsValid = 0;
}
}
if (param.threadSpaceWidth == 0)
{
CM_ASSERTMESSAGE("Error: Invalid thread space.");
hr = CM_INVALID_THREAD_SPACE;
goto finish;
}
task->GetColorCountMinusOne(param.colorCountMinusOne);
task->GetMediaWalkerGroupSelect(param.mediaWalkerGroupSelect);
param.syncBitmap = task->GetSyncBitmap();
param.conditionalEndBitmap = task->GetConditionalEndBitmap();
param.userDefinedMediaState = task->GetMediaStatePtr();
CmSafeMemCopy(param.conditionalEndInfo, task->GetConditionalEndInfo(), sizeof(param.conditionalEndInfo));
CmSafeMemCopy(¶m.taskConfig, task->GetTaskConfig(), sizeof(param.taskConfig));
cmData = (PCM_CONTEXT_DATA)m_device->GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnSetPowerOption(cmData->cmHalState, task->GetPowerOption()));
m_device->RegisterSyncEvent(nullptr);
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnExecuteTask(cmData->cmHalState, ¶m));
if( param.taskIdOut < 0 )
{
CM_ASSERTMESSAGE("Error: Invalid task ID.");
hr = CM_FAILURE;
goto finish;
}
TASK_LOG(task);
task->GetTaskEvent( event );
CM_CHK_NULL_GOTOFINISH_CMERROR(event);
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskDriverId( param.taskIdOut ));
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskOsData( param.osData ));
CM_CHK_CMSTATUS_GOTOFINISH(task->ResetKernelDataStatus());
//GT-PIN
if(m_device->CheckGTPinEnabled())
{
//No need to clear the SurEntryInfoArrays here. It will be destored by CmInternalTask
CM_CHK_CMSTATUS_GOTOFINISH(event->SetSurfaceDetails(param.surfEntryInfoArrays));
}
finish:
MosSafeDeleteArray( param.kernels );
MosSafeDeleteArray( param.kernelSizes );
MosSafeDeleteArray( param.threadCoordinates);
MosSafeDeleteArray( param.dependencyMasks);
MosSafeDeleteArray( param.kernelCurbeOffset);
return hr;
}
//*-----------------------------------------------------------------------------
//! Flush a thread group based task to HAL CM layer for execution.
//! This is a non-blocking call. i.e. it returs immediately without waiting for
//! GPU to finish the execution of tasks.
//! INPUT: task -- Pointer to CmTaskInternal object
//! OUTPUT:
//! CM_SUCCESS if all tasks in the queue are submitted
//! CM_FAILURE otherwise.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::FlushGroupTask(CmTaskInternal* task)
{
CM_RETURN_CODE hr = CM_SUCCESS;
CM_HAL_EXEC_TASK_GROUP_PARAM param;
CmKernelData* kernelData = nullptr;
uint32_t kernelDataSize = 0;
uint32_t count = 0;
PCM_CONTEXT_DATA cmData = nullptr;
CmEventRT * event = nullptr;
PCM_HAL_KERNEL_PARAM tempData = nullptr;
CmSafeMemSet( ¶m, 0, sizeof( CM_HAL_EXEC_TASK_GROUP_PARAM ) );
//GT-PIN
if(this->m_device->CheckGTPinEnabled())
{
CM_CHK_CMSTATUS_GOTOFINISH(task->GetKernelSurfInfo(param.surEntryInfoArrays));
}
task->GetKernelCount( count );
param.numKernels = count;
param.kernels = MOS_NewArray(PCM_HAL_KERNEL_PARAM, count);
param.kernelSizes = MOS_NewArray(uint32_t, count);
param.kernelCurbeOffset = MOS_NewArray(uint32_t, count);
param.queueOption = m_queueOption;
CmSafeMemCopy(¶m.taskConfig, task->GetTaskConfig(), sizeof(param.taskConfig));
CM_CHK_NULL_GOTOFINISH_CMERROR(param.kernels);
CM_CHK_NULL_GOTOFINISH_CMERROR(param.kernelSizes);
CM_CHK_NULL_GOTOFINISH_CMERROR(param.kernelCurbeOffset);
for( uint32_t i = 0; i < count; i ++ )
{
task->GetKernelData( i, kernelData );
CM_CHK_NULL_GOTOFINISH_CMERROR(kernelData);
task->GetKernelDataSize( i, kernelDataSize );
if( kernelDataSize == 0)
{
CM_ASSERTMESSAGE("Error: Invalid kernel data size.");
hr = CM_FAILURE;
goto finish;
}
tempData = kernelData->GetHalCmKernelData( );
param.kernels[ i ] = tempData;
param.kernelSizes[ i ] = kernelDataSize;
param.kernelCurbeOffset [ i ] = task->GetKernelCurbeOffset(i);
param.globalSurfaceUsed |= tempData->globalSurfaceUsed;
param.kernelDebugEnabled |= tempData->kernelDebugEnabled;
}
task->GetSLMSize(param.slmSize);
if(param.slmSize > MAX_SLM_SIZE_PER_GROUP_IN_1K)
{
CM_ASSERTMESSAGE("Error: SLM size exceeds the maximum per group.");
hr = CM_EXCEED_MAX_SLM_SIZE;
goto finish;
}
if (task->IsThreadGroupSpaceCreated())//thread group size
{
task->GetThreadGroupSpaceSize(param.threadSpaceWidth, param.threadSpaceHeight,
param.threadSpaceDepth, param.groupSpaceWidth,
param.groupSpaceHeight, param.groupSpaceDepth);
}
param.syncBitmap = task->GetSyncBitmap();
param.conditionalEndBitmap = task->GetConditionalEndBitmap();
param.userDefinedMediaState = task->GetMediaStatePtr();
CmSafeMemCopy(param.conditionalEndInfo, task->GetConditionalEndInfo(), sizeof(param.conditionalEndInfo));
CmSafeMemCopy(param.krnExecCfg, task->GetKernelExecuteConfig(), sizeof(param.krnExecCfg));
// Call HAL layer to execute pfnExecuteGroupTask
cmData = (PCM_CONTEXT_DATA)m_device->GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR( cmData->cmHalState->pfnSetPowerOption( cmData->cmHalState, task->GetPowerOption() ) );
m_device->RegisterSyncEvent(nullptr);
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR( cmData->cmHalState->pfnExecuteGroupTask( cmData->cmHalState, ¶m ) );
if( param.taskIdOut < 0 )
{
CM_ASSERTMESSAGE("Error: Invalid task ID.");
hr = CM_FAILURE;
goto finish;
}
TASK_LOG(task);
task->GetTaskEvent( event );
CM_CHK_NULL_GOTOFINISH_CMERROR( event );
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskDriverId( param.taskIdOut ));
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskOsData( param.osData ));
CM_CHK_CMSTATUS_GOTOFINISH(task->ResetKernelDataStatus());
//GT-PIN
if(this->m_device->CheckGTPinEnabled())
{
CM_CHK_CMSTATUS_GOTOFINISH(event->SetSurfaceDetails(param.surEntryInfoArrays));
}
finish:
MosSafeDeleteArray( param.kernels );
MosSafeDeleteArray( param.kernelSizes );
MosSafeDeleteArray( param.kernelCurbeOffset);
return hr;
}
//*-----------------------------------------------------------------------------
//! Flush a VEBOX task to HAL CM layer for execution.
//! This is a non-blocking call. i.e. it returs immediately without waiting for
//! GPU to finish the execution of tasks.
//! INPUT: task -- Pointer to CmTaskInternal object
//! OUTPUT:
//! CM_SUCCESS if all tasks in the queue are submitted
//! CM_FAILURE otherwise.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::FlushVeboxTask(CmTaskInternal* task)
{
CM_RETURN_CODE hr = CM_SUCCESS;
CM_HAL_EXEC_VEBOX_TASK_PARAM param;
PCM_CONTEXT_DATA cmData = nullptr;
CmEventRT * event = nullptr;
uint8_t *stateData = nullptr;
uint8_t *surfaceData = nullptr;
CmBuffer_RT * temp = nullptr;
CmSafeMemSet( ¶m, 0, sizeof( CM_HAL_EXEC_VEBOX_TASK_PARAM ) );
//Set VEBOX state data pointer and size
//Set VEBOX surface data pointer and size
CM_VEBOX_STATE cmVeboxState;
CmBufferUP *veboxParamBuf = nullptr;
CM_VEBOX_SURFACE_DATA cmVeboxSurfaceData;
task->GetVeboxState(cmVeboxState);
task->GetVeboxParam(veboxParamBuf);
task->GetVeboxSurfaceData(cmVeboxSurfaceData);
CM_CHK_NULL_GOTOFINISH_CMERROR(veboxParamBuf);
temp = static_cast<CmBuffer_RT*>(veboxParamBuf);
temp->GetHandle(param.veboxParamIndex);
param.cmVeboxState = cmVeboxState;
param.veboxParam = veboxParamBuf;
param.veboxSurfaceData = cmVeboxSurfaceData;
param.queueOption = m_queueOption;
//Set VEBOX task id to -1
param.taskIdOut = -1;
cmData = (PCM_CONTEXT_DATA)m_device->GetAccelData();
m_device->RegisterSyncEvent(nullptr);
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR( cmData->cmHalState->pfnExecuteVeboxTask( cmData->cmHalState, ¶m ) );
if( param.taskIdOut < 0 )
{
CM_ASSERTMESSAGE("Error: Invalid task ID.");
hr = CM_FAILURE;
goto finish;
}
task->GetTaskEvent( event );
CM_CHK_NULL_GOTOFINISH_CMERROR( event );
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskDriverId( param.taskIdOut ));
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskOsData( param.osData ));
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//! Flush the queue, i.e. submit all tasks in the queue to execute according
//! to their order in the the queue. The queue will be empty after flush,
//! This is a non-blocking call. i.e. it returns immediately without waiting for
//! GPU to finish the execution of tasks.
//! INPUT:
//! OUTPUT:
//! CM_SUCCESS if all tasks in the queue are submitted
//! CM_FAILURE otherwise.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::FlushEnqueueWithHintsTask( CmTaskInternal* task )
{
CM_RETURN_CODE hr = CM_SUCCESS;
CM_HAL_EXEC_HINTS_TASK_PARAM param;
PCM_CONTEXT_DATA cmData = nullptr;
CmKernelData* kernelData = nullptr;
uint32_t kernelDataSize = 0;
uint32_t count = 0;
CmEventRT *event = nullptr;
PCM_HAL_KERNEL_PARAM tempData = nullptr;
CmSafeMemSet( ¶m, 0, sizeof( CM_HAL_EXEC_HINTS_TASK_PARAM ) );
task->GetKernelCount ( count );
param.numKernels = count;
param.kernels = MOS_NewArray(PCM_HAL_KERNEL_PARAM, count);
param.kernelSizes = MOS_NewArray(uint32_t, count);
param.kernelCurbeOffset = MOS_NewArray(uint32_t, count);
param.queueOption = m_queueOption;
CM_CHK_NULL_GOTOFINISH_CMERROR(param.kernels);
CM_CHK_NULL_GOTOFINISH_CMERROR(param.kernelSizes);
CM_CHK_NULL_GOTOFINISH_CMERROR(param.kernelCurbeOffset);
task->GetHints(param.hints);
task->GetNumTasksGenerated(param.numTasksGenerated);
task->GetLastTask(param.isLastTask);
for( uint32_t i = 0; i < count; i ++ )
{
task->GetKernelData( i, kernelData );
CM_CHK_NULL_GOTOFINISH_CMERROR( kernelData );
task->GetKernelDataSize( i, kernelDataSize );
if( kernelDataSize == 0 )
{
CM_ASSERTMESSAGE("Error: Invalid kernel data size.");
hr = CM_FAILURE;
goto finish;
}
tempData = kernelData->GetHalCmKernelData();
param.kernels[ i ] = tempData;
param.kernelSizes[ i ] = kernelDataSize;
param.kernelCurbeOffset[ i ] = task->GetKernelCurbeOffset(i);
}
param.userDefinedMediaState = task->GetMediaStatePtr();
cmData = (PCM_CONTEXT_DATA)m_device->GetAccelData();
CM_CHK_NULL_GOTOFINISH_CMERROR(cmData);
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnSetPowerOption(cmData->cmHalState, task->GetPowerOption()));
m_device->RegisterSyncEvent(nullptr);
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnExecuteHintsTask(cmData->cmHalState, ¶m));
if( param.taskIdOut < 0 )
{
CM_ASSERTMESSAGE("Error: Invalid task ID.");
hr = CM_FAILURE;
goto finish;
}
TASK_LOG(task);
task->GetTaskEvent( event );
CM_CHK_NULL_GOTOFINISH_CMERROR( event );
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskDriverId( param.taskIdOut ));
CM_CHK_CMSTATUS_GOTOFINISH(event->SetTaskOsData( param.osData ));
CM_CHK_CMSTATUS_GOTOFINISH(task->ResetKernelDataStatus());
finish:
MosSafeDeleteArray( param.kernels );
MosSafeDeleteArray( param.kernelSizes );
MosSafeDeleteArray( param.kernelCurbeOffset );
return hr;
}
//*-----------------------------------------------------------------------------
//! Flush the queue, i.e. submit all tasks in the queue to execute according
//! to their order in the the queue. The queue will be empty after flush,
//! This is a non-blocking call. i.e. it returs immediately without waiting for
//! GPU to finish the execution of tasks.
//! INPUT:
//! OUTPUT:
//! CM_SUCCESS if all tasks in the queue are submitted
//! CM_FAILURE otherwise.
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::FlushTaskWithoutSync( bool flushBlocked )
{
int32_t hr = CM_SUCCESS;
CmTaskInternal* task = nullptr;
uint32_t taskType = CM_TASK_TYPE_DEFAULT;
uint32_t freeSurfNum = 0;
CmSurfaceManager* surfaceMgr = nullptr;
CSync* surfaceLock = nullptr;
m_criticalSectionHalExecute.Acquire(); // Enter HalCm Execute Protection
while( !m_enqueuedTasks.IsEmpty() )
{
uint32_t flushedTaskCount = m_flushedTasks.GetCount();
if ( flushBlocked )
{
while( flushedTaskCount >= m_halMaxValues->maxTasks )
{
// If the task count in flushed queue is no less than hw restrictiion,
// query the staus of flushed task queue. Remove any finished tasks from the queue
QueryFlushedTasks();
flushedTaskCount = m_flushedTasks.GetCount();
}
}
else
{
if( flushedTaskCount >= m_halMaxValues->maxTasks )
{
// If the task count in flushed queue is no less than hw restrictiion,
// query the staus of flushed task queue. Remove any finished tasks from the queue
QueryFlushedTasks();
flushedTaskCount = m_flushedTasks.GetCount();
if( flushedTaskCount >= m_halMaxValues->maxTasks )
{
// If none of flushed tasks finishes, we can't flush more taks.
break;
}
}
}
task = (CmTaskInternal*)m_enqueuedTasks.Pop();
CM_CHK_NULL_GOTOFINISH_CMERROR( task );
CmNotifierGroup *notifiers = m_device->GetNotifiers();
if (notifiers != nullptr)
{
notifiers->NotifyTaskFlushed(m_device, task);
}
task->GetTaskType(taskType);
switch(taskType)
{
case CM_INTERNAL_TASK_WITH_THREADSPACE:
hr = FlushGeneralTask(task);
break;
case CM_INTERNAL_TASK_WITH_THREADGROUPSPACE:
hr = FlushGroupTask(task);
break;
case CM_INTERNAL_TASK_VEBOX:
hr = FlushVeboxTask(task);
break;
case CM_INTERNAL_TASK_ENQUEUEWITHHINTS:
hr = FlushEnqueueWithHintsTask(task);
break;
default: // by default, assume the task is considered as general task: CM_INTERNAL_TASK_WITH_THREADSPACE
hr = FlushGeneralTask(task);
break;
}
if(hr == CM_SUCCESS)
{
m_flushedTasks.Push( task );
task->VtuneSetFlushTime(); // Record Flush Time
}
else
{
// Failed to flush, destroy the task.
CmTaskInternal::Destroy( task );
}
} // loop for task
QueryFlushedTasks();
finish:
m_criticalSectionHalExecute.Release();//Leave HalCm Execute Protection
//Delayed destroy for resource
m_device->GetSurfaceManager(surfaceMgr);
if (!surfaceMgr)
{
CM_ASSERTMESSAGE("Error: Pointer to surface manager is null.");
return CM_NULL_POINTER;
}
surfaceLock = m_device->GetSurfaceCreationLock();
if (surfaceLock == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to surface creation lock is null.");
return CM_NULL_POINTER;
}
surfaceLock->Acquire();
surfaceMgr->RefreshDelayDestroySurfaces(freeSurfNum);
surfaceLock->Release();
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Enqueue a Vebox Task
//| Arguments :
//| pVebox_G75 [in] Pointer to a CmVebox object
//| event [in] Reference to the pointer to Event
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueVebox(CmVebox * vebox, CmEvent* & event)
{
INSERT_API_CALL_LOG();
int32_t hr = CM_SUCCESS;
CmTaskInternal* task = nullptr;
int32_t taskDriverId = -1;
bool isEventVisible = (event == CM_NO_EVENT)? false:true;
CmEventRT *eventRT = static_cast<CmEventRT *>(event);
//Check if the input is valid
if ( vebox == nullptr )
{
CM_ASSERTMESSAGE("Error: Pointer to vebox is null.");
return CM_NULL_POINTER;
}
CmVeboxRT *veboxRT = static_cast<CmVeboxRT *>(vebox);
CM_CHK_CMSTATUS_GOTOFINISH(CmTaskInternal::Create(m_device, veboxRT, task ));
LARGE_INTEGER nEnqueueTime;
if ( !(MOS_QueryPerformanceCounter( (uint64_t*)&nEnqueueTime.QuadPart )) )
{
CM_ASSERTMESSAGE("Error: Query Performance counter failure.");
return CM_FAILURE;
}
CM_CHK_CMSTATUS_GOTOFINISH(CreateEvent(task, isEventVisible, taskDriverId, eventRT));
if ( eventRT != nullptr )
{
eventRT->SetEnqueueTime( nEnqueueTime );
}
event = eventRT;
if (!m_enqueuedTasks.Push(task))
{
CM_ASSERTMESSAGE("Error: Push enqueued tasks failure.")
hr = CM_FAILURE;
goto finish;
}
CM_CHK_CMSTATUS_GOTOFINISH(FlushTaskWithoutSync());
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Event and Update event in m_eventArray
//| Returns: result of operation
//*-----------------------------------------------------------------------------
int32_t CmQueueRT::CreateEvent(CmTaskInternal *task, bool isVisible, int32_t &taskDriverId, CmEventRT *&event )
{
int32_t hr = CM_SUCCESS;
m_criticalSectionEvent.Acquire();
uint32_t freeSlotInEventArray = m_eventArray.GetFirstFreeIndex();
hr = CmEventRT::Create( freeSlotInEventArray, this, task, taskDriverId, m_device, isVisible, event );
if (hr == CM_SUCCESS)
{
m_eventArray.SetElement( freeSlotInEventArray, event );
m_eventCount ++;
task->SetTaskEvent( event );
if(!isVisible)
{
event = nullptr;
}
}
else
{
CM_ASSERTMESSAGE("Error: Create Event failure.")
}
m_criticalSectionEvent.Release();
return hr;
}
//*---------------------------------------------------------------------------------------------------------
//| Name: EnqueueCopyCPUToGPUFullStride()
//| Purpose: Copy data from system memory to video memory (surface)
//| Arguments:
//| surface [in] Pointer to a CmSurface2D object as copy destination
//| sysMem [in] Pointer to a system memory as copy source
//| widthStride [in] Width stride in bytes for system memory (to calculate start of next line)
//| heightStride [in] Width stride in row for system memory (to calculate start of next plane)
//| option [in] Option passed from user, blocking copy, non-blocking copy or disable turbo boost
//| event [in,out] Reference to the pointer to Event
//| Returns: Result of the operation.
//|
//| Restrictions & Notes:
//| 1) sysMem must be 16-byte aligned.
//| 2) Surface's width must be 16-byte aligned regarding performance.
//| 3) widthStride and heightStride are used to indicate the padding information in system memory
//| widthStride = width_in_pixel * bytes_per_pixel + padding_in_bytes
//| heightStride = height + padding_in_row
//*---------------------------------------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueCopyCPUToGPUFullStride( CmSurface2D* surface,
const unsigned char* sysMem,
const uint32_t widthStride,
const uint32_t heightStride,
const uint32_t option,
CmEvent* & event )
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuCopyKernel())
{
return CM_NOT_IMPLEMENTED;
}
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT *>(surface);
return EnqueueCopyInternal(surfaceRT, (unsigned char*)sysMem, widthStride, heightStride, CM_FASTCOPY_CPU2GPU, option, event);
}
//*---------------------------------------------------------------------------------------------------------
//| Name: EnqueueCopyGPUToCPUFullStride()
//| Purpose: Copy data from tiled video memory (surface) to linear system memory
//| Arguments:
//| surface [in] Pointer to a CmSurface2D object as copy source
//| sysMem [in] Pointer to a system memory as copy destination
//| widthStride [in] Width stride in bytes for system memory (to calculate start of next line)
//| heightStride [in] Width stride in row for system memory (to calculate start of next plane)
//| option [in] Option passed from user, blocking copy,non-blocking copy or disable turbo boost
//| event [in,out] Reference to the pointer to Event
//| Returns: Result of the operation.
//|
//| Restrictions & Notes:
//| 1) sysMem must be 16-byte aligned.
//| 2) Surface's width must be 16-byte aligned regarding performance.
//| 3) widthStride and heightStride are used to indicate the padding information in system memory
//| widthStride = width_in_pixel * bytes_per_pixel + padding_in_bytes
//| heightStride = height + padding_in_row
//*---------------------------------------------------------------------------------------------------------
CM_RT_API int32_t CmQueueRT::EnqueueCopyGPUToCPUFullStride( CmSurface2D* surface,
unsigned char* sysMem,
const uint32_t widthStride,
const uint32_t heightStride,
const uint32_t option,
CmEvent* & event )
{
INSERT_API_CALL_LOG();
if (!m_device->HasGpuCopyKernel())
{
return CM_NOT_IMPLEMENTED;
}
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT *>(surface);
return EnqueueCopyInternal(surfaceRT, sysMem, widthStride, heightStride, CM_FASTCOPY_GPU2CPU, option, event);
}
//*---------------------------------------------------------------------------------------------------------
//| Name: CreateGPUCopyKernel()
//| Purpose: Create GPUCopy kernel, reuse the kernel if it has been created and resuable
//| Arguments:
//| widthInByte [in] surface's width in bytes
//| height [in] surface's height
//| format [in] surface's height
//| copyDirection [in] copy direction, cpu -> gpu or gpu -> cpu
//| gpuCopyKernelParam [out] kernel param
//|
//| Returns: Result of the operation.
//|
//*---------------------------------------------------------------------------------------------------------
int32_t CmQueueRT::CreateGPUCopyKernel(uint32_t widthInByte,
uint32_t height,
CM_SURFACE_FORMAT format,
CM_GPUCOPY_DIRECTION copyDirection,
CM_GPUCOPY_KERNEL* &gpuCopyKernelParam)
{
int32_t hr = CM_SUCCESS;
//Search existing kernel
CM_CHK_CMSTATUS_GOTOFINISH(SearchGPUCopyKernel(widthInByte, height, format, copyDirection, gpuCopyKernelParam));
if(gpuCopyKernelParam != nullptr)
{ // reuse
GPUCOPY_KERNEL_LOCK(gpuCopyKernelParam);
}
else
{
gpuCopyKernelParam = new (std::nothrow) CM_GPUCOPY_KERNEL ;
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyKernelParam);
CmSafeMemSet(gpuCopyKernelParam, 0, sizeof(CM_GPUCOPY_KERNEL));
CM_CHK_CMSTATUS_GOTOFINISH(AllocateGPUCopyKernel(widthInByte, height, format, copyDirection, gpuCopyKernelParam->kernel));
CM_CHK_CMSTATUS_GOTOFINISH(GetGPUCopyKrnID(widthInByte, height, format, copyDirection, gpuCopyKernelParam->kernelID));
GPUCOPY_KERNEL_LOCK(gpuCopyKernelParam);
CM_CHK_CMSTATUS_GOTOFINISH(AddGPUCopyKernel(gpuCopyKernelParam));
}
finish:
if( hr != CM_SUCCESS)
{
CmSafeDelete(gpuCopyKernelParam);
}
return hr;
}
//*---------------------------------------------------------------------------------------------------------
//| Name: SearchGPUCopyKernel()
//| Purpose: Search if the required kernel exists
//| Arguments:
//| widthInByte [in] surface's width in bytes
//| height [in] surface's height
//| format [in] surface's height
//| copyDirection [in] copy direction, cpu -> gpu or gpu -> cpu
//| gpuCopyKernelParam [out] kernel param
//|
//| Returns: Result of the operation.
//|
//*---------------------------------------------------------------------------------------------------------
int32_t CmQueueRT::SearchGPUCopyKernel(uint32_t widthInByte,
uint32_t height,
CM_SURFACE_FORMAT format,
CM_GPUCOPY_DIRECTION copyDirection,
CM_GPUCOPY_KERNEL* &kernelParam)
{
int32_t hr = CM_SUCCESS;
CM_GPUCOPY_KERNEL *gpucopyKernel = nullptr;
CM_GPUCOPY_KERNEL_ID kernelTypeID = GPU_COPY_KERNEL_UNKNOWN;
kernelParam = nullptr;
CM_CHK_CMSTATUS_GOTOFINISH(GetGPUCopyKrnID(widthInByte, height, format, copyDirection, kernelTypeID));
for(uint32_t index =0 ; index< m_copyKernelParamArrayCount; index++)
{
gpucopyKernel = (CM_GPUCOPY_KERNEL*)m_copyKernelParamArray.GetElement(index);
if(gpucopyKernel != nullptr)
{
if(!gpucopyKernel->locked &&
gpucopyKernel->kernelID == kernelTypeID)
{
kernelParam = gpucopyKernel;
break;
}
}
}
finish:
return hr;
}
//*---------------------------------------------------------------------------------------------------------
//| Name: AddGPUCopyKernel()
//| Purpose: Add new kernel into m_copyKernelParamArray
//| Arguments:
//| widthInByte [in] surface's width in bytes
//| height [in] surface's height
//| format [in] surface's height
//| copyDirection [in] copy direction, cpu -> gpu or gpu -> cpu
//| gpuCopyKernelParam [out] kernel param
//|
//| Returns: Result of the operation.
//|
//*---------------------------------------------------------------------------------------------------------
int32_t CmQueueRT::AddGPUCopyKernel(CM_GPUCOPY_KERNEL* &kernelParam)
{
int32_t hr = CM_SUCCESS;
// critical section protection
CLock locker(m_criticalSectionGPUCopyKrn);
CM_CHK_NULL_GOTOFINISH(kernelParam, CM_INVALID_GPUCOPY_KERNEL);
// the newly created kernel must be locked
if(!kernelParam->locked)
{
CM_ASSERTMESSAGE("Error: The newly created kernel must be locked.")
hr = CM_INVALID_GPUCOPY_KERNEL;
goto finish;
}
m_copyKernelParamArray.SetElement(m_copyKernelParamArrayCount, kernelParam);
m_copyKernelParamArrayCount ++;
finish:
return hr;
}
//*---------------------------------------------------------------------------------------------------------
//| Name: GetGPUCopyKrnID()
//| Purpose: Calculate the kernel ID accroding surface's width, height and copy direction
//| Arguments:
//| widthInByte [in] surface's width in bytes
//| height [in] surface's height
//| format [in] surface's height
//| copyDirection [in] copy direction, cpu -> gpu or gpu -> cpu
//| kernelID [out] kernel id
//|
//| Returns: Result of the operation.
//|
//*---------------------------------------------------------------------------------------------------------
int32_t CmQueueRT::GetGPUCopyKrnID( uint32_t widthInByte, uint32_t height, CM_SURFACE_FORMAT format,
CM_GPUCOPY_DIRECTION copyDirection, CM_GPUCOPY_KERNEL_ID &kernelID )
{
int32_t hr = CM_SUCCESS;
kernelID = GPU_COPY_KERNEL_UNKNOWN;
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
switch(copyDirection)
{
case CM_FASTCOPY_GPU2CPU:
if ( (height&0x7) ||(widthInByte&0x7f))
{
kernelID = GPU_COPY_KERNEL_GPU2CPU_UNALIGNED_NV12_ID ;
}
else
{ // height 8-row aligned, widthByte 128 multiple
kernelID = GPU_COPY_KERNEL_GPU2CPU_ALIGNED_NV12_ID ;
}
break;
case CM_FASTCOPY_CPU2GPU:
kernelID = GPU_COPY_KERNEL_CPU2GPU_NV12_ID;
break;
case CM_FASTCOPY_GPU2GPU:
kernelID = GPU_COPY_KERNEL_GPU2GPU_NV12_ID;
break;
case CM_FASTCOPY_CPU2CPU:
kernelID = GPU_COPY_KERNEL_CPU2CPU_ID;
break;
default :
CM_ASSERTMESSAGE("Error: Invalid fast copy direction.")
hr = CM_FAILURE;
break;
}
}
else
{
switch(copyDirection)
{
case CM_FASTCOPY_GPU2CPU:
if ( (height&0x7) ||(widthInByte&0x7f))
{
kernelID = GPU_COPY_KERNEL_GPU2CPU_UNALIGNED_ID;
}
else
{ // height 8-row aligned, widthByte 128 multiple
kernelID = GPU_COPY_KERNEL_GPU2CPU_ALIGNED_ID;
}
break;
case CM_FASTCOPY_CPU2GPU:
kernelID = GPU_COPY_KERNEL_CPU2GPU_ID;
break;
case CM_FASTCOPY_GPU2GPU:
kernelID = GPU_COPY_KERNEL_GPU2GPU_ID;
break;
case CM_FASTCOPY_CPU2CPU:
kernelID = GPU_COPY_KERNEL_CPU2CPU_ID;
break;
default :
CM_ASSERTMESSAGE("Error: Invalid fast copy direction.")
hr = CM_FAILURE;
break;
}
}
return hr;
}
//*---------------------------------------------------------------------------------------------------------
//| Name: AllocateGPUCopyKernel()
//| Purpose: Allocate GPUCopy Kernel
//| Arguments:
//| widthInByte [in] surface's width in bytes
//| height [in] surface's height
//| format [in] surface's height
//| copyDirection [in] copy direction, cpu -> gpu or gpu -> cpu
//| kernel [out] pointer to created kernel
//|
//| Returns: Result of the operation.
//|
//*---------------------------------------------------------------------------------------------------------
int32_t CmQueueRT::AllocateGPUCopyKernel( uint32_t widthInByte, uint32_t height, CM_SURFACE_FORMAT format,
CM_GPUCOPY_DIRECTION copyDirection, CmKernel *&kernel )
{
int32_t hr = CM_SUCCESS;
CmProgram *gpuCopyProgram = nullptr;
CM_CHK_CMSTATUS_GOTOFINISH( m_device->LoadPredefinedCopyKernel(gpuCopyProgram));
CM_CHK_NULL_GOTOFINISH_CMERROR(gpuCopyProgram);
if (format == CM_SURFACE_FORMAT_NV12 || format == CM_SURFACE_FORMAT_P010 || format == CM_SURFACE_FORMAT_P016)
{
switch(copyDirection)
{
case CM_FASTCOPY_GPU2CPU:
if ( (height&0x7) ||(widthInByte&0x7f))
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel( gpuCopyProgram, _NAME( surfaceCopy_read_NV12_32x32 ) , kernel,"PredefinedGPUCopyKernel"));
}
else
{ // height 8-row aligned, widthByte 128 multiple
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel( gpuCopyProgram, _NAME( surfaceCopy_read_NV12_aligned_32x32 ) , kernel,"PredefinedGPUCopyKernel"));
}
break;
case CM_FASTCOPY_CPU2GPU:
CM_CHK_CMSTATUS_GOTOFINISH( m_device->CreateKernel( gpuCopyProgram, _NAME( surfaceCopy_write_NV12_32x32 ), kernel, "PredefinedGPUCopyKernel"));
break;
case CM_FASTCOPY_GPU2GPU:
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(SurfaceCopy_2DTo2D_NV12_32x32), kernel, "PredefinedGPUCopyKernel"));
break;
case CM_FASTCOPY_CPU2CPU:
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(SurfaceCopy_BufferToBuffer_4k), kernel, "PredefinedGPUCopyKernel"));
break;
default :
CM_ASSERTMESSAGE("Error: Invalid fast copy direction.")
hr = CM_FAILURE;
break;
}
}
else
{
switch(copyDirection)
{
case CM_FASTCOPY_GPU2CPU:
if ( (height&0x7) ||(widthInByte&0x7f))
{
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel( gpuCopyProgram, _NAME( surfaceCopy_read_32x32 ) , kernel, "PredefinedGPUCopyKernel"));
}
else
{ // height 8-row aligned, widthByte 128 multiple
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel( gpuCopyProgram, _NAME( surfaceCopy_read_aligned_32x32 ) , kernel, "PredefinedGPUCopyKernel"));
}
break;
case CM_FASTCOPY_CPU2GPU:
CM_CHK_CMSTATUS_GOTOFINISH( m_device->CreateKernel( gpuCopyProgram, _NAME( surfaceCopy_write_32x32 ), kernel, "PredefinedGPUCopyKernel" ));
break;
case CM_FASTCOPY_GPU2GPU:
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(SurfaceCopy_2DTo2D_32x32), kernel, "PredefinedGPUCopyKernel"));
break;
case CM_FASTCOPY_CPU2CPU:
CM_CHK_CMSTATUS_GOTOFINISH(m_device->CreateKernel(gpuCopyProgram, _NAME(SurfaceCopy_BufferToBuffer_4k), kernel, "PredefinedGPUCopyKernel"));
break;
default :
CM_ASSERTMESSAGE("Error: Invalid fast copy direction.")
hr = CM_FAILURE;
break;
}
}
finish:
return hr;
}
CM_RT_API int32_t CmQueueRT::EnqueueFast(CmTask *task,
CmEvent *&event,
const CmThreadSpace *threadSpace)
{
CM_HAL_STATE * state = ((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
if (state == nullptr || state->advExecutor == nullptr)
{
return CM_NULL_POINTER;
}
else
{
const CmThreadSpaceRT *threadSpaceRTConst = static_cast<const CmThreadSpaceRT *>(threadSpace);
if (state->cmHalInterface->CheckMediaModeAvailability() == false)
{
if (threadSpaceRTConst != nullptr)
{
return state->advExecutor->SubmitComputeTask(this, task, event, threadSpaceRTConst->GetThreadGroupSpace(), (MOS_GPU_CONTEXT)m_queueOption.GPUContext);
}
}
return state->advExecutor->SubmitTask(this, task, event, threadSpace, (MOS_GPU_CONTEXT)m_queueOption.GPUContext);
}
}
CM_RT_API int32_t CmQueueRT::DestroyEventFast(CmEvent *&event)
{
CM_HAL_STATE * state = ((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
if (state == nullptr || state->advExecutor == nullptr)
{
return CM_NULL_POINTER;
}
else
{
return state->advExecutor->DestoryEvent(this, event);
}
}
CM_RT_API int32_t CmQueueRT::EnqueueWithGroupFast(CmTask *task,
CmEvent *&event,
const CmThreadGroupSpace *threadGroupSpace)
{
CM_HAL_STATE * state = ((PCM_CONTEXT_DATA)m_device->GetAccelData())->cmHalState;
if (state == nullptr || state->advExecutor == nullptr)
{
return CM_NULL_POINTER;
}
return state->advExecutor->SubmitComputeTask(this, task, event, threadGroupSpace, (MOS_GPU_CONTEXT)m_queueOption.GPUContext);
}
}
|