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()
|
WellContributions::~WellContributions()
|
||||||
{
|
{
|
||||||
|
#if HAVE_CUDA
|
||||||
|
freeCudaMemory();
|
||||||
|
#endif
|
||||||
if (h_x) {
|
if (h_x) {
|
||||||
delete[] h_x;
|
delete[] h_x;
|
||||||
delete[] h_y;
|
delete[] h_y;
|
||||||
@ -53,10 +56,6 @@ WellContributions::~WellContributions()
|
|||||||
delete ms;
|
delete ms;
|
||||||
}
|
}
|
||||||
multisegments.clear();
|
multisegments.clear();
|
||||||
|
|
||||||
#if HAVE_CUDA
|
|
||||||
freeStandardWells();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ void WellContributions::allocStandardWells()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WellContributions::freeStandardWells() {
|
void WellContributions::freeCudaMemory() {
|
||||||
// delete data for StandardWell
|
// delete data for StandardWell
|
||||||
if (num_std_wells > 0) {
|
if (num_std_wells > 0) {
|
||||||
cudaFree(d_Cnnzs);
|
cudaFree(d_Cnnzs);
|
||||||
@ -151,6 +151,12 @@ void WellContributions::freeStandardWells() {
|
|||||||
delete[] val_pointers;
|
delete[] val_pointers;
|
||||||
cudaFree(d_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) {
|
if (h_x == nullptr) {
|
||||||
cudaMallocHost(&h_x, sizeof(double) * N);
|
cudaMallocHost(&h_x, sizeof(double) * N);
|
||||||
cudaMallocHost(&h_y, sizeof(double) * N);
|
cudaMallocHost(&h_y, sizeof(double) * N);
|
||||||
host_mem_cuda = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy vectors x and y from GPU to CPU
|
// copy vectors x and y from GPU to CPU
|
||||||
|
@ -100,7 +100,6 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
double *h_x = nullptr, *h_y = nullptr; // CUDA pinned memory for GPU memcpy
|
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;
|
int *toOrder = nullptr;
|
||||||
bool reorder = false;
|
bool reorder = false;
|
||||||
@ -115,8 +114,8 @@ private:
|
|||||||
/// Allocate GPU memory for StandardWells
|
/// Allocate GPU memory for StandardWells
|
||||||
void allocStandardWells();
|
void allocStandardWells();
|
||||||
|
|
||||||
/// Free GPU memory from StandardWells
|
/// Free GPU memory allocated with cuda.
|
||||||
void freeStandardWells();
|
void freeCudaMemory();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user