icl-utk-edu / slate

SLATE is a distributed, GPU-accelerated, dense linear algebra library targetting current and upcoming high-performance computing (HPC) systems. It is developed as part of the U.S. Department of Energy Exascale Computing Project (ECP).
https://icl.utk.edu/slate/
BSD 3-Clause "New" or "Revised" License
84 stars 20 forks source link

Read-Only `Tile` View #59

Open wavefunction91 opened 1 year ago

wavefunction91 commented 1 year ago

Describe the problem you are solving

Currently, the Tile accessor in BaseMatrix is not const-accessible. https://github.com/icl-utk-edu/slate/blob/6dbdcd2bf5702d366e6955ffab0586e2aa4eaed1/include/slate/BaseMatrix.hh#L153

It would be highly desirable to expose a read-only, const compatible overload of this function for appropriate const-correct contexts.

Describe your proposed solution

I am unfamiliar with the shallow Tile interface, but one would generally want to return a Tile which wraps immutable data, e.g.

const Tile<scalar_t> MatrixBase::operator()(int64_t,  int64_t, int64_t) const;
// or
const Tile<const scalar_t> MatrixBase::operator()(int64_t,  int64_t, int64_t) const;

The latter precludes mutation downstream

mgates3 commented 1 year ago

I understand the desire for this.

Because of dealing with remote memory and CPU and GPU memory spaces, we almost never have const Matrix objects. E.g.,

gemm( scalar_t alpha, Matrix& A, Matrix& B, scalar_t beta, Matrix& C )

with no const on A or B, even though they are logically const. This is because we need to move or copy tiles from CPU to GPU memory, and also to insert temporary remote tiles from other MPI processes. So while the numerical data of A and B isn't changing, their Matrix objects change quite a lot during gemm.