mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
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:
commit
da40f0200e
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user