Want more features on Pastebin? Sign Up, it's FREE!
Guest

OpenCL stuff

By: a guest on Oct 25th, 2011  |  syntax: C  |  size: 1.98 KB  |  views: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. clGetPlatformIDs(1, &platformID, &numPlatforms);
  2.         clGetDeviceIDs(platformID, CL_DEVICE_TYPE_DEFAULT, 1, &deviceID, &numDevices);
  3.         context = clCreateContext(NULL, 1, &deviceID, NULL, NULL, NULL);
  4.         commandQueue = clCreateCommandQueue(context, deviceID, 0, NULL);
  5.  
  6.         memOP = clCreateBuffer(context, CL_MEM_READ_ONLY, MAX_OP * sizeof(Coord), NULL, NULL);
  7.         memSegment = clCreateBuffer(context, CL_MEM_READ_ONLY, MAX_SEGMENTEN * sizeof(Coord), NULL, NULL);
  8.         memAfstanden = clCreateBuffer(context, CL_MEM_WRITE_ONLY, MAX_AFSTANDEN * sizeof(double), NULL, NULL);
  9.        
  10.         clEnqueueWriteBuffer(commandQueue, memOP, CL_TRUE, 0, MAX_OP * sizeof(Coord), OP, 0, NULL, NULL);
  11.         clEnqueueWriteBuffer(commandQueue, memSegment, CL_TRUE, 0, MAX_SEGMENTEN * sizeof(Coord), segmentArray, 0, NULL, NULL);
  12.  
  13.         clCreateProgramWithSource(context, 1, (const char **)&kernelSource, (const size_t *)&kernelLength, NULL);
  14.  
  15.         clBuildProgram(program, 1, &deviceID, NULL, NULL, NULL);
  16.  
  17.         kernel = clCreateKernel(program, "afstand", NULL);
  18.  
  19.         clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memOP);
  20.         clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&memSegment);
  21.         clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&memAfstanden);
  22.         clSetKernelArg(kernel, 3, sizeof(int), FLIGHTALTITUDE);
  23.        
  24.         clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, MAX_AFSTANDEN, 1, 0, NULL, NULL);
  25.  
  26.         clEnqueueReadBuffer(commandQueue, memAfstanden, CL_TRUE, 0, MAX_AFSTANDEN * sizeof(double), afstanden, 0, NULL, NULL);
  27.        
  28.         fopen_s(&optr, "C:\\Cio\\IO.txt", "wt");
  29.         for(i = 0; i < MAX_OP; i++)
  30.         {
  31.                 for(z = 0; z < MAX_SEGMENTEN; z++)
  32.                 {
  33.                         fprintf(optr, "OP %d ligt %3.2lfkm van segment %d af\n", i, afstanden[MAX_SEGMENTEN*i + z], z);
  34.                 }
  35.         }
  36.         fclose(optr);
  37.  
  38.         clFlush(commandQueue);
  39.     clFinish(commandQueue);
  40.     clReleaseKernel(kernel);
  41.     clReleaseProgram(program);
  42.     clReleaseMemObject(memOP);
  43.     clReleaseMemObject(memSegment);
  44.     clReleaseMemObject(memAfstanden);
  45.     clReleaseCommandQueue(commandQueue);
  46.     clReleaseContext(context);
  47.  
clone this paste RAW Paste Data