-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Which proposal does this relate to?
https://github.com/microsoft/hlsl-specs/blob/main/proposals/0035-linalg-matrix.md
Describe the issue or outstanding question.
I don't think the memory semantics for the linalg::Matrix type are well enough defined.
The crux of the problem is that in HLSL the object looks like it holds or automatically manages the memory for the contents of the matrix. This object holds a handle type that translates to a dx.types.MatrixRef in DXIL, which just references a matrix (like a pointer). The MatrixRef value in DXIL does not represent the actual matrix memory allocated, and the dx.op.createMatrix operation marks a point of allocation for the matrix referred to by the MatrixRef, though you don't know what's allocated or where until the handle is used in an annotation call.
For instance, depending on the linalg::MatrixScope, the linalg::Matrix could refer to per-thread matrix loaded from global mem, which may be meant to be folded into an operation through optimization without actually allocating any local memory. Or it could refer to local per-thread fragments making up a wave-scope matrix, or to groupshared memory, which isn't counted in our groupshared memory accounting for a shader.
The current plan is to use the constructor to call dx.op.createMatrix, but what happens when one matrix variable overwrites another? I assume the handle of the second would replace the first, leaving a dangling matrix allocation, if we don't fully optimize that away somehow.
So, how do we track matrix content allocation lifetime? What happens when you assign one linalg::Matrix to another, or pass it through a function parameter (which copies the handle)? What rules guarantee the driver can track lifetimes and eliminate copies or re-use memory? How can you tell when a particular matrix allocation is no longer in use and may be freed?
I think the vagueness in this area of the spec is the root problem with coming up with a correct, reliable implementation plan for the compiler.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Status