Skip to content

Commit 26697ec

Browse files
[C++ for OpenCL] Make dtors with named address spaces optional. (#736)
This feature was not fully supported by clang and got de-prioritized from the release due to the following: - global dtors were not supported originally. - private and local address spaces can be supported through generic address space. - local dtors can't be invoked automatically and object in this address space are pseudo-global anyway. The WIP implementation review for supporting this feature can be tracked through: https://reviews.llvm.org/D109609.
1 parent 192847c commit 26697ec

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

cxx4opencl/address_spaces.txt

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,6 @@ constructors and destructors, the implementation defines an ABI format for
337337
runtime initialization and destruction of global objects before/after all
338338
kernels are enqueued.
339339

340-
Non-trivial destructors for global objects are not required to be supported
341-
by all implementations. The macro `__opencl_cpp_global_destructor`,
342-
which is defined if and only if such destructors are supported by the implementation,
343-
can be used to check whether this functionality is available when compiling kernel code.
344-
345340
Objects in `__local` address space can not have initializers in
346341
declarations and therefore a constructor can not be called. All objects
347342
created in the local address space have undefined state at the point of
@@ -395,6 +390,41 @@ __constant C1 cobj2 = C1();
395390
__constant C2 cobj3(1);
396391
------------
397392

393+
Non-trivial destructors for objects in non-default address spaces (i.e. all
394+
other than generic address space) are not required to be supported by
395+
implementations. The macro `+__opencl_cpp_destructor_with_address_spaces+`,
396+
which is defined if and only if such destructors are supported by an
397+
implementation, can be used to check whether this functionality can be used
398+
in kernel sources. Additionally destructors with global objects might not be
399+
supported even if address spaces are supported with destructors in general.
400+
Such functionality is indicated by the presence of the
401+
`+__opencl_cpp_global_destructor+` macro. If the macro
402+
`+__opencl_cpp_global_destructor+` is defined then
403+
`+__opencl_cpp_destructor_with_address_spaces+` must also be defined. Note that
404+
the destruction of objects in named address spaces global, local, or private
405+
can be performed using destructors with default address space (i.e. generic)
406+
by utilising address space conversions.
407+
408+
[source,cpp]
409+
------------
410+
1 class C {
411+
2 public:
412+
3 #ifdef __opencl_cpp_destructor_with_address_spaces
413+
4 ~C() __local;
414+
5 #else
415+
6 ~C();
416+
7 #endif
417+
8 };
418+
9
419+
10 kernel void foo() {
420+
11 __local C locobj;
421+
12 locobj.~C(); // uses destructor in local address space (on line 4)
422+
13 // if such destructors are supported,
423+
14 // otherwise uses generic address space destructor (on line 6)
424+
15 // converting to generic address prior to call into destructor.
425+
16 }
426+
------------
427+
398428
==== Nested pointers
399429

400430
{cpp} for OpenCL does not allow implicit address space conversions in nested

0 commit comments

Comments
 (0)