Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/cl-target/fragments/c-output-grid.in
ViewVC logotype

View of /branches/vis12-cl/src/compiler/cl-target/fragments/c-output-grid.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2767 - (download) (annotate)
Sat Oct 11 14:24:05 2014 UTC (4 years, 9 months ago) by jhr
File size: 1819 byte(s)
  working on OpenCL support
// helper function for getting output values from a grid of strands
//
STATIC_INLINE bool OutputGrid (@PREFIX@World_t *wrld, int nDims, size_t *sizes, cl_kernel kern, Nrrd *nData)
{
    cl_int sts;

  // compute the total size
    size_t totalSz = 1;
    for (int i = 0;  i < nDims;  i++) {
	totalSz *= sizes[i];
    }

  // Allocate GPU buffer
    cl_mem gpuData = clCreateBuffer (wrld->context, CL_MEM_WRITE_ONLY, totalSz, 0, &sts);
    if (CheckOCLStatus (wrld, sts, "error allocating GPU memory for output")) {
	return true;
    }

  // work sizes for the program
    size_t globalWorkSize[1];
    size_t localWorkSize[1]; 
    globalWorkSize[0] = wrld->nWorkers * wrld->device->cuWidth; 
    localWorkSize[0] = wrld->device->cuWidth;

  // Run the copy kernel
    if (((sts = clSetKernelArg (kern, 0, sizeof(cl_mem), &(wrld->schedBuf))) != CL_SUCCESS)
    ||  ((sts = clSetKernelArg (kern, 1, sizeof(cl_mem), &(gpuData))) != CL_SUCCESS)
    ||  ((sts = clSetKernelArg (kern, 2, sizeof(cl_uint), &(wrld->numStrands))) != CL_SUCCESS)
    ||  ((sts = clEnqueueNDRangeKernel(wrld->cmdQ, kern, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, NULL)) != CL_SUCCESS)) {
	ReportOCLError (wrld, sts, "error enqueuing output kernel");
	return true;
    }

  // Allocate nData nrrd
    if (nrrdMaybeAlloc_nva(nData, nrrdTypeFloat, 3, sizes)!=0) {
        char *msg = biffGetDone(NRRD);
        biffMsgAdd(wrld->errors, msg);
        free(msg);
	clReleaseMemObject(gpuData);
        return true;
    }

  // copy data to output nrrd
    sts = clEnqueueReadBuffer (wrld->cmdQ, gpuData, CL_TRUE, 0, totalSz, nData->data, 0, 0, 0);
    if (CheckOCLStatus (wrld, sts, "error copying output from GPU")) {
	clReleaseMemObject(gpuData);
	return true;
    }

  // free GPU buffer
    clReleaseMemObject(gpuData);
    return false;

}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0