diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2012-03-14 14:06:52 -0400 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2012-03-14 14:06:52 -0400 |
commit | 6fb01e9c6775c554a314da607ae926a451802fb8 (patch) | |
tree | 4d5f971ea26e1b1813bb4e294930f5ef442e4c84 /loop.c | |
parent | fc42b01d96c37ac107e6e24a2b3340f12c7b156b (diff) |
Add loop example
Diffstat (limited to 'loop.c')
-rw-r--r-- | loop.c | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -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"); + } +} |