Skip to content

Commit 7125227

Browse files
Add DPCTLEvent_GetWaitList func
1 parent c822d80 commit 7125227

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

dpctl-capi/include/dpctl_sycl_event_interface.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "dpctl_data_types.h"
3232
#include "dpctl_sycl_enum_types.h"
3333
#include "dpctl_sycl_types.h"
34+
#include "dpctl_sycl_event_manager.h"
35+
3436

3537
DPCTL_C_EXTERN_C_BEGIN
3638

@@ -91,4 +93,15 @@ DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);
9193
DPCTL_API
9294
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef);
9395

96+
/*!
97+
* @brief Return the vector of events that this event waits for
98+
*
99+
* @param ERef Opaque pointer to a ``sycl::event``
100+
* @return A DPCTLEventVectorRef of DPCTLSyclEventRef objects
101+
* @ingroup EventInterface
102+
*/
103+
DPCTL_API
104+
__dpctl_give DPCTLEventVectorRef
105+
DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef);
106+
94107
DPCTL_C_EXTERN_C_END
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===-- dpctl_sycl_event_manager.h - Helpers for sycl::event -*-C++-*- =//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This header declares helper functions to work with sycl::event objects.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#include "Support/DllExport.h"
29+
#include "Support/ExternC.h"
30+
#include "Support/MemOwnershipAttrs.h"
31+
#include "dpctl_sycl_types.h"
32+
#include "dpctl_vector.h"
33+
34+
DPCTL_C_EXTERN_C_BEGIN
35+
36+
/*! \addtogroup EventManager Event class helper functions
37+
* Helper functions for ``sycl::event`` objects that do not directly map to
38+
* any ``sycl::event`` member function.
39+
* @{
40+
*/
41+
42+
// Declares a set of types abd functions to deal with vectors of
43+
// DPCTLSyclEventRef. Refer dpctl_vector_macros.h
44+
45+
DPCTL_DECLARE_VECTOR(Event)
46+
47+
/*! @} */
48+
49+
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace
3535
{
3636
// Create wrappers for C Binding types (see CBindingWrapping.h)
3737
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef)
38+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclEventRef>,
39+
DPCTLEventVectorRef)
3840
} /* end of anonymous namespace */
3941

4042
__dpctl_give DPCTLSyclEventRef DPCTLEvent_Create()
@@ -91,3 +93,39 @@ DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef)
9193
}
9294
return BTy;
9395
}
96+
97+
__dpctl_give DPCTLEventVectorRef
98+
DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef)
99+
{
100+
auto E = unwrap(ERef);
101+
if (!E) {
102+
std::cerr << "Cannot get wait list as input is a nullptr\n";
103+
return nullptr;
104+
}
105+
vector_class<DPCTLSyclEventRef> *EventsVectorPtr = nullptr;
106+
try {
107+
EventsVectorPtr = new vector_class<DPCTLSyclEventRef>();
108+
} catch (std::bad_alloc const &ba) {
109+
// \todo log error
110+
std::cerr << ba.what() << '\n';
111+
return nullptr;
112+
}
113+
try {
114+
auto Events = E->get_wait_list();
115+
EventsVectorPtr->reserve(Events.size());
116+
for (const auto &Ev : Events) {
117+
EventsVectorPtr->emplace_back(wrap(new event(Ev)));
118+
}
119+
return wrap(EventsVectorPtr);
120+
} catch (std::bad_alloc const &ba) {
121+
delete EventsVectorPtr;
122+
// \todo log error
123+
std::cerr << ba.what() << '\n';
124+
return nullptr;
125+
} catch (const runtime_error &re) {
126+
delete EventsVectorPtr;
127+
// \todo log error
128+
std::cerr << re.what() << '\n';
129+
return nullptr;
130+
}
131+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//=== dpctl_sycl_event_manager.cpp - Implements helpers for sycl::event //
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This file implements the functions declared in
23+
/// dpctl_sycl_event_manager.h.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
#include "dpctl_sycl_event_manager.h"
28+
#include "../helper/include/dpctl_utils_helper.h"
29+
#include "Support/CBindingWrapping.h"
30+
#include "dpctl_sycl_event_interface.h"
31+
#include <CL/sycl.hpp>
32+
33+
34+
using namespace cl::sycl;
35+
36+
namespace
37+
{
38+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef);
39+
}
40+
41+
#undef EL
42+
#define EL Event
43+
#include "dpctl_vector_templ.cpp"
44+
#undef EL

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
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>
32+
#include <typeinfo>
3133

3234
using namespace cl::sycl;
3335

3436
namespace
3537
{
3638
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef)
39+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclEventRef>,
40+
DPCTLEventVectorRef)
3741
} // namespace
3842

3943
struct TestDPCTLSyclEventInterface : public ::testing::Test
@@ -100,3 +104,12 @@ TEST_F(TestDPCTLSyclEventInterface, CheckGetBackend_Invalid)
100104
EXPECT_NO_FATAL_FAILURE(Bty = DPCTLEvent_GetBackend(E));
101105
EXPECT_TRUE(Bty == DPCTL_UNKNOWN_BACKEND);
102106
}
107+
108+
TEST_F(TestDPCTLSyclEventInterface, CheckGetWaitList)
109+
{
110+
DPCTLEventVectorRef EVRef = nullptr;
111+
EXPECT_NO_FATAL_FAILURE(EVRef = DPCTLEvent_GetWaitList(ERef));
112+
ASSERT_TRUE(EVRef);
113+
EXPECT_NO_FATAL_FAILURE(DPCTLEventVector_Clear(EVRef));
114+
EXPECT_NO_FATAL_FAILURE(DPCTLEventVector_Delete(EVRef));
115+
}

0 commit comments

Comments
 (0)