Skip to content

Commit fdfbe1b

Browse files
DPCTLDeviceVector_CreateFromArray now copies devices too
Modified test to reflect that.
1 parent fe5782b commit fdfbe1b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

dpctl-capi/source/dpctl_vector_templ.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ __dpctl_give VECTOR(EL) FN(EL, Create)()
4949

5050
/*!
5151
* @brief Creates a new std::vector of the opaque SYCL pointer types from given
52-
* C array.
52+
* C array with deep copy.
5353
*
5454
* @return A new dynamically allocated std::vector of opaque pointer types.
5555
*/
5656
__dpctl_give VECTOR(EL)
5757
FN(EL, CreateFromArray)(size_t n, __dpctl_keep SYCLREF(EL) * elems)
5858
{
5959
try {
60-
auto Vec = new vector_class<SYCLREF(EL)>(n);
61-
Vec->assign(elems, elems + n);
60+
auto Vec = new vector_class<SYCLREF(EL)>();
61+
for (size_t i = 0; i < n; ++i) {
62+
auto Ref = unwrap(elems[i]);
63+
Vec->emplace_back(
64+
wrap(new std::remove_pointer<decltype(Ref)>::type(*Ref)));
65+
}
6266
return wrap(Vec);
6367
} catch (std::bad_alloc const &ba) {
6468
return nullptr;

dpctl-capi/tests/test_sycl_context_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ TEST_P(TestDPCTLContextInterface, Chk_CreateWithDevices_GetDevices)
126126
const size_t len = subDevices.size();
127127
auto ar = new DPCTLSyclDeviceRef[len];
128128
for (size_t i = 0; i < len; ++i) {
129-
ar[i] = wrap(new device(subDevices.at(i)));
129+
ar[i] = wrap(&subDevices.at(i));
130130
}
131131
EXPECT_NO_FATAL_FAILURE(
132132
DVRef = DPCTLDeviceVector_CreateFromArray(len, ar));

0 commit comments

Comments
 (0)