Skip to content

Commit ca114f2

Browse files
densmirnoleksandr-pavlyk
authored andcommitted
Extand main cython funcs with queues and events (part 2)
1 parent c9f977f commit ca114f2

20 files changed

+1325
-372
lines changed

dpnp/backend/include/dpnp_iface.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ INP_DLLEXPORT void dpnp_cumprod_c(void* array1_in, void* result1, size_t size);
533533
* @param [in] q_ref Reference to SYCL queue.
534534
* @param [in] array1_in Input array.
535535
* @param [out] result1 Output array.
536-
* @param [in] size Number of elements in input arrays.
536+
* @param [in] size Number of elements in input arrays.
537537
* @param [in] dep_event_vec_ref Reference to vector of SYCL events.
538538
*
539539
*/
@@ -551,7 +551,7 @@ INP_DLLEXPORT void dpnp_cumsum_c(void* array1_in, void* result1, size_t size);
551551
* @ingroup BACKEND_API
552552
* @brief The differences between consecutive elements of an array.
553553
*
554-
* @param [in] q_ref Reference to SYCL queue.
554+
* @param [in] q_ref Reference to SYCL queue.
555555
* @param [out] result_out Output array.
556556
* @param [in] result_size Size of output array.
557557
* @param [in] result_ndim Number of output array dimensions.

dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,6 @@ DPCTLSyclEventRef dpnp_vander_c(DPCTLSyclQueueRef q_ref,
617617
const int increasing,
618618
const DPCTLEventVectorRef dep_event_vec_ref)
619619
{
620-
// avoid warning unused variable
621-
(void)dep_event_vec_ref;
622-
623620
DPCTLSyclEventRef event_ref = nullptr;
624621

625622
if ((array1_in == nullptr) || (result1 == nullptr))
@@ -637,8 +634,7 @@ DPCTLSyclEventRef dpnp_vander_c(DPCTLSyclQueueRef q_ref,
637634

638635
if (N == 1)
639636
{
640-
dpnp_ones_c<_DataType_output>(result, size_in);
641-
return event_ref;
637+
return dpnp_ones_c<_DataType_output>(q_ref, result, size_in, dep_event_vec_ref);
642638
}
643639

644640
if (increasing)
@@ -762,9 +758,10 @@ DPCTLSyclEventRef dpnp_trace_c(DPCTLSyclQueueRef q_ref,
762758
};
763759

764760
auto event = q.submit(kernel_func);
765-
event.wait();
766761

767-
return event_ref;
762+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
763+
764+
return DPCTLEvent_Copy(event_ref);
768765
}
769766

770767
template <typename _DataType, typename _ResultType>
@@ -849,9 +846,9 @@ DPCTLSyclEventRef dpnp_tri_c(DPCTLSyclQueueRef q_ref,
849846

850847
event = q.submit(kernel_func);
851848

852-
event.wait();
849+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
853850

854-
return event_ref;
851+
return DPCTLEvent_Copy(event_ref);
855852
}
856853

857854
template <typename _DataType>

dpnp/backend/kernels/dpnp_krnl_indexing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ DPCTLSyclEventRef dpnp_choose_c(DPCTLSyclQueueRef q_ref,
8787
};
8888

8989
sycl::event event = q.submit(kernel_func);
90-
event.wait();
9190

92-
return event_ref;
91+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
92+
93+
return DPCTLEvent_Copy(event_ref);
9394
}
9495

9596
template <typename _DataType1, typename _DataType2>
@@ -917,9 +918,9 @@ DPCTLSyclEventRef dpnp_take_c(DPCTLSyclQueueRef q_ref,
917918

918919
sycl::event event = q.submit(kernel_func);
919920

920-
event.wait();
921+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
921922

922-
return event_ref;
923+
return DPCTLEvent_Copy(event_ref);
923924
}
924925

925926
template <typename _DataType, typename _IndecesType>

dpnp/backend/kernels/dpnp_krnl_linalg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ DPCTLSyclEventRef dpnp_kron_c(DPCTLSyclQueueRef q_ref,
502502

503503
sycl::event event = q.submit(kernel_func);
504504

505-
event.wait();
505+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
506506

507-
return event_ref;
507+
return DPCTLEvent_Copy(event_ref);
508508
}
509509

