Added error checking and std::call_once

This commit is contained in:
tqiu 2021-01-26 17:32:18 +01:00
parent 1e09b1f4d9
commit 837a83fc16
2 changed files with 12 additions and 7 deletions

View File

@ -487,9 +487,13 @@ void FGPILU::decomposition(
const int block_size = 3;
try {
if (initialized == false) {
// just put everything in the capture list
std::call_once(initialize_flag, [&](){
cl::Program::Sources source(1, std::make_pair(fgpilu_sweep_s, strlen(fgpilu_sweep_s))); // what does this '1' mean? cl::Program::Sources is of type 'std::vector<std::pair<const char*, long unsigned int> >'
cl::Program program = cl::Program(*context, source, &err);
if (err != CL_SUCCESS) {
OPM_THROW(std::logic_error, "FGPILU OpenCL could not create Program");
}
std::vector<cl::Device> devices = context->getInfo<CL_CONTEXT_DEVICES>();
program.build(devices);
@ -499,6 +503,9 @@ void FGPILU::decomposition(
cl::Buffer&, cl::Buffer&, cl::Buffer&,
cl::Buffer&, cl::Buffer&,
const int, cl::LocalSpaceArg, cl::LocalSpaceArg>(cl::Kernel(program, "fgpilu_sweep", &err)));
if (err != CL_SUCCESS) {
OPM_THROW(std::logic_error, "FGPILU OpenCL could not create Kernel");
}
// allocate GPU memory
d_Ut_vals = cl::Buffer(*context, CL_MEM_READ_WRITE, sizeof(double) * Ut_nnzbs * block_size * block_size);
@ -530,9 +537,7 @@ void FGPILU::decomposition(
out << "FGPILU PARALLEL: " << PARALLEL;
OpmLog::info(out.str());
}
initialized = true;
}
});
// copy to GPU

View File

@ -21,8 +21,9 @@
#define FGPILU_HEADER_INCLUDED
#include <opm/simulators/linalg/bda/opencl.hpp>
#include <mutex>
#include <opm/simulators/linalg/bda/opencl.hpp>
namespace bda
@ -43,6 +44,7 @@ namespace bda
cl::Event event;
cl_int err;
std::once_flag initialize_flag;
std::unique_ptr<cl::make_kernel<cl::Buffer&, cl::Buffer&, cl::Buffer&,
cl::Buffer&, cl::Buffer&, cl::Buffer&,
@ -50,8 +52,6 @@ namespace bda
cl::Buffer&, cl::Buffer&,
const int, cl::LocalSpaceArg, cl::LocalSpaceArg> > fgpilu_sweep_k;
bool initialized = false;
public:
/// Executes the FGPILU sweeps
/// also copies data from CPU to GPU and GPU to CPU