Skip to content
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

[Upstream] Cannot switch to Laser-based tensors #412

Open
mratsim opened this issue Jan 10, 2020 · 1 comment
Open

[Upstream] Cannot switch to Laser-based tensors #412

mratsim opened this issue Jan 10, 2020 · 1 comment

Comments

@mratsim
Copy link
Owner

mratsim commented Jan 10, 2020

Laser-based tensors use either a raw pointer to be able to plug in buffers coming from external libraries (Numpy, PyTorch, Tensorflow) and also exchange buffer with zero-copy. Or they use a seq for Nim ref types or strings.

type
RawImmutableView*[T] = distinct ptr UncheckedArray[T]
RawMutableView*[T] = distinct ptr UncheckedArray[T]
Metadata* = DynamicStackArray[int]
Tensor*[T] = object # Total stack: 128 bytes = 2 cache-lines
shape*: Metadata # 56 bytes
strides*: Metadata # 56 bytes
offset*: int # 8 bytes
storage*: CpuStorage[T] # 8 bytes
CpuStorage*{.shallow.}[T] = ref object # Total heap: 25 bytes = 1 cache-line
when supportsCopyMem(T):
raw_buffer*: ptr UncheckedArray[T] # 8 bytes
memalloc*: pointer # 8 bytes
isMemOwner*: bool # 1 byte
else: # Tensors of strings, other ref types or non-trivial destructors
raw_buffer*: seq[T] # 8 bytes (16 for seq v2 backed by destructors?)

Unfortunately supportsCopyMem doesn't work properly in type section, making Laser Dead On Arrival :/. nim-lang/Nim#13095

@mratsim
Copy link
Owner Author

mratsim commented Jan 18, 2020

Original issue fixed but now there is a new one it's not a showstopper but always having to put the generic type is annoying and even if Arraymancer is clean, users proc can still trigger it: nim-lang/Nim#13193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant