#include #include #include #include #include "cl_simple.h" #include "cl_util.h" int main (int argc, char ** argv) { int i,j; struct cl_simple_context context; cl_int error; cl_mem out_buffer; int * out_data; size_t global_work_size = 5; int iterations; unsigned out_data_size; if (argc != 2) { fprintf(stderr, "Usage: loop iterations\n"); return EXIT_FAILURE; } iterations = atoi(argv[1]); out_data_size = global_work_size * iterations * sizeof(int); out_data = malloc(out_data_size); if (!clSimpleSimpleInit(&context, "loop")) { return EXIT_FAILURE; } out_buffer = clCreateBuffer(context.cl_ctx, CL_MEM_WRITE_ONLY, out_data_size, NULL, &error); assert(error == CL_SUCCESS); if (!clSimpleKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer) || !clSimpleKernelSetArg(context.kernel, 1, sizeof(int), &iterations)) { 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, out_data_size, out_data, 0, NULL, NULL); assert(error == CL_SUCCESS); for (i = 0; i < global_work_size; i++) { for (j = 0; j < iterations; j++) { fprintf(stderr, "%2u ", out_data[(i * iterations) + j]); } fprintf(stderr, "\n"); } }