[compute] 29/46: Fix OpenCL2.0 test cases in test_fill and test_svm_ptr

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Dec 21 18:28:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository compute.

commit acf83372db00df1efac12c96f1181500943cf887
Author: Jakub Szuppe <j.szuppe at gmail.com>
Date:   Sat Oct 24 20:14:14 2015 +0200

    Fix OpenCL2.0 test cases in test_fill and test_svm_ptr
---
 test/test_fill.cpp    | 16 ++++++++++------
 test/test_svm_ptr.cpp | 19 ++++++++++++-------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/test/test_fill.cpp b/test/test_fill.cpp
index 47c1bfd..34783f7 100644
--- a/test/test_fill.cpp
+++ b/test/test_fill.cpp
@@ -306,12 +306,16 @@ BOOST_AUTO_TEST_CASE(fill_svm_buffer)
 {
     REQUIRES_OPENCL_VERSION(2, 0);
 
-    bc::svm_ptr<int> ptr = bc::svm_alloc<int>(context, 16);
-    bc::fill_n(ptr, 16, 42, queue);
-
-    int value = 0;
-    queue.enqueue_svm_memcpy(&value, ptr.get(), sizeof(int));
-    BOOST_CHECK_EQUAL(value, 42);
+    size_t size = 4;
+    bc::svm_ptr<cl_int> ptr =
+        bc::svm_alloc<cl_int>(context, size * sizeof(cl_int));
+    bc::fill_n(ptr, size * sizeof(cl_int), 42, queue);
+
+    queue.enqueue_svm_map(ptr.get(), size * sizeof(cl_int), CL_MAP_READ);
+    for(size_t i = 0; i < size; i++) {
+        BOOST_CHECK_EQUAL(static_cast<cl_int*>(ptr.get())[i], 42);
+    }
+    queue.enqueue_svm_unmap(ptr.get());
 
     bc::svm_free(context, ptr);
 }
diff --git a/test/test_svm_ptr.cpp b/test/test_svm_ptr.cpp
index ad00340..1a8ad8f 100644
--- a/test/test_svm_ptr.cpp
+++ b/test/test_svm_ptr.cpp
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(alloc)
 {
     REQUIRES_OPENCL_VERSION(2, 0);
 
-    compute::svm_ptr<int> ptr = compute::svm_alloc<int>(context, 8);
+    compute::svm_ptr<cl_int> ptr = compute::svm_alloc<cl_int>(context, 8);
     compute::svm_free(context, ptr);
 }
 
@@ -50,21 +50,26 @@ BOOST_AUTO_TEST_CASE(sum_svm_kernel)
     );
 
     compute::program program =
-        compute::program::build_with_source(source, context);
+        compute::program::build_with_source(source, context, "-cl-std=CL2.0");
 
     compute::kernel sum_svm_mem_kernel = program.create_kernel("sum_svm_mem");
 
-    int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
-    compute::svm_ptr<int> ptr = compute::svm_alloc<int>(context, 8);
-    queue.enqueue_svm_memcpy(ptr.get(), data, 8 * sizeof(int));
+    cl_int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
+    compute::svm_ptr<cl_int> ptr = compute::svm_alloc<cl_int>(context, 8);
+    queue.enqueue_svm_map(ptr.get(), 8 * sizeof(cl_int), CL_MAP_WRITE);
+    for(size_t i = 0; i < 8; i ++) {
+        static_cast<cl_int*>(ptr.get())[i] = data[i];
+    }
+    queue.enqueue_svm_unmap(ptr.get());
 
-    compute::vector<int> result(1, context);
+    compute::vector<cl_int> result(1, context);
 
     sum_svm_mem_kernel.set_arg(0, ptr);
     sum_svm_mem_kernel.set_arg(1, result);
     queue.enqueue_task(sum_svm_mem_kernel);
 
-    CHECK_RANGE_EQUAL(int, 1, result, (36));
+    queue.finish();
+    BOOST_CHECK_EQUAL(result[0], (36));
 
     compute::svm_free(context, ptr);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/compute.git



More information about the debian-science-commits mailing list