From 837a83fc16b601d4abc68aa859e58c9abdf04430 Mon Sep 17 00:00:00 2001 From: tqiu Date: Tue, 26 Jan 2021 17:32:18 +0100 Subject: [PATCH] Added error checking and std::call_once --- opm/simulators/linalg/bda/fgpilu.cpp | 13 +++++++++---- opm/simulators/linalg/bda/fgpilu.hpp | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/opm/simulators/linalg/bda/fgpilu.cpp b/opm/simulators/linalg/bda/fgpilu.cpp index 70226f44f..d57ca981a 100644 --- a/opm/simulators/linalg/bda/fgpilu.cpp +++ b/opm/simulators/linalg/bda/fgpilu.cpp @@ -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 >' 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 devices = context->getInfo(); 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 diff --git a/opm/simulators/linalg/bda/fgpilu.hpp b/opm/simulators/linalg/bda/fgpilu.hpp index d51c21061..880db43b2 100644 --- a/opm/simulators/linalg/bda/fgpilu.hpp +++ b/opm/simulators/linalg/bda/fgpilu.hpp @@ -21,8 +21,9 @@ #define FGPILU_HEADER_INCLUDED -#include +#include +#include namespace bda @@ -43,6 +44,7 @@ namespace bda cl::Event event; cl_int err; + std::once_flag initialize_flag; std::unique_ptr > fgpilu_sweep_k; - bool initialized = false; - public: /// Executes the FGPILU sweeps /// also copies data from CPU to GPU and GPU to CPU