summaryrefslogtreecommitdiff
path: root/loop.c
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2012-03-14 14:06:52 -0400
committerTom Stellard <thomas.stellard@amd.com>2012-03-14 14:06:52 -0400
commit6fb01e9c6775c554a314da607ae926a451802fb8 (patch)
tree4d5f971ea26e1b1813bb4e294930f5ef442e4c84 /loop.c
parentfc42b01d96c37ac107e6e24a2b3340f12c7b156b (diff)
Add loop example
Diffstat (limited to 'loop.c')
-rw-r--r--loop.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/loop.c b/loop.c
new file mode 100644
index 0000000..adac26d
--- /dev/null
+++ b/loop.c
@@ -0,0 +1,61 @@
+#include <assert.h>
+#include <stdio.h>
+
+#include <CL/cl.h>
+
+#include "util.h"
+
+int main (int argc, char ** argv)
+{
+ int i,j;
+
+ struct clu_context context;
+
+ cl_int error;
+
+ cl_mem out_buffer;
+ int out_data[100];
+ size_t global_work_size = 10;
+
+ if (!cluSimpleInit(&context, "loop")) {
+ return EXIT_FAILURE;
+ }
+
+ out_buffer = clCreateBuffer(context.cl_ctx,
+ CL_MEM_WRITE_ONLY,
+ sizeof(out_data),
+ NULL, &error);
+
+ assert(error == CL_SUCCESS);
+
+ if (!cluKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) {
+ return EXIT_FAILURE;
+ }
+
+ error = clEnqueueNDRangeKernel(context.command_queue,
+ context.kernel,
+ 1,
+ NULL,
+ &global_work_size,
+ &global_work_size,
+ 0, NULL, NULL);
+
+ assert(error == CL_SUCCESS);
+
+ error = clEnqueueReadBuffer(context.command_queue,
+ out_buffer,
+ CL_TRUE,
+ 0,
+ sizeof(out_data),
+ out_data,
+ 0, NULL, NULL);
+
+ assert(error == CL_SUCCESS);
+
+ for (i = 0; i < global_work_size; i++) {
+ for (j = 0; j < 10; j++) {
+ fprintf(stderr, "%2u ", out_data[i * global_work_size + j]);
+ }
+ fprintf(stderr, "\n");
+ }
+}