Added flat_address_space tests
authorBenjamin Segovia <segovia.benjamin@gmail.com>
Thu, 3 May 2012 17:25:24 +0000 (17:25 +0000)
committerKeith Packard <keithp@keithp.com>
Fri, 10 Aug 2012 23:17:00 +0000 (16:17 -0700)
utests/CMakeLists.txt
utests/compiler_eot.cpp [deleted file]
utests/runtime_flat_address_space.cpp
utests/utest_file_map.hpp
utests/utest_helper.cpp
utests/utest_helper.hpp

index 29c753b..4a54d2a 100644 (file)
@@ -1,15 +1,20 @@
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
                     ${CMAKE_CURRENT_SOURCE_DIR}/../include)
 
-ADD_EXECUTABLE(run
-               utest_error.c
-               utest_helper.cpp
-               utest_file_map.cpp
-               utest_assert.cpp
-               utest.cpp
-               utest_run.cpp
-               compiler_write_only.cpp
-               compiler_copy_buffer.cpp
-               compiler_copy_buffer_row.cpp)
-TARGET_LINK_LIBRARIES(run cl m)
+ADD_LIBRARY(utests SHARED
+            utest_error.c
+            utest_helper.cpp
+            utest_file_map.cpp
+            utest_assert.cpp
+            utest.cpp
+            compiler_write_only.cpp
+            compiler_copy_buffer.cpp
+            compiler_copy_buffer_row.cpp)
+TARGET_LINK_LIBRARIES(utests cl m)
+
+ADD_EXECUTABLE(run utest_run.cpp)
+TARGET_LINK_LIBRARIES(run utests)
+
+ADD_EXECUTABLE(flat_address_space runtime_flat_address_space.cpp)
+TARGET_LINK_LIBRARIES(flat_address_space utests)
 
diff --git a/utests/compiler_eot.cpp b/utests/compiler_eot.cpp
deleted file mode 100644 (file)
index b55bed4..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/* 
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-#include "cl_test.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-main (int argc, char *argv[])
-{
-  const size_t n = 1024;
-  const size_t global_work_size = n;
-  const size_t local_work_size = 16;
-  int status = 0;
-
-  if ((status = cl_test_init("dummy.ll", "hop", LLVM)) != 0) goto error;
-
-  /* Run the kernel */
-  CALL (clEnqueueNDRangeKernel, queue,
-                                kernel,
-                                1,
-                                NULL,
-                                &global_work_size,
-                                &local_work_size,
-                                0,
-                                NULL,
-                                NULL);
-
-  cl_test_destroy();
-  printf("%i memory leaks\n", clIntelReportUnfreed());
-  assert(clIntelReportUnfreed() == 0);
-
-error:
-  cl_report_error(status);
-  return status;
-}
-
index 68aeef0..d2f4aef 100644 (file)
  * Author: Benjamin Segovia <benjamin.segovia@intel.com>
  */
 
-#include "cl_test.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include "utest_helper.hpp"
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
   cl_mem dst[24];
   int *dst_buffer;
   const size_t n = 32 * 1024 * 1024;
   const size_t global_work_size = n;
   const size_t local_work_size = 16;
-  int status = 0, i, j;
+  int status = 0;
 
   if ((status = cl_test_init("test_write_only.cl", "test_write_only", SOURCE)) != 0)
     goto error;
 
-  for (j = 0; j < 24; ++j) {
-    /* Allocate the two buffers */
+  for (uint32_t j = 0; j < 24; ++j)
+  {
+    // Allocate the two buffers
     dst[j] = clCreateBuffer(ctx, 0, n * sizeof(uint32_t), NULL, &status);
     if (status != CL_SUCCESS) goto error;
 
-    /* Set source and destination */
-    CALL (clSetKernelArg, kernel, 0, sizeof(cl_mem), &dst[j]);
+    // Set source and destination
+    OCL_CALL (clSetKernelArg, kernel, 0, sizeof(cl_mem), &dst[j]);
 
-    /* Run the kernel */
-    CALL (clEnqueueNDRangeKernel, queue,
+    // Run the kernel
+    OCL_CALL (clEnqueueNDRangeKernel, queue,
                                   kernel,
                                   1,
                                   NULL,
@@ -55,21 +52,20 @@ main (int argc, char *argv[])
                                   NULL,
                                   NULL);
 
-    /* Be sure that everything run fine */
+    // Be sure that everything run fine
     dst_buffer = (int *) clIntelMapBuffer(dst[j], &status);
     if (status != CL_SUCCESS)
       goto error;
-    for (i = 0; i < n; ++i) assert(dst_buffer[i] == i);
-    CALL (clIntelUnmapBuffer, dst[j]);
+    for (uint32_t i = 0; i < n; ++i) assert(dst_buffer[i] == int(i));
+    OCL_CALL (clIntelUnmapBuffer, dst[j]);
   }
 
-  for (j = 0; j < 24; ++j) CALL (clReleaseMemObject, dst[j]);
+  for (uint32_t j = 0; j < 24; ++j) OCL_CALL (clReleaseMemObject, dst[j]);
   cl_test_destroy();
   printf("%i memory leaks\n", clIntelReportUnfreed());
   assert(clIntelReportUnfreed() == 0);
 
 error:
-  cl_report_error(status);
   return status;
 }
 
index d01ca70..83d79ea 100644 (file)
@@ -27,7 +27,7 @@
 #define __UTEST_FILE_MAP_HPP__
 
 #include "CL/cl.h"
-#include <stdlib.h>
+#include <cstdlib>
 
 /* Map a file into memory for direct / cached / simple accesses */
 typedef struct cl_file_map {
index 0083618..d9979ae 100644 (file)
 #include "CL/cl.h"
 #include "CL/cl_intel.h"
 
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <assert.h>
+#include <cstdio>
+#include <cstdint>
+#include <cstring>
+#include <casserth>
 
 #define FATAL(...) \
 do { \
index bf0c3ab..c17a1e7 100644 (file)
@@ -30,9 +30,9 @@
 #include "utest.hpp"
 #include "utest_assert.hpp"
 #include "utest_error.h"
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cassert>
+#include <cstdio>
+#include <cstdlib>
 
 #define OCL_THROW_ERROR(FN, STATUS) \
   do { \
 
 #define OCL_UNMAP_BUFFER(ID) \
   do { \
-    OCL_CALL (clIntelUnmapBuffer, buf[ID]); \
-    buf_data[ID] = NULL; \
+    if (buf[ID] != NULL) { \
+      OCL_CALL (clIntelUnmapBuffer, buf[ID]); \
+      buf_data[ID] = NULL; \
+    } \
   } while (0)
 
 #define OCL_NDRANGE(DIM_N) \