Merge pull request #2720 from blattms/correctly-free-cuda-mem-for-ms

Also free memory allocated with CUDA later with CUDA
This commit is contained in:
Markus Blatt 2020-08-04 13:50:33 +02:00 committed by GitHub
commit da40f0200e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -43,6 +43,9 @@ void WellContributions::alloc()
WellContributions::~WellContributions()
{
#if HAVE_CUDA
freeCudaMemory();
#endif
if (h_x) {
delete[] h_x;
delete[] h_y;
@ -53,10 +56,6 @@ WellContributions::~WellContributions()
delete ms;
}
multisegments.clear();
#if HAVE_CUDA
freeStandardWells();
#endif
}

View File

@ -140,7 +140,7 @@ void WellContributions::allocStandardWells()
}
}
void WellContributions::freeStandardWells() {
void WellContributions::freeCudaMemory() {
// delete data for StandardWell
if (num_std_wells > 0) {
cudaFree(d_Cnnzs);
@ -151,6 +151,12 @@ void WellContributions::freeStandardWells() {
delete[] val_pointers;
cudaFree(d_val_pointers);
}
if (num_ms_wells > 0 && h_x) {
cudaFreeHost(h_x);
cudaFreeHost(h_y);
h_x = h_y = nullptr; // Mark as free for constructor
}
}
@ -168,7 +174,6 @@ void WellContributions::apply(double *d_x, double *d_y)
if (h_x == nullptr) {
cudaMallocHost(&h_x, sizeof(double) * N);
cudaMallocHost(&h_y, sizeof(double) * N);
host_mem_cuda = true;
}
// copy vectors x and y from GPU to CPU

View File

@ -100,7 +100,6 @@ private:
#endif
double *h_x = nullptr, *h_y = nullptr; // CUDA pinned memory for GPU memcpy
bool host_mem_cuda = false; // true iff h_x and h_y are allocated by cudaMallocHost(), so they need to be freed using cudaFreeHost()
int *toOrder = nullptr;
bool reorder = false;
@ -115,8 +114,8 @@ private:
/// Allocate GPU memory for StandardWells
void allocStandardWells();
/// Free GPU memory from StandardWells
void freeStandardWells();
/// Free GPU memory allocated with cuda.
void freeCudaMemory();
public: