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

Fixes corruption of memory datatypes caused by short circuit logic in modeMemory_t::slice #727

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/occa/internal/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ namespace occa {

modeMemory_t* modeMemory_t::slice(const dim_t offset_,
const udim_t bytes) {

//quick return if we're not really slicing
if ((offset_ == 0) && (bytes == size)) return this;

OCCA_ERROR("ModeMemory not initialized or has been freed",
modeBuffer != NULL);

Expand Down
17 changes: 17 additions & 0 deletions tests/src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
void testMalloc();
void testSlice();
void testUnwrap();
void testCast();

int main(const int argc, const char **argv) {
testMalloc();
testSlice();
testUnwrap();
testCast();

return 0;
}
Expand Down Expand Up @@ -154,3 +156,18 @@ void testUnwrap() {

delete[] host_memory;
}

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

occa::memory occa_memory = occa_device.malloc<double>(10);

ASSERT_TRUE(occa::dtype::double_ == occa_memory.dtype());

occa::memory casted_memory = occa_memory.cast(occa::dtype::byte);

ASSERT_TRUE(occa::dtype::double_ == occa_memory.dtype());
ASSERT_TRUE(occa::dtype::byte == casted_memory.dtype());

ASSERT_EQ(occa_memory.size(), casted_memory.size());
}