We should always check whether a dri_bo_map success or fail.
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
return err;
}
-static void
+static int
cl_upload_constant_buffer(cl_command_queue queue, cl_kernel ker)
{
/* calculate constant buffer size
}
}
if(raw_size == 0)
- return;
+ return 0;
cl_buffer bo = cl_gpgpu_alloc_constant_buffer(gpgpu, aligned_size);
+ if (bo == NULL)
+ return -1;
cl_buffer_map(bo, 1);
char * cst_addr = cl_buffer_get_virtual(bo);
+ if (cst_addr == NULL)
+ return -1;
/* upload the global constant data */
if (global_const_size > 0) {
}
}
cl_buffer_unmap(bo);
+ return 0;
}
/* Will return the total amount of slm used */
cl_gpgpu_set_stack(gpgpu, offset, stack_sz, cl_gpgpu_get_cache_ctrl());
}
-static void
+static int
cl_bind_printf(cl_gpgpu gpgpu, cl_kernel ker, void* printf_info, int printf_num, size_t global_sz) {
int32_t value = GBE_CURBE_PRINTF_INDEX_POINTER;
int32_t offset = interp_kernel_get_curbe_offset(ker->opaque, value, 0);
size_t buf_size = global_sz * sizeof(int) * printf_num;
- if (offset > 0)
- cl_gpgpu_set_printf_buffer(gpgpu, 0, buf_size, offset);
+ if (offset > 0) {
+ if (cl_gpgpu_set_printf_buffer(gpgpu, 0, buf_size, offset) != 0)
+ return -1;
+ }
value = GBE_CURBE_PRINTF_BUF_POINTER;
offset = interp_kernel_get_curbe_offset(ker->opaque, value, 0);
buf_size = interp_get_printf_sizeof_size(printf_info) * global_sz;
- if (offset > 0)
- cl_gpgpu_set_printf_buffer(gpgpu, 1, buf_size, offset);
+ if (offset > 0) {
+ if (cl_gpgpu_set_printf_buffer(gpgpu, 1, buf_size, offset) != 0)
+ return -1;
+ }
+ return 0;
}
LOCAL cl_int
/* Setup the kernel */
if (queue->props & CL_QUEUE_PROFILING_ENABLE)
- cl_gpgpu_state_init(gpgpu, ctx->device->max_compute_unit * ctx->device->max_thread_per_unit, cst_sz / 32, 1);
+ err = cl_gpgpu_state_init(gpgpu, ctx->device->max_compute_unit * ctx->device->max_thread_per_unit, cst_sz / 32, 1);
else
- cl_gpgpu_state_init(gpgpu, ctx->device->max_compute_unit * ctx->device->max_thread_per_unit, cst_sz / 32, 0);
-
+ err = cl_gpgpu_state_init(gpgpu, ctx->device->max_compute_unit * ctx->device->max_thread_per_unit, cst_sz / 32, 0);
+ if (err != 0)
+ goto error;
printf_num = interp_get_printf_num(printf_info);
if (printf_num) {
- cl_bind_printf(gpgpu, ker, printf_info, printf_num, global_size);
+ if (cl_bind_printf(gpgpu, ker, printf_info, printf_num, global_size) != 0)
+ goto error;
}
/* Bind user buffers */
/* Bind all samplers */
cl_gpgpu_bind_sampler(gpgpu, ker->samplers, ker->sampler_sz);
- cl_gpgpu_set_scratch(gpgpu, scratch_sz);
+ if (cl_gpgpu_set_scratch(gpgpu, scratch_sz) != 0)
+ goto error;
/* Bind a stack if needed */
cl_bind_stack(gpgpu, ker);
- cl_upload_constant_buffer(queue, ker);
+ if (cl_upload_constant_buffer(queue, ker) != 0)
+ goto error;
cl_gpgpu_states_setup(gpgpu, &kernel);
memcpy(final_curbe + cst_sz * i, ker->curbe, cst_sz);
}
TRY (cl_set_varying_payload, ker, final_curbe, local_wk_sz, simd_sz, cst_sz, thread_n);
- cl_gpgpu_upload_curbes(gpgpu, final_curbe, thread_n*cst_sz);
+ if (cl_gpgpu_upload_curbes(gpgpu, final_curbe, thread_n*cst_sz) != 0)
+ goto error;
}
/* Start a new batch buffer */
batch_sz = cl_kernel_compute_batch_sz(ker);
- cl_gpgpu_batch_reset(gpgpu, batch_sz);
+ if (cl_gpgpu_batch_reset(gpgpu, batch_sz) != 0)
+ goto error;
cl_set_thread_batch_buf(queue, cl_gpgpu_ref_batch_buf(gpgpu));
cl_gpgpu_batch_start(gpgpu);
/* Close the batch buffer and submit it */
cl_gpgpu_batch_end(gpgpu, 0);
+ return CL_SUCCESS;
+
error:
- return err;
+ fprintf(stderr, "error occured. \n");
+ exit(-1);
+ return CL_OUT_OF_RESOURCES;
}
extern cl_gpgpu_set_stack_cb *cl_gpgpu_set_stack;
/* Setup scratch */
-typedef void (cl_gpgpu_set_scratch_cb)(cl_gpgpu, uint32_t per_thread_size);
+typedef int (cl_gpgpu_set_scratch_cb)(cl_gpgpu, uint32_t per_thread_size);
extern cl_gpgpu_set_scratch_cb *cl_gpgpu_set_scratch;
/* Configure internal state */
-typedef void (cl_gpgpu_state_init_cb)(cl_gpgpu, uint32_t max_threads, uint32_t size_cs_entry, int profiling);
+typedef int (cl_gpgpu_state_init_cb)(cl_gpgpu, uint32_t max_threads, uint32_t size_cs_entry, int profiling);
extern cl_gpgpu_state_init_cb *cl_gpgpu_state_init;
/* Set the buffer object where to report performance counters */
extern cl_gpgpu_set_perf_counters_cb *cl_gpgpu_set_perf_counters;
/* Fills current curbe buffer with data */
-typedef void (cl_gpgpu_upload_curbes_cb)(cl_gpgpu, const void* data, uint32_t size);
+typedef int (cl_gpgpu_upload_curbes_cb)(cl_gpgpu, const void* data, uint32_t size);
extern cl_gpgpu_upload_curbes_cb *cl_gpgpu_upload_curbes;
typedef cl_buffer (cl_gpgpu_alloc_constant_buffer_cb)(cl_gpgpu, uint32_t size);
extern cl_gpgpu_set_sampler_cb *cl_gpgpu_set_sampler;
/* Allocate the batch buffer and return the BO used for the batch buffer */
-typedef void (cl_gpgpu_batch_reset_cb)(cl_gpgpu, size_t sz);
+typedef int (cl_gpgpu_batch_reset_cb)(cl_gpgpu, size_t sz);
extern cl_gpgpu_batch_reset_cb *cl_gpgpu_batch_reset;
/* Atomic begin, pipeline select, urb, pipeline state and constant buffer */
extern cl_gpgpu_unref_batch_buf_cb *cl_gpgpu_unref_batch_buf;
/* Set the printf buffer */
-typedef void (cl_gpgpu_set_printf_buffer_cb)(cl_gpgpu, uint32_t, uint32_t, uint32_t);
+typedef int (cl_gpgpu_set_printf_buffer_cb)(cl_gpgpu, uint32_t, uint32_t, uint32_t);
extern cl_gpgpu_set_printf_buffer_cb *cl_gpgpu_set_printf_buffer;
/* get the printf buffer offset in the apeture*/
extern cl_gpgpu_release_printf_buffer_cb *cl_gpgpu_release_printf_buffer;
/* Set the last printfset pointer */
-typedef void (cl_gpgpu_set_printf_info_cb)(cl_gpgpu, void *, size_t*);
+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 */
#include <string.h>
#include <assert.h>
-LOCAL void
+LOCAL int
intel_batchbuffer_reset(intel_batchbuffer_t *batch, size_t sz)
{
if (batch->buffer != NULL) {
"batch buffer",
sz,
64);
- assert(batch->buffer);
-
- dri_bo_map(batch->buffer, 1);
+ if (!batch->buffer || (dri_bo_map(batch->buffer, 1) != 0)) {
+ if (batch->buffer)
+ dri_bo_unreference(batch->buffer);
+ batch->buffer = NULL;
+ return -1;
+ }
batch->map = (uint8_t*) batch->buffer->virtual;
batch->size = sz;
batch->ptr = batch->map;
batch->atomic = 0;
batch->last_bo = batch->buffer;
batch->enable_slm = 0;
+ return 0;
}
LOCAL void
extern void intel_batchbuffer_init(intel_batchbuffer_t*, struct intel_driver*);
extern void intel_batchbuffer_terminate(intel_batchbuffer_t*);
extern void intel_batchbuffer_flush(intel_batchbuffer_t*);
-extern void intel_batchbuffer_reset(intel_batchbuffer_t*, size_t sz);
+extern int intel_batchbuffer_reset(intel_batchbuffer_t*, size_t sz);
static INLINE uint32_t
intel_batchbuffer_space(const intel_batchbuffer_t *batch)
#include <sys/stat.h>
#include <fcntl.h>
#include <stddef.h>
+#include <errno.h>
#include "intel/intel_gpgpu.h"
#include "intel/intel_defines.h"
intel_batchbuffer_end_atomic(gpgpu->batch);
}
-static void
+static int
intel_gpgpu_batch_reset(intel_gpgpu_t *gpgpu, size_t sz)
{
- intel_batchbuffer_reset(gpgpu->batch, sz);
+ return intel_batchbuffer_reset(gpgpu->batch, sz);
}
/* check we do not get a 0 starting address for binded buf */
static void
intel_gpgpu_check_binded_buf_address(gpgpu);
}
-static void
+static int
intel_gpgpu_state_init(intel_gpgpu_t *gpgpu,
uint32_t max_threads,
uint32_t size_cs_entry,
gpgpu->time_stamp_b.bo = NULL;
if (profiling) {
bo = dri_bo_alloc(gpgpu->drv->bufmgr, "timestamp query", 4096, 4096);
- assert(bo);
gpgpu->time_stamp_b.bo = bo;
+ if (!bo)
+ fprintf(stderr, "Could not allocate buffer for profiling.\n");
}
/* stack */
uint32_t size_aux = 0;
if(gpgpu->aux_buf.bo)
dri_bo_unreference(gpgpu->aux_buf.bo);
+ gpgpu->aux_buf.bo = NULL;
//surface heap must be 4096 bytes aligned because state base address use 20bit for the address
size_aux = ALIGN(size_aux, 4096);
size_aux += GEN_MAX_SAMPLERS * sizeof(gen7_sampler_border_color_t);
bo = dri_bo_alloc(gpgpu->drv->bufmgr, "AUX_BUFFER", size_aux, 0);
- assert(bo);
- dri_bo_map(bo, 1);
+ if (!bo || dri_bo_map(bo, 1) != 0) {
+ fprintf(stderr, "%s:%d: %s.\n", __FILE__, __LINE__, strerror(errno));
+ if (bo)
+ dri_bo_unreference(bo);
+ if (profiling && gpgpu->time_stamp_b.bo)
+ dri_bo_unreference(gpgpu->time_stamp_b.bo);
+ gpgpu->time_stamp_b.bo = NULL;
+ return -1;
+ }
memset(bo->virtual, 0, size_aux);
gpgpu->aux_buf.bo = bo;
+ return 0;
}
static void
if(gpgpu->constant_b.bo)
dri_bo_unreference(gpgpu->constant_b.bo);
gpgpu->constant_b.bo = drm_intel_bo_alloc(gpgpu->drv->bufmgr, "CONSTANT_BUFFER", s, 64);
- assert(gpgpu->constant_b.bo);
+ if (gpgpu->constant_b.bo == NULL)
+ return NULL;
ss2->ss1.base_addr = gpgpu->constant_b.bo->offset;
dri_bo_emit_reloc(gpgpu->aux_buf.bo,
I915_GEM_DOMAIN_RENDER,
gpgpu->binded_n++;
}
-static void
+static int
intel_gpgpu_set_scratch(intel_gpgpu_t * gpgpu, uint32_t per_thread_size)
{
drm_intel_bufmgr *bufmgr = gpgpu->drv->bufmgr;
old = NULL;
}
- if(!old)
+ if(!old && total) {
gpgpu->scratch_b.bo = drm_intel_bo_alloc(bufmgr, "SCRATCH_BO", total, 4096);
+ if (gpgpu->scratch_b.bo == NULL)
+ return -1;
+ }
+ return 0;
}
static void
intel_gpgpu_set_stack(intel_gpgpu_t *gpgpu, uint32_t offset, uint32_t size, uint32_t cchint)
gpgpu->aux_buf.bo);
}
-static void
+static int
intel_gpgpu_upload_curbes(intel_gpgpu_t *gpgpu, const void* data, uint32_t size)
{
unsigned char *curbe = NULL;
uint32_t i, j;
/* Upload the data first */
- dri_bo_map(gpgpu->aux_buf.bo, 1);
+ if (dri_bo_map(gpgpu->aux_buf.bo, 1) != 0) {
+ fprintf(stderr, "%s:%d: %s.\n", __FILE__, __LINE__, strerror(errno));
+ return -1;
+ }
assert(gpgpu->aux_buf.bo->virtual);
curbe = (unsigned char *) (gpgpu->aux_buf.bo->virtual + gpgpu->aux_offset.curbe_offset);
memcpy(curbe, data, size);
I915_GEM_DOMAIN_RENDER);
}
dri_bo_unmap(gpgpu->aux_buf.bo);
+ return 0;
}
static void
drm_intel_gem_bo_unmap_gtt(event->ts_buf);
}
-static void
+static int
intel_gpgpu_set_printf_buf(intel_gpgpu_t *gpgpu, uint32_t i, uint32_t size, uint32_t offset)
{
drm_intel_bo *bo = NULL;
} else
assert(0);
- drm_intel_bo_map(bo, 1);
+ if (!bo || (drm_intel_bo_map(bo, 1) != 0)) {
+ if (gpgpu->printf_b.bo)
+ drm_intel_bo_unreference(gpgpu->printf_b.bo);
+ gpgpu->printf_b.bo = NULL;
+ fprintf(stderr, "%s:%d: %s.\n", __FILE__, __LINE__, strerror(errno));
+ return -1;
+ }
memset(bo->virtual, 0, size);
drm_intel_bo_unmap(bo);
intel_gpgpu_bind_buf(gpgpu, bo, offset, 0, 0);
+ return 0;
}
static void*