-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Runtime] Allow offset to be specified in NDArray::CreateView #16938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Runtime] Allow offset to be specified in NDArray::CreateView #16938
Conversation
Prior to this commit, the `NDArray::CreateView` method could produce an aliasing view of an existing array with a different shape or datatype, but the view was required to have the same `DLTensor::byte_offset` as the existing array. This commit updates the `NDArray::CreateView` method with an additional parameter, specifying the offset of the view relative to the existing array.
|
one note is that while such view was OK. the additional byte_offset would require special kernel to interact with them(by allowing elem_offset) in the arguments, and may not be the best peforming one because there is a tradeoff in terms of continugous/alignment and zero copy |
|
Agreed, there's a tradeoff, and replacing copies with views isn't something to be applied in every case.
|
Both to match the type used in `DLTensor::byte_offset`, and to resolve compilation errors on 32-bit platforms, which fail to compile due to a missing `Type2Str` specialization.
|
We don;t need to worry about TE, since we will be able to support buffer binding side. Just mention that allowing zero elem_offset is actually an important consideration for performance. Likely in most cases we would still like zero elem_offset by default. In frameworks, some key operations would also usualy requries a compact (that triggers an explicit copy), such that the memory access and alignment are right. In some cases it is indeed useful to introduce views, in some of those cases we might be able to inline views directly into the previous operation, such that the buffer themselfs still comes with zero offset. |
I brought up TE as a potential place to implement a change, but don't think it is the best option. While buffer-binding is supported in the
Agreed, and I like this as the long-term direction. |
|
It sounds that we're in agreement that this is useful functionality to have available, and that applying that functionality will come with potential trade-offs. |
Prior to this commit, the
NDArray::CreateViewmethod could produce an aliasing view of an existing array with a different shape or datatype, but the view was required to have the sameDLTensor::byte_offsetas the existing array. This commit updates theNDArray::CreateViewmethod with an additional parameter, specifying the offset of the view relative to the existing array.