示例#1
0
文件: ocl.c 项目: Thundzz/GPU
void ocl_alloc_buffers (sotl_device_t *dev)
{
  device_create_buffers(dev);

  if (sotl_verbose)
    sotl_log(INFO, "%.2f MB of memory allocated for %d atoms on device [%s]\n",
	     dev->mem_allocated / (1024.0 * 1024.0),
             dev->atom_set.natoms, dev->name);
}
示例#2
0
文件: openmp.c 项目: amilliet/GPU
void omp_init (sotl_device_t *dev)
{
#ifdef _SPHERE_MODE_
  sotl_log(ERROR, "Sequential implementation does currently not support SPHERE_MODE\n");
  exit (1);
#endif

  borders_enabled = 1;

  dev->compute = SOTL_COMPUTE_OMP; // dummy op to avoid warning
}
示例#3
0
文件: ocl.c 项目: Thundzz/GPU
void ocl_init(sotl_device_t *dev)
{
  cl_int err = 0;

  // Create context
  //
#ifdef HAVE_LIBGL
  if(dev->display) {
#ifdef __APPLE__
    CGLContextObj cgl_context = CGLGetCurrentContext ();
    CGLShareGroupObj sharegroup = CGLGetShareGroup (cgl_context);
    cl_context_properties properties[] = {
      CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
      (cl_context_properties) sharegroup,
      0
    };

#else
    cl_context_properties properties[] = {
      CL_GL_CONTEXT_KHR,
      (cl_context_properties) glXGetCurrentContext (),
      CL_GLX_DISPLAY_KHR,
      (cl_context_properties) glXGetCurrentDisplay (),
      CL_CONTEXT_PLATFORM, (cl_context_properties) dev->platform->id,
      0
    };
#endif

    dev->context = clCreateContext (properties, 1, &dev->id, NULL, NULL, &err);
  } else
#endif
    {
      dev->context = clCreateContext (0, 1, &dev->id, NULL, NULL, &err);
    }
    check (err, "Failed to create compute context \n");

    // Load program source
    //
    const char *opencl_prog;
    opencl_prog = file_get_contents(PROGRAM_NAME);
    if (!opencl_prog) {
        sotl_log(CRITICAL, "Failed to read contents of the OpenCL program '%s'.\n", PROGRAM_NAME);
    }

    // Build program
    //
    dev->program = clCreateProgramWithSource (dev->context, 1, &opencl_prog, NULL, &err);
    check (err, "Failed to create program");

    char options[OPENCL_PROG_MAX_STRING_SIZE_OPTIONS];

    // Tile size of 32 works better on Xeon/Xeon Phi
    //
    if(dev->type != CL_DEVICE_TYPE_GPU)
      dev->tile_size = 32;
    else
      dev->tile_size = TILE_SIZE;

#ifdef SLIDE
      dev->slide_steps = SLIDE;
#else
      dev->slide_steps = 1;
#endif

    sprintf (options,
	     OPENCL_BUILD_OPTIONS
	     "-DTILE_SIZE=%d "
	     "-DSUBCELL=%d "
             "-DDELTA_T=%.10f "
#ifdef SLIDE
	     "-DSLIDE=%d "
#endif
	     OPENCL_PROG_STRING_OPTIONS " -I "OCL_INCLUDE " "
	     LENNARD_STRING,
	     dev->tile_size,
	     SUBCELL,
             1.0f,
#ifdef SLIDE
	     dev->slide_steps,
#endif
	     OPENCL_PROG_PARAM_OPTIONS,
	     LENNARD_PARAM);

    // If not a GPU, do not use Tiling
    //
    if (dev->type != CL_DEVICE_TYPE_GPU)
      strcat (options, " -DNO_LOCAL_MEM");

#ifdef TILE_CACHE
    // On GPU, use a cache of TILES
    //
    if (dev->type == CL_DEVICE_TYPE_GPU)
      strcat (options, " -DTILE_CACHE");
#endif

    // Multi-accelerators configuration
    //
    if (sotl_have_multi())
      strcat (options, " -DHAVE_MULTI");

#ifdef FORCE_N_UPDATE
    if (!sotl_have_multi())
      strcat (options, " -DFORCE_N_UPDATE");
#endif

#ifdef TORUS
    strcat (options, " -DXY_TORUS -DZ_TORUS");
#endif

#ifdef XEON_VECTORIZATION
    strcat (options, " -DXEON_VECTORIZATION");
#endif

#if defined(__APPLE__)
    strcat(options, " -DHAVE_PRINTF");
#endif

    if (sotl_verbose)
      sotl_log(INFO, "--- Compiler flags ---\n%s\n----------------------\n",
               options);

    err = clBuildProgram (dev->program, 0, NULL, options, NULL, NULL);
    if(sotl_verbose || err != CL_SUCCESS) {
      size_t len;

      // Display compiler error log
      //
      clGetProgramBuildInfo (dev->program, dev->id,
			     CL_PROGRAM_BUILD_LOG, 0, NULL, &len);
        {
	  char buffer[len + 1];

	  clGetProgramBuildInfo (dev->program, dev->id,
				 CL_PROGRAM_BUILD_LOG,
				 sizeof (buffer), buffer, NULL);
	  sotl_log(INFO, "---- Compiler log ----\n%s\n----------------------\n",
		   buffer);
        }
        check (err, "Failed to build program");
    }

    // Create an OpenCL command queue
    //
    dev->queue = clCreateCommandQueue (dev->context, dev->id,
                CL_QUEUE_PROFILING_ENABLE, &err);
    check (err, "Failed to create a command queue");

    cl_create_kernels(dev);
}