File size: 110,200 Bytes
08c8a6d |
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 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 |
OpenCL Programming Guide for the CUDA Architecture Version 2.3 8/27/2009 Table of Contents Chapter 1. Introduction ..................................................................................... 5 1.1 1.2 1.3 1.4 From Graphics Processing to General-Purpose Parallel Computing ................... 5 CUDA™: a General-Purpose Parallel Computing Architecture ........................... 7 CUDA’s Scalable Programming Model ............................................................. 8 Document’s Structure ................................................................................... 9 Chapter 2. OpenCL on the CUDA Architecture ................................................. 11 2.1 CUDA Architecture ...................................................................................... 11 2.1.1 Execution Model .................................................................................. 11 2.1.2 Memory Model ..................................................................................... 14 2.2 Compilation ................................................................................................ 16 2.2.1 PTX..................................................................................................... 16 2.2.2 Volatile ................................................................................................ 17 2.3 Compute Capability .................................................................................... 17 2.4 Mode Switches ........................................................................................... 18 2.5 Matrix Multiplication Example ...................................................................... 18 Chapter 3. Performance Guidelines ................................................................. 27 3.1 Instruction Performance ............................................................................. 27 3.1.1 Instruction Throughput ........................................................................ 27 3.1.1.1 Arithmetic Instructions .................................................................. 27 3.1.1.2 Control Flow Instructions ............................................................... 29 3.1.1.3 Memory Instructions ..................................................................... 30 3.1.1.4 Synchronization Instruction ........................................................... 30 3.1.2 Memory Bandwidth .............................................................................. 30 3.1.2.1 Global Memory .............................................................................. 31 3.1.2.2 Local Memory ............................................................................... 38 3.1.2.3 Constant Memory .......................................................................... 38 3.1.2.4 Texture Memory ........................................................................... 38 3.1.2.5 Shared Memory ............................................................................ 39 ii NVIDIA OpenCL Programming Guide Version 2.3 3.1.2.6 Registers ...................................................................................... 46 3.2 3.3 NDRange ................................................................................................... 46 Data Transfer between Host and Device ...................................................... 47 3.4 Warp-Level Synchronization ........................................................................ 48 3.5 Overall Performance Optimization Strategies ................................................ 49 Appendix A. Technical Specifications .............................................................. 51 A.1 General Specifications ................................................................................. 51 A.1.1 Specifications for Compute Capability 1.0 .............................................. 52 A.1.2 Specifications for Compute Capability 1.1 .............................................. 53 A.1.3 Specifications for Compute Capability 1.2 .............................................. 53 A.1.4 Specifications for Compute Capability 1.3 .............................................. 53 A.2 A.3 Floating-Point Standard .............................................................................. 53 Supported OpenCL Extensions ..................................................................... 54 Appendix B. Mathematical Functions Accuracy ............................................... 55 B.1 Standard Functions ..................................................................................... 55 B.1.1 Single-Precision Floating-Point Functions ............................................... 55 B.1.2 Double-Precision Floating-Point Functions ............................................. 57 B.2 Native Functions ......................................................................................... 59 NVIDIA OpenCL Programming Guide Version 2.3 iii List of Figures Figure 1-1. Floating-Point Operations per Second and Memory Bandwidth for the CPU and GPU 6 Figure 1-2. The GPU Devotes More Transistors to Data Processing ............................ 7 Figure 1-3. CUDA is Designed to Support Various Languages and Application Programming Interfaces ...................................................................................... 8 Figure 2-1. Grid of Thread Blocks ........................................................................... 12 Figure 2-2. Automatic Scalability ............................................................................ 13 Figure 2-3. CUDA Architecture ............................................................................... 16 Figure 3-1. Examples of Coalesced Global Memory Access Patterns .......................... 34 Figure 3-2. Examples of Global Memory Access Patterns That Are Non-Coalesced for Devices of Compute Capability 1.0 or 1.1 ........................................................... 35 Figure 3-3. Examples of Global Memory Access Patterns That Are Non-Coalesced for Devices of Compute Capability 1.0 or 1.1 ........................................................... 36 Figure 3-4. Examples of Global Memory Access by Devices with Compute Capability 1.2 and Higher .................................................................................................. 37 Figure 3-5. Examples of Shared Memory Access Patterns without Bank Conflicts ..... 42 Figure 3-6. Example of a Shared Memory Access Pattern without Bank Conflicts ...... 43 Figure 3-7. Examples of Shared Memory Access Patterns with Bank Conflicts ........... 44 Figure 3-8. Example of Shared Memory Read Access Patterns with Broadcast ........... 45 iv NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1. Introduction 1.1 From Graphics Processing to General-Purpose Parallel Computing Driven by the insatiable market demand for realtime, high-definition 3D graphics, the programmable Graphic Processor Unit or GPU has evolved into a highly parallel, multithreaded, manycore processor with tremendous computational horsepower and very high memory bandwidth, as illustrated by Figure 1-1. Chapter 1. 0BIntroduction GT200 G92 G80 Ultra G80 NV35 NV40 NV30 G71 G70 3.0 GHz Core2 Duo 3.2 GHz Harpertown Jan Jun Apr 2003 2004 Jun 2005 Mar Nov May 2006 2007 Jun 2008 GT200 = GeForce GTX 280 G71 = GeForce 7900 GTX NV35 = GeForce FX 5950 Ultra G92 = GeForce 9800 GTX G70 = GeForce 7800 GTX NV30 = GeForce FX 5800 G80 = GeForce 8800 GTX NV40 = GeForce 6800 Ultra G80 Ultra G80 G71 NV40 NV30 Harpertown Woodcrest Prescott EE Northwood Figure 1-1. Floating-Point Operations per Second and Memory Bandwidth for the CPU and GPU The reason behind the discrepancy in floating-point capability between the CPU and the GPU is that the GPU is specialized for compute-intensive, highly parallel computation – exactly what graphics rendering is about – and therefore designed such that more transistors are devoted to data processing rather than data caching and flow control, as schematically illustrated by Figure 1-2. 6 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1. 0BIntroduction Control Cache DRAM ALU ALU ALU ALU CPU DRAM GPU Figure 1-2. The GPU Devotes More Transistors to Data Processing More specifically, the GPU is especially well-suited to address problems that can be expressed as data-parallel computations – the same program is executed on many data elements in parallel – with high arithmetic intensity – the ratio of arithmetic operations to memory operations. Because the same program is executed for each data element, there is a lower requirement for sophisticated flow control; and because it is executed on many data elements and has high arithmetic intensity, the memory access latency can be hidden with calculations instead of big data caches. Data-parallel processing maps data elements to parallel processing threads. Many applications that process large data sets can use a data-parallel programming model to speed up the computations. In 3D rendering, large sets of pixels and vertices are mapped to parallel threads. Similarly, image and media processing applications such as post-processing of rendered images, video encoding and decoding, image scaling, stereo vision, and pattern recognition can map image blocks and pixels to parallel processing threads. In fact, many algorithms outside the field of image rendering and processing are accelerated by data-parallel processing, from general signal processing or physics simulation to computational finance or computational biology. 1.2 CUDA™: a General-Purpose Parallel Computing Architecture In November 2006, NVIDIA introduced CUDA™, a general purpose parallel computing architecture – with a new parallel programming model and instruction set architecture – that leverages the parallel compute engine in NVIDIA GPUs to solve many complex computational problems in a more efficient way than on a CPU. As illustrated by Figure 1-3, there are several languages and application programming interfaces that can be used to program the CUDA architecture. NVIDIA OpenCL Programming Guide Version 2.3 7 Chapter 1. 0BIntroduction Figure 1-3. CUDA is Designed to Support Various Languages and Application Programming Interfaces 1.3 CUDA’s Scalable Programming Model The advent of multicore CPUs and manycore GPUs means that mainstream processor chips are now parallel systems. Furthermore, their parallelism continues to scale with Moore’s law. The challenge is to develop application software that transparently scales its parallelism to leverage the increasing number of processor cores, much as 3D graphics applications transparently scale their parallelism to manycore GPUs with widely varying numbers of cores. CUDA’s parallel programming model is designed to overcome this challenge with three key abstractions: a hierarchy of thread groups, a hierarchy of shared memories, and barrier synchronization. These abstractions provide fine-grained data parallelism and thread parallelism, nested within coarse-grained data parallelism and task parallelism. They guide the programmer to partition the problem into coarse sub-problems that can be solved independently in parallel, and then into finer pieces that can be solved cooperatively in parallel. Such a decomposition preserves language expressivity by allowing threads to cooperate when solving each sub-problem, and at the same time enables transparent scalability since each sub-problem can be scheduled to be solved on any of the available processor cores: A compiled program can therefore execute on any number of processor cores, and only the runtime system needs to know the physical processor count. This scalable programming model allows the CUDA architecture to span a wide market range by simply scaling the number of processors and memory partitions: from the high-performance enthusiast GeForce GTX 280 GPU and professional Quadro and Tesla computing products to a variety of inexpensive, mainstream GeForce GPUs (see Appendix A for a list of all CUDA-enabled GPUs). 8 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1. 0BIntroduction 1.4 Document’s Structure This document is organized into the following chapters: (cid:137) Chapter 1 is a general introduction to GPU computing and the CUDA architecture. (cid:137) Chapter 2 describes how the OpenCL architecture maps to the CUDA architecture and the specifics of NVIDIA’s OpenCL implementation. (cid:137) Chapter 3 gives some guidance on how to achieve maximum performance. (cid:137) Appendix A lists the CUDA-enabled GPUs with their technical specifications. (cid:137) Appendix B lists the accuracy of each mathematical function on the CUDA architecture. NVIDIA OpenCL Programming Guide Version 2.3 9 Chapter 2. OpenCL on the CUDA Architecture 2.1 CUDA Architecture 2.1.1 Execution Model The CUDA architecture is a close match to the OpenCL architecture. A CUDA device is built around a scalable array of multithreaded Streaming Multiprocessors (SMs). A multiprocessor corresponds to an OpenCL compute unit. A multiprocessor executes a CUDA thread for each OpenCL work-item and a thread block for each OpenCL work-group. A kernel is executed over an OpenCL NDRange by a grid of thread blocks. As illustrated in Figure 2-1, each of the thread blocks that execute a kernel is therefore uniquely identified by its work-group ID, and each thread by its global ID or by a combination of its local ID and work-group ID. Chapter 2. 1BOpenCL on the CUDA Architecture Grid Block (0, 0) Block (1, 0) Block (2, 0) Block (0, 1) Block (1, 1) Block (2, 1) Block (1, 1) Thread (0, 0) Thread (1, 0) Thread (2, 0) Thread (3, 0) Thread (0, 1) Thread (1, 1) Thread (2, 1) Thread (3, 1) Thread (0, 2) Thread (1, 2) Thread (2, 2) Thread (3, 2) A kernel is executed over an NDRange by a grid of thread blocks. Figure 2-1. Grid of Thread Blocks A thread is also given a unique thread ID within its block. The local ID of a thread and its thread ID relate to each other in a straightforward way: For a one- dimensional block, they are the same; for a two-dimensional block of size (Dx, Dy), the thread ID of a thread of index (x, y) is (x + y Dx); for a three-dimensional block of size (Dx, Dy, Dz), the thread ID of a thread of index (x, y, z) is (x + y Dx + z Dx Dy). When an OpenCL program on the host invokes a kernel, the work-groups are enumerated and distributed as thread blocks to the multiprocessors with available execution capacity. The threads of a thread block execute concurrently on one multiprocessor. As thread blocks terminate, new blocks are launched on the vacated multiprocessors. Thread blocks are required to execute independently: It must be possible to execute them in any order, in parallel or in series. This independence requirement allows thread blocks to be scheduled in any order across any number of cores, enabling 12 NVIDIA OpenCL Programming Guide Version 2.3 programmers to write code that scales with the number of cores, as illustrated in Figure 2-2. Chapter 1 Kernel Block 0 Block 1 Block 2 Block 3 Block 4 Block 5 Block 5 Block 6 Block 6 Block 7 Device with 2 SMs Device with 4 SMs SM 0 SM 1 SM 0 SM 1 SM 2 SM 3 Block 0 Block 1 Block 0 Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 A device with more multiprocessors will automatically execute a kernel in less time than a device with fewer multiprocessors. Figure 2-2. Automatic Scalability A multiprocessor consists of eight Scalar Processor (SP) cores, two special function units for transcendentals, a multithreaded instruction unit, and on-chip shared memory, which is used to implement OpenCL local memory. The multiprocessor creates, manages, and executes concurrent threads in hardware with zero scheduling overhead. It implements the work-group barrier function with a single instruction. Fast barrier synchronization together with lightweight thread creation and zero- overhead thread scheduling efficiently support very fine-grained parallelism, allowing, for example, a low granularity decomposition of problems by assigning one thread to each data element (such as a pixel in an image, a voxel in a volume, a cell in a grid-based computation). To manage hundreds of threads running several different programs, the multiprocessor employs a new architecture we call SIMT (single-instruction, multiple-thread). The multiprocessor maps each thread to one SP, and each scalar NVIDIA OpenCL Programming Guide Version 2.3 13 Chapter 2. 1BOpenCL on the CUDA Architecture thread executes independently with its own instruction address and register state. The multiprocessor SIMT unit creates, manages, schedules, and executes threads in groups of 32 parallel threads called warps. (This term originates from weaving, the first parallel thread technology. A half-warp is either the first or second half of a warp.) Individual threads composing a SIMT warp start together at the same program address but are otherwise free to branch and execute independently. When a multiprocessor is given one or more thread blocks to execute, it splits them into warps that get scheduled by the SIMT unit. The way a block is split into warps is always the same; each warp contains threads of consecutive, increasing thread IDs with the first warp containing the thread of thread ID zero. Every instruction issue time, the SIMT unit selects a warp that is ready to execute and issues the next instruction to the active threads of the warp. A warp executes one common instruction at a time, so full efficiency is realized when all 32 threads of a warp agree on their execution path. If threads of a warp diverge via a data- dependent conditional branch, the warp serially executes each branch path taken, disabling threads that are not on that path, and when all paths complete, the threads converge back to the same execution path. Branch divergence occurs only within a warp; different warps execute independently regardless of whether they are executing common or disjointed code paths. SIMT architecture is akin to SIMD (Single Instruction, Multiple Data) vector organizations in that a single instruction controls multiple processing elements. A key difference is that SIMD vector organizations expose the SIMD width to the software, whereas SIMT instructions specify the execution and branching behavior of a single thread. In contrast with SIMD vector machines, SIMT enables programmers to write thread-level parallel code for independent, scalar threads, as well as data-parallel code for coordinated threads. For the purposes of correctness, the programmer can essentially ignore the SIMT behavior; however, substantial performance improvements can be realized by taking care that the code seldom requires threads in a warp to diverge. In practice, this is analogous to the role of cache lines in traditional code: Cache line size can be safely ignored when designing for correctness but must be considered in the code structure when designing for peak performance. Vector architectures, on the other hand, require the software to coalesce loads into vectors and manage divergence manually. 2.1.2 Memory Model As illustrated by Figure 2-3, each multiprocessor has on-chip memory of the four following types: (cid:137) One set of local 32-bit registers per processor, (cid:137) A parallel data cache or shared memory that is shared by all scalar processor cores and is where OpenCL local memory resides, (cid:137) A read-only constant cache that is shared by all scalar processor cores and speeds up reads from OpenCL constant memory, (cid:137) A read-only texture cache that is shared by all scalar processor cores and speeds up reads from OpenCL image objects; each multiprocessor accesses the texture cache via a texture unit that implements the various addressing modes and data filtering specified by OpenCL sampler objects; the region of device memory addressed by image objects is referred to a texture memory. 14 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1 There is also a global memory address space that is used for OpenCL global memory and a local memory address space that is private to each thread (and should not be confused with OpenCL local memory). Both memory spaces are read-write regions of device memory and are not cached. A variable in OpenCL private memory generally resides in a register. However in some cases the compiler might choose to place it in CUDA local memory, which can have adverse performance consequences because of local memory high latency and bandwidth (see Section 3.1.2.2). Variables that are likely to be placed in CUDA local memory are large structures or arrays that would consume too much register space, and arrays for which the compiler cannot determine that they are indexed with constant quantities. The number of blocks a multiprocessor can process at once – referred to as the number of active blocks per multiprocessor – depends on how many registers per thread and how much shared memory per block are required for a given kernel since the multiprocessor’s registers and shared memory are split among all the threads of the active blocks. If there are not enough registers or shared memory available per multiprocessor to process at least one block, the kernel will fail to launch. The maximum number of active blocks per multiprocessor, as well as the maximum number of active warps and maximum number of active threads are given in Appendix A. If a non-atomic instruction executed by a warp writes to the same location in global or shared memory for more than one of the threads of the warp, the number of serialized writes that occur to that location and the order in which they occur is undefined, but one of the writes is guaranteed to succeed. If an atomic instruction executed by a warp reads, modifies, and writes to the same location in global memory for more than one of the threads of the warp, each read, modify, write to that location occurs and they are all serialized, but the order in which they occur is undefined. NVIDIA OpenCL Programming Guide Version 2.3 15 Chapter 2. 1BOpenCL on the CUDA Architecture Device Multiprocessor N Multiprocessor 2 Multiprocessor 1 Shared Memory Registers Registers Registers Processor 1 Processor 2 … Processor M Instruction Unit Constant Cache Texture Cache Device Memory A set of SIMT multiprocessors with on-chip shared memory. Figure 2-3. CUDA Architecture 2.2 Compilation 2.2.1 PTX Kernels written in OpenCL C are compiled into PTX, which is CUDA’s instruction set architecture and is described in a separate document. Currently, the PTX intermediate representation can be obtained by calling clGetProgramInfo() with CL_PROGRAM_BINARIES and can be passed to 16 NVIDIA OpenCL Programming Guide Version 2.3 2.2.2 Chapter 1 clCreateProgramWithBinary() to create a program object, but this will likely not be supported in future versions. Volatile Only after the execution of barrier(), mem_fence(), read_mem_fence(), or write_mem_fence() are prior writes to global or shared memory of a given thread guaranteed to be visible by other threads. As long as this requirement is met, the compiler is free to optimize reads and writes to global or shared memory. For example, in the code sample below, the first reference to myArray[tid] compiles into a global or shared memory read instruction, but the second reference does not as the compiler simply reuses the result of the first read. // myArray is an array of non-zero integers // located in global or shared memory __kernel void myKernel(__global int* result) { int tid = get_local_id(0); int ref1 = myArray[tid] * 1; myArray[tid + 1] = 2; int ref2 = myArray[tid] * 1; result[tid] = ref1 * ref2; } Therefore, ref2 cannot possibly be equal to 2 in thread tid as a result of thread tid-1 overwriting myArray[tid] by 2. This behavior can be changed using the volatile keyword: If a variable located in global or shared memory is declared as volatile, the compiler assumes that its value can be changed at any time by another thread and therefore any reference to this variable compiles to an actual memory read instruction. Note that even if myArray is declared as volatile in the code sample above, there is no guarantee, in general, that ref2 will be equal to 2 in thread tid since thread tid might read myArray[tid] into ref2 before thread tid-1 overwrites its value by 2. Synchronization is required as mentioned in Section 3.4. 2.3 Compute Capability The compute capability of a CUDA device is defined by a major revision number and a minor revision number. Devices with the same major revision number are of the same core architecture. The devices listed in Appendix A are all of compute capability 1.x (Their major revision number is 1). The minor revision number corresponds to an incremental improvement to the core architecture, possibly including new features. The technical specifications of the various compute capabilities are given in Appendix A. NVIDIA OpenCL Programming Guide Version 2.3 17 Chapter 2. 1BOpenCL on the CUDA Architecture 2.4 Mode Switches GPUs dedicate some DRAM memory to the so-called primary surface, which is used to refresh the display device whose output is viewed by the user. When users initiate a mode switch of the display by changing the resolution or bit depth of the display (using NVIDIA control panel or the Display control panel on Windows), the amount of memory needed for the primary surface changes. For example, if the user changes the display resolution from 1280x1024x32-bit to 1600x1200x32-bit, the system must dedicate 7.68 MB to the primary surface rather than 5.24 MB. (Full- screen graphics applications running with anti-aliasing enabled may require much more display memory for the primary surface.) On Windows, other events that may initiate display mode switches include launching a full-screen DirectX application, hitting Alt+Tab to task switch away from a full-screen DirectX application, or hitting Ctrl+Alt+Del to lock the computer. If a mode switch increases the amount of memory needed for the primary surface, the system may have to cannibalize memory allocations dedicated to OpenCL applications. Therefore, a mode switch results in any call to the OpenCL runtime to fail and return an invalid context error. 2.5 Matrix Multiplication Example The following matrix multiplication example illustrates the typical data-parallel approach used by OpenCL applications to achieve good performance on GPUs. It also illustrates the use of OpenCL local memory that maps to shared memory on the CUDA architecture. Shared memory is much faster than global memory as mentioned in Section 2.1.2 and detailed in Section 3.1.2.5, so any opportunity to replace global memory accesses by shared memory accesses should be exploited. The following code sample is a straightforward implementation of matrix multiplication that does not take advantage of shared memory. Each thread reads one row of A and one column of B and computes the corresponding element of C as illustrated in Figure 2-4. A is therefore read B.width times from global memory and B is read A.height times. // Host code // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.width + col) typedef struct { int width; int height; cl_mem elements; } Matrix; // Thread block size #define BLOCK_SIZE 16 // Matrix multiplication - Host code // Matrix dimensions are assumed to be multiples of BLOCK_SIZE void MatMulHost(const Matrix A, const Matrix B, Matrix C, 18 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1 const cl_context context, const cl_kernel matMulKernel, const cl_command_queue queue) { // Load A and B to device memory Matrix d_A; d_A.width = A.width; d_A.height = A.height; size_t size = A.width * A.height * sizeof(float); d_A.elements = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size, A.elements, 0); Matrix d_B; d_B.width = B.width; d_B.height = B.height; size = B.width * B.height * sizeof(float); d_B.elements = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size, B.elements, 0); // Allocate C in device memory Matrix d_C; d_C.width = C.width; d_C.height = C.height; size = C.width * C.height * sizeof(float); d_C.elements = clCreateBuffer(context, CL_MEM_WRITE_ONLY, size, 0, 0); // Invoke kernel cl_uint i = 0; clSetKernelArg(matMulKernel, i++, sizeof(d_A.width), (void*)&d_A.width); clSetKernelArg(matMulKernel, i++, sizeof(d_A.height), (void*)&d_A.height); clSetKernelArg(matMulKernel, i++, sizeof(d_A.elements), (void*)&d_A.elements); clSetKernelArg(matMulKernel, i++, sizeof(d_B.width), (void*)&d_B.width); clSetKernelArg(matMulKernel, i++, sizeof(d_B.height), (void*)&d_B.height); clSetKernelArg(matMulKernel, i++, sizeof(d_B.elements), (void*)&d_B.elements); clSetKernelArg(matMulKernel, i++, sizeof(d_C.width), (void*)&d_C.width); clSetKernelArg(matMulKernel, i++, sizeof(d_C.height), (void*)&d_C.height); clSetKernelArg(matMulKernel, i++, sizeof(d_C.elements), (void*)&d_C.elements); size_t localWorkSize[] = { BLOCK_SIZE, BLOCK_SIZE }; size_t globalWorkSize[] = { B.width / dimBlock.x, A.height / dimBlock.y }; clEnqueueNDRangeKernel(queue, matMulKernel, 2, 0, globalWorkSize, localWorkSize, 0, 0, 0); // Read C from device memory clEnqueueReadBuffer(queue, d_C.elements, CL_TRUE, 0, size, C.elements, 0, 0, 0); // Free device memory NVIDIA OpenCL Programming Guide Version 2.3 19 Chapter 2. 1BOpenCL on the CUDA Architecture clReleaseMemObject(d_A.elements); clReleaseMemObject(d_C.elements); clReleaseMemObject(d_B.elements); } // Kernel code // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.width + col) typedef struct { int width; int height; __global float* elements; } Matrix; // Thread block size #define BLOCK_SIZE 16 // Matrix multiplication function called by MatMulKernel() void MatMul(Matrix A, Matrix B, Matrix C) { float Cvalue = 0; int row = get_global_id(1); int col = get_global_id(0); for (int e = 0; e < A.width; ++e) Cvalue += A.elements[row * A.width + e] * B.elements[e * B.width + col]; C.elements[row * C.width + col] = Cvalue; } // Matrix multiplication kernel called by MatMulHost() __kernel void MatMulKernel( int Awidth, int Aheight, __global float* Aelements, int Bwidth, int Bheight, __global float* Belements, int Cwidth, int Cheight, __global float* Celements) { Matrix A = { Awidth, Aheight, Aelements }; Matrix B = { Bwidth, Bheight, Belements }; Matrix C = { Cwidth, Cheight, Celements }; matrixMul(A, B, C); } 20 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1 1 - h t d w B . i col 0 B C t h g i e h B . t h g i e h A . A.width B.width 0 A row A.height-1 Figure 2-4. Matrix Multipliation without Shared Memory The following code sample is an implementation of matrix multiplication that does take advantage of shared memory. In this implementation, each thread block is responsible for computing one square sub-matrix Csub of C and each thread within the block is responsible for computing one element of Csub. As illustrated in Figure 2-5, Csub is equal to the product of two rectangular matrices: the sub-matrix of A of dimension (A.width, block_size) that has the same line indices as Csub, and the sub- matrix of B of dimension (block_size, A.width) that has the same column indices as Csub. In order to fit into the device’s resources, these two rectangular matrices are divided into as many square matrices of dimension block_size as necessary and Csub is computed as the sum of the products of these square matrices. Each of these products is performed by first loading the two corresponding square matrices from global memory to shared memory with one thread loading one element of each matrix, and then by having each thread compute one element of the product. Each thread accumulates the result of each of these products into a register and once done writes the result to global memory. NVIDIA OpenCL Programming Guide Version 2.3 21 Chapter 2. 1BOpenCL on the CUDA Architecture By blocking the computation this way, we take advantage of fast shared memory and save a lot of global memory bandwidth since A is only read (B.width / block_size) times from global memory and B is read (A.height / block_size) times. The Matrix type from the previous code sample is augmented with a stride field, so that sub-matrices can be efficiently represented with the same type. // Host code // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.stride + col) typedef struct { int width; int height; int stride; cl_mem elements; } Matrix; // Thread block size #define BLOCK_SIZE 16 // Matrix multiplication - Host code // Matrix dimensions are assumed to be multiples of BLOCK_SIZE void MatMulHost(const Matrix A, const Matrix B, Matrix C, const cl_context context, const cl_kernel matMulKernel, const cl_command_queue queue) { // Load A and B to device memory Matrix d_A; d_A.width = d_A.stride = A.width; d_A.height = A.height; size_t size = A.width * A.height * sizeof(float); d_A.elements = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size, A.elements, 0); Matrix d_B; d_B.width = d_B.stride = B.width; d_B.height = B.height; size = B.width * B.height * sizeof(float); d_B.elements = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size, B.elements, 0); // Allocate C in device memory Matrix d_C; d_C.width = d_C.stride = C.width; d_C.height = C.height; size = C.width * C.height * sizeof(float); d_C.elements = clCreateBuffer(context, CL_MEM_WRITE_ONLY, size, 0, 0); // Invoke kernel cl_uint i = 0; clSetKernelArg(matMulKernel, i++, sizeof(d_A.width), (void*)&d_A.width); clSetKernelArg(matMulKernel, i++, sizeof(d_A.height), (void*)&d_A.height); clSetKernelArg(matMulKernel, i++, 22 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1 sizeof(d_A.stride), (void*)&d_A.stride); clSetKernelArg(matMulKernel, i++, sizeof(d_A.elements), (void*)&d_A.elements); clSetKernelArg(matMulKernel, i++, sizeof(d_B.width), (void*)&d_B.width); clSetKernelArg(matMulKernel, i++, sizeof(d_B.height), (void*)&d_B.height); clSetKernelArg(matMulKernel, i++, sizeof(d_B. stride), (void*)&d_B.stride); clSetKernelArg(matMulKernel, i++, sizeof(d_B.elements), (void*)&d_B.elements); clSetKernelArg(matMulKernel, i++, sizeof(d_C.width), (void*)&d_C.width); clSetKernelArg(matMulKernel, i++, sizeof(d_C.height), (void*)&d_C.height); clSetKernelArg(matMulKernel, i++, sizeof(d_C.stride), (void*)&d_C.stride); clSetKernelArg(matMulKernel, i++, sizeof(d_C.elements), (void*)&d_C.elements); size_t localWorkSize[] = { BLOCK_SIZE, BLOCK_SIZE }; size_t globalWorkSize[] = { B.width / dimBlock.x, A.height / dimBlock.y }; clEnqueueNDRangeKernel(queue, matMulKernel, 2, 0, globalWorkSize, localWorkSize, 0, 0, 0); // Read C from device memory clEnqueueReadBuffer(queue, d_C.elements, CL_TRUE, 0, size, C.elements, 0, 0, 0); // Free device memory clReleaseMemObject(d_A.elements); clReleaseMemObject(d_C.elements); clReleaseMemObject(d_B.elements); } // Kernel code // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.stride + col) typedef struct { int width; int height; int stride; __global float* elements; } Matrix; // Thread block size #define BLOCK_SIZE 16 // Get a matrix element float GetElement(const Matrix A, int row, int col) { return A.elements[row * A.stride + col]; } NVIDIA OpenCL Programming Guide Version 2.3 23 Chapter 2. 1BOpenCL on the CUDA Architecture // Set a matrix element void SetElement(Matrix A, int row, int col, float value) { A.elements[row * A.stride + col] = value; } // Get the BLOCK_SIZExBLOCK_SIZE sub-matrix Asub of A that is // located col sub-matrices to the right and row sub-matrices down // from the upper-left corner of A Matrix GetSubMatrix(Matrix A, int row, int col) { Matrix Asub; Asub.width = BLOCK_SIZE; Asub.height = BLOCK_SIZE; Asub.stride = A.stride; Asub.elements = &A.elements[A.stride * BLOCK_SIZE * row + BLOCK_SIZE * col]; return Asub; } // Matrix multiplication function called by MatMulKernel() void MatMul(Matrix C, Matrix A, Matrix B, __local float As[BLOCK_SIZE][BLOCK_SIZE], __local float Bs[BLOCK_SIZE][BLOCK_SIZE]) { // Block row and column int blockRow = get_group_id(1); int blockCol = get_group_id(0); // Each thread block computes one sub-matrix Csub of C Matrix Csub = GetSubMatrix(C, blockRow, blockCol); // Each thread computes one element of Csub // by accumulating results into Cvalue float Cvalue = 0; // Thread row and column within Csub int row = get_local_id(1); int col = get_local_id(0); // Loop over all the sub-matrices of A and B that are // required to compute Csub // Multiply each pair of sub-matrices together // and accumulate the results for (int m = 0; m < (A.width / BLOCK_SIZE); ++m) { // Get sub-matrix Asub of A Matrix Asub = GetSubMatrix(A, blockRow, m); // Get sub-matrix Bsub of B Matrix Bsub = GetSubMatrix(B, m, blockCol); // Load Asub and Bsub from device memory to shared memory // Each thread loads one element of each sub-matrix As[row][col] = GetElement(Asub, row, col); Bs[row][col] = GetElement(Bsub, row, col); 24 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 1 // Synchronize to make sure the sub-matrices are loaded // before starting the computation barrier(CLK_LOCAL_MEM_FENCE); // Multiply Asub and Bsub together for (int e = 0; e < BLOCK_SIZE; ++e) Cvalue += As[row][e] * Bs[e][col]; // Synchronize to make sure that the preceding // computation is done before loading two new // sub-matrices of A and B in the next iteration barrier(CLK_LOCAL_MEM_FENCE); } // Write Csub to device memory // Each thread writes one element SetElement(Csub, row, col, Cvalue); } // Matrix multiplication kernel called by MatMulHost() __kernel void matrixMulKernel( int Cwidth, int Cheight, int Cstride, __global float* Celements, int Awidth, int Aheight, int Astride, __global float* Aelements, int Bwidth, int Bheight, int Bstride, __global float* Belements, __local float As[BLOCK_SIZE][BLOCK_SIZE], __local float Bs[BLOCK_SIZE][BLOCK_SIZE]) { Matrix C = { Cwidth, Cheight, Cstride, Celements }; Matrix A = { Awidth, Aheight, Astride, Aelements }; Matrix B = { Bwidth, Bheight, Bstride, Belements }; MatMul(A, B, C, As, Bs); } NVIDIA OpenCL Programming Guide Version 2.3 25 Chapter 2. 1BOpenCL on the CUDA Architecture B C blockCol 1 - E Z I S _ K C O L B 0 col 0 Csub row BLOCK_SIZE-1 E Z I S _ K C O L B E Z I S _ K C O L B E Z I S _ K C O L B t h g i e h B . t h g i e h A . A w o R k c o b l BLOCK_SIZE BLOCK_SIZE BLOCK_SIZE A.width B.width Figure 2-5. Matrix Multipliation with Shared Memory 26 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines 3.1 Instruction Performance To process an instruction for a warp of threads, a multiprocessor must: (cid:137) Read the instruction operands for each thread of the warp, (cid:137) Execute the instruction, (cid:137) Write the result for each thread of the warp. Therefore, the effective instruction throughput depends on the nominal instruction throughput as well as the memory latency and bandwidth. It is maximized by: (cid:137) Minimizing the use of instructions with low throughput (see Section 3.1.1), (cid:137) Maximizing the use of the available memory bandwidth for each category of memory (see Section 3.1.2), (cid:137) Allowing the thread scheduler to overlap memory transactions with mathematical computations as much as possible, which requires that: (cid:190) The program executed by the threads is of high arithmetic intensity, that is, has a high number of arithmetic operations per memory operation; (cid:190) There are many active threads per multiprocessor, as detailed in Section 3.2. 3.1.1 3.1.1.1 Instruction Throughput In this section, throughputs are given in number of operations per clock cycle per multiprocessor. For a warp size of 32, an instruction is made of 32 operations. Therefore, if T is the number of operations per clock cycle, the instruction throughput is one instruction every 32/T clock cycles. All throughputs are for one multiprocessor. They must be multiplied by the number of multiprocessors in the device to get throughput for the whole device. Arithmetic Instructions For single-precision floating-point code, we highly recommend use of the float type and the single-precision floating-point mathematical functions. When compiling for devices without native double-precision floating-point support, such as devices of compute capability 1.2 and lower, each double variable gets converted to single-precision floating-point format (but retains its size of 64 bits) Chapter 3. Performance Guidelines and double-precision floating-point arithmetic gets demoted to single-precision floating-point arithmetic. We also recommend using native_* functions wherever possible and the -cl-mad-enable build option, both of them can lead to large performance gains. Single-Precision Floating-Point Basic Arithmetic Throughput of single-precision floating-point add, multiply, and multiply-add is 8 operations per clock cycle. Throughput of reciprocal is 2 operations per clock cycle. Throughput of single-precision floating-point division is 0.88 operations per clock cycle, but native_divide(x, y) provides a faster version with a throughput of 1.6 operations per clock cycle. Single-Precision Floating-Point Square Root and Reciprocal Square Root Throughput of reciprocal square root is 2 operations per clock cycle. Single-precision floating-point square root is implemented as a reciprocal square root followed by a reciprocal instead of a reciprocal square root followed by a multiplication, so that it gives correct results for 0 and infinity. Therefore, its throughput is 1 operation per clock cycle. Single-Precision Floating-Point Logarithm Throughput of native_log(x) (see Section B.2) is 2 operations per clock cycle. Sine and Cosine Throughput of native_sin(x), native_cos(x), native_exp(x) is 1 operation per clock cycle. sin(x), cos(x), tan(x), sincos(x) are much more expensive and even more so if the absolute value of x needs to be reduced. More precisely, the argument reduction code comprises two code paths referred to as the fast path and the slow path, respectively. The fast path is used for arguments sufficiently small in magnitude and essentially consists of a few multiply-add operations. The slow path is used for arguments large in magnitude, and consists of lengthy computations required to achieve correct results over the entire argument range. At present, the argument reduction code for the trigonometric functions selects the fast path for arguments whose magnitude is less than 48039.0f for the single- precision functions, and less than 2147483648.0 for the double-precision functions. As the slow path requires more registers than the fast path, an attempt has been made to reduce register pressure in the slow path by storing some intermediate variables in CUDA local memory, which may affect performance because of local memory high latency and bandwidth (see Section 3.1.2.2). At present, 28 bytes of CUDA local memory are used by single-precision functions, and 44 bytes are used by double-precision functions. However, the exact amount is subject to change. 28 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines Due to the lengthy computations and use of CUDA local memory in the slow path, the trigonometric functions throughput is lower by one order of magnitude when the slow path reduction is used as opposed to the fast path reduction. Integer Arithmetic Throughput of integer add is 8 operations per clock cycle. Throughput of 32-bit integer multiplication is 2 operations per clock cycle, but mul24 provide 24-bit integer multiplication with a troughput of 8 operations per clock cycle. On future architectures however, mul24 will be slower than 32-bit integer multiplication, so we recommend to provide two kernels, one using mul24 and the other using generic 32-bit integer multiplication, to be called appropriately by the application. Integer division and modulo operation are particularly costly and should be avoided if possible or replaced with bitwise operations whenever possible: If n is a power of 2, (i/n) is equivalent to (i>>log2(n)) and (i%n) is equivalent to (i&(n-1)); the compiler will perform these conversions if n is literal. Comparison Throughput of compare, min, max is 8 operations per clock cycle. Bitwise Operations Throughput of any bitwise operation is 8 operations per clock cycle. Type Conversion Throughput of type conversion operations is 8 operations per clock cycle. Sometimes, the compiler must insert conversion instructions, introducing additional execution cycles. This is the case for: (cid:137) Functions operating on char or short whose operands generally need to be converted to int, (cid:137) Double-precision floating-point constants (defined without any type suffix) used as input to single-precision floating-point computations. This last case can be avoided by using single-precision floating-point constants, defined with an f suffix such as 3.141592653589793f, 1.0f, 0.5f. Control Flow Instructions Any flow control instruction (if, switch, do, for, while) can significantly impact the effective instruction throughput by causing threads of the same warp to diverge, that is, to follow different execution paths. If this happens, the different executions paths have to be serialized, increasing the total number of instructions executed for this warp. When all the different execution paths have completed, the threads converge back to the same execution path. To obtain best performance in cases where the control flow depends on the thread ID, the controlling condition should be written so as to minimize the number of divergent warps. This is possible because the distribution of the warps across the block is deterministic as mentioned in Section 2.1.1. A trivial example is when the controlling condition only depends on (get_local_id(0) / WSIZE) where WSIZE is the warp size. In this case, no warp diverges since the controlling condition is perfectly aligned with the warps. 3.1.1.2 NVIDIA OpenCL Programming Guide Version 2.3 29 Chapter 3. Performance Guidelines Sometimes, the compiler may unroll loops or it may optimize out if or switch statements by using branch predication instead, as detailed below. In these cases, no warp can ever diverge. When using branch predication none of the instructions whose execution depends on the controlling condition gets skipped. Instead, each of them is associated with a per-thread condition code or predicate that is set to true or false based on the controlling condition and although each of these instructions gets scheduled for execution, only the instructions with a true predicate are actually executed. Instructions with a false predicate do not write results, and also do not evaluate addresses or read operands. The compiler replaces a branch instruction with predicated instructions only if the number of instructions controlled by the branch condition is less or equal to a certain threshold: If the compiler determines that the condition is likely to produce many divergent warps, this threshold is 7, otherwise it is 4. 3.1.1.3 Memory Instructions Memory instructions include any instruction that reads from or writes to CUDA shared, local, or global memory. Throughput of memory operations is 8 operations per clock cycle. When accessing CUDA local or global memory, there are, in addition, 400 to 600 clock cycles of memory latency. As an example, the throughput for the assignment operator in the following sample code: __local float shared[32]; __global float device[32]; shared[threadIdx.x] = device[threadIdx.x]; is 8 operations per clock cycle for the read from global memory, 8 operations per clock cycle for the write to shared memory, but above all, there is a latency of 400 to 600 clock cycles to read data from global memory. Much of this global memory latency can be hidden by the thread scheduler if there are sufficient independent arithmetic instructions that can be issued while waiting for the global memory access to complete. 3.1.1.4 Synchronization Instruction Throughput for the barrier function is 8 operations per clock cycle in the case where no thread has to wait for any other threads. 3.1.2 Memory Bandwidth The effective bandwidth of each memory space depends significantly on the memory access pattern as detailed in the following sub-sections. Since device memory is of much higher latency and lower bandwidth than on-chip memory, device memory accesses should be minimized. A typical programming pattern is to stage data coming from device memory into shared memory; in other words, to have each thread of a block: (cid:137) Load data from device memory to shared memory, 30 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines (cid:137) Synchronize with all the other threads of the block so that each thread can safely read shared memory locations that were written by different threads, (cid:137) Process the data in shared memory, (cid:137) Synchronize again if necessary to make sure that shared memory has been updated with the results, (cid:137) Write the results back to device memory. 3.1.2.1 Global Memory Global memory is not cached, so it is all the more important to follow the right access pattern to get maximum memory bandwidth, especially given how costly accesses to device memory are. First, the device is capable of reading 4-byte, 8-byte, or 16-byte words from global memory into registers in a single instruction. To have assignments such as: __global type device[32]; type data = device[tid]; compile to a single load instruction, type must be such that sizeof(type) is equal to 4, 8, or 16 and variables of type type must be aligned to sizeof(type) bytes (that is, have their address be a multiple of sizeof(type)). The alignment requirement is automatically fulfilled for built-in types. For structures, the size and alignment requirements can be enforced by the compiler using the alignment specifiers __attribute__ ((aligned(8))) or __attribute__ ((aligned(16))), such as struct { float a; float b; } __attribute__ ((aligned(8))); or struct { float a; float b; float c; } __attribute__ ((aligned(16))); For structures larger than 16 bytes, the compiler generates several load instructions. To ensure that it generates the minimum number of instructions, such structures should be defined with __attribute__ ((aligned(16))) , such as struct { float a; float b; float c; float d; float e; } __attribute__ ((aligned(16))); which is compiled into two 16-byte load instructions instead of five 4-byte load instructions. Any address of a variable residing in global memory or returned by one of the memory allocation routines from the driver or runtime API is always aligned to at least 256 bytes. NVIDIA OpenCL Programming Guide Version 2.3 31 Chapter 3. Performance Guidelines Second, global memory bandwidth is used most efficiently when the simultaneous memory accesses by threads in a half-warp (during the execution of a single read or write instruction) can be coalesced into a single memory transaction of 32, 64, or 128 bytes. The rest of this section describes the various requirements for memory accesses to coalesce based on the compute capability of the device. If a half-warp fulfills these requirements, coalescing is achieved even if the warp is divergent and some threads of the half-warp do not actually access memory. For the purpose of the following discussion, global memory is considered to be partitioned into segments of size equal to 32, 64, or 128 bytes and aligned to this size. Coalescing on Devices with Compute Capability 1.0 and 1.1 The global memory access by all threads of a half-warp is coalesced into one or two memory transactions if it satisfies the following three conditions: (cid:137) Threads must access (cid:137) Either 4-byte words, resulting in one 64-byte memory transaction, (cid:137) Or 8-byte words, resulting in one 128-byte memory transaction, (cid:137) Or 16-byte words, resulting in two 128-byte memory transactions; (cid:137) All 16 words must lie in the same segment of size equal to the memory transaction size (or twice the memory transaction size when accessing 16-byte words); (cid:137) Threads must access the words in sequence: The kth thread in the half-warp must access the kth word. If a half-warp does not fulfill all the requirements above, a separate memory transaction is issued for each thread and throughput is significantly reduced. Figure 3-1 shows some examples of coalesced memory accesses, while Figure 3-2 and Figure 3-3 show some examples of memory accesses that are non-coalesced for devices of compute capability 1.0 or 1.1. Coalesced 8-byte accesses deliver a little lower bandwidth than coalesced 4-byte accesses and coalesced 16-byte accesses deliver a noticeably lower bandwidth than coalesced 4-byte accesses. But, while bandwidth for non-coalesced accesses is around an order of magnitude lower than for coalesced accesses when these accesses are 4-byte, it is only around four times lower when they are 8-byte and around two times when they are 16-byte. Coalescing on Devices with Compute Capability 1.2 and Higher The global memory access by all threads of a half-warp is coalesced into a single memory transaction as soon as the words accessed by all threads lie in the same segment of size equal to: (cid:137) 32 bytes if all threads access 1-byte words, (cid:137) 64 bytes if all threads access 2-byte words, (cid:137) 128 bytes if all threads access 4-byte or 8-byte words. Coalescing is achieved for any pattern of addresses requested by the half-warp, including patterns where multiple threads access the same address. This is in 32 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines contrast with devices of lower compute capabilities where threads need to access words in sequence. If a half-warp addresses words in n different segments, n memory transactions are issued (one for each segment), whereas devices with lower compute capabilities would issue 16 transactions as soon as n is greater than 1. In particular, if threads access 16-byte words, at least two memory transactions are issued. Unused words in a memory transaction are still read, so they waste bandwidth. To reduce waste, hardware will automatically issue the smallest memory transaction that contains the requested words. For example, if all the requested words lie in one half of a 128-byte segment, a 64-byte transaction will be issued. More precisely, the following protocol is used to issue a memory transaction for a half-warp: (cid:137) Find the memory segment that contains the address requested by the lowest numbered active thread. Segment size is 32 bytes for 1-byte data, 64 bytes for 2-byte data, 128 bytes for 4-, 8- and 16-byte data. (cid:137) Find all other active threads whose requested address lies in the same segment. (cid:137) Reduce the transaction size, if possible: (cid:137) If the transaction size is 128 bytes and only the lower or upper half is used, reduce the transaction size to 64 bytes; (cid:137) If the transaction size is 64 bytes and only the lower or upper half is used, reduce the transaction sizez to 32 bytes. (cid:137) Carry out the transaction and mark the serviced threads as inactive. (cid:137) Repeat until all threads in the half-warp are serviced. Figure 3-4 shows some examples of global memory accesses for devices of compute capability 1.2 and higher. NVIDIA OpenCL Programming Guide Version 2.3 33 Chapter 3. Performance Guidelines Thread 0 Address 128 Thread 0 Address 128 Thread 1 Address 132 Thread 1 Address 132 Thread 2 Address 136 Thread 2 Address 136 Thread 3 Address 140 Thread 3 Address 140 Thread 4 Address 144 Thread 4 Address 144 Thread 5 Address 148 Thread 5 Address 148 Thread 6 Address 152 Thread 6 Address 152 Thread 7 Address 156 Thread 7 Address 156 Thread 8 Address 160 Thread 8 Address 160 Thread 9 Address 164 Thread 9 Address 164 Thread 10 Address 168 Thread 10 Address 168 Thread 11 Address 172 Thread 11 Address 172 Thread 12 Address 176 Thread 12 Address 176 Thread 13 Address 180 Thread 13 Address 180 Thread 14 Address 184 Thread 14 Address 184 Thread 15 Address 188 Thread 15 Address 188 Left: coalesced float memory access, resulting in a single memory transaction. Right: coalesced float memory access (divergent warp), resulting in a single memory transaction. Figure 3-1. Examples of Coalesced Global Memory Access Patterns 34 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines Thread 0 Address 128 Thread 0 Address 128 Thread 1 Address 132 Thread 1 Address 132 Thread 2 Address 136 Thread 2 Address 136 Thread 3 Address 140 Thread 3 Address 140 Thread 4 Address 144 Thread 4 Address 144 Thread 5 Address 148 Thread 5 Address 148 Thread 6 Address 152 Thread 6 Address 152 Thread 7 Address 156 Thread 7 Address 156 Thread 8 Address 160 Thread 8 Address 160 Thread 9 Address 164 Thread 9 Address 164 Thread 10 Address 168 Thread 10 Address 168 Thread 11 Address 172 Thread 11 Address 172 Thread 12 Address 176 Thread 12 Address 176 Thread 13 Address 180 Thread 13 Address 180 Thread 14 Address 184 Thread 14 Address 184 Thread 15 Address 188 Thread 15 Address 188 Left: non-sequential float memory access, resulting in 16 memory transactions. Right: access with a misaligned starting address, resulting in 16 memory transactions. Figure 3-2. Examples of Global Memory Access Patterns That Are Non-Coalesced for Devices of Compute Capability 1.0 or 1.1 NVIDIA OpenCL Programming Guide Version 2.3 35 Chapter 3. Performance Guidelines Thread 0 Address 128 Thread 0 Address 128 Thread 1 Address 132 Thread 2 Address 136 Thread 3 Address 140 Thread 1 Address 140 Thread 4 Address 144 Thread 5 Address 148 Thread 6 Address 152 Thread 2 Address 152 Thread 7 Address 156 Thread 8 Address 160 Thread 9 Address 164 Thread 3 Address 164 Thread 10 Address 168 Thread 11 Address 172 Thread 12 Address 176 Thread 4 Address 176 Thread 13 Address 180 Thread 14 Address 184 Thread 15 Address 188 Thread 5 Address 188 Left: non-contiguous float memory access, resulting in 16 memory transactions. Right: non-coalesced float3 memory access, resulting in 16 memory transactions. Figure 3-3. Examples of Global Memory Access Patterns That Are Non-Coalesced for Devices of Compute Capability 1.0 or 1.1 36 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines 6 4 B s e g m e n t Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 6 Thread 7 Thread 8 Thread 9 Thread 10 Thread 11 Thread 12 Thread 13 Thread 14 Thread 15 Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 6 Thread 7 Thread 8 Thread 9 Thread 10 Thread 11 Thread 12 Thread 13 Thread 14 Thread 15 Address 120 Address 124 Address 128 Address 132 Address 136 Address 140 Address 144 Address 148 Address 152 Address 156 Address 160 Address 164 Address 168 Address 172 Address 176 Address 180 Address 184 Address 188 Address 192 Address 196 Address 200 Address 204 Address 208 Address 212 Address 120 Address 124 Address 128 Address 132 Address 136 Address 140 Address 144 Address 148 Address 152 Address 156 Address 160 Address 164 Address 168 Address 172 Address 176 Address 180 Address 184 Address 188 Address 192 Address 19 6 … Address 204 Address 252 Address 256 1 2 8 B s e g m e n t Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 6 Thread 7 Thread 8 Thread 9 Thread 10 Thread 11 Thread 12 Thread 13 Thread 14 Thread 15 3 2 B s e g m e n t 6 4 B s e g m e n t Address 96 Address 100 Address 104 Address 108 Address 112 Address 116 Address 120 Address 124 Address 128 Address 132 Address 136 Address 140 Address 144 Address 148 Address 152 Address 156 Address 160 Address 164 Address 168 Address 172 Address 176 Address 180 Address 184 Address 188 Left: random float memory access within a 64B segment, resulting in one memory transaction. Center: misaligned float memory access, resulting in one transaction. Right: misaligned float memory access, resulting in two transactions. Figure 3-4. Examples of Global Memory Access by Devices with Compute Capability 1.2 and Higher NVIDIA OpenCL Programming Guide Version 2.3 37 Chapter 3. Performance Guidelines Common Access Patterns Array of Structures A common global memory access pattern is when each thread of thread ID tid accesses one element of an array located at address BaseAddress of type type* using the following address: BaseAddress + tid To get memory coalescing, type must meet the size and alignment requirements discussed above. In particular, this means that if type is a structure larger than 16 bytes, it should be split into several structures that meet these requirements and the data should be laid out in memory as a list of several arrays of these structures instead of a single array of type type*. Two-Dimensional Array Another common global memory access pattern is when each thread of index (tx,ty) accesses one element of a 2D array located at address BaseAddress of type type* and of width width using the following address: BaseAddress + width * ty + tx In such a case, one gets memory coalescing for all half-warps of the thread block only if: (cid:137) The width of the thread block is a multiple of half the warp size; (cid:137) width is a multiple of 16. In particular, this means that an array whose width is not a multiple of 16 will be accessed much more efficiently if it is actually allocated with a width rounded up to the closest multiple of 16 and its rows padded accordingly. Local Memory Like global memory, CUDA local memory is not cached, so accesses to local memory are as expensive as accesses to global memory. Local memory accesses are always coalesced though since they are per-thread by definition. Constant Memory Constant memory is cached so a read from constant memory costs one memory read from device memory only on a cache miss, otherwise it just costs one read from the constant cache. For all threads of a half-warp, reading from the constant cache is as fast as reading from a register as long as all threads read the same address. The cost scales linearly with the number of different addresses read by all threads. We recommend having all threads of the entire warp read the same address as opposed to all threads within each of its halves only, as future devices will require it for full speed read. Texture Memory Texture memory is cached so an image read costs one memory read from device memory only on a cache miss, otherwise it just costs one read from the texture cache. The texture cache is optimized for 2D spatial locality, so threads of the same warp that read image addresses that are close together will achieve best performance. Also, it is designed for streaming reads with a constant latency, i.e. a cache hit reduces DRAM bandwidth demand, but not read latency. 3.1.2.2 3.1.2.3 3.1.2.4 38 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines Reading device memory through image objects present some benefits that can make it an advantageous alternative to reading device memory from global or constant memory: (cid:137) If the memory reads do not follow the access patterns that global or constant memory reads must respect to get good performance (see Sections 3.1.2.1 and 3.1.2.3), higher bandwidth can be achieved providing that there is locality in the image reads; (cid:137) The latency of addressing calculations is hidden better, possibly improving performance for applications that perform random accesses to the data; (cid:137) Packed data may be broadcast to separate variables in a single operation; (cid:137) 8-bit and 16-bit integer input data may be optionally converted to 32-bit floating- point values in the range [0.0, 1.0] or [-1.0, 1.0]. However, within the same kernel call, the texture cache is not kept coherent with respect to image writes, so that any image read to an address that has been written to via an image write in the same kernel call returns undefined data. In other words, a thread can safely read via an image object some memory location only if this memory location has been updated by a previous kernel call or memory copy, but not if it has been previously updated by the same thread or another thread from the same kernel call. 3.1.2.5 Shared Memory Shared memory is where OpenCL local memory resides. Because it is on-chip, shared memory is much faster than local and global memory. In fact, for all threads of a warp, accessing shared memory is as fast as accessing a register as long as there are no bank conflicts between the threads, as detailed below. To achieve high memory bandwidth, shared memory is divided into equally-sized memory modules, called banks, which can be accessed simultaneously. So, any memory read or write request made of n addresses that fall in n distinct memory banks can be serviced simultaneously, yielding an effective bandwidth that is n times as high as the bandwidth of a single module. However, if two addresses of a memory request fall in the same memory bank, there is a bank conflict and the access has to be serialized. The hardware splits a memory request with bank conflicts into as many separate conflict-free requests as necessary, decreasing the effective bandwidth by a factor equal to the number of separate memory requests. If the number of separate memory requests is n, the initial memory request is said to cause n-way bank conflicts. To get maximum performance, it is therefore important to understand how memory addresses map to memory banks in order to schedule the memory requests so as to minimize bank conflicts. In the case of shared memory, the banks are organized such that successive 32-bit words are assigned to successive banks and each bank has a bandwidth of 32 bits per two clock cycles. For devices of compute capability 1.x, the warp size is 32 and the number of banks is 16 (see Section 5.1); a shared memory request for a warp is split into one request for the first half of the warp and one request for the second half of the warp. As a consequence, there can be no bank conflict between a thread belonging to the first half of a warp and a thread belonging to the second half of the same warp. NVIDIA OpenCL Programming Guide Version 2.3 39 Chapter 3. Performance Guidelines A common case is for each thread to access a 32-bit word from an array indexed by the thread ID tid and with some stride s: __local float shared[32]; float data = shared[BaseIndex + s * tid]; In this case, the threads tid and tid+n access the same bank whenever s*n is a multiple of the number of banks m or equivalently, whenever n is a multiple of m/d where d is the greatest common divisor of m and s. As a consequence, there will be no bank conflict only if half the warp size is less than or equal to m/d. For devices of compute capability 1.x, this translates to no bank conflict only if d is equal to 1, or in other words, only if s is odd since m is a power of two. Figure 3-5 and Figure 3-6 show some examples of conflict-free memory accesses while Figure 3-7 shows some examples of memory accesses that cause bank conflicts. Other cases worth mentioning are when each thread accesses an element that is smaller or larger than 32 bits in size. For example, there are bank conflicts if an array of char is accessed the following way: __local char shared[32]; char data = shared[BaseIndex + tid]; because shared[0], shared[1], shared[2], and shared[3], for example, belong to the same bank. There are no bank conflicts however, if the same array is accessed the following way: char data = shared[BaseIndex + 4 * tid]; There are also 2-way bank conflicts for arrays of double: __local double shared[32]; double data = shared[BaseIndex + tid]; since the memory request is compiled into two separate 32-bit requests. One way to avoid bank conflicts in this case is two split the double operands like in the following sample code: __local int shared_lo[32]; __local int shared_hi[32]; double dataIn; shared_lo[BaseIndex + tid] = __double2loint(dataIn); shared_hi[BaseIndex + tid] = __double2hiint(dataIn); double dataOut = __hiloint2double(shared_hi[BaseIndex + tid], shared_lo[BaseIndex + tid]); It might not always improve performance though and will perform worse on future architectures. A structure assignment is compiled into as many memory requests as necessary for each member in the structure, so the following code, for example: __local struct type shared[32]; struct type data = shared[BaseIndex + tid]; results in: (cid:137) Three separate memory reads without bank conflicts if type is defined as struct type { 40 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines float x, y, z; }; since each member is accessed with a stride of three 32-bit words; (cid:137) Two separate memory reads with bank conflicts if type is defined as struct type { float x, y; }; since each member is accessed with a stride of two 32-bit words; (cid:137) Two separate memory reads with bank conflicts if type is defined as struct type { float f; char c; }; since each member is accessed with a stride of five bytes. Finally, shared memory also features a broadcast mechanism whereby a 32-bit word can be read and broadcast to several threads simultaneously when servicing one memory read request. This reduces the number of bank conflicts when several threads of a half-warp read from an address within the same 32-bit word. More precisely, a memory read request made of several addresses is serviced in several steps over time – one step every two clock cycles – by servicing one conflict-free subset of these addresses per step until all addresses have been serviced; at each step, the subset is built from the remaining addresses that have yet to be serviced using the following procedure: (cid:137) Select one of the words pointed to by the remaining addresses as the broadcast word, (cid:137) Include in the subset: (cid:137) All addresses that are within the broadcast word, (cid:137) One address for each bank pointed to by the remaining addresses. Which word is selected as the broadcast word and which address is picked up for each bank at each cycle are unspecified. A common conflict-free case is when all threads of a half-warp read from an address within the same 32-bit word. Figure 3-8 shows some examples of memory read accesses that involve the broadcast mechanism. NVIDIA OpenCL Programming Guide Version 2.3 41 Chapter 3. Performance Guidelines Thread 0 Bank 0 Thread 0 Bank 0 Thread 1 Bank 1 Thread 1 Bank 1 Thread 2 Bank 2 Thread 2 Bank 2 Thread 3 Bank 3 Thread 3 Bank 3 Thread 4 Bank 4 Thread 4 Bank 4 Thread 5 Bank 5 Thread 5 Bank 5 Thread 6 Bank 6 Thread 6 Bank 6 Thread 7 Bank 7 Thread 7 Bank 7 Thread 8 Bank 8 Thread 8 Bank 8 Thread 9 Bank 9 Thread 9 Bank 9 Thread 10 Bank 10 Thread 10 Bank 10 Thread 11 Bank 11 Thread 11 Bank 11 Thread 12 Bank 12 Thread 12 Bank 12 Thread 13 Bank 13 Thread 13 Bank 13 Thread 14 Bank 14 Thread 14 Bank 14 Thread 15 Bank 15 Thread 15 Bank 15 Left: linear addressing with a stride of one 32-bit word. Right: random permutation. Figure 3-5. Examples of Shared Memory Access Patterns without Bank Conflicts 42 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines Thread 0 Bank 0 Thread 1 Bank 1 Thread 2 Bank 2 Thread 3 Bank 3 Thread 4 Bank 4 Thread 5 Bank 5 Thread 6 Bank 6 Thread 7 Bank 7 Thread 8 Bank 8 Thread 9 Bank 9 Thread 10 Bank 10 Thread 11 Bank 11 Thread 12 Bank 12 Thread 13 Bank 13 Thread 14 Bank 14 Thread 15 Bank 15 Linear addressing with a stride of three 32-bit words. Figure 3-6. Example of a Shared Memory Access Pattern without Bank Conflicts NVIDIA OpenCL Programming Guide Version 2.3 43 Chapter 3. Performance Guidelines Thread 0 Bank 0 Thread 0 Bank 0 Thread 1 Bank 1 Thread 1 Bank 1 Thread 2 Bank 2 Thread 2 Bank 2 Thread 3 Bank 3 Thread 3 Bank 3 Thread 4 Bank 4 Thread 4 Bank 4 Thread 5 Bank 5 Thread 5 Bank 5 Thread 6 Bank 6 Thread 6 Bank 6 Thread 7 Bank 7 Thread 7 Bank 7 Thread 8 Bank 8 Thread 8 Bank 8 Thread 9 Bank 9 Thread 9 Bank 9 Thread 10 Bank 10 Thread 10 Bank 10 Thread 11 Bank 11 Thread 11 Bank 11 Thread 12 Bank 12 Thread 12 Bank 12 Thread 13 Bank 13 Thread 13 Bank 13 Thread 14 Bank 14 Thread 14 Bank 14 Thread 15 Bank 15 Thread 15 Bank 15 Left: Linear addressing with a stride of two 32-bit words causes 2-way bank conflicts. Right: Linear addressing with a stride of eight 32-bit words causes 8-way bank conflicts. Figure 3-7. Examples of Shared Memory Access Patterns with Bank Conflicts 44 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines Thread 0 Bank 0 Thread 0 Bank 0 Thread 1 Bank 1 Thread 1 Bank 1 Thread 2 Bank 2 Thread 2 Bank 2 Thread 3 Bank 3 Thread 3 Bank 3 Thread 4 Bank 4 Thread 4 Bank 4 Thread 5 Bank 5 Thread 5 Bank 5 Thread 6 Bank 6 Thread 6 Bank 6 Thread 7 Bank 7 Thread 7 Bank 7 Thread 8 Bank 8 Thread 8 Bank 8 Thread 9 Bank 9 Thread 9 Bank 9 Thread 10 Bank 10 Thread 10 Bank 10 Thread 11 Bank 11 Thread 11 Bank 11 Thread 12 Bank 12 Thread 12 Bank 12 Thread 13 Bank 13 Thread 13 Bank 13 Thread 14 Bank 14 Thread 14 Bank 14 Thread 15 Bank 15 Thread 15 Bank 15 Left: This access pattern is conflict-free since all threads read from an address within the same 32-bit word. Right: This access pattern causes either no bank conflicts if the word from bank 5 is chosen as the broadcast word during the first step or 2-way bank conflicts, otherwise. Figure 3-8. Example of Shared Memory Read Access Patterns with Broadcast NVIDIA OpenCL Programming Guide Version 2.3 45 Chapter 3. Performance Guidelines 3.1.2.6 Registers Generally, accessing a register is zero extra clock cycles per instruction, but delays may occur due to register read-after-write dependencies and register memory bank conflicts. The delays introduced by read-after-write dependencies can be ignored as soon as there are at least 192 active threads per multiprocessor to hide them. The compiler and thread scheduler schedule the instructions as optimally as possible to avoid register memory bank conflicts. They achieve best results when the number of threads per block is a multiple of 64. Other than following this rule, an application has no direct control over these bank conflicts. In particular, there is no need to pack data into float4 or int4 types. 3.2 NDRange How the NDRange affects the execution time of a kernel launch generally depends on the kernel code. Experimentation is therefore recommended and applications should set the work-group size explicitly as opposed to rely on the OpenCL implementation to determine the right size (by setting local_work_size to NULL in clEnqueueNDRangeKernel()). There are however general guidelines, described in this section. For a start, the kernel will simply fail to launch if the number of threads per block either is above the maximum number of threads per block as specified in Appendix A, or requires too many registers or shared memory than available per multiprocessor as mentioned in Section 2.1.2. The total number of registers required for a block is equal to ceil ( R × ceil ),32,( T maxR 32 ) ) R ceil yx ,( maxR is the number of registers required for the kernel, is equal to x rounded up to the nearest multiple of where is the number of registers per multiprocessor given in Appendix A, T is the number of threads per . The total block, and amount of shared memory required for a block is equal to the sum of the amount of statically allocated shared memory, the amount of dynamically allocated shared memory, and the amount of shared memory used to pass the kernel’s arguments. Note that each double or long long variable uses two registers. However, devices of compute capability 1.2 and higher have twice as many registers per multiprocessor as devices with lower compute capability. y Then, given a total number of threads per grid, the number of threads per block might be dictated by the need to have enough blocks in the grid to maximize the utilization of the available computing resources. First, there should be at least as many blocks as there are multiprocessors in the device. Then, running only one block per multiprocessor will force the multiprocessor to idle during thread synchronization and also during device memory reads if there are not enough threads per block to cover the load latency. It is therefore usually better to allow for two or more blocks to be active on each multiprocessor to allow overlap between blocks that wait and blocks that can run. For this to happen, not only should there be at least twice as many blocks as there are multiprocessors in the device, but also 46 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines the amount of registers and shared memory required per block must be low enough to allow for more than one active block (see Section 2.1.2). More thread blocks stream in pipeline fashion through the device and amortize overhead even more. The number of blocks per grid should be at least 100 if one wants it to scale to future devices; 1000 blocks will scale across several generations. With a high enough number of blocks, the number of threads per block should be chosen as a multiple of the warp size to avoid swasting computing resources with under-populated warps, or better, a multiple of 64 for the reason invoked in Section 3.1.2.6. Allocating more threads per block is better for efficient time slicing, but the more threads per block, the fewer registers are available per thread, which might prevent the kernel invocation from succeeding. Usually, 64 threads per block is minimal and makes sense only if there are multiple active blocks per multiprocessor; 192 or 256 threads per block is better and usually allows for enough registers to compile. The ratio of the number of active warps per multiprocessor to the maximum number of active warps (given in Appendix A) is called the multiprocessor occupancy. In order to maximize occupancy, the compiler attempts to minimize register usage while keeping the number of instructions and CUDA local memory usage to a minimum. The CUDA Software Development Kit provides a spreadsheet to assist programmers in choosing thread block size based on shared memory and register requirements. 3.3 Data Transfer between Host and Device The bandwidth between device memory and the device is much higher than the bandwidth between device memory and host memory. Therefore, one should strive to minimize data transfer between the host and the device, for example, by moving more code from the host to the device, even if that means running kernels with low parallelism computations. Intermediate data structures may be created in device memory, operated on by the device, and destroyed without ever being mapped by the host or copied to host memory. Also, because of the overhead associated with each transfer, batching many small transfers into a big one always performs much better than making each transfer separately. Finally, higher performance for data transfers between host and device is achieved for memory objects allocated in page-locked (also known as pinned) host memory (as opposed to regular pageable host memory allocated by malloc()), which has several benefits: (cid:137) Bandwidth between host memory and device memory is higher if host memory is allocated as page-locked. (cid:137) For some devices, copies between page-locked host memory and device memory can be performed concurrently with kernel execution. (cid:137) For some devices, page-locked host memory can be mapped into the device’s address space. In this case, there is no need to allocate any device memory and to explicitly copy data between device and host memory. Data transfers are implicitly performed each time the kernel accesses the mapped memory. For maximum performance, these memory accesses must be coalesced like if they NVIDIA OpenCL Programming Guide Version 2.3 47 Chapter 3. Performance Guidelines were accesses to global memory (see Section 3.1.2.1). Assuming that they are an that the mapped memory is read or written only once, avoiding explicit copies between device and host memory can be a win performance-wise. It is always a win on integrated systems where device memory and host memory are physically the same and therefore any copy between host and device memory is superfluous. enCL applicat ions do not have direct control over whether memory objects are Op allocated in page-locked memory or not, but they can create objects using the CL_MEM_ALLOC_HOST_PTR flag and such objects are likely to be allocated in locked memory by the driver for best performance. page- d 3.4 Warp-Level Synchronization Because a warp executes one common instruction at a time, threads within a warp are implicitly synchronized and this can be used to omit calls to the barrier() function for better performance. example, both calls to barrier() are required to In the following code sample, for get the expected result (i.e. result[i] = 2 * myArray[i] for i > 0). Without synchronization, any of the two references to myArray[tid] could return either 2 or the value initially stored in myArray, depending on whether t memory read occurs before or after the memory write from myArray[tid + 1] = 2. he // myArray is an array of integers located in global or shared // memory __kernel void myKernel(__global int* result) { int tid = get_local_id(0); ... int ref1 = myArray[tid] * 1; barrier(CLK_LOCAL_MEM_FENCE|CLK_GLOBAL_MEM_FENCE); myArray[tid + 1] = 2; barrier(CLK_LOCAL_MEM_FENCE|CLK_GLOBAL_MEM_FENCE); int ref2 = myArray[tid] * 1; result[tid] = ref1 * ref2; ... } However, in the following slightly modified code sample, threads are guaranteed to belong to the same warp, so that there is no need for any barrier() call. // myArray is an array of integers located in global or shared // memory __kernel void myKernel(__global int* result) { int tid = get_local_id(0); ... if (tid < warpSize) { int ref1 = myArray[tid] * 1; myArray[tid + 1] = 2; int ref2 = myArray[tid] * 1; result[tid] = ref1 * ref2; } ... } 48 NVIDIA OpenCL Programming Guide Version 2.3 Chapter 3. Performance Guidelines Simply removing the call to barrier() is not enough however; myArray also needs to be declared as volatile as described in Section 2.2.2. 3.5 Overall Performance Optimization Strategies Performance optimization revolves around three basic strategies: (cid:137) Maximizing parallel execution; (cid:137) Optimizing memory usage to achieve maximum memory bandwidth; (cid:137) Optimizing instruction usage to achieve maximum instruction throughput. Maximizing parallel execution starts with structuring the algorithm in a way that exposes as much data parallelism as possible. At points in the algorithm where parallelism is broken because some threads need to synchronize in order to share data between each other, there are two cases: Either these threads belong to the same block, in which case they should use the barrier() function and share data through shared memory within the same kernel call, or they belong to different blocks, in which case they must share data through global memory using two separate kernel invocations, one for writing to and one for reading from global memory. Once the parallelism of the algorithm has been exposed it needs to be mapped to the hardware as efficiently as possible. This is done by carefully choosing the NDRange of each kernel invocation as detailed in Section 3.2. The application should also maximize parallel execution at a higher level by explicitly exposing concurrent execution on the device through queues, as well as maximizing concurrent execution between host and device. Optimizing memory usage starts with minimizing data transfers with low- bandwidth. That means minimizing data transfers between the host and the device, as detailed in Section 3.3, since these have much lower bandwidth than data transfers between device and global memory. That also means minimizing data transfers between device and global memory by maximizing use of shared memory on the device, as mentioned in Section 3.1.2. Sometimes, the best optimization might even be to avoid any data transfer in the first place by simply recomputing the data instead whenever it is needed. As detailed in Sections 3.1.2.1, 3.1.2.3, 3.1.2.4, and 3.1.2.5, the effective bandwidth can vary by an order of magnitude depending on access pattern for each type of memory. The next step in optimizing memory usage is therefore to organize memory accesses as optimally as possible based on the optimal memory access patterns. This optimization is especially important for global memory accesses as global memory bandwidth is low and its latency is hundreds of clock cycles (see Section 3.1.1.3). Shared memory accesses, on the other hand, are usually worth optimizing only in case they have a high degree of bank conflicts. As for optimizing instruction usage, the use of arithmetic instructions with low throughput (see Section 3.1.1.1) should be minimized. This includes trading precision for speed when it does not affect the end result, such as using intrinsic instead of regular functions (intrinsic functions are listed in Section B.2) or single- precision instead of double-precision. Particular attention must be paid to control flow instructions due to the SIMT nature of the device as detailed in Section 3.1.1.2. NVIDIA OpenCL Programming Guide Version 2.3 49 Appendix A. Technical Specifications A.1 General Specifications The general specifications and features of a compute device depend on its compute capability (see Section 2.3). The following sections describe the technical specifications and features associated to each compute capability. The specifications for a given compute capability are the same as for the compute capability just below unless otherwise mentioned. Similarly, any feature supported for a given compute capability is supported for any higher compute capability. The compute capability and number of multiprocessors of all CUDA-enabled devices are given in the following table: Number of Multiprocessors Compute Capability GeForce GTX 295 GeForce GTX 285, GTX 280 GeForce GTX 260 GeForce 9800 GX2 GeForce GTS 250, GTS 150, 9800 GTX, 9800 GTX+, 8800 GTS 512 GeForce 8800 Ultra, 8800 GTX GeForce 9800 GT, 8800 GT, 9800M GTX GeForce GT 130, 9600 GSO, 8800 GS, 8800M GTX, 9800M GT GeForce 8800 GTS GeForce 9600 GT, 8800M GTS, 9800M GTS GeForce 9700M GT GeForce GT 120, 9500 GT, 8600 GTS, 8600 GT, 9700M GT, 9650M GS, 9600M GT, 9600M GS, 9500M GS, 8700M GT, 8600M GT, 8600M GS GeForce G100, 8500 GT, 8400 GS, 8400M GT, 9500M G, 9300M G, 8400M GS, 9400 mGPU, 9300 mGPU, 8300 mGPU, 8200 mGPU, (1 Multiprocessor = 8 Processors) 2x30 30 24 2x16 16 16 14 12 12 8 6 4 2 1.3 1.3 1.3 1.1 1.1 1.0 1.1 1.1 1.0 1.1 1.1 1.1 1.1 Appendix A. Technical Specifications 8100 mGPU GeForce 9300M GS, 9200M GS, 9100M G, 8400M G Tesla S1070 Tesla C1060 Tesla S870 Tesla D870 Tesla C870 Quadro Plex 2200 D2 Quadro Plex 2100 D4 Quadro Plex 2100 Model S4 Quadro Plex 1000 Model IV Quadro FX 5800 Quadro FX 4800 Quadro FX 4700 X2 Quadro FX 3700M Quadro FX 5600 Quadro FX 3700 Quadro FX 3600M Quadro FX 4600 Quadro FX 2700M Quadro FX 1700, FX 570, NVS 320M, FX 1700M, FX 1600M, FX 770M, FX 570M Quadro FX 370, NVS 290, NVS 140M, NVS 135M, FX 360M Quadro FX 370M, NVS 130M 1 4x30 30 4x16 2x16 16 2x30 4x14 4x16 2x16 30 24 2x14 16 16 14 12 12 6 4 2 1 1.1 1.3 1.3 1.0 1.0 1.0 1.3 1.1 1.0 1.0 1.3 1.3 1.1 1.1 1.0 1.1 1.1 1.0 1.1 1.1 1.1 1.1 The number of multiprocessors, the clock frequency and the total amount of device memory can be queried using the runtime. A.1.1 Specifications for Compute Capability 1.0 (cid:137) The maximum number of threads per block is 512; (cid:137) The maximum sizes of the x-, y-, and z-dimension of a thread block are 512, 512, and 64, respectively; (cid:137) The maximum size of each dimension of a grid of thread blocks is 65535; (cid:137) The warp size is 32 threads; (cid:137) The number of 32-bit registers per multiprocessor is 8192; (cid:137) The amount of shared memory available per multiprocessor is 16 KB organized into 16 banks (see Section 3.1.2.5); (cid:137) The total amount of constant memory is 64 KB; (cid:137) The total amount of local memory per thread is 16 KB; (cid:137) The cache working set for constant memory is 8 KB per multiprocessor; (cid:137) The cache working set for texture memory varies between 6 and 8 KB per multiprocessor; 52 NVIDIA OpenCL Programming Guide Version 2.3 Appendix A. Technical Specifications (cid:137) The maximum number of active blocks per multiprocessor is 8; (cid:137) The maximum number of active warps per multiprocessor is 24; (cid:137) The maximum number of active threads per multiprocessor is 768; (cid:137) The limit on kernel size is 2 million PTX instructions; A.1.2 A.1.3 Specifications for Compute Capability 1.1 (cid:137) Support for atomic functions operating on 32-bit words in global memory. Specifications for Compute Capability 1.2 (cid:137) Support for atomic functions operating in shared memory and atomic functions operating on 64-bit words in global memory; (cid:137) Support for warp vote functions; (cid:137) The number of registers per multiprocessor is 16384; (cid:137) The maximum number of active warps per multiprocessor is 32; (cid:137) The maximum number of active threads per multiprocessor is 1024. A.1.4 Specifications for Compute Capability 1.3 (cid:137) Support for double-precision floating-point numbers. A.2 Floating-Point Standard All compute devices follow the IEEE-754 standard for binary floating-point arithmetic with the following deviations: (cid:137) There is no dynamically configurable rounding mode; however, most of the operations support IEEE rounding modes, exposed via device functions; (cid:137) There is no mechanism for detecting that a floating-point exception has occurred and all operations behave as if the IEEE-754 exceptions are always masked, and deliver the masked response as defined by IEEE-754 if there is an exceptional event; for the same reason, while SNaN encodings are supported, they are not signaling; (cid:137) Absolute value and negation are not compliant with IEEE-754 with respect to NaNs; these are passed through unchanged; (cid:137) For single-precision floating-point numbers only: (cid:137) Denormalized numbers are not supported; floating-point arithmetic and comparison instructions convert denormalized operands to zero prior to the floating-point operation; (cid:137) Underflowed results are flushed to zero; (cid:137) The result of an operation involving one or more input NaNs is the quiet NaN of bit pattern 0x7fffffff; note that; (cid:137) Some instructions are not IEEE-compliant: NVIDIA OpenCL Programming Guide Version 2.3 53 Appendix A. Technical Specifications (cid:137) Addition and multiplication are often combined into a single multiply-add instruction (FMAD), which truncates the intermediate result of the multiplication; (cid:137) Division is implemented via the reciprocal in a non-standard-compliant way; (cid:137) Square root is implemented via the reciprocal square root in a non- standard-compliant way; (cid:137) For addition and multiplication, only round-to-nearest-even and round-towards-zero are supported via static rounding modes; directed rounding towards +/- infinity is not supported; But, IEEE-compliant software (and therefore slower) implementations are provided through the following intrinsics from Appendix B: (cid:137) fma(float, float, float): single-precision fused multiply-add with IEEE rounding modes, (cid:137) native_recip(float): single-precision reciprocal with IEEE rounding modes, (cid:137) native_divide(float, float): single-precision division with IEEE rounding modes, (cid:137) native_sqrt(float): single-precision square root with IEEE rounding modes; (cid:137) For double-precision floating-point numbers only: (cid:137) Round-to-nearest-even is the only supported IEEE rounding mode for reciprocal, division, and square root. In accordance to the IEEE-754R standard, if one of the input parameters to fmin() or fmax() is NaN, but not the other, the result is the non-NaN parameter. (cid:137) The conversion of a floating-point value to an integer value in the case where the floating-point value falls outside the range of the integer format is left undefined by IEEE-754. For compute devices, the behavior is to clamp to the end of the supported range. This is unlike the x86 architecture behaves. A.3 Supported OpenCL Extensions All compute devices supports the cl_khr_byte_addressable_store extension. Devices of compute capability 1.1 and higher support the cl_khr_global_int32_base_atomics, cl_khr_global_int32_extended_atomics, cl_khr_local_int32_base_atomics, and cl_khr_local_int32_extended_atomics extensions. 54 NVIDIA OpenCL Programming Guide Version 2.3 Appendix B. Mathematical Functions Accuracy B.1 Standard Functions Error bounds in this section are generated from extensive but not exhaustive tests, so they are not guaranteed bounds. B.1.1 Single-Precision Floating-Point Functions Table C-1 lists errors for the standard single-precision floating-point functions. The recommended way to round a single-precision floating-point operand to an integer, with the result being a single-precision floating-point number is rint(), not round(). The reason is that round() maps to an 8-instruction sequence on the device, whereas rint() maps to a single instruction. trunc(), ceil(), and floor() each map to a single instruction as well. Table C-1. Mathematical Standard Library Functions with Maximum ULP Error The maximum error is stated as the absolute value of the difference in ulps between a correctly rounded single-precision result and the result returned by the CUDA library function. Function x+y x*y x/y 1/x 1/sqrt(x) rsqrt(x) sqrt(x) cbrt(x) hypot(x,y) exp(x) Maximum ulp error 0 (IEEE-754 round-to-nearest-even) (except when merged into an FMAD) 0 (IEEE-754 round-to-nearest-even) (except when merged into an FMAD) 2 (full range) 1 (full range) 2 (full range) 3 (full range) 1 (full range) 3 (full range) 2 (full range) Appendix B. Mathematical Functions Accuracy Function exp2(x) exp10(x) expm1(x) log(x) log2(x) log10(x) log1p(x) sin(x) cos(x) tan(x) sincos(x,cptr) asin(x) acos(x) atan(x) atan2(y,x) sinh(x) cosh(x) tanh(x) asinh(x) acosh(x) atanh(x) pow(x,y) erf(x) erfc(x) erfinv(x) erfcinv(x) lgamma(x) tgamma(x) fma(x,y,z) frexp(x,exp) ldexp(x,exp) scalbn(x,n) scalbln(x,l) logb(x) ilogb(x) fmod(x,y) remainder(x,y) remquo(x,y,iptr) modf(x,iptr) fdim(x,y) trunc(x) round(x) Maximum ulp error 2 (full range) 2 (full range) 1 (full range) 1 (full range) 3 (full range) 3 (full range) 2 (full range) 2 (full range) 2 (full range) 4 (full range) 2 (full range) 4 (full range) 3 (full range) 2 (full range) 3 (full range) 3 (full range) 2 (full range) 2 (full range) 3 (full range) 4 (full range) 3 (full range) 8 (full range) 3 (full range) 8 (full range) 5 (full range) 7 (full range) 6 (outside interval -10.001 ... -2.264; larger inside) 11 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 56 NVIDIA OpenCL Programming Guide Version 2.3 Appendix B. Mathematical Functions Accuracy Function rint(x) nearbyint(x) ceil(x) floor(x) lrint(x) lround(x) llrint(x) llround(x) Maximum ulp error 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) B.1.2 Double-Precision Floating-Point Functions Table C-2 lists errors for the standard double-precision floating-point functions. These errors only apply when compiling for devices with native double-precision support. When compiling for devices without such support, such as devices of compute capability 1.2 and lower, the double type gets demoted to float by default and the double-precision math functions are mapped to their single- precision equivalents. The recommended way to round a double-precision floating-point operand to an integer, with the result being a double-precision floating-point number is rint(), not round(). The reason is that round() maps to an 8-instruction sequence on the device, whereas rint() maps to a single instruction. trunc(), ceil(), and floor() each map to a single instruction as well. Table C-2. Mathematical Standard Library Functions with Maximum ULP Error The maximum error is stated as the absolute value of the difference in ulps between a correctly rounded double-precision result and the result returned by the CUDA library function. Function x+y x*y x/y 1/x sqrt(x) rsqrt(x) cbrt(x) hypot(x,y) exp(x) exp2(x) exp10(x) expm1(x) log(x) log2(x) Maximum ulp error 0 (IEEE-754 round-to-nearest-even) 0 (IEEE-754 round-to-nearest-even) 0 (IEEE-754 round-to-nearest-even) 0 (IEEE-754 round-to-nearest-even) 0 (IEEE-754 round-to-nearest-even) 1 (full range) 1 (full range) 2 (full range) 1 (full range) 1 (full range) 1 (full range) 1 (full range) 1 (full range) 1 (full range) NVIDIA OpenCL Programming Guide Version 2.3 57 Appendix B. Mathematical Functions Accuracy Function log10(x) log1p(x) sin(x) cos(x) tan(x) sincos(x,sptr,cptr) asin(x) acos(x) atan(x) atan2(y,x) sinh(x) cosh(x) tanh(x) asinh(x) acosh(x) atanh(x) pow(x,y) erf(x) erfc(x) erfinv(x) erfcinv(x) lgamma(x) tgamma(x) fma(x,y,z) frexp(x,exp) ldexp(x,exp) scalbn(x,n) scalbln(x,l) logb(x) ilogb(x) fmod(x,y) remainder(x,y) remquo(x,y,iptr) modf(x,iptr) fdim(x,y) trunc(x) round(x) rint(x) nearbyint(x) ceil(x) floor(x) lrint(x) Maximum ulp error 1 (full range) 1 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 1 (full range) 1 (full range) 1 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 2 (full range) 7 (full range) 8 (full range) 8 (full range) 4 (outside interval -11.0001 ... -2.2637; larger inside) 8 (full range) 0 (IEEE-754 round-to-nearest-even) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 0 (full range) 58 NVIDIA OpenCL Programming Guide Version 2.3 Appendix B. Mathematical Functions Accuracy Function lround(x) llrint(x) llround(x) Maximum ulp error 0 (full range) 0 (full range) 0 (full range) B.2 Native Functions Table C-3 lists the native single-precision floating-point functions supported on the CUDA architecture. Both the regular floating-point division and native_divide(x,y) have the same accuracy, but for 2126 < y < 2128, native_divide(x,y) delivers a result of zero, whereas the regular division delivers the correct result to within the accuracy stated in Table C-3. Also, for 2126 < y < 2128, if x is infinity, native_divide(x,y) delivers a NaN (as a result of multiplying infinity by zero), while the regular division returns infinity. Table C-3. Single-Precision Floating-Point Native Functions with Respective Error Bounds Function native_recip(x) native_sqrt(x) Error bounds IEEE-compliant. IEEE-compliant. native_divide(x,y) For y in [2-126, 2126], the maximum ulp error is 2. native_exp(x) native_exp10(x) native_log(x) native_log2(x) native_log10(x) native_sin(x) native_cos(x) native_tan(x) native_pow(x,y) The maximum ulp error is 2 + floor(abs(1.16 * x)). The maximum ulp error is 2 + floor(abs(2.95 * x)). For x in [0.5, 2], the maximum absolute error is 2- 21.41, otherwise, the maximum ulp error is 3. For x in [0.5, 2], the maximum absolute error is 2-22, otherwise, the maximum ulp error is 2. For x in [0.5, 2], the maximum absolute error is 2-24, otherwise, the maximum ulp error is 3. For x in [-π, π], the maximum absolute error is 2-21.41, and larger otherwise. For x in [-π, π], the maximum absolute error is 2-21.19, and larger otherwise. Derived from its implementation as native_sin(x) * (1 / native_cos(x)). Derived from its implementation as exp2(y * native_log2(x)). NVIDIA OpenCL Programming Guide Version 2.3 59 Notice ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. Information furnished is believed to be accurate and reliable. However, NVIDIA Corporation assumes no responsibility for the consequences of use of such information or for any infringement of patents or other rights of third parties that may result from its use. No license is granted by implication or otherwise under any patent or patent rights of NVIDIA Corporation. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. NVIDIA Corporation products are not authorized for use as critical components in life support devices or systems without express written approval of NVIDIA Corporation. Trademarks NVIDIA, the NVIDIA logo, GeForce, Tesla, and Quadro are trademarks or registered trademarks of NVIDIA Corporation. Other company and product names may be trademarks of the respective companies with which they are associated. Copyright © 2007-2008 NVIDIA Corporation. All rights reserved. This work incorporates portions of on an earlier work: Scalable Parallel Programming with CUDA, in ACM Queue, VOL 6, No. 2 (March/April 2008), © ACM, 2008. http://mags.acm.org/queue/20080304/?u1=texterity" NVIDIA Corporation 2701 San Tomas Expressway Santa Clara, CA 95050 www.nvidia.com |