fangq / mcxcl

Monte Carlo eXtreme for OpenCL (MCXCL)
http://mcx.space/wiki/?Learn#mcxcl
Other
41 stars 29 forks source link

mcxcl v2023 fails to use cfg.bc flags, cyclic bc returned error on Intel CPUs and GPUs #47

Closed fangq closed 2 months ago

fangq commented 1 year ago

Lukai Wang reported an issue when running mcxcl/mcxlabcl on Intel CPU and GPU

https://groups.google.com/g/mcx-users/c/wqsehDZb6ws

it was previously suspected that the issue was caused by Intel GPU opencl runtimes, however, after debugging, it appears that the issue was rooted in the cfg.bc flag handling code in mcxcl's kernel, specifically, an incomplete update after the following previous attempt of fixing bc problems: https://github.com/fangq/mcxcl/commit/9b4d76f03d86c2c9f3f449e340925649d4514379

the test script showing the problem: running this on Intel CPU/GPU opencl runtimes, it returned inf/nan. (the output looks fine on nvidia gpus)

% only clear cfg to avoid accidentally clearing other useful data

clear cfg;
cfg.nphoton=1e7;
cfg.issrcfrom0=1;
cfg.vol=uint8(ones(40,40,100));
cfg.srcdir=[0 0 1];
cfg.gpuid=1;
cfg.autopilot=1;
cfg.prop=[0 0 1 1;0.01 10 0.9 1];
cfg.tstart=0;
cfg.unitinmm=0.1;

% a uniform planar source outside the volume
cfg.srctype='planar';
cfg.srcpos=[0 0 0];
cfg.srcparam1=[40 0 0 0];
cfg.srcparam2=[0 40 0 0];
cfg.tend=5e-9;
cfg.tstep=5e-9;
cfg.bc='ccrccr';
cfg.gpuid=3;

flux=mcxlabcl(cfg);

fcw=flux.data*cfg.tstep;
subplot(121);
imagesc(log10(abs(squeeze(fcw(:,10,:)))))
axis equal; colorbar
set(gca,'xlim',[0 size(cfg.vol,3)]);
title('a uniform planar source incident along an infinite slab');

subplot(122);
semilogy((1:size(cfg.vol,3))*cfg.unitinmm, squeeze(mean(mean(fcw,2),1)))
title('averaged light attenuation profile');
ylabel('averaged CW fluence 1/mm^2')
xlabel('depth (mm)')
fangq commented 1 year ago

the changes now fails amd gpu tests, reopen

fangq commented 2 months ago

I have tested mcxcl under AMD, Intel GPUs and CPUs, as well as Apple M2 GPU, all passed the test. I am closing this ticket for now.