示例#1
0
int TestKernelFlux()
{
  bool test=true;

  if(!cldevice_is_acceptable(nplatform_cl, ndevice_cl)) {
    printf("OpenCL device not acceptable.\n");
    return true;
  }

  field f;
  init_empty_field(&f);

  f.model.cfl = 0.05;
  f.model.m = 1; // only one conservative variable
  f.model.NumFlux = TransNumFlux2d;
  f.model.BoundaryFlux = TransBoundaryFlux2d;
  f.model.InitData = TransInitData2d;
  f.model.ImposedData = TransImposedData2d;
  f.varindex = GenericVarindex;

  f.interp.interp_param[0] = f.model.m;
  f.interp.interp_param[1] = 2; // x direction degree
  f.interp.interp_param[2] = 2; // y direction degree
  f.interp.interp_param[3] = 0; // z direction degree
  f.interp.interp_param[4] = 3; // x direction refinement
  f.interp.interp_param[5] = 3; // y direction refinement
  f.interp.interp_param[6] = 1; // z direction refinement

  ReadMacroMesh(&f.macromesh,"../test/testmacromesh.msh");
  //ReadMacroMesh(&f.macromesh,"test/testcube.msh");
  Detect2DMacroMesh(&f.macromesh);
  assert(f.macromesh.is2d);
  BuildConnectivity(&f.macromesh);
 
  Initfield(&f);
  CopyfieldtoGPU(&f);
  
  clFinish(f.cli.commandqueue);
  for(int ie = 0; ie < f.macromesh.nbelems; ++ie) {
    MacroCell *mcell = f.mcell + ie;

    
    DGFlux_CL(mcell, &f, 0, f.wn_cl + ie, 0, NULL, NULL);
    clFinish(f.cli.commandqueue);

    DGFlux_CL(mcell, &f, 1, f.wn_cl + ie, 0, NULL, NULL);
    clFinish(f.cli.commandqueue);

    if(!f.macromesh.is2d) {
      DGFlux_CL(mcell, &f, 2, f.wn_cl + ie, 0, NULL, NULL);
      clFinish(f.cli.commandqueue);
    }
  }
  CopyfieldtoCPU(&f);

  //Displayfield(&f);

  // save the dtwn pointer
  real *dtwn_cl = f.dtwn;

  // malloc a new dtwn.
  f.dtwn = calloc(f.wsize, sizeof(real));
 
  for(int ie = 0; ie < f.macromesh.nbelems; ++ie) {

    MacroCell *mcell = f.mcell + ie;
    real *wmc = f.wn + mcell->woffset;
    real *dtwmc = f.dtwn + mcell->woffset;

    DGSubCellInterface(f.mcell + ie, &f, wmc, dtwmc);
    //DGVolume((void*) &f.mcell[ie], &f, f.wn, f.dtwn);
  }

  //Displayfield(&f);

  //check that the results are the same
  real maxerr = 0.0;
  printf("\nDifference\tC\t\tOpenCL\n");
  for(int i = 0; i < f.wsize; ++i) {
    printf("%f\t%f\t%f\n", f.dtwn[i] - dtwn_cl[i], f.dtwn[i], dtwn_cl[i]);
    maxerr = fmax(fabs(f.dtwn[i] - dtwn_cl[i]), maxerr);
  }
  printf("max error: %f\n",maxerr);

  real tolerance;
  if(sizeof(real) == sizeof(double))
    tolerance = 1e-8;
  else
    tolerance = 1e-4;

  test = (maxerr < tolerance);

  return test;
}
示例#2
0
int TestDtfield_CL(void){
  bool test = true;

  if(!cldevice_is_acceptable(nplatform_cl, ndevice_cl)) {
    printf("OpenCL device not acceptable.\n");
    return true;
  }

  field f;
  
  // 2D meshes:
  // test/disque2d.msh
  // test/testdisque2d.msh
  // test/testmacromesh.msh
  // test/unit-cube.msh

  char *mshname =  "test/disque2d.msh";
  
  ReadMacroMesh(&(f.macromesh), mshname);
  Detect2DMacroMesh(&f.macromesh);
  BuildConnectivity(&f.macromesh);

#if 1
  // 2D version
  assert(f.macromesh.is2d);

  f.model.cfl = 0.05;
  f.model.m = 1;
  m = f.model.m;


  f.model.NumFlux = TransNumFlux2d;
  f.model.BoundaryFlux = TransBoundaryFlux2d;
  f.model.InitData = TransInitData2d;
  f.model.ImposedData = TransImposedData2d;
  f.varindex = GenericVarindex;

  f.interp.interp_param[0] = f.model.m;
  f.interp.interp_param[1] = 2; // x direction degree
  f.interp.interp_param[2] = 2; // y direction degree
  f.interp.interp_param[3] = 0; // z direction degree
  f.interp.interp_param[4] = 4; // x direction refinement
  f.interp.interp_param[5] = 4; // y direction refinement
  f.interp.interp_param[6] = 1; // z direction refinement

#else
  // 3D version
  f.model.cfl = 0.05;
  f.model.m = 1;
  f.model.NumFlux = TransNumFlux;
  f.model.BoundaryFlux = TestTransBoundaryFlux;
  f.model.InitData = TestTransInitData;
  f.model.ImposedData = TestTransImposedData;
  f.varindex = GenericVarindex;

  f.interp.interp_param[0] = f.model.m;
  f.interp.interp_param[1] = 2; // x direction degree
  f.interp.interp_param[2] = 2; // y direction degree
  f.interp.interp_param[3] = 2; // z direction degree
  f.interp.interp_param[4] = 3; // x direction refinement
  f.interp.interp_param[5] = 3; // y direction refinement
  f.interp.interp_param[6] = 3; // z direction refinement
#endif

  set_global_m(f.model.m);
  set_source_CL(&f, "OneSource");
  Initfield(&f);
  
  cl_event clv_dtfield = clCreateUserEvent(f.cli.context, NULL);
  
  dtfield_CL(&f, &f.wn_cl, 0, NULL, &clv_dtfield);
  clWaitForEvents(1, &clv_dtfield);
  CopyfieldtoCPU(&f);

  // Displayfield(&f);
  show_cl_timing(&f);

  real *saveptr = f.dtwn;
  f.dtwn = calloc(f.wsize, sizeof(real));

  f.model.Source = OneSource;
  dtfield(&f, f.wn, f.dtwn);
 
  real maxerr = 0;
  for(int i = 0; i < f.wsize; i++) {
    real error = f.dtwn[i] - saveptr[i];
    //printf("error= \t%f\t%f\t%f\n", error, f.dtwn[i], saveptr[i]);
    maxerr = fmax(fabs(error), maxerr);
  }
  printf("max error: %f\n", maxerr);

  test = (maxerr < 1e-8);

  return test;
}
示例#3
0
int TestKernelVolume(void){
  bool test=true;

  if(!cldevice_is_acceptable(nplatform_cl, ndevice_cl)) {
    printf("OpenCL device not acceptable.\n");
    return true;
  }

  field f;
  init_empty_field(&f);

  f.model.cfl = 0.05;
  f.model.m = 1; // only one conservative variable
  f.model.NumFlux = TransNumFlux2d;
  f.model.BoundaryFlux = TransBoundaryFlux2d;
  f.model.InitData = TransInitData2d;
  f.model.ImposedData = TransImposedData2d;
  f.varindex = GenericVarindex;

  f.interp.interp_param[0] = 1;  // _M
  f.interp.interp_param[1] = 1;  // x direction degree
  f.interp.interp_param[2] = 1;  // y direction degree
  f.interp.interp_param[3] = 0;  // z direction degree
  f.interp.interp_param[4] = 3;  // x direction refinement
  f.interp.interp_param[5] = 3;  // y direction refinement
  f.interp.interp_param[6] = 1;  // z direction refinement

  ReadMacroMesh(&f.macromesh,"../test/testmacromesh.msh");
  //ReadMacroMesh(&f.macromesh,"test/testcube.msh");
  Detect2DMacroMesh(&f.macromesh);
  assert(f.macromesh.is2d);
  BuildConnectivity(&f.macromesh);

  //PrintMacroMesh(&f.macromesh);

  //AffineMapMacroMesh(&f.macromesh);
 
  Initfield(&f);

  CopyfieldtoGPU(&f);
  
  /* // set dtwn to 1 for testing */
  
  /* void* chkptr; */
  /* cl_int status; */
  /* chkptr=clEnqueueMapBuffer(f.cli.commandqueue, */
  /*       		    f.dtwn_cl,  // buffer to copy from */
  /*       		    CL_TRUE,  // block until the buffer is available */
  /*       		     CL_MAP_WRITE,  */
  /*       		    0, // offset */
  /*       		    sizeof(real)*(f.wsize),  // buffersize */
  /*       		    0,NULL,NULL, // events management */
  /*       		    &status); */
  /*   assert(status == CL_SUCCESS); */
  /*   assert(chkptr == f.dtwn); */

  /* for(int i=0;i<f.wsize;i++){ */
  /*   f.dtwn[i]=1; */
  /* } */

  /* status=clEnqueueUnmapMemObject (f.cli.commandqueue, */
  /*       			  f.dtwn_cl, */
  /*       			  f.dtwn, */
  /*   			     0,NULL,NULL); */

  /* assert(status == CL_SUCCESS); */
  /* status=clFinish(f.cli.commandqueue); */
  /* assert(status == CL_SUCCESS); */

  clFinish(f.cli.commandqueue);
  for(int ie = 0; ie < f.macromesh.nbelems; ++ie) {
    DGVolume_CL(f.mcell + ie, &f, f.wn_cl + ie, 0, NULL, NULL);
    clFinish(f.cli.commandqueue);
  }
  
  clFinish(f.cli.commandqueue);
  
  CopyfieldtoCPU(&f);

  //Displayfield(&f);

  // save the dtwn pointer
  real *dtwn_cl = f.dtwn;

  // malloc a new dtwn.
  f.dtwn = calloc(f.wsize, sizeof(real));
 
  for(int ie = 0; ie < f.macromesh.nbelems; ++ie) {
    MacroCell *mcell = f.mcell + ie;
    real *dtwmc = f.dtwn + mcell->woffset;
    real *wmc = f.wn + mcell->woffset;
    DGVolume(f.mcell + ie, &f, wmc, dtwmc);
  }

  //Displayfield(&f);

  //check that the results are the same
  real maxerr = 0.0;
  //printf("\nDifference\tC\t\tOpenCL\n");
  for(int i = 0; i < f.wsize; ++i) {
    real err = fabs(f.dtwn[i] - dtwn_cl[i]);
    //printf("%f\t%f\t%f\n", err, f.dtwn[i], dtwn_cl[i]);
    maxerr = fmax(err, maxerr);
  }
  printf("max error: %f\n",maxerr);

    real tolerance;
  if(sizeof(real) == sizeof(double))
    tolerance = 1e-8;
  else
    tolerance = 1e-4;

  test = (maxerr < tolerance);

  return test;
}