openclKernels.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPENCL_HPP
21#define OPENCL_HPP
22
23#include <string>
24#include <memory>
25#include <cstddef>
26
28
29namespace Opm
30{
31namespace Accelerator
32{
33
34using spmv_blocked_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int,
35 const cl::Buffer&, cl::Buffer&, const unsigned int, cl::LocalSpaceArg>;
36using spmv_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int,
37 const cl::Buffer&, cl::Buffer&, cl::LocalSpaceArg>;
38using residual_blocked_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int,
39 cl::Buffer&, const cl::Buffer&, cl::Buffer&, const unsigned int, cl::LocalSpaceArg>;
40using residual_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int,
41 cl::Buffer&, const cl::Buffer&, cl::Buffer&, cl::LocalSpaceArg>;
42using ilu_apply1_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, const cl::Buffer&,
43 cl::Buffer&, cl::Buffer&, const unsigned int, const unsigned int, cl::LocalSpaceArg>;
44using ilu_apply2_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&,
45 cl::Buffer&, cl::Buffer&, const unsigned int, const unsigned int, cl::LocalSpaceArg>;
46using stdwell_apply_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&,
47 cl::Buffer&, cl::Buffer&, cl::Buffer&,
48 const unsigned int, const unsigned int, cl::Buffer&,
49 cl::LocalSpaceArg, cl::LocalSpaceArg, cl::LocalSpaceArg>;
50using ilu_decomp_kernel_type = cl::KernelFunctor<const unsigned int, const unsigned int, cl::Buffer&, cl::Buffer&, cl::Buffer&,
51 cl::Buffer&, cl::Buffer&, cl::Buffer&, const int, cl::LocalSpaceArg>;
52using isaiL_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&,
53 cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int>;
54using isaiU_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&,
55 cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int>;
56
58{
59private:
60 static int verbosity;
61 static cl::CommandQueue *queue;
62 static std::vector<double> tmp; // used as tmp CPU buffer for dot() and norm()
63 static bool initialized;
64 static std::size_t preferred_workgroup_size_multiple; // stores CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
65
66 static std::unique_ptr<cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int, cl::LocalSpaceArg> > dot_k;
67 static std::unique_ptr<cl::KernelFunctor<cl::Buffer&, cl::Buffer&, const unsigned int, cl::LocalSpaceArg> > norm_k;
68 static std::unique_ptr<cl::KernelFunctor<cl::Buffer&, const double, cl::Buffer&, const unsigned int> > axpy_k;
69 static std::unique_ptr<cl::KernelFunctor<cl::Buffer&, const double, const unsigned int> > scale_k;
70 static std::unique_ptr<cl::KernelFunctor<const double, cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int> > vmul_k;
71 static std::unique_ptr<cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const double, const double, const unsigned int> > custom_k;
72 static std::unique_ptr<cl::KernelFunctor<const cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int> > full_to_pressure_restriction_k;
73 static std::unique_ptr<cl::KernelFunctor<cl::Buffer&, cl::Buffer&, const unsigned int, const unsigned int> > add_coarse_pressure_correction_k;
74 static std::unique_ptr<cl::KernelFunctor<const cl::Buffer&, cl::Buffer&, const cl::Buffer&, const unsigned int> > prolongate_vector_k;
75 static std::unique_ptr<spmv_blocked_kernel_type> spmv_blocked_k;
76 static std::unique_ptr<spmv_blocked_kernel_type> spmv_blocked_add_k;
77 static std::unique_ptr<spmv_kernel_type> spmv_k;
78 static std::unique_ptr<spmv_kernel_type> spmv_noreset_k;
79 static std::unique_ptr<residual_blocked_kernel_type> residual_blocked_k;
80 static std::unique_ptr<residual_kernel_type> residual_k;
81 static std::unique_ptr<ilu_apply1_kernel_type> ILU_apply1_k;
82 static std::unique_ptr<ilu_apply2_kernel_type> ILU_apply2_k;
83 static std::unique_ptr<stdwell_apply_kernel_type> stdwell_apply_k;
84 static std::unique_ptr<ilu_decomp_kernel_type> ilu_decomp_k;
85 static std::unique_ptr<isaiL_kernel_type> isaiL_k;
86 static std::unique_ptr<isaiU_kernel_type> isaiU_k;
87
88 OpenclKernels(){}; // disable instantiation
89
90public:
91 static const std::string axpy_str;
92 static const std::string scale_str;
93 static const std::string vmul_str;
94 static const std::string dot_1_str;
95 static const std::string norm_str;
96 static const std::string custom_str;
97 static const std::string full_to_pressure_restriction_str;
98 static const std::string add_coarse_pressure_correction_str;
99 static const std::string prolongate_vector_str;
100 static const std::string spmv_blocked_str;
101 static const std::string spmv_blocked_add_str;
102 static const std::string spmv_str;
103 static const std::string spmv_noreset_str;
104 static const std::string residual_blocked_str;
105 static const std::string residual_str;
106#if CHOW_PATEL
107 static const std::string ILU_apply1_str;
108 static const std::string ILU_apply2_str;
109#else
110 static const std::string ILU_apply1_fm_str;
111 static const std::string ILU_apply2_fm_str;
112#endif
113 static const std::string stdwell_apply_str;
114 static const std::string ILU_decomp_str;
115 static const std::string isaiL_str;
116 static const std::string isaiU_str;
117
118 static void init(cl::Context *context, cl::CommandQueue *queue, std::vector<cl::Device>& devices, int verbosity);
119
120 static double dot(cl::Buffer& in1, cl::Buffer& in2, cl::Buffer& out, int N);
121 static double norm(cl::Buffer& in, cl::Buffer& out, int N);
122 static void axpy(cl::Buffer& in, const double a, cl::Buffer& out, int N);
123 static void scale(cl::Buffer& in, const double a, int N);
124 static void vmul(const double alpha, cl::Buffer& in1, cl::Buffer& in2, cl::Buffer& out, int N);
125 static void custom(cl::Buffer& p, cl::Buffer& v, cl::Buffer& r, const double omega, const double beta, int N);
126 static void full_to_pressure_restriction(const cl::Buffer& fine_y, cl::Buffer& weights, cl::Buffer& coarse_y, int Nb);
127 static void add_coarse_pressure_correction(cl::Buffer& coarse_x, cl::Buffer& fine_x, int pressure_idx, int Nb);
128 static void prolongate_vector(const cl::Buffer& in, cl::Buffer& out, const cl::Buffer& cols, int N);
129 static void spmv(cl::Buffer& vals, cl::Buffer& cols, cl::Buffer& rows, const cl::Buffer& x, cl::Buffer& b, int Nb, unsigned int block_size, bool reset = true, bool add = false);
130 static void residual(cl::Buffer& vals, cl::Buffer& cols, cl::Buffer& rows, cl::Buffer& x, const cl::Buffer& rhs, cl::Buffer& out, int Nb, unsigned int block_size);
131
132 static void ILU_apply1(cl::Buffer& rowIndices, cl::Buffer& vals, cl::Buffer& cols, cl::Buffer& rows, cl::Buffer& diagIndex,
133 const cl::Buffer& y, cl::Buffer& x, cl::Buffer& rowsPerColor, int color, int Nb, unsigned int block_size);
134
135 static void ILU_apply2(cl::Buffer& rowIndices, cl::Buffer& vals, cl::Buffer& cols, cl::Buffer& rows, cl::Buffer& diagIndex,
136 cl::Buffer& invDiagVals, cl::Buffer& x, cl::Buffer& rowsPerColor, int color, int Nb, unsigned int block_size);
137
138 static void ILU_decomp(int firstRow, int lastRow, cl::Buffer& rowIndices, cl::Buffer& vals, cl::Buffer& cols, cl::Buffer& rows,
139 cl::Buffer& diagIndex, cl::Buffer& invDiagVals, int Nb, unsigned int block_size);
140
141 static void apply_stdwells(cl::Buffer& d_Cnnzs_ocl, cl::Buffer &d_Dnnzs_ocl, cl::Buffer &d_Bnnzs_ocl,
142 cl::Buffer &d_Ccols_ocl, cl::Buffer &d_Bcols_ocl, cl::Buffer &d_x, cl::Buffer &d_y,
143 int dim, int dim_wells, cl::Buffer &d_val_pointers_ocl, int num_std_wells);
144
145 static void isaiL(cl::Buffer& diagIndex, cl::Buffer& colPointers, cl::Buffer& mapping, cl::Buffer& nvc,
146 cl::Buffer& luIdxs, cl::Buffer& xxIdxs, cl::Buffer& dxIdxs, cl::Buffer& LUvals, cl::Buffer& invLvals, unsigned int Nb);
147
148 static void isaiU(cl::Buffer& diagIndex, cl::Buffer& colPointers, cl::Buffer& rowIndices, cl::Buffer& mapping,
149 cl::Buffer& nvc, cl::Buffer& luIdxs, cl::Buffer& xxIdxs, cl::Buffer& dxIdxs, cl::Buffer& LUvals,
150 cl::Buffer& invDiagVals, cl::Buffer& invUvals, unsigned int Nb);
151};
152
153} // namespace Accelerator
154} // namespace Opm
155
156#endif
Definition: openclKernels.hpp:58
static const std::string full_to_pressure_restriction_str
Definition: openclKernels.hpp:97
static const std::string norm_str
Definition: openclKernels.hpp:95
static const std::string residual_str
Definition: openclKernels.hpp:105
static void ILU_apply2(cl::Buffer &rowIndices, cl::Buffer &vals, cl::Buffer &cols, cl::Buffer &rows, cl::Buffer &diagIndex, cl::Buffer &invDiagVals, cl::Buffer &x, cl::Buffer &rowsPerColor, int color, int Nb, unsigned int block_size)
static const std::string vmul_str
Definition: openclKernels.hpp:93
static void init(cl::Context *context, cl::CommandQueue *queue, std::vector< cl::Device > &devices, int verbosity)
static void spmv(cl::Buffer &vals, cl::Buffer &cols, cl::Buffer &rows, const cl::Buffer &x, cl::Buffer &b, int Nb, unsigned int block_size, bool reset=true, bool add=false)
static void vmul(const double alpha, cl::Buffer &in1, cl::Buffer &in2, cl::Buffer &out, int N)
static const std::string isaiU_str
Definition: openclKernels.hpp:116
static const std::string ILU_apply2_fm_str
Definition: openclKernels.hpp:111
static const std::string isaiL_str
Definition: openclKernels.hpp:115
static void add_coarse_pressure_correction(cl::Buffer &coarse_x, cl::Buffer &fine_x, int pressure_idx, int Nb)
static const std::string spmv_str
Definition: openclKernels.hpp:102
static double dot(cl::Buffer &in1, cl::Buffer &in2, cl::Buffer &out, int N)
static const std::string residual_blocked_str
Definition: openclKernels.hpp:104
static const std::string prolongate_vector_str
Definition: openclKernels.hpp:99
static void isaiU(cl::Buffer &diagIndex, cl::Buffer &colPointers, cl::Buffer &rowIndices, cl::Buffer &mapping, cl::Buffer &nvc, cl::Buffer &luIdxs, cl::Buffer &xxIdxs, cl::Buffer &dxIdxs, cl::Buffer &LUvals, cl::Buffer &invDiagVals, cl::Buffer &invUvals, unsigned int Nb)
static void custom(cl::Buffer &p, cl::Buffer &v, cl::Buffer &r, const double omega, const double beta, int N)
static void scale(cl::Buffer &in, const double a, int N)
static void ILU_decomp(int firstRow, int lastRow, cl::Buffer &rowIndices, cl::Buffer &vals, cl::Buffer &cols, cl::Buffer &rows, cl::Buffer &diagIndex, cl::Buffer &invDiagVals, int Nb, unsigned int block_size)
static const std::string spmv_blocked_str
Definition: openclKernels.hpp:100
static void apply_stdwells(cl::Buffer &d_Cnnzs_ocl, cl::Buffer &d_Dnnzs_ocl, cl::Buffer &d_Bnnzs_ocl, cl::Buffer &d_Ccols_ocl, cl::Buffer &d_Bcols_ocl, cl::Buffer &d_x, cl::Buffer &d_y, int dim, int dim_wells, cl::Buffer &d_val_pointers_ocl, int num_std_wells)
static double norm(cl::Buffer &in, cl::Buffer &out, int N)
static const std::string spmv_blocked_add_str
Definition: openclKernels.hpp:101
static const std::string scale_str
Definition: openclKernels.hpp:92
static const std::string dot_1_str
Definition: openclKernels.hpp:94
static void axpy(cl::Buffer &in, const double a, cl::Buffer &out, int N)
static void ILU_apply1(cl::Buffer &rowIndices, cl::Buffer &vals, cl::Buffer &cols, cl::Buffer &rows, cl::Buffer &diagIndex, const cl::Buffer &y, cl::Buffer &x, cl::Buffer &rowsPerColor, int color, int Nb, unsigned int block_size)
static void residual(cl::Buffer &vals, cl::Buffer &cols, cl::Buffer &rows, cl::Buffer &x, const cl::Buffer &rhs, cl::Buffer &out, int Nb, unsigned int block_size)
static void isaiL(cl::Buffer &diagIndex, cl::Buffer &colPointers, cl::Buffer &mapping, cl::Buffer &nvc, cl::Buffer &luIdxs, cl::Buffer &xxIdxs, cl::Buffer &dxIdxs, cl::Buffer &LUvals, cl::Buffer &invLvals, unsigned int Nb)
static const std::string axpy_str
Definition: openclKernels.hpp:91
static const std::string stdwell_apply_str
Definition: openclKernels.hpp:113
static const std::string spmv_noreset_str
Definition: openclKernels.hpp:103
static const std::string custom_str
Definition: openclKernels.hpp:96
static void prolongate_vector(const cl::Buffer &in, cl::Buffer &out, const cl::Buffer &cols, int N)
static const std::string ILU_decomp_str
Definition: openclKernels.hpp:114
static const std::string add_coarse_pressure_correction_str
Definition: openclKernels.hpp:98
static const std::string ILU_apply1_fm_str
Definition: openclKernels.hpp:110
static void full_to_pressure_restriction(const cl::Buffer &fine_y, cl::Buffer &weights, cl::Buffer &coarse_y, int Nb)
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, cl::Buffer &, const cl::Buffer &, cl::Buffer &, cl::LocalSpaceArg > residual_kernel_type
Definition: openclKernels.hpp:41
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int > isaiL_kernel_type
Definition: openclKernels.hpp:53
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, const unsigned int, cl::Buffer &, cl::LocalSpaceArg, cl::LocalSpaceArg, cl::LocalSpaceArg > stdwell_apply_kernel_type
Definition: openclKernels.hpp:49
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, const cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, const unsigned int, cl::LocalSpaceArg > ilu_apply1_kernel_type
Definition: openclKernels.hpp:43
cl::KernelFunctor< const unsigned int, const unsigned int, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, const int, cl::LocalSpaceArg > ilu_decomp_kernel_type
Definition: openclKernels.hpp:51
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, const unsigned int, cl::LocalSpaceArg > ilu_apply2_kernel_type
Definition: openclKernels.hpp:45
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, const cl::Buffer &, cl::Buffer &, const unsigned int, cl::LocalSpaceArg > spmv_blocked_kernel_type
Definition: openclKernels.hpp:35
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, const cl::Buffer &, cl::Buffer &, cl::LocalSpaceArg > spmv_kernel_type
Definition: openclKernels.hpp:37
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int, cl::Buffer &, const cl::Buffer &, cl::Buffer &, const unsigned int, cl::LocalSpaceArg > residual_blocked_kernel_type
Definition: openclKernels.hpp:39
cl::KernelFunctor< cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, cl::Buffer &, const unsigned int > isaiU_kernel_type
Definition: openclKernels.hpp:55
Definition: BlackoilPhases.hpp:27