mtazzari / galario

Gpu Accelerated Library for Analysing Radio Interferometer Observations
https://mtazzari.github.io/galario/
GNU Lesser General Public License v3.0
31 stars 15 forks source link

galario_reduce_chi2 not linkable from C #109

Closed fredRos closed 6 years ago

fredRos commented 6 years ago

We can call the function through python because we first call the _galario_reduce_chi2 version that messes with pointers and doesn't care about const qualifiers. It fails from C/C++ because in galario.h it is correctly declared as

 void galario_reduce_chi2(int nd, const dreal* fobs_re, const dreal* fobs_im, const dcomplex* fint, const dreal* weights, dreal* chi2);

but in the actual code we overwrite fint in diff_weighted_core so it cannot be declared const.

inline void diff_weighted_core(int const idx_x, int const nd, const dreal* const __restrict__ fobs_re,
                               const dreal * const __restrict__ fobs_im, dcomplex* const __restrict__ fint,
                               const dreal* const __restrict__ weights)
{
    dcomplex const fobs_cmplx = dcomplex { fobs_re[idx_x], fobs_im[idx_x] };
    dcomplex const sqrt_w_cmplx = dcomplex { SQRT(weights[idx_x]), 0.0 } ;
    fint[idx_x] = CMPLXSUB(fint[idx_x], fobs_cmplx);
    fint[idx_x] = CMPLXMUL(fint[idx_x], sqrt_w_cmplx);
}

On the GPU we have to copy data anyways but on the CPU we overwrite. We should not. It maybe slightly less efficient or more inconvenient for us to program but it's better for the user. And it is unlikely the slow part of a calculation.

fredRos commented 6 years ago

It is obvious to combine this with #77