Save view matrices

Hi,

I want to save view matrices from the first step to be used in the following computation. I want to use copy kernel to do this job but before that, I need allocate corresponding memory for that via backend.matrix(shape, tag…). But the dimension of the view matrices is confusing to me. Could you tell me how are those data arranged? Thanks.

Regards,
Zhenyang

Swap out the view for an exchange view. Then run a packing kernel to pack the contents of the view into a buffer (the buffer being automatically allocated and managed by the exchange view).

There should be no need to copy the view indices themselves.

Regards, Freddie.

Hi Freddie,

Is it something like this part of code (I copied it from baseacvec/interp.py)? Could I understand that self._scal_lhs is the left hand side view and self._scal_rhs is a copy of that.

# Generate the left hand view matrix and its dual
self._scal_lhs = self._scal_xchg_view(lhs, 'get_scal_fpts_for_inter')
self._scal_rhs = be.xchg_matrix_for_view(self._scal_lhs)

self._pnorm_lhs = self._const_mat(lhs, 'get_pnorms_for_inter')

# Kernels
self.kernels['scal_fpts_pack'] = lambda: be.kernel(
    'pack', self._scal_lhs
)
self.kernels['scal_fpts_unpack'] = lambda: be.kernel(
    'unpack', self._scal_rhs
)

And what does pack and unpack kernels really do? What are functions of these two kernels?

Regards,
Zhenyang

Packing is the process where the values pointed to by a view are copied into a buffer (and then that buffer is copied back to the host). The matrix is a member of self._scal_lhs.

Unpacking is the process of copying data from the host to the device (but no kernel is run here).

Regards, Freddie.