Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit a7aeeb6

Browse files
authored
Merge pull request #1696 from senior-zero/fix-main/github/scan_by_key_docs
add tests for scan_by_key in-place execution
2 parents 2ac2363 + 380870d commit a7aeeb6

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

testing/cuda/scan_by_key.cu

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void TestScanByKeyDevice(ExecutionPolicy exec)
7878
}
7979
ASSERT_EQUAL(d_output, h_output);
8080

81-
// in-place scans
81+
// in-place scans: in/out values aliasing
8282
h_output = h_vals;
8383
d_output = d_vals;
8484
thrust::inclusive_scan_by_key(h_keys.begin(), h_keys.end(), h_output.begin(), h_output.begin());
@@ -98,6 +98,24 @@ void TestScanByKeyDevice(ExecutionPolicy exec)
9898
ASSERT_EQUAL(cudaSuccess, err);
9999
}
100100
ASSERT_EQUAL(d_output, h_output);
101+
102+
// in-place scans: keys/values aliasing
103+
thrust::inclusive_scan_by_key(h_keys.begin(), h_keys.end(), h_vals.begin(), h_output.begin());
104+
inclusive_scan_by_key_kernel<<<1,1>>>(exec, d_keys.begin(), d_keys.end(), d_vals.begin(), d_keys.begin());
105+
{
106+
cudaError_t const err = cudaDeviceSynchronize();
107+
ASSERT_EQUAL(cudaSuccess, err);
108+
}
109+
ASSERT_EQUAL(d_keys, h_output);
110+
111+
d_keys = h_keys;
112+
thrust::exclusive_scan_by_key(h_keys.begin(), h_keys.end(), h_vals.begin(), h_output.begin(), 11);
113+
exclusive_scan_by_key_kernel<<<1,1>>>(exec, d_keys.begin(), d_keys.end(), d_vals.begin(), d_keys.begin(), 11);
114+
{
115+
cudaError_t const err = cudaDeviceSynchronize();
116+
ASSERT_EQUAL(cudaSuccess, err);
117+
}
118+
ASSERT_EQUAL(d_keys, h_output);
101119
}
102120

103121

testing/scan_by_key.exclusive.cu

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ void TestExclusiveScanByKeyInPlace(const size_t n)
309309
}
310310
thrust::device_vector<T> d_vals = h_vals;
311311

312+
// in-place scans: in/out values aliasing
312313
thrust::host_vector<T> h_output = h_vals;
313314
thrust::device_vector<T> d_output = d_vals;
314315
thrust::exclusive_scan_by_key(h_keys.begin(),
@@ -322,6 +323,19 @@ void TestExclusiveScanByKeyInPlace(const size_t n)
322323
d_output.begin(),
323324
(T)11);
324325
ASSERT_EQUAL(d_output, h_output);
326+
327+
// in-place scans: in/out keys aliasing
328+
thrust::exclusive_scan_by_key(h_keys.begin(),
329+
h_keys.end(),
330+
h_vals.begin(),
331+
h_keys.begin(),
332+
(T)11);
333+
thrust::exclusive_scan_by_key(d_keys.begin(),
334+
d_keys.end(),
335+
d_vals.begin(),
336+
d_keys.begin(),
337+
(T)11);
338+
ASSERT_EQUAL(d_keys, h_keys);
325339
}
326340
DECLARE_VARIABLE_UNITTEST(TestExclusiveScanByKeyInPlace);
327341

testing/scan_by_key.inclusive.cu

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void TestInclusiveScanByKeyInPlace(const size_t n)
309309
thrust::host_vector<T> h_output(n);
310310
thrust::device_vector<T> d_output(n);
311311

312-
// in-place scans
312+
// in-place scans: in/out values aliasing
313313
h_output = h_vals;
314314
d_output = d_vals;
315315
thrust::inclusive_scan_by_key(h_keys.begin(),
@@ -321,6 +321,17 @@ void TestInclusiveScanByKeyInPlace(const size_t n)
321321
d_output.begin(),
322322
d_output.begin());
323323
ASSERT_EQUAL(d_output, h_output);
324+
325+
// in-place scans: in/out keys aliasing
326+
thrust::inclusive_scan_by_key(h_keys.begin(),
327+
h_keys.end(),
328+
h_vals.begin(),
329+
h_keys.begin());
330+
thrust::inclusive_scan_by_key(d_keys.begin(),
331+
d_keys.end(),
332+
d_vals.begin(),
333+
d_keys.begin());
334+
ASSERT_EQUAL(d_keys, h_keys);
324335
}
325336
DECLARE_VARIABLE_UNITTEST(TestInclusiveScanByKeyInPlace);
326337

0 commit comments

Comments
 (0)