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

occa::memory::setDtype Modifies other references #747

Open
noelchalmers opened this issue Mar 22, 2024 · 0 comments
Open

occa::memory::setDtype Modifies other references #747

noelchalmers opened this issue Mar 22, 2024 · 0 comments
Labels
bug Use this label when reporting bugs! runtime Related to the OCCA runtime API
Milestone

Comments

@noelchalmers
Copy link
Contributor

Following the recent change to occa::memory::size() the following program:

#include <occa.hpp>

int main(const int argc, const char **argv) {

  occa::device device({{"mode", "Serial"}});

  size_t Nentries = 10;
  occa::memory a = device.malloc<double>(Nentries);

  printf("Size of a = %ld \n", a.size());

  occa::memory b = a;
  b.setDtype(occa::dtype::char_);

  printf("Size of a = %ld \n", a.size());

  return 0;
}

will print

Size of a = 10
Size of a = 80

I.e., calling occa::memory::setDtype on b modifies the 'size' of a and all other memory handles that wrap the same modeMemory. This is because dtype is held in the modeMemory class, not the memory wrapper.

While this is a bit corner case-y, I think the behavior should be that memory wrappers hold the dtype, not the modeMemory so that the return values of size when performing such type-punning is more intuitive.

@kris-rowe kris-rowe added bug Use this label when reporting bugs! runtime Related to the OCCA runtime API labels May 8, 2024
@kris-rowe kris-rowe added this to the v2.1 milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Use this label when reporting bugs! runtime Related to the OCCA runtime API
Projects
None yet
Development

No branches or pull requests

2 participants