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

Commit 2e3cc93

Browse files
committed
unique_count: add missing cuda tests
1 parent 545aa3f commit 2e3cc93

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

testing/cuda/unique.cu

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,128 @@ void TestUniqueCopyCudaStreamsNoSync()
320320
}
321321
DECLARE_UNITTEST(TestUniqueCopyCudaStreamsNoSync);
322322

323+
324+
template<typename ExecutionPolicy, typename Iterator1, typename Iterator2>
325+
__global__
326+
void unique_count_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Iterator2 result)
327+
{
328+
*result = thrust::unique_count(exec, first, last);
329+
}
330+
331+
332+
template<typename ExecutionPolicy, typename Iterator1, typename BinaryPredicate, typename Iterator2>
333+
__global__
334+
void unique_count_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, BinaryPredicate pred, Iterator2 result)
335+
{
336+
*result = thrust::unique_count(exec, first, last, pred);
337+
}
338+
339+
340+
template<typename ExecutionPolicy>
341+
void TestUniqueCountDevice(ExecutionPolicy exec)
342+
{
343+
typedef thrust::device_vector<int> Vector;
344+
typedef Vector::value_type T;
345+
346+
Vector data(10);
347+
data[0] = 11;
348+
data[1] = 11;
349+
data[2] = 12;
350+
data[3] = 20;
351+
data[4] = 29;
352+
data[5] = 21;
353+
data[6] = 21;
354+
data[7] = 31;
355+
data[8] = 31;
356+
data[9] = 37;
357+
358+
Vector output(1, -1);
359+
360+
unique_count_kernel<<<1,1>>>(exec, data.begin(), data.end(), output.begin());
361+
{
362+
cudaError_t const err = cudaDeviceSynchronize();
363+
ASSERT_EQUAL(cudaSuccess, err);
364+
}
365+
366+
ASSERT_EQUAL(output[0], 7);
367+
368+
unique_count_kernel<<<1,1>>>(exec, data.begin(), data.end(), is_equal_div_10_unique<T>(), output.begin());
369+
{
370+
cudaError_t const err = cudaDeviceSynchronize();
371+
ASSERT_EQUAL(cudaSuccess, err);
372+
}
373+
374+
ASSERT_EQUAL(output[0], 3);
375+
}
376+
377+
378+
void TestUniqueCountDeviceSeq()
379+
{
380+
TestUniqueCountDevice(thrust::seq);
381+
}
382+
DECLARE_UNITTEST(TestUniqueCountDeviceSeq);
383+
384+
385+
void TestUniqueCountDeviceDevice()
386+
{
387+
TestUniqueCountDevice(thrust::device);
388+
}
389+
DECLARE_UNITTEST(TestUniqueCountDeviceDevice);
390+
391+
392+
void TestUniqueCountDeviceNoSync()
393+
{
394+
TestUniqueCountDevice(thrust::cuda::par_nosync);
395+
}
396+
DECLARE_UNITTEST(TestUniqueCountDeviceNoSync);
397+
398+
399+
template<typename ExecutionPolicy>
400+
void TestUniqueCountCudaStreams(ExecutionPolicy policy)
401+
{
402+
typedef thrust::device_vector<int> Vector;
403+
typedef Vector::value_type T;
404+
405+
Vector data(10);
406+
data[0] = 11;
407+
data[1] = 11;
408+
data[2] = 12;
409+
data[3] = 20;
410+
data[4] = 29;
411+
data[5] = 21;
412+
data[6] = 21;
413+
data[7] = 31;
414+
data[8] = 31;
415+
data[9] = 37;
416+
417+
cudaStream_t s;
418+
cudaStreamCreate(&s);
419+
420+
auto streampolicy = policy.on(s);
421+
422+
int result = thrust::unique_count(streampolicy, data.begin(), data.end());
423+
cudaStreamSynchronize(s);
424+
425+
ASSERT_EQUAL(result, 7);
426+
427+
result = thrust::unique_count(streampolicy, data.begin(), data.end(), is_equal_div_10_unique<T>());
428+
cudaStreamSynchronize(s);
429+
430+
ASSERT_EQUAL(result, 3);
431+
432+
cudaStreamDestroy(s);
433+
}
434+
435+
void TestUniqueCountCudaStreamsSync()
436+
{
437+
TestUniqueCountCudaStreams(thrust::cuda::par);
438+
}
439+
DECLARE_UNITTEST(TestUniqueCountCudaStreamsSync);
440+
441+
442+
void TestUniqueCountCudaStreamsNoSync()
443+
{
444+
TestUniqueCountCudaStreams(thrust::cuda::par_nosync);
445+
}
446+
DECLARE_UNITTEST(TestUniqueCountCudaStreamsNoSync);
447+

0 commit comments

Comments
 (0)