Skip to content

Commit b433ce7

Browse files
Add DPCTLEvent_GetWaitList func
1 parent b283185 commit b433ce7

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

dpctl-capi/include/dpctl_sycl_event_interface.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@
3131
#include "dpctl_data_types.h"
3232
#include "dpctl_sycl_enum_types.h"
3333
#include "dpctl_sycl_types.h"
34+
#include "dpctl_vector.h"
3435

3536
DPCTL_C_EXTERN_C_BEGIN
3637

3738
/**
3839
* @defgroup EventInterface Event class C wrapper
3940
*/
4041

42+
// Declares a set of types and functions to deal with vectors of
43+
// DPCTLSyclEventRef. Refer dpctl_vector_macros.h
44+
DPCTL_DECLARE_VECTOR(Event)
45+
4146
/*!
4247
* @brief A wrapper for ``sycl::event`` contructor to construct a new event.
4348
*
@@ -103,4 +108,16 @@ DPCTL_API
103108
DPCTLSyclEventStatusType
104109
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef);
105110

111+
/*!
112+
* @brief C-API wrapper for ``sycl::event::get_wait_list``.
113+
* Returns a vector of events that this event still waits for.
114+
*
115+
* @param ERef Opaque pointer to a ``sycl::event``.
116+
* @return A DPCTLEventVectorRef of DPCTLSyclEventRef objects.
117+
* @ingroup EventInterface
118+
*/
119+
DPCTL_API
120+
__dpctl_give DPCTLEventVectorRef
121+
DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef);
122+
106123
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ namespace
3737
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef)
3838
} /* end of anonymous namespace */
3939

40+
#undef EL
41+
#define EL Event
42+
#include "dpctl_vector_templ.cpp"
43+
#undef EL
44+
4045
__dpctl_give DPCTLSyclEventRef DPCTLEvent_Create()
4146
{
4247
DPCTLSyclEventRef ERef = nullptr;
@@ -117,3 +122,39 @@ DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef)
117122
}
118123
return ESTy;
119124
}
125+
126+
__dpctl_give DPCTLEventVectorRef
127+
DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef)
128+
{
129+
auto E = unwrap(ERef);
130+
if (!E) {
131+
std::cerr << "Cannot get wait list as input is a nullptr\n";
132+
return nullptr;
133+
}
134+
vector_class<DPCTLSyclEventRef> *EventsVectorPtr = nullptr;
135+
try {
136+
EventsVectorPtr = new vector_class<DPCTLSyclEventRef>();
137+
} catch (std::bad_alloc const &ba) {
138+
// \todo log error
139+
std::cerr << ba.what() << '\n';
140+
return nullptr;
141+
}
142+
try {
143+
auto Events = E->get_wait_list();
144+
EventsVectorPtr->reserve(Events.size());
145+
for (const auto &Ev : Events) {
146+
EventsVectorPtr->emplace_back(wrap(new event(Ev)));
147+
}
148+
return wrap(EventsVectorPtr);
149+
} catch (std::bad_alloc const &ba) {
150+
delete EventsVectorPtr;
151+
// \todo log error
152+
std::cerr << ba.what() << '\n';
153+
return nullptr;
154+
} catch (const runtime_error &re) {
155+
delete EventsVectorPtr;
156+
// \todo log error
157+
std::cerr << re.what() << '\n';
158+
return nullptr;
159+
}
160+
}

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,39 @@
2626

2727
#include "Support/CBindingWrapping.h"
2828
#include "dpctl_sycl_event_interface.h"
29+
#include "dpctl_sycl_types.h"
2930
#include <CL/sycl.hpp>
3031
#include <gtest/gtest.h>
3132

3233
using namespace cl::sycl;
3334

3435
namespace
3536
{
36-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef)
37+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef);
38+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclEventRef>,
39+
DPCTLEventVectorRef);
40+
41+
#ifndef DPCTL_COVERAGE
42+
sycl::event produce_event(sycl::queue &Q, sycl::buffer<int> &data)
43+
{
44+
int N = data.get_range()[0];
45+
46+
auto e1 = Q.submit([&](sycl::handler &h) {
47+
sycl::accessor a{data, h, sycl::write_only, sycl::noinit};
48+
h.parallel_for(N, [=](sycl::id<1> i) { a[i] = 1; });
49+
});
50+
51+
auto e2 = Q.submit([&](sycl::handler &h) {
52+
sycl::accessor a{data, h};
53+
h.single_task([=]() {
54+
for (int i = 1; i < N; i++)
55+
a[0] += a[i];
56+
});
57+
});
58+
59+
return e2;
60+
}
61+
#endif
3762
} // namespace
3863

3964
struct TestDPCTLSyclEventInterface : public ::testing::Test
@@ -121,3 +146,26 @@ TEST_F(TestDPCTLSyclEventInterface, ChkGetCommandExecutionStatus)
121146
EXPECT_TRUE(ESTy != DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS);
122147
EXPECT_TRUE(ESTy == DPCTLSyclEventStatusType::DPCTL_COMPLETE);
123148
}
149+
150+
TEST_F(TestDPCTLSyclEventInterface, CheckGetWaitList)
151+
{
152+
DPCTLEventVectorRef EVRef = nullptr;
153+
EXPECT_NO_FATAL_FAILURE(EVRef = DPCTLEvent_GetWaitList(ERef));
154+
ASSERT_TRUE(EVRef);
155+
EXPECT_NO_FATAL_FAILURE(DPCTLEventVector_Clear(EVRef));
156+
EXPECT_NO_FATAL_FAILURE(DPCTLEventVector_Delete(EVRef));
157+
}
158+
159+
#ifndef DPCTL_COVERAGE
160+
TEST_F(TestDPCTLSyclEventInterface, CheckGetWaitListSYCL)
161+
{
162+
sycl::queue q;
163+
sycl::buffer<int> data{42};
164+
165+
auto eD = produce_event(q, data);
166+
DPCTLSyclEventRef ERef = reinterpret_cast<DPCTLSyclEventRef>(&eD);
167+
auto EVRef = DPCTLEvent_GetWaitList(ERef);
168+
ASSERT_TRUE(DPCTLEventVector_Size(EVRef) > 0);
169+
DPCTLEventVector_Delete(EVRef);
170+
}
171+
#endif

0 commit comments

Comments
 (0)