@@ -1631,285 +1631,6 @@ parameters of protocol-qualified type.
1631
1631
Query the presence of this new mangling with
1632
1632
``__has_feature(objc_protocol_qualifier_mangling) ``.
1633
1633
1634
-
1635
- OpenCL Features
1636
- ===============
1637
-
1638
- C++ for OpenCL
1639
- --------------
1640
-
1641
- This functionality is built on top of OpenCL C v2.0 and C++17 enabling most of
1642
- regular C++ features in OpenCL kernel code. Most functionality from OpenCL C
1643
- is inherited. This section describes minor differences to OpenCL C and any
1644
- limitations related to C++ support as well as interactions between OpenCL and
1645
- C++ features that are not documented elsewhere.
1646
-
1647
- Restrictions to C++17
1648
- ^^^^^^^^^^^^^^^^^^^^^
1649
-
1650
- The following features are not supported:
1651
-
1652
- - Virtual functions
1653
- - Exceptions
1654
- - ``dynamic_cast `` operator
1655
- - Non-placement ``new ``/``delete `` operators
1656
- - Standard C++ libraries. Currently there is no solution for alternative C++
1657
- libraries provided. Future release will feature library support.
1658
-
1659
-
1660
- Interplay of OpenCL and C++ features
1661
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1662
-
1663
- Address space behavior
1664
- """"""""""""""""""""""
1665
-
1666
- Address spaces are part of the type qualifiers; many rules are just inherited
1667
- from the qualifier behavior documented in OpenCL C v2.0 s6.5 and Embedded C
1668
- extension ISO/IEC JTC1 SC22 WG14 N1021 s3.1. Note that since the address space
1669
- behavior in C++ is not documented formally, Clang extends the existing concept
1670
- from C and OpenCL. For example conversion rules are extended from qualification
1671
- conversion but the compatibility is determined using notation of sets and
1672
- overlapping of address spaces from Embedded C (ISO/IEC JTC1 SC22 WG14 N1021
1673
- s3.1.3). For OpenCL it means that implicit conversions are allowed from
1674
- a named address space (except for ``__constant ``) to ``__generic `` (OpenCL C
1675
- v2.0 6.5.5). Reverse conversion is only allowed explicitly. The ``__constant ``
1676
- address space does not overlap with any other and therefore no valid conversion
1677
- between ``__constant `` and other address spaces exists. Most of the rules
1678
- follow this logic.
1679
-
1680
- **Casts **
1681
-
1682
- C-style casts follow OpenCL C v2.0 rules (s6.5.5). All cast operators
1683
- permit conversion to ``__generic `` implicitly. However converting from
1684
- ``__generic `` to named address spaces can only be done using ``addrspace_cast ``.
1685
- Note that conversions between ``__constant `` and any other address space
1686
- are disallowed.
1687
-
1688
- .. _opencl_cpp_addrsp_deduction :
1689
-
1690
- **Deduction **
1691
-
1692
- Address spaces are not deduced for:
1693
-
1694
- - non-pointer/non-reference template parameters or any dependent types except
1695
- for template specializations.
1696
- - non-pointer/non-reference class members except for static data members that are
1697
- deduced to ``__global `` address space.
1698
- - non-pointer/non-reference alias declarations.
1699
- - ``decltype `` expressions.
1700
-
1701
- .. code-block :: c++
1702
-
1703
- template <typename T>
1704
- void foo () {
1705
- T m; // address space of m will be known at template instantiation time.
1706
- T * ptr; // ptr points to __generic address space object.
1707
- T & ref = ...; // ref references an object in __generic address space.
1708
- };
1709
-
1710
- template <int N>
1711
- struct S {
1712
- int i; // i has no address space
1713
- static int ii; // ii is in global address space
1714
- int * ptr; // ptr points to __generic address space int.
1715
- int & ref = ...; // ref references int in __generic address space.
1716
- };
1717
-
1718
- template <int N>
1719
- void bar ()
1720
- {
1721
- S<N> s; // s is in __private address space
1722
- }
1723
-
1724
- TODO: Add example for type alias and decltype!
1725
-
1726
- **References **
1727
-
1728
- Reference types can be qualified with an address space.
1729
-
1730
- .. code-block :: c++
1731
-
1732
- __private int & ref = ...; // references int in __private address space
1733
-
1734
- By default references will refer to ``__generic `` address space objects, except
1735
- for dependent types that are not template specializations
1736
- (see :ref: `Deduction <opencl_cpp_addrsp_deduction >`). Address space compatibility
1737
- checks are performed when references are bound to values. The logic follows the
1738
- rules from address space pointer conversion (OpenCL v2.0 s6.5.5).
1739
-
1740
- **Default address space **
1741
-
1742
- All non-static member functions take an implicit object parameter ``this `` that
1743
- is a pointer type. By default this pointer parameter is in the ``__generic ``
1744
- address space. All concrete objects passed as an argument to ``this `` parameter
1745
- will be converted to the ``__generic `` address space first if such conversion is
1746
- valid. Therefore programs using objects in the ``__constant `` address space will
1747
- not be compiled unless the address space is explicitly specified using address
1748
- space qualifiers on member functions
1749
- (see :ref: `Member function qualifier <opencl_cpp_addrspace_method_qual >`) as the
1750
- conversion between ``__constant `` and ``__generic `` is disallowed. Member function
1751
- qualifiers can also be used in case conversion to the ``__generic `` address space
1752
- is undesirable (even if it is legal). For example, a method can be implemented to
1753
- exploit memory access coalescing for segments with memory bank. This not only
1754
- applies to regular member functions but to constructors and destructors too.
1755
-
1756
- .. _opencl_cpp_addrspace_method_qual :
1757
-
1758
- **Member function qualifier **
1759
-
1760
- Clang allows specifying an address space qualifier on member functions to signal
1761
- that they are to be used with objects constructed in some specific address space.
1762
- This works just the same as qualifying member functions with ``const `` or any
1763
- other qualifiers. The overloading resolution will select the candidate with the
1764
- most specific address space if multiple candidates are provided. If there is no
1765
- conversion to an address space among candidates, compilation will fail with a
1766
- diagnostic.
1767
-
1768
- .. code-block :: c++
1769
-
1770
- struct C {
1771
- void foo () __local;
1772
- void foo ();
1773
- };
1774
-
1775
- __kernel void bar () {
1776
- __local C c1;
1777
- C c2;
1778
- __constant C c3;
1779
- c1.foo (); // will resolve to the first foo
1780
- c2.foo (); // will resolve to the second foo
1781
- c3.foo (); // error due to mismatching address spaces - can't convert to
1782
- // __local or __generic
1783
- }
1784
-
1785
- **Implicit special members **
1786
-
1787
- All implicit special members (default, copy, or move constructor, copy or move
1788
- assignment, destructor) will be generated with the ``__generic `` address space.
1789
-
1790
- .. code-block :: c++
1791
-
1792
- class C {
1793
- // Has the following implicit definition
1794
- // void C () __generic;
1795
- // void C (const __generic C &) __generic;
1796
- // void C (__generic C &&) __generic;
1797
- // operator= '__generic C &(__generic C &&)'
1798
- // operator= '__generic C &(const __generic C &) __generic
1799
- }
1800
-
1801
- **Builtin operators **
1802
-
1803
- All builtin operators are available in the specific address spaces, thus no
1804
- conversion to ``__generic `` is performed.
1805
-
1806
- **Templates **
1807
-
1808
- There is no deduction of address spaces in non-pointer/non-reference template
1809
- parameters and dependent types (see :ref: `Deduction <opencl_cpp_addrsp_deduction >`).
1810
- The address space of a template parameter is deduced during type deduction if
1811
- it is not explicitly provided in the instantiation.
1812
-
1813
- .. code-block :: c++
1814
-
1815
- 1 template<typename T>
1816
- 2 void foo (T* i){
1817
- 3 T var;
1818
- 4 }
1819
- 5
1820
- 6 __global int g;
1821
- 7 void bar (){
1822
- 8 foo (&g); // error: template instantiation failed as function scope variable
1823
- 9 // appears to be declared in __global address space (see line 3)
1824
- 10 }
1825
-
1826
- It is not legal to specify multiple different address spaces between template
1827
- definition and instantiation. If multiple different address spaces are specified in
1828
- template definition and instantiation, compilation of such a program will fail with
1829
- a diagnostic.
1830
-
1831
- .. code-block :: c++
1832
-
1833
- template <typename T>
1834
- void foo () {
1835
- __private T var;
1836
- }
1837
-
1838
- void bar () {
1839
- foo<__global int>(); // error: conflicting address space qualifiers are provided
1840
- // __global and __private
1841
- }
1842
-
1843
- Once a template has been instantiated, regular restrictions for address spaces will
1844
- apply.
1845
-
1846
- .. code-block :: c++
1847
-
1848
- template<typename T>
1849
- void foo (){
1850
- T var;
1851
- }
1852
-
1853
- void bar (){
1854
- foo<__global int>(); // error: function scope variable cannot be declared in
1855
- // __global address space
1856
- }
1857
-
1858
- **Temporary materialization **
1859
-
1860
- All temporaries are materialized in the ``__private `` address space. If a
1861
- reference with another address space is bound to them, the conversion will be
1862
- generated in case it is valid, otherwise compilation will fail with a diagnostic.
1863
-
1864
- .. code-block :: c++
1865
-
1866
- int bar (const unsigned int &i);
1867
-
1868
- void foo () {
1869
- bar (1); // temporary is created in __private address space but converted
1870
- // to __generic address space of parameter reference
1871
- }
1872
-
1873
- __global const int& f (__global float &ref) {
1874
- return ref; // error: address space mismatch between temporary object
1875
- // created to hold value converted float->int and return
1876
- // value type (can't convert from __private to __global)
1877
- }
1878
-
1879
- **Initialization of local and constant address space objects **
1880
-
1881
- TODO
1882
-
1883
- Constructing and destroying global objects
1884
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1885
-
1886
- Global objects must be constructed before the first kernel using the global
1887
- objects is executed and destroyed just after the last kernel using the
1888
- program objects is executed. In OpenCL v2.0 drivers there is no specific
1889
- API for invoking global constructors. However, an easy workaround would be
1890
- to enqueue a constructor initialization kernel that has a name
1891
- ``@_GLOBAL__sub_I_<compiled file name> ``. This kernel is only present if there
1892
- are any global objects to be initialized in the compiled binary. One way to
1893
- check this is by passing ``CL_PROGRAM_KERNEL_NAMES `` to ``clGetProgramInfo ``
1894
- (OpenCL v2.0 s5.8.7).
1895
-
1896
- Note that if multiple files are compiled and linked into libraries, multiple
1897
- kernels that initialize global objects for multiple modules would have to be
1898
- invoked.
1899
-
1900
- Applications are currently required to run initialization of global objects
1901
- manually before running any kernels in which the objects are used.
1902
-
1903
- .. code-block :: console
1904
-
1905
- clang -cl-std=clc++ test.cl
1906
-
1907
- If there are any global objects to be initialized, the final binary will
1908
- contain the ``@_GLOBAL__sub_I_test.cl `` kernel to be enqueued.
1909
-
1910
- Global destructors can not be invoked in OpenCL v2.0 drivers. However, all
1911
- memory used for program scope objects is released on ``clReleaseProgram ``.
1912
-
1913
1634
Initializer lists for complex numbers in C
1914
1635
==========================================
1915
1636
0 commit comments