#include #include #include #include "util.h" int main(int argc, char ** argv) { cl_int error; struct cltest_context context; cl_mem out_buffer; unsigned i; int out_data[10]; size_t global_work_size = 10; clTestSimpleInit(&context, "global_id"); out_buffer = clCreateBuffer(context.cl_ctx, CL_MEM_WRITE_ONLY, /* Flags */ sizeof(out_data), /* Size of buffer */ NULL, /* Pointer to the data */ &error); /* error code */ if (error != CL_SUCCESS) { fprintf(stderr, "clCreateBuffer() failed: %s\n", clTestErrorString(error)); return EXIT_FAILURE; } fprintf(stderr, "clCreateBuffer() succeeded.\n"); if ( !clTestKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) { return EXIT_FAILURE; } error = clEnqueueNDRangeKernel(context.command_queue, context.kernel, 1, /* Number of dimensions */ NULL, /* Global work offset */ &global_work_size, &global_work_size, /* local work size */ 0, /* Events in wait list */ NULL, /* Wait list */ NULL); /* Event object for this event */ if (error != CL_SUCCESS) { fprintf(stderr, "clEnqueueNDRangeKernel() failed: %s\n", clTestErrorString(error)); return EXIT_FAILURE; } fprintf(stderr, "clEnqueueNDRangeKernel() suceeded.\n"); error = clEnqueueReadBuffer(context.command_queue, out_buffer, CL_TRUE, /* TRUE means it is a blocking read. */ 0, /* Buffer offset to read from. */ sizeof(out_data), /* Bytes to read */ out_data, /* Pointer to store the data */ 0, /* Events in wait list */ NULL, /* Wait list */ NULL); /* Event object */ if (error != CL_SUCCESS) { fprintf(stderr, "clEnqueueReadBuffer() failed: %s\n", clTestErrorString(error)); return EXIT_FAILURE; } fprintf(stderr, "clEnqueueReadBuffer() suceeded.\n"); for (i = 0; i < 10; i++) { fprintf(stderr, "id %u = %u\n", i, out_data[i]); } /* if (out_value == expected) { fprintf(stderr, "Pass\n"); return EXIT_SUCCESS; } else { fprintf(stderr, "Expected %d, but got %d\n", expected, out_value); return EXIT_FAILURE; } */ }