summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cl_simple.c29
-rw-r--r--cl_simple.h2
2 files changed, 23 insertions, 8 deletions
diff --git a/cl_simple.c b/cl_simple.c
index 2752027..eddfe21 100644
--- a/cl_simple.c
+++ b/cl_simple.c
@@ -63,6 +63,25 @@ unsigned clSimpleKernelSetArg(cl_kernel kernel, cl_uint index, size_t size,
return 1;
}
+unsigned clSimpleCreateBuffer(cl_mem * buffer, cl_context context,
+ cl_mem_flags flags, size_t size)
+{
+ cl_int error;
+
+ *buffer = clCreateBuffer(context,
+ flags, /* Flags */
+ size, /* Size of buffer */
+ NULL, /* Pointer to the data */
+ &error); /* error code */
+
+ if (error != CL_SUCCESS) {
+ fprintf(stderr, "clCreateBuffer() failed: %s\n", clUtilErrorString(error));
+ return 0;
+ }
+
+ return 1;
+}
+
unsigned clSimpleEnqueueNDRangeKernel(cl_command_queue command_queue,
cl_kernel kernel, cl_uint work_dim, const size_t * global_work_size,
const size_t * local_work_size)
@@ -264,14 +283,8 @@ unsigned clSimpleSetOutputBuffer(struct cl_simple_context * context,
{
cl_int error;
- context->out_buffer = clCreateBuffer(context->cl_ctx,
- CL_MEM_WRITE_ONLY, /* Flags */
- buffer_size, /* Size of buffer */
- NULL, /* Pointer to the data */
- &error); /* error code */
-
- if (error != CL_SUCCESS) {
- fprintf(stderr, "clCreateBuffer() failed: %s\n", clUtilErrorString(error));
+ if (!clSimpleCreateBuffer(&context->out_buffer, context->cl_ctx,
+ CL_MEM_WRITE_ONLY, buffer_size)) {
return 0;
}
diff --git a/cl_simple.h b/cl_simple.h
index 44a8b16..6bde48e 100644
--- a/cl_simple.h
+++ b/cl_simple.h
@@ -12,6 +12,8 @@ unsigned clSimpleCreateCommandQueue(cl_command_queue * command_queue,
cl_context context, cl_device_id device_id);
unsigned clSimpleKernelSetArg(cl_kernel kernel, cl_uint index, size_t size,
const void * value);
+unsigned clSimpleCreateBuffer(cl_mem * buffer, cl_context context,
+ cl_mem_flags flags, size_t size);
unsigned clSimpleEnqueueNDRangeKernel(cl_command_queue command_queue,
cl_kernel kernel, cl_uint work_dim, const size_t * global_work_size,
const size_t * local_work_size);