510510
template <typename _DataType1, typename _DataType2, typename _ResultType>

dpnp/backend/kernels/dpnp_krnl_logic.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ DPCTLSyclEventRef dpnp_all_c(DPCTLSyclQueueRef q_ref,
8181

8282
event = q.submit(kernel_func);
8383

84-
event.wait();
84+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
8585

86-
return event_ref;
86+
return DPCTLEvent_Copy(event_ref);
8787
}
8888

8989
template <typename _DataType, typename _ResultType>
@@ -166,9 +166,9 @@ DPCTLSyclEventRef dpnp_allclose_c(DPCTLSyclQueueRef q_ref,
166166

167167
event = q.submit(kernel_func);
168168

169-
event.wait();
169+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
170170

171-
return event_ref;
171+
return DPCTLEvent_Copy(event_ref);
172172
}
173173

174174
template <typename _DataType1, typename _DataType2, typename _ResultType>
@@ -258,9 +258,9 @@ DPCTLSyclEventRef dpnp_any_c(DPCTLSyclQueueRef q_ref,
258258

259259
event = q.submit(kernel_func);
260260

261-
event.wait();
261+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
262262

263-
return event_ref;
263+
return DPCTLEvent_Copy(event_ref);
264264
}
265265

266266
template <typename _DataType, typename _ResultType>

dpnp/backend/kernels/dpnp_krnl_manipulation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ DPCTLSyclEventRef dpnp_repeat_c(DPCTLSyclQueueRef q_ref,
8080

8181
event = q.submit(kernel_func);
8282

83-
event.wait();
83+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
8484

85-
return event_ref;
85+
return DPCTLEvent_Copy(event_ref);
8686
}
8787

8888
template <typename _DataType>

dpnp/backend/kernels/dpnp_krnl_mathematical.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ DPCTLSyclEventRef dpnp_around_c(DPCTLSyclQueueRef q_ref,
8484
event = q.submit(kernel_func);
8585
}
8686

87-
event.wait();
87+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
8888

89-
return event_ref;
89+
return DPCTLEvent_Copy(event_ref);
9090
}
9191

9292
template <typename _DataType>
@@ -170,9 +170,9 @@ DPCTLSyclEventRef dpnp_elemwise_absolute_c(DPCTLSyclQueueRef q_ref,
170170
event = q.submit(kernel_func);
171171
}
172172

173-
event.wait();
173+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
174174

175-
return event_ref;
175+
return DPCTLEvent_Copy(event_ref);
176176
}
177177

178178
template <typename _DataType>
@@ -753,9 +753,9 @@ DPCTLSyclEventRef dpnp_modf_c(DPCTLSyclQueueRef q_ref,
753753
event = q.submit(kernel_func);
754754
}
755755

756-
event.wait();
756+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
757757

758-
return event_ref;
758+
return DPCTLEvent_Copy(event_ref);
759759
}
760760

761761
template <typename _DataType_input, typename _DataType_output>

dpnp/backend/kernels/dpnp_krnl_statistics.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ DPCTLSyclEventRef dpnp_mean_c(DPCTLSyclQueueRef q_ref,
598598
sycl::event event = mkl_stats::mean(q, dataset, result);
599599

600600
event.wait();
601+
602+
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event);
603+
604+
return DPCTLEvent_Copy(event_ref);
601605
}
602606
else
603607
{
@@ -608,9 +612,9 @@ DPCTLSyclEventRef dpnp_mean_c(DPCTLSyclQueueRef q_ref,
608612
result[0] = sum[0] / static_cast<_ResultType>(size);
609613

610614
sycl::free(sum, q);
611-
}
612615

613-
return event_ref;
616+
return event_ref;
617+
}
614618
}
615619

