diff options
author | Junyan He <junyan.he@linux.intel.com> | 2015-01-12 13:55:22 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2015-01-13 14:33:08 +0800 |
commit | 62ad21c61dd0440d017f3f2e54c8ed79df6c667c (patch) | |
tree | e5295285ff156273827f366b418e7f5230d7cc4d /src | |
parent | 8702b08890e1ad3bb5d9b93430684ec4025a7c06 (diff) |
Fix the printf buffer size bug.
We can not know the accurate size of the printf buffer
size before run the kernel. Sometimes, especially when
the global work items size is huge, the output buffer
is not enough and the print message logic will cause the
segment fault.
We increase the printf buffer to 16M at most and add out
of range check to avoid crash.
Signed-off-by: Junyan He <junyan.he@linux.intel.com>
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/cl_command_queue.c | 5 | ||||
-rw-r--r-- | src/cl_command_queue_gen7.c | 2 | ||||
-rw-r--r-- | src/cl_driver.h | 2 | ||||
-rw-r--r-- | src/intel/intel_gpgpu.c | 5 |
4 files changed, 9 insertions, 5 deletions
diff --git a/src/cl_command_queue.c b/src/cl_command_queue.c index 61039097..89afa075 100644 --- a/src/cl_command_queue.c +++ b/src/cl_command_queue.c @@ -216,7 +216,8 @@ LOCAL void cl_command_queue_flush_gpgpu(cl_command_queue queue, cl_gpgpu gpgpu) { size_t global_wk_sz[3]; - void* printf_info = cl_gpgpu_get_printf_info(gpgpu, global_wk_sz); + size_t outbuf_sz = 0; + void* printf_info = cl_gpgpu_get_printf_info(gpgpu, global_wk_sz, &outbuf_sz); cl_gpgpu_flush(gpgpu); @@ -227,7 +228,7 @@ cl_command_queue_flush_gpgpu(cl_command_queue queue, cl_gpgpu gpgpu) buf_addr = cl_gpgpu_map_printf_buffer(gpgpu, 1); interp_output_printf(printf_info, index_addr, buf_addr, global_wk_sz[0], - global_wk_sz[1], global_wk_sz[2]); + global_wk_sz[1], global_wk_sz[2], outbuf_sz); cl_gpgpu_unmap_printf_buffer(gpgpu, 0); if (interp_get_printf_sizeof_size(printf_info)) diff --git a/src/cl_command_queue_gen7.c b/src/cl_command_queue_gen7.c index 734267a2..eec39b43 100644 --- a/src/cl_command_queue_gen7.c +++ b/src/cl_command_queue_gen7.c @@ -281,7 +281,7 @@ cl_bind_printf(cl_gpgpu gpgpu, cl_kernel ker, void* printf_info, int printf_num, if (buf_size < 1*1024) buf_size = 1*1024*1024; else - buf_size = 4*1024*1024; //at most. + buf_size = 16*1024*1024; //at most. if (offset > 0) { if (cl_gpgpu_set_printf_buffer(gpgpu, 1, buf_size, offset, interp_get_printf_buf_bti(printf_info)) != 0) diff --git a/src/cl_driver.h b/src/cl_driver.h index f13ebee8..c88b9be3 100644 --- a/src/cl_driver.h +++ b/src/cl_driver.h @@ -266,7 +266,7 @@ typedef int (cl_gpgpu_set_printf_info_cb)(cl_gpgpu, void *, size_t*); extern cl_gpgpu_set_printf_info_cb *cl_gpgpu_set_printf_info; /* Get the last printfset pointer */ -typedef void* (cl_gpgpu_get_printf_info_cb)(cl_gpgpu, size_t*); +typedef void* (cl_gpgpu_get_printf_info_cb)(cl_gpgpu, size_t*, size_t*); extern cl_gpgpu_get_printf_info_cb *cl_gpgpu_get_printf_info; /* Will spawn all threads */ diff --git a/src/intel/intel_gpgpu.c b/src/intel/intel_gpgpu.c index 1836bfd5..479077c8 100644 --- a/src/intel/intel_gpgpu.c +++ b/src/intel/intel_gpgpu.c @@ -1896,11 +1896,14 @@ intel_gpgpu_set_printf_info(intel_gpgpu_t *gpgpu, void* printf_info, size_t * gl } static void* -intel_gpgpu_get_printf_info(intel_gpgpu_t *gpgpu, size_t * global_sz) +intel_gpgpu_get_printf_info(intel_gpgpu_t *gpgpu, size_t * global_sz, size_t *outbuf_sz) { global_sz[0] = gpgpu->global_wk_sz[0]; global_sz[1] = gpgpu->global_wk_sz[1]; global_sz[2] = gpgpu->global_wk_sz[2]; + + if (gpgpu->printf_b.bo) + *outbuf_sz = gpgpu->printf_b.bo->size; return gpgpu->printf_info; } |