diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2012-04-27 09:53:28 -0400 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2012-04-27 09:53:28 -0400 |
commit | 569da6c94c9aa21cd35ccd19a9614c8a658106ec (patch) | |
tree | 3dbc17884c6f8bfae9f1febcfa0d576c6624622d | |
parent | 97793539673f4b65198bfe3d40ac51ec1fce8729 (diff) |
loop: Add argument for number of iterations
-rw-r--r-- | loop.c | 26 | ||||
-rw-r--r-- | loop.cl | 6 |
2 files changed, 22 insertions, 10 deletions
@@ -16,8 +16,19 @@ int main (int argc, char ** argv) cl_int error; cl_mem out_buffer; - int out_data[100]; - size_t global_work_size = 10; + 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; @@ -25,12 +36,13 @@ int main (int argc, char ** argv) out_buffer = clCreateBuffer(context.cl_ctx, CL_MEM_WRITE_ONLY, - sizeof(out_data), + out_data_size, NULL, &error); assert(error == CL_SUCCESS); - if (!clSimpleKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) { + if (!clSimpleKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer) + || !clSimpleKernelSetArg(context.kernel, 1, sizeof(int), &iterations)) { return EXIT_FAILURE; } @@ -48,15 +60,15 @@ int main (int argc, char ** argv) out_buffer, CL_TRUE, 0, - sizeof(out_data), + out_data_size, 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]); + for (j = 0; j < iterations; j++) { + fprintf(stderr, "%2u ", out_data[(i * iterations) + j]); } fprintf(stderr, "\n"); } @@ -1,8 +1,8 @@ -__kernel void loop(__global int * out) +__kernel void loop(__global int * out, int iterations) { unsigned i; - for (i = 0; i < 10; i++) { - unsigned id = get_global_id(0) + i; + for (i = 0; i < iterations; i++) { + unsigned id = (get_global_id(0) * iterations) + i; out[id] = id; } } |