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

ToDevice should allocate buf with size equal to storage length, not shape numel #461

Closed
coreylowman opened this issue Feb 16, 2023 · 2 comments · Fixed by #465
Closed

ToDevice should allocate buf with size equal to storage length, not shape numel #461

coreylowman opened this issue Feb 16, 2023 · 2 comments · Fixed by #465
Labels
bug Something isn't working

Comments

@coreylowman
Copy link
Owner

let b = a.broadcast::<Rank2<5, 3>, _>();
assert_eq!(b.array(), [[1.0, 2.0, 3.0]; 5]);

let c = b.broadcast::<Rank4<7, 5, 3, 2>, _>().to_device(&Cpu::default());
assert_eq!(c.array(), [[[[1.0; 2], [2.0; 2], [3.0; 2]]; 5]; 7]);

let d = c.mean::<Rank2<5, 3>, _>();
assert_eq!(d.array(), [[1.0, 2.0, 3.0]; 5]);

let e = dev.tensor([1.0]);
let f = e.broadcast::<Rank2<1, 1>, Axis<1>>();

still results in the very weird assertion error inside cudarc-0.7.0/src/driver/safe.rs:531:9.

Originally posted by @TimerErTim in #451 (comment)

@coreylowman coreylowman added the bug Something isn't working label Feb 16, 2023
@coreylowman coreylowman changed the title Broadcast & to_device weirdness ToDevice should allocate buf with size equal to storage length, not shape numel Feb 19, 2023
@coreylowman
Copy link
Owner Author

Caused by

        let mut buf = std::vec![E::default(); self.shape().num_elements()];
        self.copy_into(&mut buf);
        device.tensor((buf, *self.shape()))

let mut buf = std::vec![E::default(); self.shape().num_elements()]; should use the number of elements of the underlying storage instead.

@coreylowman
Copy link
Owner Author

Other issues:

  1. Cuda as_vec() returns vec of physical storage, Cpu as_vec() returns vec of actual storage
  2. CopySlice for both Cpu/Cuda copy physical storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant