Common Reference Semantics#
Each of the following SYCL runtime classes:
sycl::accessor, sycl::buffer, sycl::context, sycl::device,
sycl::device_image, sycl::event, sycl::host_accessor,
sycl::host_sampled_image_accessor, sycl::host_unsampled_image_accessor,
sycl::kernel, sycl::kernel_id, sycl::kernel_bundle,
sycl::local_accessor, sycl::platform, sycl::queue, sycl::sampled_image,
sycl::sampled_image_accessor, sycl::unsampled_image and sycl::unsampled_image_accessor
must obey the following statements, where T
is the runtime class type:
T
must be copy constructible and copy assignable in the host application and within SYCL kernel functions in the case thatT
is a valid kernel argument. Any instance ofT
that is constructed as a copy of another instance, via either the copy constructor or copy assignment operator, must behave as-if it were the original instance and as-if any action performed on it were also performed on the original instance and must represent the same underlying native backend object as the original instance where applicable.T
must be destructible in the host application and within SYCL kernel functions in the case thatT
is a valid kernel argument. When any instance ofT
is destroyed, including as a result of the copy assignment operator, any behavior specific to T that is specified as performed on destruction is only performed if this instance is the last remaining host copy, in accordance with the above definition of a copy.T
must be move constructible and move assignable in the host application and within SYCL kernel functions in the case that T is a valid kernel argument. Any instance of T that is constructed as a move of another instance, via either the move constructor or move assignment operator, must replace the original instance rendering said instance invalid and must represent the same underlying native backend object as the original instance where applicable.T
must be equality comparable in the host application. Equality between two instances of T (i.e.a == b
) must be true if one instance is a copy of the other and non-equality between two instances ofT
(i.e.a != b
) must be true if neither instance is a copy of the other, in accordance with the above definition of a copy, unless either instance has become invalidated by a move operation. By extension of the requirements above, equality onT
must guarantee to be reflexive (i.e.a == a
), symmetric (i.e.a == b
impliesb == a
anda != b
impliesb != a
) and transitive (i.e.a == b && b == c
impliesc == a
).A specialization of
std::hash
forT
must exist on the host application that returns a unique value such that if two instances of T are equal, in accordance with the above definition, then their resulting hash values are also equal and subsequently if two hash values are not equal, then their corresponding instances are also not equal, in accordance with the above definition.
Some SYCL runtime classes will have additional behavior associated with copy, movement, assignment or destruction semantics. If these are specified they are in addition to those specified above unless stated otherwise.
Each of the runtime classes mentioned above must provide a common interface of special member functions in order to fulfill the copy, move, destruction requirements and hidden friend functions in order to fulfill the equality requirements.
namespace sycl {
class T {
...
public:
T(const T& rhs);
T(T&& rhs);
T& operator=(const T& rhs);
T& operator=(T&& rhs);
~T();
...
friend bool operator==(const T& lhs, const T& rhs) { /* ... */ }
friend bool operator!=(const T& lhs, const T& rhs) { /* ... */ }
...
};
} // namespace sycl
See also
SYCL Specification Section 4.5.2
Common special member functions for reference semantics#
Special member function |
Description |
---|---|
|
Constructs a SYCL |
|
Constructs a SYCL |
|
Assigns this SYCL |
|
Assigns this SYCL |
|
Destroys this SYCL |