@@ -48,17 +48,21 @@ class interop_handle {
48
48
// / of the command group requirements (e.g. it is an unregistered placeholder
49
49
// / accessor), the exception `cl::sycl::invalid_object` is thrown
50
50
// / asynchronously.
51
- template <backend BackendName = backend::opencl, typename DataT, int Dims,
51
+ template <backend Backend = backend::opencl, typename DataT, int Dims,
52
52
access::mode Mode, access::target Target, access::placeholder IsPlh>
53
- typename detail::enable_if_t <
54
- Target == access::target::global_buffer ||
55
- Target == access::target::constant_buffer,
56
- typename interop<BackendName,
57
- accessor<DataT, Dims, Mode, Target, IsPlh>>::type>
53
+ backend_return_t <Backend, buffer<DataT, Dims>>
58
54
get_native_mem (const accessor<DataT, Dims, Mode, Target, IsPlh> &Acc) const {
55
+ // TODO: the method is available when the target is target::device. Add it
56
+ // to the assert below when target::device enum is created.
57
+ static_assert (Target == access ::target::global_buffer ||
58
+ Target == access ::target::constant_buffer,
59
+ " The method is available only for target::device accessors" );
59
60
#ifndef __SYCL_DEVICE_ONLY__
61
+ if (Backend != get_backend ())
62
+ throw invalid_object_error (" Incorrect backend argument was passed" ,
63
+ PI_INVALID_MEM_OBJECT);
60
64
const auto *AccBase = static_cast <const detail::AccessorBaseHost *>(&Acc);
61
- return getMemImpl<BackendName , DataT, Dims, Mode, Target, IsPlh >(
65
+ return getMemImpl<Backend , DataT, Dims>(
62
66
detail::getSyclObjImpl (*AccBase).get ());
63
67
#else
64
68
(void )Acc;
@@ -67,64 +71,71 @@ class interop_handle {
67
71
#endif
68
72
}
69
73
70
- template <backend BackendName = backend::opencl, typename DataT, int Dims,
71
- access::mode Mode, access::target Target, access::placeholder IsPlh>
72
- typename detail::enable_if_t <
73
- !(Target == access::target::global_buffer ||
74
- Target == access::target::constant_buffer),
75
- typename interop<BackendName,
76
- accessor<DataT, Dims, Mode,
77
- access::target::global_buffer, IsPlh>>::type>
78
- get_native_mem (const accessor<DataT, Dims, Mode, Target, IsPlh> &) const {
79
- throw invalid_object_error (" Getting memory object out of accessor for "
80
- " specified target is not allowed" ,
81
- PI_INVALID_MEM_OBJECT);
82
- }
83
-
84
- // / Returns an underlying OpenCL queue for the SYCL queue used to submit the
85
- // / command group, or the fallback queue if this command-group is re-trying
86
- // / execution on an OpenCL queue. The OpenCL command queue returned is
74
+ // / Returns an underlying native backend object associated with teh queue
75
+ // / that the host task was submitted to. If the command group was submitted
76
+ // / with a secondary queue and the fall-back was triggered, the queue that
77
+ // / is associated with the interop_handle must be the fall-back queue.
78
+ // / The native backend object returned must be in a state where it is capable
79
+ // / of being used in a way appropriate for the associated SYCL backend. It is
87
80
// / implementation-defined in cases where the SYCL queue maps to multiple
88
- // / underlying OpenCL objects. It is responsibility of the SYCL runtime to
89
- // / ensure the OpenCL queue returned is in a state that can be used to
90
- // / dispatch work, and that other potential OpenCL command queues associated
81
+ // / underlying backend objects. It is responsibility of the SYCL runtime to
82
+ // / ensure the backend queue returned is in a state that can be used to
83
+ // / dispatch work, and that other potential backend command queues associated
91
84
// / with the same SYCL command queue are not executing commands while the host
92
85
// / task is executing.
93
- template <backend BackendName = backend::opencl>
94
- auto get_native_queue () const noexcept ->
95
- typename interop<BackendName, queue>::type {
86
+ template <backend Backend = backend::opencl>
87
+ backend_return_t <Backend, queue> get_native_queue () const {
96
88
#ifndef __SYCL_DEVICE_ONLY__
97
- return reinterpret_cast <typename interop<BackendName, queue>::type>(
98
- getNativeQueue ());
89
+ // TODO: replace the exception thrown below with the SYCL-2020 exception
90
+ // with the error code 'errc::backend_mismatch' when those new exceptions
91
+ // are ready to be used.
92
+ if (Backend != get_backend ())
93
+ throw invalid_object_error (" Incorrect backend argument was passed" ,
94
+ PI_INVALID_MEM_OBJECT);
95
+ return reinterpret_cast <backend_return_t <Backend, queue>>(getNativeQueue ());
99
96
#else
100
97
// we believe this won't be ever called on device side
101
98
return 0 ;
102
99
#endif
103
100
}
104
101
105
- // / Returns an underlying OpenCL device associated with the SYCL queue used
106
- // / to submit the command group, or the fallback queue if this command-group
107
- // / is re-trying execution on an OpenCL queue.
108
- template <backend BackendName = backend::opencl>
109
- auto get_native_device () const noexcept ->
110
- typename interop<BackendName, device>::type {
102
+ // / Returns the SYCL application interoperability native backend object
103
+ // / associated with the device associated with the SYCL queue that the host
104
+ // / task was submitted to. The native backend object returned must be in
105
+ // / a state where it is capable of being used in a way appropriate for
106
+ // / the associated SYCL backend.
107
+ template <backend Backend = backend::opencl>
108
+ backend_return_t <Backend, device> get_native_device () const {
111
109
#ifndef __SYCL_DEVICE_ONLY__
112
- return reinterpret_cast <typename interop<BackendName, device>::type>(
110
+ // TODO: replace the exception thrown below with the SYCL-2020 exception
111
+ // with the error code 'errc::backend_mismatch' when those new exceptions
112
+ // are ready to be used.
113
+ if (Backend != get_backend ())
114
+ throw invalid_object_error (" Incorrect backend argument was passed" ,
115
+ PI_INVALID_MEM_OBJECT);
116
+ return reinterpret_cast <backend_return_t <Backend, device>>(
113
117
getNativeDevice ());
114
118
#else
115
119
// we believe this won't be ever called on device side
116
120
return 0 ;
117
121
#endif
118
122
}
119
123
120
- // / Returns an underlying OpenCL context associated with the SYCL queue used
121
- // / to submit the command group, or the fallback queue if this command-group
122
- // / is re-trying execution on an OpenCL queue.
123
- template <backend BackendName = backend::opencl>
124
- auto get_native_context () const noexcept ->
125
- typename interop<BackendName, context>::type {
124
+ // / Returns the SYCL application interoperability native backend object
125
+ // / associated with the context associated with the SYCL queue that the host
126
+ // / task was submitted to. The native backend object returned must be in
127
+ // / a state where it is capable of being used in a way appropriate for
128
+ // / the associated SYCL backend.
129
+ template <backend Backend = backend::opencl>
130
+ backend_return_t <Backend, context> get_native_context () const {
126
131
#ifndef __SYCL_DEVICE_ONLY__
127
- return reinterpret_cast <typename interop<BackendName, context>::type>(
132
+ // TODO: replace the exception thrown below with the SYCL-2020 exception
133
+ // with the error code 'errc::backend_mismatch' when those new exceptions
134
+ // are ready to be used.
135
+ if (Backend != get_backend ())
136
+ throw invalid_object_error (" Incorrect backend argument was passed" ,
137
+ PI_INVALID_MEM_OBJECT);
138
+ return reinterpret_cast <backend_return_t <Backend, context>>(
128
139
getNativeContext ());
129
140
#else
130
141
// we believe this won't be ever called on device side
@@ -144,11 +155,9 @@ class interop_handle {
144
155
: MQueue(Queue), MDevice(Device), MContext(Context),
145
156
MMemObjs (std::move(MemObjs)) {}
146
157
147
- template <backend BackendName, typename DataT, int Dims, access::mode Mode,
148
- access::target Target, access::placeholder IsPlh>
149
- auto getMemImpl (detail::Requirement *Req) const ->
150
- typename interop<BackendName,
151
- accessor<DataT, Dims, Mode, Target, IsPlh>>::type {
158
+ template <backend Backend, typename DataT, int Dims>
159
+ backend_return_t <Backend, buffer<DataT, Dims>>
160
+ getMemImpl (detail::Requirement *Req) const {
152
161
/*
153
162
Do not update this cast: a C-style cast is required here.
154
163
@@ -167,9 +176,7 @@ class interop_handle {
167
176
https://en.cppreference.com/w/cpp/language/reinterpret_cast
168
177
https://en.cppreference.com/w/cpp/language/explicit_cast
169
178
*/
170
- return (typename interop<BackendName,
171
- accessor<DataT, Dims, Mode, Target, IsPlh>>::type)(
172
- getNativeMem (Req));
179
+ return (backend_return_t <Backend, buffer<DataT, Dims>>)(getNativeMem (Req));
173
180
}
174
181
175
182
__SYCL_EXPORT pi_native_handle getNativeMem (detail::Requirement *Req) const ;
0 commit comments