Skip to content

Commit

Permalink
Move manager assignment outside of if-else block
Browse files Browse the repository at this point in the history
  • Loading branch information
csbnw committed Sep 20, 2023
1 parent b630efd commit 32d06e6
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions include/cudawrappers/cu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,16 @@ class DeviceMemory : public Wrapper<CUdeviceptr> {
unsigned int flags = 0) {
if (type == CU_MEMORYTYPE_DEVICE and !flags) {
checkCudaCall(cuMemAlloc(&_obj, size));
manager = std::shared_ptr<CUdeviceptr>(new CUdeviceptr(_obj),
[](CUdeviceptr *ptr) {
cuMemFree(*ptr);
delete ptr;
});
} else if (type == CU_MEMORYTYPE_UNIFIED) {
checkCudaCall(cuMemAllocManaged(&_obj, size, flags));
manager = std::shared_ptr<CUdeviceptr>(new CUdeviceptr(_obj),
[](CUdeviceptr *ptr) {
cuMemFree(*ptr);
delete ptr;
});
} else {
throw Error(CUDA_ERROR_INVALID_VALUE);
}
manager = std::shared_ptr<CUdeviceptr>(new CUdeviceptr(_obj),
[](CUdeviceptr *ptr) {
cuMemFree(*ptr);
delete ptr;
});
}

explicit DeviceMemory(CUdeviceptr ptr) : Wrapper(ptr) {}
Expand Down

0 comments on commit 32d06e6

Please sign in to comment.