Hash :
41b817f3
Author :
Date :
2021-05-31T17:38:43
CL: Add buffer enqueue commands Add buffer enqueue commands to front end and pass-through back end. Bug: angleproject:6015 Change-Id: I936530d31903e395550e4540339ebec2e6702e65 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2928425 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
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
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationCL.cpp: Validation functions for generic CL entry point parameters
// based on the OpenCL Specification V3.0.7, see https://www.khronos.org/registry/OpenCL/
// Each used CL error code is preceeded by a citation of the relevant rule in the spec.
#include "libANGLE/validationCL_autogen.h"
#include "libANGLE/cl_utils.h"
#define ANGLE_VALIDATE_VERSION(version, major, minor) \
do \
{ \
if (version < CL_MAKE_VERSION(major##u, minor##u, 0u)) \
{ \
return CL_INVALID_VALUE; \
} \
} while (0)
namespace cl
{
namespace
{
cl_int ValidateContextProperties(const cl_context_properties *properties, const Platform *&platform)
{
platform = nullptr;
bool hasUserSync = false;
if (properties != nullptr)
{
while (*properties != 0)
{
switch (*properties++)
{
case CL_CONTEXT_PLATFORM:
{
// CL_INVALID_PROPERTY if the same property name is specified more than once.
if (platform != nullptr)
{
return CL_INVALID_PROPERTY;
}
cl_platform_id nativePlatform = reinterpret_cast<cl_platform_id>(*properties++);
// CL_INVALID_PLATFORM if platform value specified in properties
// is not a valid platform.
if (!Platform::IsValid(nativePlatform))
{
return CL_INVALID_PLATFORM;
}
platform = &nativePlatform->cast<Platform>();
break;
}
case CL_CONTEXT_INTEROP_USER_SYNC:
{
// CL_INVALID_PROPERTY if the value specified for a supported property name
// is not valid, or if the same property name is specified more than once.
if ((*properties != CL_FALSE && *properties != CL_TRUE) || hasUserSync)
{
return CL_INVALID_PROPERTY;
}
++properties;
hasUserSync = true;
break;
}
default:
{
// CL_INVALID_PROPERTY if context property name in properties
// is not a supported property name.
return CL_INVALID_PROPERTY;
}
}
}
}
if (platform == nullptr)
{
platform = Platform::GetDefault();
// CL_INVALID_PLATFORM if properties is NULL and no platform could be selected.
if (platform == nullptr)
{
return CL_INVALID_PLATFORM;
}
}
return CL_SUCCESS;
}
bool ValidateMemoryFlags(MemFlags flags, const Platform &platform)
{
// CL_MEM_READ_WRITE, CL_MEM_WRITE_ONLY, and CL_MEM_READ_ONLY are mutually exclusive.
MemFlags allowedFlags(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY);
if (!flags.areMutuallyExclusive(CL_MEM_READ_WRITE, CL_MEM_WRITE_ONLY, CL_MEM_READ_ONLY))
{
return false;
}
// CL_MEM_USE_HOST_PTR is mutually exclusive with either of the other two flags.
allowedFlags.set(CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR);
if (!flags.areMutuallyExclusive(CL_MEM_USE_HOST_PTR,
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return false;
}
if (platform.isVersionOrNewer(1u, 2u))
{
// CL_MEM_HOST_WRITE_ONLY, CL_MEM_HOST_READ_ONLY,
// and CL_MEM_HOST_NO_ACCESS are mutually exclusive.
allowedFlags.set(CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS);
if (!flags.areMutuallyExclusive(CL_MEM_HOST_WRITE_ONLY, CL_MEM_HOST_READ_ONLY,
CL_MEM_HOST_NO_ACCESS))
{
return false;
}
}
if (platform.isVersionOrNewer(2u, 0u))
{
allowedFlags.set(CL_MEM_KERNEL_READ_AND_WRITE);
}
if (flags.hasOtherBitsThan(allowedFlags))
{
return false;
}
return true;
}
bool ValidateMapFlags(MapFlags flags, const Platform &platform)
{
MemFlags allowedFlags(CL_MAP_READ | CL_MAP_WRITE);
if (platform.isVersionOrNewer(1u, 2u))
{
// CL_MAP_READ or CL_MAP_WRITE and CL_MAP_WRITE_INVALIDATE_REGION are mutually exclusive.
allowedFlags.set(CL_MAP_WRITE_INVALIDATE_REGION);
if (!flags.areMutuallyExclusive(CL_MAP_WRITE_INVALIDATE_REGION, CL_MAP_READ | CL_MAP_WRITE))
{
return false;
}
}
if (flags.hasOtherBitsThan(allowedFlags))
{
return false;
}
return true;
}
bool ValidateMemoryProperties(const cl_mem_properties *properties)
{
if (properties != nullptr)
{
// OpenCL 3.0 does not define any optional properties.
// This function is reserved for extensions and future use.
if (*properties != 0)
{
return false;
}
}
return true;
}
bool ValidateImageFormat(const cl_image_format *imageFormat, const Platform &platform)
{
if (imageFormat == nullptr)
{
return false;
}
switch (imageFormat->image_channel_order)
{
case CL_R:
case CL_A:
case CL_LUMINANCE:
case CL_INTENSITY:
case CL_RG:
case CL_RA:
case CL_RGB:
case CL_RGBA:
case CL_ARGB:
case CL_BGRA:
break;
case CL_Rx:
case CL_RGx:
case CL_RGBx:
if (!platform.isVersionOrNewer(1u, 1u))
{
return false;
}
break;
case CL_DEPTH:
case CL_ABGR:
case CL_sRGB:
case CL_sRGBA:
case CL_sBGRA:
case CL_sRGBx:
if (!platform.isVersionOrNewer(2u, 0u))
{
return false;
}
break;
default:
return false;
}
switch (imageFormat->image_channel_data_type)
{
case CL_SNORM_INT8:
case CL_SNORM_INT16:
case CL_UNORM_INT8:
case CL_UNORM_INT16:
case CL_SIGNED_INT8:
case CL_SIGNED_INT16:
case CL_SIGNED_INT32:
case CL_UNSIGNED_INT8:
case CL_UNSIGNED_INT16:
case CL_UNSIGNED_INT32:
case CL_HALF_FLOAT:
case CL_FLOAT:
break;
case CL_UNORM_SHORT_565:
case CL_UNORM_SHORT_555:
case CL_UNORM_INT_101010:
if (imageFormat->image_channel_order != CL_RGB &&
imageFormat->image_channel_order != CL_RGBx)
{
return false;
}
break;
case CL_UNORM_INT_101010_2:
if (!platform.isVersionOrNewer(2u, 1u) || imageFormat->image_channel_order != CL_RGBA)
{
return false;
}
break;
default:
return false;
}
return true;
}
cl_int ValidateCommandQueueAndEventWaitList(cl_command_queue commandQueue,
cl_uint numEvents,
const cl_event *events)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(commandQueue))
{
return CL_INVALID_COMMAND_QUEUE;
}
const CommandQueue &queue = commandQueue->cast<CommandQueue>();
if (!queue.isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0,
// or event_wait_list is not NULL and num_events_in_wait_list is 0, ...
if ((events == nullptr) != (numEvents == 0u))
{
return CL_INVALID_EVENT_WAIT_LIST;
}
while (numEvents-- != 0u)
{
// or if event objects in event_wait_list are not valid events.
if (!Event::IsValid(*events))
{
return CL_INVALID_EVENT_WAIT_LIST;
}
// CL_INVALID_CONTEXT if the context associated with command_queue
// and events in event_wait_list are not the same.
if (&queue.getContext() != &(*events++)->cast<Event>().getContext())
{
return CL_INVALID_CONTEXT;
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueBuffer(const CommandQueue &queue,
cl_mem buffer,
bool hostRead,
bool hostWrite)
{
// CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object.
if (!Buffer::IsValid(buffer))
{
return CL_INVALID_MEM_OBJECT;
}
const Buffer &buf = buffer->cast<Buffer>();
// CL_INVALID_CONTEXT if the context associated with command_queue and buffer are not the same.
if (&queue.getContext() != &buf.getContext())
{
return CL_INVALID_CONTEXT;
}
// CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and offset specified
// when the sub-buffer object is created is not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN
// value for device associated with queue.
if (buf.isSubBuffer() &&
(buf.getOffset() % queue.getDevice().getInfo().mMemBaseAddrAlign) != 0u)
{
return CL_MISALIGNED_SUB_BUFFER_OFFSET;
}
// CL_INVALID_OPERATION if a read function is called on buffer which
// has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS.
if (hostRead && buf.getEffectiveFlags().isSet(CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_OPERATION if a write function is called on buffer which
// has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS.
if (hostWrite && buf.getEffectiveFlags().isSet(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS))
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateBufferRect(const Buffer &buffer,
const size_t *origin,
const size_t *region,
size_t rowPitch,
size_t slicePitch)
{
// CL_INVALID_VALUE if origin or region is NULL.
if (origin == nullptr || region == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if any region array element is 0.
if (region[0] == 0u || region[1] == 0u || region[2] == 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if row_pitch is not 0 and is less than region[0].
if (rowPitch == 0u)
{
rowPitch = region[0];
}
else if (rowPitch < region[0])
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if slice_pitch is not 0 and is less than
// region[1] x row_pitch and not a multiple of row_pitch.
if (slicePitch == 0u)
{
slicePitch = region[1] * rowPitch;
}
else if (slicePitch < region[1] * rowPitch || (slicePitch % rowPitch) != 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if the region being read or written specified
// by (origin, region, row_pitch, slice_pitch) is out of bounds.
if (!buffer.isRegionValid(
origin[2] * slicePitch + origin[1] * rowPitch + origin[0],
(region[2] - 1u) * slicePitch + (region[1] - 1u) * rowPitch + region[0]))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateHostRect(const size_t *hostOrigin,
const size_t *region,
size_t hostRowPitch,
size_t hostSlicePitch,
const void *ptr)
{
// CL_INVALID_VALUE if host_origin or region is NULL.
if (hostOrigin == nullptr || region == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if any region array element is 0.
if (region[0] == 0u || region[1] == 0u || region[2] == 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if host_row_pitch is not 0 and is less than region[0].
if (hostRowPitch == 0u)
{
hostRowPitch = region[0];
}
else if (hostRowPitch < region[0])
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if host_slice_pitch is not 0 and is less than
// region[1] x host_row_pitch and not a multiple of host_row_pitch.
if (hostSlicePitch != 0u &&
(hostSlicePitch < region[1] * hostRowPitch || (hostSlicePitch % hostRowPitch) != 0u))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if ptr is NULL.
if (ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
} // namespace
// CL 1.0
cl_int ValidateGetPlatformIDs(cl_uint num_entries,
const cl_platform_id *platforms,
const cl_uint *num_platforms)
{
// CL_INVALID_VALUE if num_entries is equal to zero and platforms is not NULL
// or if both num_platforms and platforms are NULL.
if ((num_entries == 0u && platforms != nullptr) ||
(platforms == nullptr && num_platforms == nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateGetPlatformInfo(cl_platform_id platform,
PlatformInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_PLATFORM if platform is not a valid platform.
if (!Platform::IsValidOrDefault(platform))
{
return CL_INVALID_PLATFORM;
}
// CL_INVALID_VALUE if param_name is not one of the supported values.
const cl_version version = platform->cast<Platform>().getVersion();
switch (param_name)
{
case PlatformInfo::HostTimerResolution:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case PlatformInfo::NumericVersion:
case PlatformInfo::ExtensionsWithVersion:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case PlatformInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetDeviceIDs(cl_platform_id platform,
DeviceType device_type,
cl_uint num_entries,
const cl_device_id *devices,
const cl_uint *num_devices)
{
// CL_INVALID_PLATFORM if platform is not a valid platform.
if (!Platform::IsValidOrDefault(platform))
{
return CL_INVALID_PLATFORM;
}
// CL_INVALID_DEVICE_TYPE if device_type is not a valid value.
if (!Device::IsValidType(device_type))
{
return CL_INVALID_DEVICE_TYPE;
}
// CL_INVALID_VALUE if num_entries is equal to zero and devices is not NULL
// or if both num_devices and devices are NULL.
if ((num_entries == 0u && devices != nullptr) || (num_devices == nullptr && devices == nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateGetDeviceInfo(cl_device_id device,
DeviceInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_DEVICE if device is not a valid device.
if (!Device::IsValid(device))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if param_name is not one of the supported values
// or if param_name is a value that is available as an extension
// and the corresponding extension is not supported by the device.
const cl_version version = device->cast<Device>().getVersion();
// Enums ordered within their version block as they appear in the OpenCL spec V3.0.7, table 5
switch (param_name)
{
case DeviceInfo::PreferredVectorWidthHalf:
case DeviceInfo::NativeVectorWidthChar:
case DeviceInfo::NativeVectorWidthShort:
case DeviceInfo::NativeVectorWidthInt:
case DeviceInfo::NativeVectorWidthLong:
case DeviceInfo::NativeVectorWidthFloat:
case DeviceInfo::NativeVectorWidthDouble:
case DeviceInfo::NativeVectorWidthHalf:
case DeviceInfo::HostUnifiedMemory:
case DeviceInfo::OpenCL_C_Version:
ANGLE_VALIDATE_VERSION(version, 1, 1);
break;
case DeviceInfo::ImageMaxBufferSize:
case DeviceInfo::ImageMaxArraySize:
case DeviceInfo::DoubleFpConfig:
case DeviceInfo::LinkerAvailable:
case DeviceInfo::BuiltInKernels:
case DeviceInfo::PrintfBufferSize:
case DeviceInfo::PreferredInteropUserSync:
case DeviceInfo::ParentDevice:
case DeviceInfo::PartitionMaxSubDevices:
case DeviceInfo::PartitionProperties:
case DeviceInfo::PartitionAffinityDomain:
case DeviceInfo::PartitionType:
case DeviceInfo::ReferenceCount:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case DeviceInfo::MaxReadWriteImageArgs:
case DeviceInfo::ImagePitchAlignment:
case DeviceInfo::ImageBaseAddressAlignment:
case DeviceInfo::MaxPipeArgs:
case DeviceInfo::PipeMaxActiveReservations:
case DeviceInfo::PipeMaxPacketSize:
case DeviceInfo::MaxGlobalVariableSize:
case DeviceInfo::GlobalVariablePreferredTotalSize:
case DeviceInfo::QueueOnDeviceProperties:
case DeviceInfo::QueueOnDevicePreferredSize:
case DeviceInfo::QueueOnDeviceMaxSize:
case DeviceInfo::MaxOnDeviceQueues:
case DeviceInfo::MaxOnDeviceEvents:
case DeviceInfo::SVM_Capabilities:
case DeviceInfo::PreferredPlatformAtomicAlignment:
case DeviceInfo::PreferredGlobalAtomicAlignment:
case DeviceInfo::PreferredLocalAtomicAlignment:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case DeviceInfo::IL_Version:
case DeviceInfo::MaxNumSubGroups:
case DeviceInfo::SubGroupIndependentForwardProgress:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case DeviceInfo::ILsWithVersion:
case DeviceInfo::BuiltInKernelsWithVersion:
case DeviceInfo::NumericVersion:
case DeviceInfo::OpenCL_C_AllVersions:
case DeviceInfo::OpenCL_C_Features:
case DeviceInfo::ExtensionsWithVersion:
case DeviceInfo::AtomicMemoryCapabilities:
case DeviceInfo::AtomicFenceCapabilities:
case DeviceInfo::NonUniformWorkGroupSupport:
case DeviceInfo::WorkGroupCollectiveFunctionsSupport:
case DeviceInfo::GenericAddressSpaceSupport:
case DeviceInfo::DeviceEnqueueCapabilities:
case DeviceInfo::PipeSupport:
case DeviceInfo::PreferredWorkGroupSizeMultiple:
case DeviceInfo::LatestConformanceVersionPassed:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case DeviceInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateCreateContext(const cl_context_properties *properties,
cl_uint num_devices,
const cl_device_id *devices,
void(CL_CALLBACK *pfn_notify)(const char *errinfo,
const void *private_info,
size_t cb,
void *user_data),
const void *user_data)
{
const Platform *platform = nullptr;
const cl_int errorCode = ValidateContextProperties(properties, platform);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_VALUE if devices is NULL or if num_devices is equal to zero
// or if pfn_notify is NULL but user_data is not NULL.
if (devices == nullptr || num_devices == 0u || (pfn_notify == nullptr && user_data != nullptr))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in devices is not a valid device.
while (num_devices-- > 0u)
{
if (!Device::IsValid(*devices) || &(*devices)->cast<Device>().getPlatform() != platform)
{
return CL_INVALID_DEVICE;
}
++devices;
}
return CL_SUCCESS;
}
cl_int ValidateCreateContextFromType(const cl_context_properties *properties,
DeviceType device_type,
void(CL_CALLBACK *pfn_notify)(const char *errinfo,
const void *private_info,
size_t cb,
void *user_data),
const void *user_data)
{
const Platform *platform = nullptr;
const cl_int errorCode = ValidateContextProperties(properties, platform);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_DEVICE_TYPE if device_type is not a valid value.
if (!Device::IsValidType(device_type))
{
return CL_INVALID_DEVICE_TYPE;
}
// CL_INVALID_VALUE if pfn_notify is NULL but user_data is not NULL.
if (pfn_notify == nullptr && user_data != nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainContext(cl_context context)
{
// CL_INVALID_CONTEXT if context is not a valid OpenCL context.
return Context::IsValid(context) ? CL_SUCCESS : CL_INVALID_CONTEXT;
}
cl_int ValidateReleaseContext(cl_context context)
{
// CL_INVALID_CONTEXT if context is not a valid OpenCL context.
return Context::IsValid(context) ? CL_SUCCESS : CL_INVALID_CONTEXT;
}
cl_int ValidateGetContextInfo(cl_context context,
ContextInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if param_name is not one of the supported values.
if (param_name == ContextInfo::InvalidEnum)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainCommandQueue(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
return CommandQueue::IsValid(command_queue) ? CL_SUCCESS : CL_INVALID_COMMAND_QUEUE;
}
cl_int ValidateReleaseCommandQueue(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
return CommandQueue::IsValid(command_queue) ? CL_SUCCESS : CL_INVALID_COMMAND_QUEUE;
}
cl_int ValidateGetCommandQueueInfo(cl_command_queue command_queue,
CommandQueueInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue ...
if (!CommandQueue::IsValid(command_queue))
{
return CL_INVALID_COMMAND_QUEUE;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// or if command_queue is not a valid command-queue for param_name.
if (param_name == CommandQueueInfo::Size && queue.isOnDevice())
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_VALUE if param_name is not one of the supported values.
const cl_version version = queue.getDevice().getVersion();
switch (param_name)
{
case CommandQueueInfo::Size:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case CommandQueueInfo::DeviceDefault:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case CommandQueueInfo::PropertiesArray:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case CommandQueueInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateCreateBuffer(cl_context context, MemFlags flags, size_t size, const void *host_ptr)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if values specified in flags are not valid
// as defined in the Memory Flags table.
if (!ValidateMemoryFlags(flags, ctx.getPlatform()))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_BUFFER_SIZE if size is 0 ...
if (size == 0u)
{
CL_INVALID_BUFFER_SIZE;
}
for (const DevicePtr &device : ctx.getDevices())
{
// or if size is greater than CL_DEVICE_MAX_MEM_ALLOC_SIZE for all devices in context.
if (size > device->getInfo().mMaxMemAllocSize)
{
return CL_INVALID_BUFFER_SIZE;
}
}
// CL_INVALID_HOST_PTR
// if host_ptr is NULL and CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are set in flags or
// if host_ptr is not NULL but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags.
if ((host_ptr != nullptr) != flags.isSet(CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return CL_INVALID_HOST_PTR;
}
return CL_SUCCESS;
}
cl_int ValidateRetainMemObject(cl_mem memobj)
{
// CL_INVALID_MEM_OBJECT if memobj is not a valid memory object.
return Memory::IsValid(memobj) ? CL_SUCCESS : CL_INVALID_MEM_OBJECT;
}
cl_int ValidateReleaseMemObject(cl_mem memobj)
{
// CL_INVALID_MEM_OBJECT if memobj is not a valid memory object.
return Memory::IsValid(memobj) ? CL_SUCCESS : CL_INVALID_MEM_OBJECT;
}
cl_int ValidateGetSupportedImageFormats(cl_context context,
MemFlags flags,
MemObjectType image_type,
cl_uint num_entries,
const cl_image_format *image_formats,
const cl_uint *num_image_formats)
{
return CL_SUCCESS;
}
cl_int ValidateGetMemObjectInfo(cl_mem memobj,
MemInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_MEM_OBJECT if memobj is a not a valid memory object.
if (!Memory::IsValid(memobj))
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = memobj->cast<Memory>().getContext().getPlatform().getVersion();
switch (param_name)
{
case MemInfo::AssociatedMemObject:
case MemInfo::Offset:
ANGLE_VALIDATE_VERSION(version, 1, 1);
break;
case MemInfo::UsesSVM_Pointer:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case MemInfo::Properties:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case MemInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetImageInfo(cl_mem image,
ImageInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_MEM_OBJECT if image is a not a valid image object.
if (!Image::IsValid(image))
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = image->cast<Image>().getContext().getPlatform().getVersion();
switch (param_name)
{
case ImageInfo::ArraySize:
case ImageInfo::Buffer:
case ImageInfo::NumMipLevels:
case ImageInfo::NumSamples:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case ImageInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateRetainSampler(cl_sampler sampler)
{
// CL_INVALID_SAMPLER if sampler is not a valid sampler object.
return Sampler::IsValid(sampler) ? CL_SUCCESS : CL_INVALID_SAMPLER;
}
cl_int ValidateReleaseSampler(cl_sampler sampler)
{
// CL_INVALID_SAMPLER if sampler is not a valid sampler object.
return Sampler::IsValid(sampler) ? CL_SUCCESS : CL_INVALID_SAMPLER;
}
cl_int ValidateGetSamplerInfo(cl_sampler sampler,
SamplerInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_SAMPLER if sampler is a not a valid sampler object.
if (!Sampler::IsValid(sampler))
{
return CL_INVALID_SAMPLER;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = sampler->cast<Sampler>().getContext().getPlatform().getVersion();
switch (param_name)
{
case SamplerInfo::Properties:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case SamplerInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithSource(cl_context context,
cl_uint count,
const char **strings,
const size_t *lengths)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if count is zero or if strings or any entry in strings is NULL.
if (count == 0u || strings == nullptr)
{
return CL_INVALID_VALUE;
}
while (count-- != 0u)
{
if (*strings++ == nullptr)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithBinary(cl_context context,
cl_uint num_devices,
const cl_device_id *device_list,
const size_t *lengths,
const unsigned char **binaries,
const cl_int *binary_status)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if device_list is NULL or num_devices is zero.
// CL_INVALID_VALUE if lengths or binaries is NULL.
if (device_list == nullptr || num_devices == 0u || lengths == nullptr || binaries == nullptr)
{
return CL_INVALID_VALUE;
}
while (num_devices-- != 0u)
{
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with context.
if (!ctx.hasDevice(*device_list++))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if any entry in lengths[i] is zero or binaries[i] is NULL.
if (*lengths++ == 0u || *binaries++ == nullptr)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateRetainProgram(cl_program program)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
return Program::IsValid(program) ? CL_SUCCESS : CL_INVALID_PROGRAM;
}
cl_int ValidateReleaseProgram(cl_program program)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
return Program::IsValid(program) ? CL_SUCCESS : CL_INVALID_PROGRAM;
}
cl_int ValidateBuildProgram(cl_program program,
cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateGetProgramInfo(cl_program program,
ProgramInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_PROGRAM if program is a not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = program->cast<Program>().getContext().getPlatform().getVersion();
switch (param_name)
{
case ProgramInfo::NumKernels:
case ProgramInfo::KernelNames:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case ProgramInfo::IL:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case ProgramInfo::ScopeGlobalCtorsPresent:
case ProgramInfo::ScopeGlobalDtorsPresent:
ANGLE_VALIDATE_VERSION(version, 2, 2);
break;
case ProgramInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetProgramBuildInfo(cl_program program,
cl_device_id device,
ProgramBuildInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
return CL_SUCCESS;
}
cl_int ValidateCreateKernel(cl_program program, const char *kernel_name)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
// CL_INVALID_VALUE if kernel_name is NULL.
if (kernel_name == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateKernelsInProgram(cl_program program,
cl_uint num_kernels,
const cl_kernel *kernels,
const cl_uint *num_kernels_ret)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
return CL_SUCCESS;
}
cl_int ValidateRetainKernel(cl_kernel kernel)
{
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
return Kernel::IsValid(kernel) ? CL_SUCCESS : CL_INVALID_KERNEL;
}
cl_int ValidateReleaseKernel(cl_kernel kernel)
{
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
return Kernel::IsValid(kernel) ? CL_SUCCESS : CL_INVALID_KERNEL;
}
cl_int ValidateSetKernelArg(cl_kernel kernel,
cl_uint arg_index,
size_t arg_size,
const void *arg_value)
{
return CL_SUCCESS;
}
cl_int ValidateGetKernelInfo(cl_kernel kernel,
KernelInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_KERNEL if kernel is a not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version =
kernel->cast<Kernel>().getProgram().getContext().getPlatform().getVersion();
switch (param_name)
{
case KernelInfo::Attributes:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case KernelInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetKernelWorkGroupInfo(cl_kernel kernel,
cl_device_id device,
KernelWorkGroupInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_KERNEL if kernel is a not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
const Kernel &krnl = kernel->cast<Kernel>();
const Device *dev = nullptr;
if (device != nullptr)
{
// CL_INVALID_DEVICE if device is not in the list of devices associated with kernel ...
if (krnl.getProgram().getContext().hasDevice(device))
{
dev = &device->cast<Device>();
}
else
{
return CL_INVALID_DEVICE;
}
}
else
{
// or if device is NULL but there is more than one device associated with kernel.
if (krnl.getProgram().getContext().getDevices().size() == 1u)
{
dev = krnl.getProgram().getContext().getDevices().front().get();
}
else
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = krnl.getProgram().getContext().getPlatform().getInfo().mVersion;
switch (param_name)
{
case KernelWorkGroupInfo::GlobalWorkSize:
ANGLE_VALIDATE_VERSION(version, 1, 2);
// CL_INVALID_VALUE if param_name is CL_KERNEL_GLOBAL_WORK_SIZE and
// device is not a custom device and kernel is not a built-in kernel.
if (!dev->supportsBuiltInKernel(krnl.getInfo().mFunctionName))
{
return CL_INVALID_VALUE;
}
break;
case KernelWorkGroupInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateWaitForEvents(cl_uint num_events, const cl_event *event_list)
{
// CL_INVALID_VALUE if num_events is zero or event_list is NULL.
if (num_events == 0u || event_list == nullptr)
{
return CL_INVALID_VALUE;
}
const Context *context = nullptr;
while (num_events-- != 0u)
{
// CL_INVALID_EVENT if event objects specified in event_list are not valid event objects.
if (!Event::IsValid(*event_list))
{
return CL_INVALID_EVENT;
}
// CL_INVALID_CONTEXT if events specified in event_list do not belong to the same context.
const Context *eventContext = &(*event_list++)->cast<Event>().getContext();
if (context == nullptr)
{
context = eventContext;
}
else if (context != eventContext)
{
return CL_INVALID_CONTEXT;
}
}
return CL_SUCCESS;
}
cl_int ValidateGetEventInfo(cl_event event,
EventInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_EVENT if event is a not a valid event object.
if (!Event::IsValid(event))
{
return CL_INVALID_EVENT;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = event->cast<Event>().getContext().getPlatform().getVersion();
switch (param_name)
{
case EventInfo::Context:
ANGLE_VALIDATE_VERSION(version, 1, 1);
break;
case EventInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateRetainEvent(cl_event event)
{
// CL_INVALID_EVENT if event is not a valid event object.
return Event::IsValid(event) ? CL_SUCCESS : CL_INVALID_EVENT;
}
cl_int ValidateReleaseEvent(cl_event event)
{
// CL_INVALID_EVENT if event is not a valid event object.
return Event::IsValid(event) ? CL_SUCCESS : CL_INVALID_EVENT;
}
cl_int ValidateGetEventProfilingInfo(cl_event event,
ProfilingInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
return CL_SUCCESS;
}
cl_int ValidateFlush(cl_command_queue command_queue)
{
return CL_SUCCESS;
}
cl_int ValidateFinish(cl_command_queue command_queue)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueReadBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_read,
size_t offset,
size_t size,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateEnqueueBuffer(command_queue->cast<CommandQueue>(), buffer, true, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_VALUE if the region being read or written specified
// by (offset, size) is out of bounds or if ptr is a NULL value.
if (!buffer->cast<Buffer>().isRegionValid(offset, size) || ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueWriteBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_write,
size_t offset,
size_t size,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateEnqueueBuffer(command_queue->cast<CommandQueue>(), buffer, false, true);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_VALUE if the region being read or written specified
// by (offset, size) is out of bounds or if ptr is a NULL value.
if (!buffer->cast<Buffer>().isRegionValid(offset, size) || ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyBuffer(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_buffer,
size_t src_offset,
size_t dst_offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
errorCode = ValidateEnqueueBuffer(queue, src_buffer, false, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const Buffer &src = src_buffer->cast<Buffer>();
errorCode = ValidateEnqueueBuffer(queue, dst_buffer, false, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const Buffer &dst = dst_buffer->cast<Buffer>();
// CL_INVALID_VALUE if src_offset, dst_offset, size, src_offset + size or dst_offset + size
// require accessing elements outside the src_buffer and dst_buffer buffer objects respectively.
if (!src.isRegionValid(src_offset, size) || !dst.isRegionValid(dst_offset, size))
{
return CL_INVALID_VALUE;
}
// CL_MEM_COPY_OVERLAP if src_buffer and dst_buffer are the same buffer or sub-buffer object
// and the source and destination regions overlap or if src_buffer and dst_buffer are
// different sub-buffers of the same associated buffer object and they overlap.
if ((src.isSubBuffer() ? src.getParent().get() : &src) ==
(dst.isSubBuffer() ? dst.getParent().get() : &dst))
{
// Only sub-buffers have offsets larger than zero
src_offset += src.getOffset();
dst_offset += dst.getOffset();
// The regions overlap if src_offset <= dst_offset <= src_offset + size - 1
// or if dst_offset <= src_offset <= dst_offset + size - 1.
if ((src_offset <= dst_offset && dst_offset <= src_offset + size - 1u) ||
(dst_offset <= src_offset && src_offset <= dst_offset + size - 1u))
{
return CL_MEM_COPY_OVERLAP;
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueReadImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_read,
const size_t *origin,
const size_t *region,
size_t row_pitch,
size_t slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueWriteImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_write,
const size_t *origin,
const size_t *region,
size_t input_row_pitch,
size_t input_slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyImage(cl_command_queue command_queue,
cl_mem src_image,
cl_mem dst_image,
const size_t *src_origin,
const size_t *dst_origin,
const size_t *region,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyImageToBuffer(cl_command_queue command_queue,
cl_mem src_image,
cl_mem dst_buffer,
const size_t *src_origin,
const size_t *region,
size_t dst_offset,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyBufferToImage(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_image,
size_t src_offset,
const size_t *dst_origin,
const size_t *region,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueMapBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_map,
MapFlags map_flags,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// CL_INVALID_OPERATION if buffer has been created with CL_MEM_HOST_WRITE_ONLY or
// CL_MEM_HOST_NO_ACCESS and CL_MAP_READ is set in map_flags
// or if buffer has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS
// and CL_MAP_WRITE or CL_MAP_WRITE_INVALIDATE_REGION is set in map_flags.
errorCode =
ValidateEnqueueBuffer(queue, buffer, map_flags.isSet(CL_MAP_READ),
map_flags.isSet(CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION));
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_VALUE if region being mapped given by (offset, size) is out of bounds
// or if size is 0 or if values specified in map_flags are not valid.
if (!buffer->cast<Buffer>().isRegionValid(offset, size) || size == 0u ||
!ValidateMapFlags(map_flags, queue.getContext().getPlatform()))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueMapImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_map,
MapFlags map_flags,
const size_t *origin,
const size_t *region,
const size_t *image_row_pitch,
const size_t *image_slice_pitch,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueUnmapMemObject(cl_command_queue command_queue,
cl_mem memobj,
const void *mapped_ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueNDRangeKernel(cl_command_queue command_queue,
cl_kernel kernel,
cl_uint work_dim,
const size_t *global_work_offset,
const size_t *global_work_size,
const size_t *local_work_size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueNativeKernel(cl_command_queue command_queue,
void(CL_CALLBACK *user_func)(void *),
const void *args,
size_t cb_args,
cl_uint num_mem_objects,
const cl_mem *mem_list,
const void **args_mem_loc,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateSetCommandQueueProperty(cl_command_queue command_queue,
CommandQueueProperties properties,
cl_bool enable,
const cl_command_queue_properties *old_properties)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
if (!CommandQueue::IsValid(command_queue))
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_VALUE if values specified in properties are not valid.
if (properties.hasOtherBitsThan(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
CL_QUEUE_PROFILING_ENABLE))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateImage2D(cl_context context,
MemFlags flags,
const cl_image_format *image_format,
size_t image_width,
size_t image_height,
size_t image_row_pitch,
const void *host_ptr)
{
const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, image_width, image_height, 0u, 0u,
image_row_pitch, 0u, 0u, 0u, {nullptr}};
return ValidateCreateImage(context, flags, image_format, &desc, host_ptr);
}
cl_int ValidateCreateImage3D(cl_context context,
MemFlags flags,
const cl_image_format *image_format,
size_t image_width,
size_t image_height,
size_t image_depth,
size_t image_row_pitch,
size_t image_slice_pitch,
const void *host_ptr)
{
const cl_image_desc desc = {
CL_MEM_OBJECT_IMAGE3D, image_width, image_height, image_depth, 0u,
image_row_pitch, image_slice_pitch, 0u, 0u, {nullptr}};
return ValidateCreateImage(context, flags, image_format, &desc, host_ptr);
}
cl_int ValidateEnqueueMarker(cl_command_queue command_queue, const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueWaitForEvents(cl_command_queue command_queue,
cl_uint num_events,
const cl_event *event_list)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueBarrier(cl_command_queue command_queue)
{
return CL_SUCCESS;
}
cl_int ValidateUnloadCompiler()
{
return CL_SUCCESS;
}
cl_int ValidateGetExtensionFunctionAddress(const char *func_name)
{
return func_name != nullptr && *func_name != '\0' ? CL_SUCCESS : CL_INVALID_VALUE;
}
cl_int ValidateCreateCommandQueue(cl_context context,
cl_device_id device,
CommandQueueProperties properties)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_DEVICE if device is not a valid device or is not associated with context.
if (!context->cast<Context>().hasDevice(device))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if values specified in properties are not valid.
if (properties.hasOtherBitsThan(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
CL_QUEUE_PROFILING_ENABLE))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateSampler(cl_context context,
cl_bool normalized_coords,
AddressingMode addressing_mode,
FilterMode filter_mode)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if addressing_mode, filter_mode, normalized_coords
// or a combination of these arguements are not valid.
if ((normalized_coords != CL_FALSE && normalized_coords != CL_TRUE) ||
addressing_mode == AddressingMode::InvalidEnum || filter_mode == FilterMode::InvalidEnum)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_OPERATION if images are not supported by any device associated with context.
if (!context->cast<Context>().supportsImages())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueTask(cl_command_queue command_queue,
cl_kernel kernel,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
// CL 1.1
cl_int ValidateCreateSubBuffer(cl_mem buffer,
MemFlags flags,
cl_buffer_create_type buffer_create_type,
const void *buffer_create_info)
{
// CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object or is a sub-buffer object.
if (!Buffer::IsValid(buffer))
{
return CL_INVALID_MEM_OBJECT;
}
const Buffer &buf = buffer->cast<Buffer>();
if (buf.isSubBuffer() || !buf.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_MEM_OBJECT;
}
if (!ValidateMemoryFlags(flags, buf.getContext().getPlatform()))
{
return CL_INVALID_VALUE;
}
const MemFlags bufFlags = buf.getFlags();
// CL_INVALID_VALUE if buffer was created with CL_MEM_WRITE_ONLY
// and flags specifies CL_MEM_READ_WRITE or CL_MEM_READ_ONLY,
if ((bufFlags.isSet(CL_MEM_WRITE_ONLY) && flags.isSet(CL_MEM_READ_WRITE | CL_MEM_READ_ONLY)) ||
// or if buffer was created with CL_MEM_READ_ONLY
// and flags specifies CL_MEM_READ_WRITE or CL_MEM_WRITE_ONLY,
(bufFlags.isSet(CL_MEM_READ_ONLY) && flags.isSet(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) ||
// or if flags specifies CL_MEM_USE_HOST_PTR, CL_MEM_ALLOC_HOST_PTR or CL_MEM_COPY_HOST_PTR.
flags.isSet(CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if buffer was created with CL_MEM_HOST_WRITE_ONLY
// and flags specify CL_MEM_HOST_READ_ONLY,
if ((bufFlags.isSet(CL_MEM_HOST_WRITE_ONLY) && flags.isSet(CL_MEM_HOST_READ_ONLY)) ||
// or if buffer was created with CL_MEM_HOST_READ_ONLY
// and flags specify CL_MEM_HOST_WRITE_ONLY,
(bufFlags.isSet(CL_MEM_HOST_READ_ONLY) && flags.isSet(CL_MEM_HOST_WRITE_ONLY)) ||
// or if buffer was created with CL_MEM_HOST_NO_ACCESS
// and flags specify CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_WRITE_ONLY.
(bufFlags.isSet(CL_MEM_HOST_NO_ACCESS) &&
flags.isSet(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY)))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if the value specified in buffer_create_type is not valid.
if (buffer_create_type != CL_BUFFER_CREATE_TYPE_REGION)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if value(s) specified in buffer_create_info
// (for a given buffer_create_type) is not valid or if buffer_create_info is NULL.
// CL_INVALID_VALUE if the region specified by the cl_buffer_region structure
// passed in buffer_create_info is out of bounds in buffer.
const cl_buffer_region *region = static_cast<const cl_buffer_region *>(buffer_create_info);
if (region == nullptr || !buf.isRegionValid(*region))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_BUFFER_SIZE if the size field of the cl_buffer_region structure
// passed in buffer_create_info is 0.
if (region->size == 0u)
{
return CL_INVALID_BUFFER_SIZE;
}
return CL_SUCCESS;
}
cl_int ValidateSetMemObjectDestructorCallback(cl_mem memobj,
void(CL_CALLBACK *pfn_notify)(cl_mem memobj,
void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateCreateUserEvent(cl_context context)
{
// CL_INVALID_CONTEXT if context is not a valid context.
return Context::IsValidAndVersionOrNewer(context, 1u, 1u) ? CL_SUCCESS : CL_INVALID_CONTEXT;
}
cl_int ValidateSetUserEventStatus(cl_event event, cl_int execution_status)
{
// CL_INVALID_EVENT if event is not a valid user event object.
if (!Event::IsValid(event))
{
return CL_INVALID_EVENT;
}
const Event &evt = event->cast<Event>();
if (!evt.getContext().getPlatform().isVersionOrNewer(1u, 1u) ||
evt.getCommandType() != CL_COMMAND_USER)
{
return CL_INVALID_EVENT;
}
// CL_INVALID_VALUE if the execution_status is not CL_COMPLETE or a negative integer value.
if (execution_status != CL_COMPLETE && execution_status >= 0)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_OPERATION if the execution_status for event has already been changed
// by a previous call to clSetUserEventStatus.
if (evt.wasStatusChanged())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateSetEventCallback(cl_event event,
cl_int command_exec_callback_type,
void(CL_CALLBACK *pfn_notify)(cl_event event,
cl_int event_command_status,
void *user_data),
const void *user_data)
{
// CL_INVALID_EVENT if event is not a valid event object.
if (!Event::IsValid(event) ||
!event->cast<Event>().getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_EVENT;
}
// CL_INVALID_VALUE if pfn_event_notify is NULL
// or if command_exec_callback_type is not CL_SUBMITTED, CL_RUNNING, or CL_COMPLETE.
if (pfn_notify == nullptr ||
(command_exec_callback_type != CL_SUBMITTED && command_exec_callback_type != CL_RUNNING &&
command_exec_callback_type != CL_COMPLETE))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueReadBufferRect(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_read,
const size_t *buffer_origin,
const size_t *host_origin,
const size_t *region,
size_t buffer_row_pitch,
size_t buffer_slice_pitch,
size_t host_row_pitch,
size_t host_slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_COMMAND_QUEUE;
}
errorCode = ValidateEnqueueBuffer(queue, buffer, true, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateBufferRect(buffer->cast<Buffer>(), buffer_origin, region, buffer_row_pitch,
buffer_slice_pitch);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateHostRect(host_origin, region, host_row_pitch, host_slice_pitch, ptr);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueWriteBufferRect(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_write,
const size_t *buffer_origin,
const size_t *host_origin,
const size_t *region,
size_t buffer_row_pitch,
size_t buffer_slice_pitch,
size_t host_row_pitch,
size_t host_slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_COMMAND_QUEUE;
}
errorCode = ValidateEnqueueBuffer(queue, buffer, false, true);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateBufferRect(buffer->cast<Buffer>(), buffer_origin, region, buffer_row_pitch,
buffer_slice_pitch);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateHostRect(host_origin, region, host_row_pitch, host_slice_pitch, ptr);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyBufferRect(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_buffer,
const size_t *src_origin,
const size_t *dst_origin,
const size_t *region,
size_t src_row_pitch,
size_t src_slice_pitch,
size_t dst_row_pitch,
size_t dst_slice_pitch,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_COMMAND_QUEUE;
}
errorCode = ValidateEnqueueBuffer(queue, src_buffer, false, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const Buffer &src = src_buffer->cast<Buffer>();
errorCode = ValidateEnqueueBuffer(queue, dst_buffer, false, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const Buffer &dst = dst_buffer->cast<Buffer>();
errorCode = ValidateBufferRect(src, src_origin, region, src_row_pitch, src_slice_pitch);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
errorCode = ValidateBufferRect(dst, dst_origin, region, dst_row_pitch, dst_slice_pitch);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_VALUE if src_buffer and dst_buffer are the same buffer object and src_slice_pitch
// is not equal to dst_slice_pitch or src_row_pitch is not equal to dst_row_pitch.
if (&src == &dst && (src_slice_pitch != dst_slice_pitch || src_row_pitch != dst_row_pitch))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
// CL 1.2
cl_int ValidateCreateSubDevices(cl_device_id in_device,
const cl_device_partition_property *properties,
cl_uint num_devices,
const cl_device_id *out_devices,
const cl_uint *num_devices_ret)
{
// CL_INVALID_DEVICE if in_device is not a valid device.
if (!Device::IsValid(in_device))
{
return CL_INVALID_DEVICE;
}
const Device &device = in_device->cast<Device>();
if (!device.isVersionOrNewer(1u, 2u))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if values specified in properties are not valid
// or if values specified in properties are valid but not supported by the device
const std::vector<cl_device_partition_property> &devProps =
device.getInfo().mPartitionProperties;
if (properties == nullptr ||
std::find(devProps.cbegin(), devProps.cend(), *properties) == devProps.cend())
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainDevice(cl_device_id device)
{
// CL_INVALID_DEVICE if device is not a valid device.
if (!Device::IsValid(device) || !device->cast<Device>().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_DEVICE;
}
return CL_SUCCESS;
}
cl_int ValidateReleaseDevice(cl_device_id device)
{
// CL_INVALID_DEVICE if device is not a valid device.
if (!Device::IsValid(device) || !device->cast<Device>().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_DEVICE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateImage(cl_context context,
MemFlags flags,
const cl_image_format *image_format,
const cl_image_desc *image_desc,
const void *host_ptr)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 1u, 2u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if values specified in flags are not valid.
if (!ValidateMemoryFlags(flags, ctx.getPlatform()))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in image_format are not valid
// or if image_format is NULL.
if (!ValidateImageFormat(image_format, ctx.getPlatform()))
{
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
}
// CL_INVALID_IMAGE_DESCRIPTOR if image_desc is NULL.
if (image_desc == nullptr)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
const size_t elemSize = GetElementSize(*image_format);
if (elemSize == 0u)
{
ASSERT(false);
ERR() << "Failed to calculate image element size";
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
}
const size_t rowPitch = image_desc->image_row_pitch != 0u ? image_desc->image_row_pitch
: image_desc->image_width * elemSize;
const size_t imageHeight =
image_desc->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ? 1u : image_desc->image_height;
const size_t sliceSize = imageHeight * rowPitch;
// CL_INVALID_IMAGE_DESCRIPTOR if values specified in image_desc are not valid.
switch (image_desc->image_type)
{
case CL_MEM_OBJECT_IMAGE1D:
if (image_desc->image_width == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case CL_MEM_OBJECT_IMAGE2D:
if (image_desc->image_width == 0u || image_desc->image_height == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case CL_MEM_OBJECT_IMAGE3D:
if (image_desc->image_width == 0u || image_desc->image_height == 0u ||
image_desc->image_depth == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
if (image_desc->image_width == 0u || image_desc->image_array_size == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
if (image_desc->image_width == 0u || image_desc->image_height == 0u ||
image_desc->image_array_size == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
if (image_desc->image_width == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
default:
return CL_INVALID_IMAGE_DESCRIPTOR;
}
if (image_desc->image_row_pitch != 0u)
{
// image_row_pitch must be 0 if host_ptr is NULL.
if (host_ptr == nullptr)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// image_row_pitch can be either 0
// or >= image_width * size of element in bytes if host_ptr is not NULL.
if (image_desc->image_row_pitch < image_desc->image_width * elemSize)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// If image_row_pitch is not 0, it must be a multiple of the image element size in bytes.
if ((image_desc->image_row_pitch % elemSize) != 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
}
if (image_desc->image_slice_pitch != 0u)
{
// image_slice_pitch must be 0 if host_ptr is NULL.
if (host_ptr == nullptr)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// If host_ptr is not NULL, image_slice_pitch can be either 0
// or >= image_row_pitch * image_height for a 2D image array or 3D image
// and can be either 0 or >= image_row_pitch for a 1D image array.
if (image_desc->image_slice_pitch < sliceSize)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// If image_slice_pitch is not 0, it must be a multiple of the image_row_pitch.
if ((image_desc->image_slice_pitch % rowPitch) != 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
}
// num_mip_levels and num_samples must be 0.
if (image_desc->num_mip_levels != 0u || image_desc->num_samples != 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// buffer can be a buffer memory object if image_type is CL_MEM_OBJECT_IMAGE1D_BUFFER or
// CL_MEM_OBJECT_IMAGE2D. buffer can be an image object if image_type is CL_MEM_OBJECT_IMAGE2D.
// Otherwise it must be NULL.
if (image_desc->buffer != nullptr &&
(!Buffer::IsValid(image_desc->buffer) ||
(image_desc->image_type != CL_MEM_OBJECT_IMAGE1D_BUFFER &&
image_desc->image_type != CL_MEM_OBJECT_IMAGE2D)) &&
(!Image::IsValid(image_desc->buffer) || image_desc->image_type != CL_MEM_OBJECT_IMAGE2D))
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// CL_INVALID_OPERATION if there are no devices in context that support images.
if (!ctx.supportsImages())
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_IMAGE_SIZE if image dimensions specified in image_desc exceed the maximum
// image dimensions described in the Device Queries table for all devices in context.
const DevicePtrs &devices = ctx.getDevices();
if (std::find_if(devices.cbegin(), devices.cend(), [&](const DevicePtr &ptr) {
switch (image_desc->image_type)
{
case CL_MEM_OBJECT_IMAGE1D:
return image_desc->image_width <= ptr->getInfo().mImage2D_MaxWidth;
case CL_MEM_OBJECT_IMAGE2D:
return image_desc->image_width <= ptr->getInfo().mImage2D_MaxWidth &&
image_desc->image_height <= ptr->getInfo().mImage2D_MaxHeight;
case CL_MEM_OBJECT_IMAGE3D:
return image_desc->image_width <= ptr->getInfo().mImage3D_MaxWidth &&
image_desc->image_height <= ptr->getInfo().mImage3D_MaxHeight &&
image_desc->image_depth <= ptr->getInfo().mImage3D_MaxDepth;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
return image_desc->image_width <= ptr->getInfo().mImage2D_MaxWidth &&
image_desc->image_array_size <= ptr->getInfo().mImageMaxArraySize;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
return image_desc->image_width <= ptr->getInfo().mImage2D_MaxWidth &&
image_desc->image_height <= ptr->getInfo().mImage2D_MaxHeight &&
image_desc->image_array_size <= ptr->getInfo().mImageMaxArraySize;
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
return image_desc->image_width <= ptr->getInfo().mImageMaxBufferSize;
default:
ASSERT(false);
break;
}
return false;
}) == devices.cend())
{
return CL_INVALID_IMAGE_SIZE;
}
// CL_INVALID_HOST_PTR
// if host_ptr is NULL and CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are set in flags or
// if host_ptr is not NULL but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags.
if ((host_ptr != nullptr) != flags.isSet(CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return CL_INVALID_HOST_PTR;
}
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithBuiltInKernels(cl_context context,
cl_uint num_devices,
const cl_device_id *device_list,
const char *kernel_names)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 1u, 2u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if device_list is NULL or num_devices is zero or if kernel_names is NULL.
if (device_list == nullptr || num_devices == 0u || kernel_names == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with context.
for (size_t index = 0u; index < num_devices; ++index)
{
if (!ctx.hasDevice(device_list[index]))
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if kernel_names contains a kernel name
// that is not supported by any of the devices in device_list.
const char *start = kernel_names;
do
{
const char *end = start;
while (*end != '\0' && *end != ';')
{
++end;
}
const size_t length = end - start;
if (length != 0u && !ctx.supportsBuiltInKernel(std::string(start, length)))
{
return CL_INVALID_VALUE;
}
start = end;
} while (*start++ != '\0');
return CL_SUCCESS;
}
cl_int ValidateCompileProgram(cl_program program,
cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
cl_uint num_input_headers,
const cl_program *input_headers,
const char **header_include_names,
void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateLinkProgram(cl_context context,
cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
cl_uint num_input_programs,
const cl_program *input_programs,
void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateUnloadPlatformCompiler(cl_platform_id platform)
{
return CL_SUCCESS;
}
cl_int ValidateGetKernelArgInfo(cl_kernel kernel,
cl_uint arg_index,
KernelArgInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_KERNEL if kernel is a not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
const Kernel &krnl = kernel->cast<Kernel>();
if (!krnl.getProgram().getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_KERNEL;
}
// CL_INVALID_ARG_INDEX if arg_index is not a valid argument index.
if (arg_index >= krnl.getInfo().mArgs.size())
{
return CL_INVALID_ARG_INDEX;
}
// CL_KERNEL_ARG_INFO_NOT_AVAILABLE if the argument information is not available for kernel.
if (!krnl.getInfo().mArgs[arg_index].isAvailable())
{
return CL_KERNEL_ARG_INFO_NOT_AVAILABLE;
}
// CL_INVALID_VALUE if param_name is not valid.
if (param_name == KernelArgInfo::InvalidEnum)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueFillBuffer(cl_command_queue command_queue,
cl_mem buffer,
const void *pattern,
size_t pattern_size,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
cl_int errorCode = ValidateCommandQueueAndEventWaitList(command_queue, num_events_in_wait_list,
event_wait_list);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_COMMAND_QUEUE;
}
errorCode = ValidateEnqueueBuffer(queue, buffer, false, false);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_VALUE if offset or offset + size require accessing
// elements outside the buffer object respectively.
if (!buffer->cast<Buffer>().isRegionValid(offset, size))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if pattern is NULL or if pattern_size is 0 or
// if pattern_size is not one of { 1, 2, 4, 8, 16, 32, 64, 128 }.
if (pattern == nullptr || pattern_size == 0u || pattern_size > 128u ||
(pattern_size & (pattern_size - 1u)) != 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if offset and size are not a multiple of pattern_size.
if ((offset % pattern_size) != 0u || (size % pattern_size) != 0u)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueFillImage(cl_command_queue command_queue,
cl_mem image,
const void *fill_color,
const size_t *origin,
const size_t *region,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueMigrateMemObjects(cl_command_queue command_queue,
cl_uint num_mem_objects,
const cl_mem *mem_objects,
MemMigrationFlags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueMarkerWithWaitList(cl_command_queue command_queue,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueBarrierWithWaitList(cl_command_queue command_queue,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateGetExtensionFunctionAddressForPlatform(cl_platform_id platform,
const char *func_name)
{
if (!Platform::IsValid(platform) || func_name == nullptr || *func_name == '\0')
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
// CL 2.0
cl_int ValidateCreateCommandQueueWithProperties(cl_context context,
cl_device_id device,
const cl_queue_properties *properties)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 2u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_DEVICE if device is not a valid device or is not associated with context.
if (!context->cast<Context>().hasDevice(device) ||
!device->cast<Device>().isVersionOrNewer(2u, 0u))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if values specified in properties are not valid.
if (properties != nullptr)
{
bool isQueueOnDevice = false;
bool hasQueueSize = false;
while (*properties != 0)
{
switch (*properties++)
{
case CL_QUEUE_PROPERTIES:
{
const CommandQueueProperties props(*properties++);
const CommandQueueProperties validProps(
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE |
CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT);
if (props.hasOtherBitsThan(validProps) ||
// If CL_QUEUE_ON_DEVICE is set, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
// must also be set.
(props.isSet(CL_QUEUE_ON_DEVICE) &&
!props.isSet(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)) ||
// CL_QUEUE_ON_DEVICE_DEFAULT can only be used with CL_QUEUE_ON_DEVICE.
(props.isSet(CL_QUEUE_ON_DEVICE_DEFAULT) &&
!props.isSet(CL_QUEUE_ON_DEVICE)))
{
return CL_INVALID_VALUE;
}
isQueueOnDevice = props.isSet(CL_QUEUE_ON_DEVICE);
break;
}
case CL_QUEUE_SIZE:
{
// CL_QUEUE_SIZE must be a value <= CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE.
if (*properties++ > device->cast<Device>().getInfo().mQueueOnDeviceMaxSize)
{
return CL_INVALID_VALUE;
}
hasQueueSize = true;
break;
}
default:
return CL_INVALID_VALUE;
}
}
// CL_QUEUE_SIZE can only be specified if CL_QUEUE_ON_DEVICE is set in CL_QUEUE_PROPERTIES.
if (hasQueueSize && !isQueueOnDevice)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreatePipe(cl_context context,
MemFlags flags,
cl_uint pipe_packet_size,
cl_uint pipe_max_packets,
const cl_pipe_properties *properties)
{
return CL_SUCCESS;
}
cl_int ValidateGetPipeInfo(cl_mem pipe,
PipeInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
return CL_SUCCESS;
}
cl_int ValidateSVMAlloc(cl_context context, SVM_MemFlags flags, size_t size, cl_uint alignment)
{
return CL_SUCCESS;
}
cl_int ValidateSVMFree(cl_context context, const void *svm_pointer)
{
return CL_SUCCESS;
}
cl_int ValidateCreateSamplerWithProperties(cl_context context,
const cl_sampler_properties *sampler_properties)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 2u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if the property name in sampler_properties is not a supported property name,
// if the value specified for a supported property name is not valid,
// or if the same property name is specified more than once.
if (sampler_properties != nullptr)
{
bool hasNormalizedCoords = false;
bool hasAddressingMode = false;
bool hasFilterMode = false;
const cl_sampler_properties *propIt = sampler_properties;
while (*propIt != 0)
{
switch (*propIt++)
{
case CL_SAMPLER_NORMALIZED_COORDS:
if (hasNormalizedCoords || (*propIt != CL_FALSE && *propIt != CL_TRUE))
{
return CL_INVALID_VALUE;
}
hasNormalizedCoords = true;
++propIt;
break;
case CL_SAMPLER_ADDRESSING_MODE:
if (hasAddressingMode || FromCLenum<AddressingMode>(static_cast<CLenum>(
*propIt++)) == AddressingMode::InvalidEnum)
{
return CL_INVALID_VALUE;
}
hasAddressingMode = true;
break;
case CL_SAMPLER_FILTER_MODE:
if (hasFilterMode || FromCLenum<FilterMode>(static_cast<CLenum>(*propIt++)) ==
FilterMode::InvalidEnum)
{
return CL_INVALID_VALUE;
}
hasFilterMode = true;
break;
default:
return CL_INVALID_VALUE;
}
}
}
// CL_INVALID_OPERATION if images are not supported by any device associated with context.
if (!context->cast<Context>().supportsImages())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateSetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, const void *arg_value)
{
return CL_SUCCESS;
}
cl_int ValidateSetKernelExecInfo(cl_kernel kernel,
KernelExecInfo param_name,
size_t param_value_size,
const void *param_value)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMFree(cl_command_queue command_queue,
cl_uint num_svm_pointers,
void *const svm_pointers[],
void(CL_CALLBACK *pfn_free_func)(cl_command_queue queue,
cl_uint num_svm_pointers,
void *svm_pointers[],
void *user_data),
const void *user_data,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMemcpy(cl_command_queue command_queue,
cl_bool blocking_copy,
const void *dst_ptr,
const void *src_ptr,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMemFill(cl_command_queue command_queue,
const void *svm_ptr,
const void *pattern,
size_t pattern_size,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMap(cl_command_queue command_queue,
cl_bool blocking_map,
MapFlags flags,
const void *svm_ptr,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMUnmap(cl_command_queue command_queue,
const void *svm_ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
// CL 2.1
cl_int ValidateSetDefaultDeviceCommandQueue(cl_context context,
cl_device_id device,
cl_command_queue command_queue)
{
return CL_SUCCESS;
}
cl_int ValidateGetDeviceAndHostTimer(cl_device_id device,
const cl_ulong *device_timestamp,
const cl_ulong *host_timestamp)
{
return CL_SUCCESS;
}
cl_int ValidateGetHostTimer(cl_device_id device, const cl_ulong *host_timestamp)
{
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithIL(cl_context context, const void *il, size_t length)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 2u, 1u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_OPERATION if no devices in context support intermediate language programs.
if (!ctx.supportsIL())
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_VALUE if il is NULL or if length is zero.
if (il == nullptr || length == 0u)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCloneKernel(cl_kernel source_kernel)
{
return CL_SUCCESS;
}
cl_int ValidateGetKernelSubGroupInfo(cl_kernel kernel,
cl_device_id device,
KernelSubGroupInfo param_name,
size_t input_value_size,
const void *input_value,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMigrateMem(cl_command_queue command_queue,
cl_uint num_svm_pointers,
const void **svm_pointers,
const size_t *sizes,
MemMigrationFlags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
// CL 2.2
cl_int ValidateSetProgramReleaseCallback(cl_program program,
void(CL_CALLBACK *pfn_notify)(cl_program program,
void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateSetProgramSpecializationConstant(cl_program program,
cl_uint spec_id,
size_t spec_size,
const void *spec_value)
{
return CL_SUCCESS;
}
// CL 3.0
cl_int ValidateSetContextDestructorCallback(cl_context context,
void(CL_CALLBACK *pfn_notify)(cl_context context,
void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateCreateBufferWithProperties(cl_context context,
const cl_mem_properties *properties,
MemFlags flags,
size_t size,
const void *host_ptr)
{
const cl_int errorCode = ValidateCreateBuffer(context, flags, size, host_ptr);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_CONTEXT if context is not a valid context.
if (!context->cast<Context>().getPlatform().isVersionOrNewer(3u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_PROPERTY if a property name in properties is not a supported property name,
// if the value specified for a supported property name is not valid,
// or if the same property name is specified more than once.
if (!ValidateMemoryProperties(properties))
{
return CL_INVALID_PROPERTY;
}
return CL_SUCCESS;
}
cl_int ValidateCreateImageWithProperties(cl_context context,
const cl_mem_properties *properties,
MemFlags flags,
const cl_image_format *image_format,
const cl_image_desc *image_desc,
const void *host_ptr)
{
const cl_int errorCode =
ValidateCreateImage(context, flags, image_format, image_desc, host_ptr);
if (errorCode != CL_SUCCESS)
{
return errorCode;
}
// CL_INVALID_CONTEXT if context is not a valid context.
if (!context->cast<Context>().getPlatform().isVersionOrNewer(3u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_PROPERTY if a property name in properties is not a supported property name,
// if the value specified for a supported property name is not valid,
// or if the same property name is specified more than once.
if (!ValidateMemoryProperties(properties))
{
return CL_INVALID_PROPERTY;
}
return CL_SUCCESS;
}
// cl_khr_icd
cl_int ValidateIcdGetPlatformIDsKHR(cl_uint num_entries,
const cl_platform_id *platforms,
const cl_uint *num_platforms)
{
if ((num_entries == 0u && platforms != nullptr) ||
(platforms == nullptr && num_platforms == nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
} // namespace cl