[Beignet] [PATCH] runtime: add macro DEBUGP() to handle debug printf.

Ruiling Song ruiling.song at intel.com
Tue Nov 24 18:46:37 PST 2015


It will output debug message under debug mode, and will
not output under release mode.

Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
 src/cl_command_queue_gen7.c | 6 +++---
 src/cl_utils.h              | 6 ++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/cl_command_queue_gen7.c b/src/cl_command_queue_gen7.c
index 2edc3be..f24085e 100644
--- a/src/cl_command_queue_gen7.c
+++ b/src/cl_command_queue_gen7.c
@@ -329,21 +329,21 @@ cl_command_queue_ND_range_gen7(cl_command_queue queue,
 
   /* Compute the number of HW threads we need */
   if(UNLIKELY(err = cl_kernel_work_group_sz(ker, local_wk_sz, 3, &local_sz) != CL_SUCCESS)) {
-    fprintf(stderr, "Beignet: Work group size exceed Kerne's work group size.\n");
+    DEBUGP("Beignet: Work group size exceed Kerne's work group size.\n");
     return err;
   }
   kernel.thread_n = thread_n = (local_sz + simd_sz - 1) / simd_sz;
   kernel.curbe_sz = cst_sz;
 
   if (scratch_sz > ker->program->ctx->device->scratch_mem_size) {
-    fprintf(stderr, "Beignet: Out of scratch memory %d.\n", scratch_sz);
+    DEBUGP("Beignet: Out of scratch memory %d.\n", scratch_sz);
     return CL_OUT_OF_RESOURCES;
   }
   /* Curbe step 1: fill the constant urb buffer data shared by all threads */
   if (ker->curbe) {
     kernel.slm_sz = cl_curbe_fill(ker, work_dim, global_wk_off, global_wk_sz, local_wk_sz, thread_n);
     if (kernel.slm_sz > ker->program->ctx->device->local_mem_size) {
-      fprintf(stderr, "Beignet: Out of shared local memory %d.\n", kernel.slm_sz);
+      DEBUGP("Beignet: Out of shared local memory %d.\n", kernel.slm_sz);
       return CL_OUT_OF_RESOURCES;
     }
   }
diff --git a/src/cl_utils.h b/src/cl_utils.h
index 28fdef6..941d90b 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -31,6 +31,12 @@
 #define JOIN(X, Y) _DO_JOIN(X, Y)
 #define _DO_JOIN(X, Y) _DO_JOIN2(X, Y)
 #define _DO_JOIN2(X, Y) X##Y
+#ifdef NDEBUG
+  #define DEBUGP(...)
+#else
+  #define DEBUGP(fmt, ...)        \
+  fprintf(stderr, fmt, ##__VA_ARGS__)
+#endif
 
 /* Check compile time errors */
 #define STATIC_ASSERT(value)                                        \
-- 
2.4.1



More information about the Beignet mailing list