Code Monkey home page Code Monkey logo

dynamix's People

Contributors

kif avatar pierrepaleo avatar yuriychushkin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dynamix's Issues

Dense FFT correlator: change computation method

The way FFT is computed is a bit difficult to understand. A big FFT of 2*Nt*Np points is computed, where Nt is the number of frames, and Np is the total number of pixels in the current bin. After multiplication and inverse FFT, the result is obtained with a non-trivial slicing.

A more straightforward (and efficient) approach would be to compute Np batched FFTS of 2*Nt points.
The theoretical number of operations with this approach is

2 * Np * Nt * (1 + 3 * log(2 * Nt))

(2 forward batched FFT, 1 batched inverse FFT, 1 multiplication on 2*Nt*Np points),
while the number of operations for the direct mat-mul method is

Nt * Nt * Np

That being said, I don't get impressive results with FFT in practice (FFTW and CUFFT).
Moreover, the memory needed for the FFT method is higher:

  • approx. 6 * Np * Nt floats with the Fourier method
  • approx. Nt * (Np + Nt) with the direct method

so the Fourier method consumes more memory as soon as Np > Nt/5, which is often the case.

Issue with amount of shared memory used in dense opencl correlator

/nobackup/lid02gpu11/conda3/envs/dahu/lib/python3.7/site-packages/pyopencl/cache.py:501: UserWarning: PyOpenCL compiler caching failed with an exception:
[begin exception]
Traceback (most recent call last):
  File "/nobackup/lid02gpu11/conda3/envs/dahu/lib/python3.7/site-packages/pyopencl/cache.py", line 478, in create_built_program_from_source_cached
    include_path=include_path)
  File "/nobackup/lid02gpu11/conda3/envs/dahu/lib/python3.7/site-packages/pyopencl/cache.py", line 398, in _create_built_program_from_source_cached
    prg.build(options_bytes, [devices[i] for i in to_be_built_indices])
  File "/nobackup/lid02gpu11/conda3/envs/dahu/lib/python3.7/site-packages/pyopencl/__init__.py", line 714, in program_build
    raise err
pyopencl._cl.RuntimeError: clBuildProgram failed: <unknown error -9999> - clBuildProgram failed: <unknown error -9999>

Build on <pyopencl.Device 'Tesla K20m' on 'NVIDIA CUDA' at 0x55ecb43b4d70>:

ptxas error   : Entry function 'compute_sums_dense' uses too much shared data (0x14004 bytes, 0xc000 max)

Deal with empty bins in qmask

There is a bug when qmask values have no pixel contributing ... It would be best to have n_bins to be the max value of qmask.

Installation Issues

Hey Guys,

I was trying your correlator and stumbled across some issues during the installation.

  • pip install dynamix does not work. Apparently the package cannot be found on the index. Installation from GitHub works.

  • numpy needs to be installed before installing dynamix, otherwise it will not work.

  • silx is not installed during the installation of dynamix which leads to an import error when trying your example.

Greetings from Hamburg,
Mario

Implement error propagation as part of correlators

Below is the code Yuriy usea to calculation correlation function with the
standard error.

def y_dense_correlator(xpcs_data, mask):
    """
    version of YC
    Reference implementation of the dense correlator.

    Parameters
    -----------
    xpcs_data: numpy.ndarray
        Stack of XPCS frames with shape (n_frames, n_rows, n_columns)
    mask: numpy.ndarray
        Mask of bins in the format (n_rows, n_columns).
        Zero pixels indicate unused pixels.
    """
    ind = np.where(mask > 0) # unused pixels are 0
    xpcs_data = xpcs_data[:, ind[0], ind[1]] # (n_tau, n_pix)
    del ind
    ltimes, lenmatr = np.shape(xpcs_data) # n_tau, n_pix
    meanmatr = np.array(np.mean(xpcs_data, axis=1),np.float32) #
xpcs_data.sum(axis=-1).sum(axis=-1)/n_pix
    meanmatr.shape = 1, ltimes

 
    if ltimes*lenmatr>3000*512*512:
        nn = 16
        newlen = lenmatr//nn
        num = np.dot(np.array(xpcs_data[:,:newlen],np.float32),
np.array(xpcs_data[:,:newlen],np.float32).T) 
        xpcs_data =  xpcs_data[:,newlen:] + 0  
        for i in range(1,nn-1,1):
            num +=
np.dot(np.array(xpcs_data[:,:newlen],np.float32),np.array(xpcs_data[:,:
newlen],np.float32).T)     
            xpcs_data = xpcs_data[:,newlen:] + 0  
        num += np.dot(np.array(xpcs_data,np.float32),
np.array(xpcs_data,np.float32).T) 
    else:
        num = np.dot(np.array(xpcs_data,np.float32),
np.array(xpcs_data,np.float32).T)  
    
    num /= lenmatr
    denom = np.dot(meanmatr.T, meanmatr)
    del meanmatr
    res = np.zeros((ltimes-1,3)) # was ones()
    for i in range(1,ltimes,1): # was ltimes-1, so res[-1] was always 1
!
        dia_n = np.diag(num, k=i)
        sdia_d = np.diag(denom, k=i)
        res[i-1,0] = i
        res[i-1,1] = np.sum(dia_n)/np.sum(sdia_d) 
        res[i-1,2] = np.std(dia_n/sdia_d) / len(sdia_d)**0.5
    return res

Divergent branches spotted by oclgrind ...

The command is:
oclgrind python3 run_tests.py -vv dynamix.correlator.test.test_dense.TestDense.test_dense_correlator

spots:

	Kernel:     compute_sums_dense
	Work-group: (0,165,0)
	Only 32 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !161
	At line 119 (column 9) of input.cl:
	  (source not available)
	

Work-group divergence detected (barrier)
	Kernel:     compute_sums_dense
	Work-group: (0,165,0)
	Only 16 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !173
	At line 123 (column 9) of input.cl:
	  (source not available)
	

Work-group divergence detected (barrier)
	Kernel:     compute_sums_dense
	Work-group: (0,165,0)
	Only 8 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !185
	At line 128 (column 9) of input.cl:
	  (source not available)
	

Work-group divergence detected (barrier)
	Kernel:     compute_sums_dense
	Work-group: (0,165,0)
	Only 4 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !197
	At line 132 (column 9) of input.cl:
	  (source not available)
	

Work-group divergence detected (barrier)
	Kernel:     compute_sums_dense
	Work-group: (0,165,0)
	Only 2 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !209
	At line 136 (column 9) of input.cl:
	  (source not available)
	

Work-group divergence detected (barrier)
	Kernel:     compute_sums_dense
	Work-group: (0,165,0)
	Only 1 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !221
	At line 140 (column 9) of input.cl:
	  (source not available)
	

Work-group divergence detected (barrier)
	Kernel:     compute_sums_dense
	Work-group: (0,167,0)
	Only 32 out of 128 work-items executed barrier
	  call spir_func void @_Z7barrierj(i32 1) #4, !dbg !161
	At line 119 (column 9) of input.cl:
	  (source not available)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.