Skip to content

Commit

Permalink
[SYCLomatic oneapi-src#481] Add test for dpct::device_vector move sem…
Browse files Browse the repository at this point in the history
…antics (oneapi-src#190)

Signed-off-by: Yilong Guo <[email protected]>
  • Loading branch information
Nuullll authored Feb 8, 2023
1 parent 83ca163 commit 4adc8d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions help_function/help_function.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<tests>
<test testName="array_copy" configFile="config/TEMPLATE_help_function.xml" />
<test testName="assign_device_vector" configFile="config/TEMPLATE_help_function.xml" />
<test testName="move_device_vector" configFile="config/TEMPLATE_help_function.xml" />
<test testName="atomic_add_float" configFile="config/TEMPLATE_help_function.xml" />
<test testName="atomic_fetch_compare_inc" configFile="config/TEMPLATE_help_function.xml" />
<test testName="async_exception" configFile="config/TEMPLATE_help_function.xml" />
Expand Down
31 changes: 31 additions & 0 deletions help_function/src/move_device_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#include <sycl.hpp>
#include <dpct/dpct.hpp>
#include <dpct/dpl_utils.hpp>

bool verify(dpct::device_vector<int> &D, int N, int V) {
if (D.size() != N)
return false;
for (int i = 0; i < N; ++i)
if (D[i] != V)
return false;
return true;
}

int main(void) {
constexpr int N = 4;
constexpr int V = 42;
// Construct D1 from move constructor.
dpct::device_vector<int> D1(std::move(dpct::device_vector<int>(N, V)));
if (!verify(D1, N, V)) {
return 1;
}
// Move assign to D2.
dpct::device_vector<int> D2;
D2 = std::move(dpct::device_vector<int>(N, V));
if (!verify(D2, N, V)) {
return 1;
}
return 0;
}

0 comments on commit 4adc8d2

Please sign in to comment.