From 5fbc65d9dfd6c9e051a26c71a54f70260124cf7a Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Thu, 31 Dec 2015 23:19:03 -0800 Subject: [PATCH] Hah, well something is happening!!!! --- Conway_OpenCL/HelloWorld.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Conway_OpenCL/HelloWorld.cpp b/Conway_OpenCL/HelloWorld.cpp index 06dc1f3..a6b4c10 100644 --- a/Conway_OpenCL/HelloWorld.cpp +++ b/Conway_OpenCL/HelloWorld.cpp @@ -179,17 +179,9 @@ int main(int argc, char* argv[]) int err = 0; - cl_mem workerCountBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &WORKER_SIZE, &err); - cl_mem gridWidthBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &GRID_WIDTH, &err); - cl_mem gridHeightBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &GRID_HEIGHT, &err); - status = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&workerCountBuffer); - status = clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&gridWidthBuffer); - status = clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&gridHeightBuffer); - - // ===================================== Loop ================================================================== while (window.isOpen()) { @@ -218,20 +210,33 @@ int main(int argc, char* argv[]) window.clear(sf::Color(49, 68, 72)); cl_mem inputBuffer = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, GRID_WIDTH * GRID_HEIGHT * 2 * sizeof(char), (void*)grid, &err); + cl_mem workerCountBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &WORKER_SIZE, &err); + cl_mem gridWidthBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &GRID_WIDTH, &err); + cl_mem gridHeightBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &GRID_HEIGHT, &err); + + status = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&inputBuffer); + status = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&workerCountBuffer); + status = clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&gridWidthBuffer); + status = clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&gridHeightBuffer); + + //status = clEnqueueWriteBuffer(commandQueue, inputBuffer, CL_TRUE, 0, GRID_WIDTH * GRID_HEIGHT * 2 * sizeof(char), (void*)grid, NULL, 0, NULL); // One work item per group, don't really know if this impacts performance - size_t global_work_size[1] = { 1 }; + size_t global_work_size[1] = { 100 }; // Run the kernel status = clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL); // Get output, put back into grid //cl_mem outputBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, GRID_WIDTH * GRID_HEIGHT * 2 * sizeof(char), grid, NULL); - status = clEnqueueReadBuffer(commandQueue, inputBuffer, CL_TRUE, 0, GRID_WIDTH * GRID_HEIGHT * 2 * sizeof(char), grid, 0, NULL, NULL); + status = clEnqueueReadBuffer(commandQueue, inputBuffer, CL_TRUE, 0, GRID_WIDTH * GRID_HEIGHT * 2 * sizeof(char), (void*)grid, 0, NULL, NULL); // Temporary status = clReleaseMemObject(inputBuffer); + status = clReleaseMemObject(workerCountBuffer); + status = clReleaseMemObject(gridWidthBuffer); + status = clReleaseMemObject(gridHeightBuffer); // Swap status's for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT * 2; i += 2) { @@ -251,9 +256,7 @@ int main(int argc, char* argv[]) } - status = clReleaseMemObject(workerCountBuffer); - status = clReleaseMemObject(gridWidthBuffer); - status = clReleaseMemObject(gridHeightBuffer); + /*Step 12: Clean the resources.*/ status = clReleaseKernel(kernel); //Release kernel.