616620
template <typename _DataType, typename _ResultType>

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,16 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_2in_1out_strides_t)(c_dpctl.DPCTLSyclQu
439439
const long * ,
440440
const c_dpctl.DPCTLEventVectorRef)
441441
ctypedef void(*fptr_blas_gemm_2in_1out_t)(void *, void * , void * , size_t, size_t, size_t)
442-
ctypedef void(*dpnp_reduction_c_t)(void *, const void * , const shape_elem_type*, const size_t, const shape_elem_type*, const size_t, const void * , const long*)
442+
ctypedef c_dpctl.DPCTLSyclEventRef(*dpnp_reduction_c_t)(c_dpctl.DPCTLSyclQueueRef,
443+
void *,
444+
const void * ,
445+
const shape_elem_type*,
446+
const size_t,
447+
const shape_elem_type*,
448+
const size_t,
449+
const void * ,
450+
const long*,
451+
const c_dpctl.DPCTLEventVectorRef)
443452

444453
cpdef dpnp_descriptor dpnp_astype(dpnp_descriptor x1, dtype)
445454
cpdef dpnp_descriptor dpnp_flatten(dpnp_descriptor x1)

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ cpdef utils.dpnp_descriptor dpnp_arange(start, stop, step, dtype):
119119
result.get_data(),
120120
result.size,
121121
NULL) # dep_events_ref)
122-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
122+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
123123
c_dpctl.DPCTLEvent_Delete(event_ref)
124124

125125
return result
@@ -150,7 +150,7 @@ cpdef utils.dpnp_descriptor dpnp_astype(utils.dpnp_descriptor x1, dtype):
150150
cdef fptr_dpnp_astype_t func = <fptr_dpnp_astype_t > kernel_data.ptr
151151
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), result.get_data(), x1.size, NULL)
152152

153-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
153+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
154154
c_dpctl.DPCTLEvent_Delete(event_ref)
155155

156156
return result
@@ -197,7 +197,7 @@ cpdef utils.dpnp_descriptor dpnp_flatten(utils.dpnp_descriptor x1):
197197
NULL,
198198
NULL) # dep_events_ref
199199

200-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
200+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
201201
c_dpctl.DPCTLEvent_Delete(event_ref)
202202

203203
return result
@@ -230,7 +230,7 @@ cpdef utils.dpnp_descriptor dpnp_init_val(shape, dtype, value):
230230
cdef fptr_dpnp_initval_t func = <fptr_dpnp_initval_t > kernel_data.ptr
231231
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), val_arr.get_data(), result.size, NULL)
232232

233-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
233+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
234234
c_dpctl.DPCTLEvent_Delete(event_ref)
235235

236236
return result
@@ -340,7 +340,7 @@ cdef utils.dpnp_descriptor call_fptr_1out(DPNPFuncName fptr_name,
340340
# Call FPTR function
341341
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), result.size, NULL)
342342

343-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
343+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
344344
c_dpctl.DPCTLEvent_Delete(event_ref)
345345

346346
return result
@@ -388,7 +388,7 @@ cdef utils.dpnp_descriptor call_fptr_1in_1out(DPNPFuncName fptr_name,
388388

389389
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), result.get_data(), x1.size, NULL)
390390

391-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
391+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
392392
c_dpctl.DPCTLEvent_Delete(event_ref)
393393

394394
return result
@@ -455,7 +455,7 @@ cdef utils.dpnp_descriptor call_fptr_1in_1out_strides(DPNPFuncName fptr_name,
455455
NULL,
456456
NULL) # dep_events_ref
457457

458-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
458+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
459459
c_dpctl.DPCTLEvent_Delete(event_ref)
460460

461461
return result
@@ -519,7 +519,7 @@ cdef utils.dpnp_descriptor call_fptr_2in_1out(DPNPFuncName fptr_name,
519519
NULL,
520520
NULL) # dep_events_ref)
521521

522-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
522+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
523523
c_dpctl.DPCTLEvent_Delete(event_ref)
524524

525525
return result
@@ -596,7 +596,7 @@ cdef utils.dpnp_descriptor call_fptr_2in_1out_strides(DPNPFuncName fptr_name,
596596
NULL,
597597
NULL) # dep_events_ref)
598598

599-
with nogil: c_dpctl.DPCTLEvent_Wait(event_ref)
599+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
600600
c_dpctl.DPCTLEvent_Delete(event_ref)
601601

602602
return result

0 commit comments

Comments
 (0)