FabioRossiArcetri / PYSSATA

1 stars 0 forks source link

Data objects converted from GPU to CPU can still trigger cupy functions #12

Open alfiopuglisi opened 1 week ago

alfiopuglisi commented 1 week ago

If a single processing object is configured with CPU while the rest is on GPU (for example the pyramid), the input data is converted to numpy arrays using cpuArray(), but the xp attribute of the data object remains set to cupy, so there will be failures if any accessed properties try to do calculations on the fly:

  File "/home/puglisi/git/PYSSATA/pyssata/processing_objects/modulated_pyramid.py", line 456, in trigger
    ef = in_ef.ef_at_lambda(self._wavelength_in_nm)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/puglisi/git/PYSSATA/pyssata/data_objects/ef.py", line 78, in ef_at_lambda
    return self._A * self.xp.exp(1j * phi, dtype=self.complex_dtype)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cupy/_core/_kernel.pyx", line 1286, in cupy._core._kernel.ufunc.__call__
  File "cupy/_core/_kernel.pyx", line 159, in cupy._core._kernel._preprocess_args
  File "cupy/_core/_kernel.pyx", line 145, in cupy._core._kernel._preprocess_arg
TypeError: Unsupported type <class 'numpy.ndarray'>
alfiopuglisi commented 6 days ago

This is partially fixed in the "bugfixes" branches. Some remaining problems if the modalrec is set to CPU while the rest of the simulation is on GPU.