Skip to content

Commit

Permalink
progress bar finally works on NVIDIA, thanks to Robert Crovella@NVIDIA
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jul 22, 2019
1 parent 2863ae3 commit 2894ea1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/mcx_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,15 @@ void mcx_run_simulation(Config *cfg,float *fluence,float *totalenergy){
OCL_ASSERT(((gmedia=clCreateBuffer(mcxcontext,RO_MEM, sizeof(cl_uint)*(dimxyz),media,&status),status)));
OCL_ASSERT(((gproperty=clCreateBuffer(mcxcontext,RO_MEM, cfg->medianum*sizeof(Medium),cfg->prop,&status),status)));
OCL_ASSERT(((gparam=clCreateBuffer(mcxcontext,RO_MEM, sizeof(MCXParam),&param,&status),status)));
OCL_ASSERT(((gprogress[0]=clCreateBuffer(mcxcontext,RW_PTR, sizeof(cl_uint),NULL,&status),status)));
progress = (cl_uint *)clEnqueueMapBuffer(mcxqueue[0], gprogress[0], CL_TRUE, CL_MAP_WRITE, 0, sizeof(cl_uint), 0, NULL, NULL, NULL);

cl_mem (*clCreateBufferNV)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*) = (cl_mem (*)(cl_context,cl_mem_flags, cl_mem_flags_NV, size_t, void*, cl_int*)) clGetExtensionFunctionAddressForPlatform(platform, "clCreateBufferNV");
if (clCreateBufferNV == NULL)
OCL_ASSERT(((gprogress[0]=clCreateBuffer(mcxcontext,RW_PTR, sizeof(cl_uint),NULL,&status),status)));
else
OCL_ASSERT(((gprogress[0]=clCreateBufferNV(mcxcontext,CL_MEM_READ_WRITE, NV_PIN, sizeof(cl_uint),NULL,&status),status)));

progress = (cl_uint *)clEnqueueMapBuffer(mcxqueue[0], gprogress[0], CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(cl_uint), 0, NULL, NULL, NULL);
*progress=0;
clEnqueueUnmapMemObject(mcxqueue[0], gprogress[0], progress, 0, NULL, NULL);

if(cfg->seed==SEED_FROM_FILE){
// replay should only work with a single device
Expand Down Expand Up @@ -673,13 +678,8 @@ void mcx_run_simulation(Config *cfg,float *fluence,float *totalenergy){

mcx_progressbar(-0.f,cfg);

progress = (cl_uint *)clEnqueueMapBuffer(mcxqueue[0], gprogress[0], CL_FALSE, CL_MAP_READ, 0, sizeof(cl_uint), 0, NULL, NULL, NULL);

do{
ndone = *progress;

MCX_FPRINTF(cfg->flog,"progress=%d\n",ndone); // debug progress bar, will remove

if (ndone > p0){
mcx_progressbar(ndone/(threadphoton*1.45f),cfg);
p0 = ndone;
Expand All @@ -688,9 +688,8 @@ void mcx_run_simulation(Config *cfg,float *fluence,float *totalenergy){
}while (p0 < (param.threadphoton*1.45f));
mcx_progressbar(1.0f,cfg);
MCX_FPRINTF(cfg->flog,"\n");

clEnqueueUnmapMemObject(mcxqueue[0], gprogress[0], progress, 0, NULL, NULL);
}
clEnqueueUnmapMemObject(mcxqueue[0], gprogress[0], progress, 0, NULL, NULL);

//clWaitForEvents(workdev,waittoread);
for(devid=0;devid<workdev;devid++)
Expand Down
6 changes: 6 additions & 0 deletions src/mcx_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ extern "C" {
#define RAND_BUF_LEN 2 //register arrays
#endif

#ifndef CL_MEM_LOCATION_HOST_NV
#define CL_MEM_LOCATION_HOST_NV (1 << 0)
typedef cl_bitfield cl_mem_flags_NV;
#endif

#define RO_MEM (CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR)
#define WO_MEM (CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR)
#define RW_MEM (CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR)
#define RW_PTR (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR)
#define NV_PIN CL_MEM_LOCATION_HOST_NV

#define OCL_ASSERT(x) ocl_assess((x),__FILE__,__LINE__)

Expand Down

0 comments on commit 2894ea1

Please sign in to comment.