mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Added opencl.hpp to define variables and import opencl
Added opencl.cpp to get OpenCL error strings
This commit is contained in:
parent
91591abd56
commit
ab49f60eca
@ -50,6 +50,7 @@ if(OPENCL_FOUND)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/BlockedMatrix.cpp)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/BILU0.cpp)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/Reorder.cpp)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/opencl.cpp)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/openclSolverBackend.cpp)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/BdaBridge.cpp)
|
||||
list (APPEND MAIN_SOURCE_FILES opm/simulators/linalg/bda/WellContributions.cu)
|
||||
@ -157,6 +158,7 @@ list (APPEND PUBLIC_HEADER_FILES
|
||||
opm/simulators/linalg/bda/cuda_header.hpp
|
||||
opm/simulators/linalg/bda/cusparseSolverBackend.hpp
|
||||
opm/simulators/linalg/bda/Reorder.hpp
|
||||
opm/simulators/linalg/bda/opencl.hpp
|
||||
opm/simulators/linalg/bda/openclKernels.hpp
|
||||
opm/simulators/linalg/bda/openclSolverBackend.hpp
|
||||
opm/simulators/linalg/bda/MultisegmentWellContribution.hpp
|
||||
|
@ -22,8 +22,7 @@
|
||||
|
||||
#include <opm/simulators/linalg/bda/BlockedMatrix.hpp>
|
||||
|
||||
#define __CL_ENABLE_EXCEPTIONS
|
||||
#include <CL/cl.hpp> // up to OpenCL 1.2
|
||||
#include <opm/simulators/linalg/bda/opencl.hpp>
|
||||
|
||||
namespace bda
|
||||
{
|
||||
|
@ -25,8 +25,7 @@
|
||||
#endif
|
||||
|
||||
#if HAVE_OPENCL
|
||||
#define __CL_ENABLE_EXCEPTIONS
|
||||
#include <CL/cl.hpp>
|
||||
#include <opm/simulators/linalg/bda/opencl.hpp>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
93
opm/simulators/linalg/bda/opencl.cpp
Normal file
93
opm/simulators/linalg/bda/opencl.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright 2020 Equinor ASA
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/simulators/linalg/bda/opencl.hpp>
|
||||
#include <string>
|
||||
|
||||
/// Translate OpenCL error codes to strings
|
||||
/// Integer - String combinations are defined in CL/cl.h
|
||||
/// \param[in] error error code
|
||||
std::string getErrorString(cl_int error)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case 0: return "CL_SUCCESS";
|
||||
case -1: return "CL_DEVICE_NOT_FOUND";
|
||||
case -2: return "CL_DEVICE_NOT_AVAILABLE";
|
||||
case -3: return "CL_COMPILER_NOT_AVAILABLE";
|
||||
case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
||||
case -5: return "CL_OUT_OF_RESOURCES";
|
||||
case -6: return "CL_OUT_OF_HOST_MEMORY";
|
||||
case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
|
||||
case -8: return "CL_MEM_COPY_OVERLAP";
|
||||
case -9: return "CL_IMAGE_FORMAT_MISMATCH";
|
||||
case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
|
||||
case -11: return "CL_BUILD_PROGRAM_FAILURE, kernels in openclKernels.hpp cannot be compiled";
|
||||
case -12: return "CL_MAP_FAILURE";
|
||||
case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
|
||||
case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
|
||||
case -15: return "CL_COMPILE_PROGRAM_FAILURE";
|
||||
case -16: return "CL_LINKER_NOT_AVAILABLE";
|
||||
case -17: return "CL_LINK_PROGRAM_FAILURE";
|
||||
case -18: return "CL_DEVICE_PARTITION_FAILED";
|
||||
case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
|
||||
|
||||
case -30: return "CL_INVALID_VALUE";
|
||||
case -31: return "CL_INVALID_DEVICE_TYPE";
|
||||
case -32: return "CL_INVALID_PLATFORM";
|
||||
case -33: return "CL_INVALID_DEVICE";
|
||||
case -34: return "CL_INVALID_CONTEXT";
|
||||
case -35: return "CL_INVALID_QUEUE_PROPERTIES";
|
||||
case -36: return "CL_INVALID_COMMAND_QUEUE";
|
||||
case -37: return "CL_INVALID_HOST_PTR";
|
||||
case -38: return "CL_INVALID_MEM_OBJECT";
|
||||
case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
|
||||
case -40: return "CL_INVALID_IMAGE_SIZE";
|
||||
case -41: return "CL_INVALID_SAMPLER";
|
||||
case -42: return "CL_INVALID_BINARY";
|
||||
case -43: return "CL_INVALID_BUILD_OPTIONS";
|
||||
case -44: return "CL_INVALID_PROGRAM";
|
||||
case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
|
||||
case -46: return "CL_INVALID_KERNEL_NAME";
|
||||
case -47: return "CL_INVALID_KERNEL_DEFINITION";
|
||||
case -48: return "CL_INVALID_KERNEL";
|
||||
case -49: return "CL_INVALID_ARG_INDEX";
|
||||
case -50: return "CL_INVALID_ARG_VALUE";
|
||||
case -51: return "CL_INVALID_ARG_SIZE";
|
||||
case -52: return "CL_INVALID_KERNEL_ARGS";
|
||||
case -53: return "CL_INVALID_WORK_DIMENSION";
|
||||
case -54: return "CL_INVALID_WORK_GROUP_SIZE";
|
||||
case -55: return "CL_INVALID_WORK_ITEM_SIZE";
|
||||
case -56: return "CL_INVALID_GLOBAL_OFFSET";
|
||||
case -57: return "CL_INVALID_EVENT_WAIT_LIST";
|
||||
case -58: return "CL_INVALID_EVENT";
|
||||
case -59: return "CL_INVALID_OPERATION";
|
||||
case -60: return "CL_INVALID_GL_OBJECT";
|
||||
case -61: return "CL_INVALID_BUFFER_SIZE";
|
||||
case -62: return "CL_INVALID_MIP_LEVEL";
|
||||
case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
|
||||
case -64: return "CL_INVALID_PROPERTY";
|
||||
case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
|
||||
case -66: return "CL_INVALID_COMPILER_OPTIONS";
|
||||
case -67: return "CL_INVALID_LINKER_OPTIONS";
|
||||
case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
|
||||
|
||||
default: return "UNKNOWN_CL_CODE";
|
||||
}
|
||||
}
|
32
opm/simulators/linalg/bda/opencl.hpp
Normal file
32
opm/simulators/linalg/bda/opencl.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2020 Equinor ASA
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// This file includes the relevant OpenCL header(s)
|
||||
/// All bda files using OpenCL declarations should include this header
|
||||
|
||||
#define __CL_ENABLE_EXCEPTIONS
|
||||
#define CL_TARGET_OPENCL_VERSION 120 // indicate OpenCL 1.2 is used
|
||||
#include <CL/cl.hpp> // supports up to OpenCL 1.2
|
||||
|
||||
#include <string>
|
||||
|
||||
/// Translate OpenCL error codes to strings
|
||||
/// Integer - String combinations are defined in CL/cl.h
|
||||
/// \param[in] error error code
|
||||
std::string getErrorString(cl_int error);
|
@ -25,13 +25,9 @@
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <dune/common/timer.hh>
|
||||
|
||||
|
||||
#define __CL_ENABLE_EXCEPTIONS
|
||||
#include <CL/cl.hpp>
|
||||
#include <opm/simulators/linalg/bda/openclSolverBackend.hpp>
|
||||
#include <opm/simulators/linalg/bda/openclKernels.hpp>
|
||||
|
||||
|
||||
#include <opm/simulators/linalg/bda/openclSolverBackend.hpp>
|
||||
#include <opm/simulators/linalg/bda/BdaResult.hpp>
|
||||
#include <opm/simulators/linalg/bda/Reorder.hpp>
|
||||
|
||||
@ -500,10 +496,12 @@ void openclSolverBackend<block_size>::initialize(int N_, int nnz_, int dim, doub
|
||||
|
||||
} catch (cl::Error error) {
|
||||
std::ostringstream oss;
|
||||
oss << "OpenCL Error: " << error.what() << "(" << error.err() << ")";
|
||||
OpmLog::error(oss.str());
|
||||
oss << "OpenCL Error: " << error.what() << "(" << error.err() << ")\n";
|
||||
oss << getErrorString(error.err());
|
||||
// rethrow exception
|
||||
OPM_THROW(std::logic_error, oss.str());
|
||||
} catch (std::logic_error error) {
|
||||
// rethrow exception, without this, a segfault occurs
|
||||
// rethrow exception by OPM_THROW in the try{}, without this, a segfault occurs
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,7 @@
|
||||
#ifndef OPM_OPENCLSOLVER_BACKEND_HEADER_INCLUDED
|
||||
#define OPM_OPENCLSOLVER_BACKEND_HEADER_INCLUDED
|
||||
|
||||
#if HAVE_OPENCL
|
||||
#define __CL_ENABLE_EXCEPTIONS
|
||||
#include <CL/cl.hpp> // up to OpenCL 1.2
|
||||
#endif
|
||||
|
||||
#include <opm/simulators/linalg/bda/opencl.hpp>
|
||||
|
||||
#include <opm/simulators/linalg/bda/BdaResult.hpp>
|
||||
#include <opm/simulators/linalg/bda/BdaSolver.hpp>
|
||||
|
Loading…
Reference in New Issue
Block a user