ViennaCL - The Vienna Computing Library  1.7.1
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
direct_solve.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_OPENCL_DIRECT_SOLVE_HPP
2 #define VIENNACL_LINALG_OPENCL_DIRECT_SOLVE_HPP
3 
4 /* =========================================================================
5  Copyright (c) 2010-2016, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include "viennacl/vector.hpp"
26 #include "viennacl/matrix.hpp"
27 #include "viennacl/ocl/kernel.hpp"
28 #include "viennacl/ocl/device.hpp"
29 #include "viennacl/ocl/handle.hpp"
32 
33 namespace viennacl
34 {
35 namespace linalg
36 {
37 namespace opencl
38 {
39 
40 namespace detail
41 {
43  inline cl_uint get_option_for_solver_tag(viennacl::linalg::unit_upper_tag) { return (1 << 0); }
44  inline cl_uint get_option_for_solver_tag(viennacl::linalg::lower_tag) { return (1 << 2); }
45  inline cl_uint get_option_for_solver_tag(viennacl::linalg::unit_lower_tag) { return (1 << 2) | (1 << 0); }
46 
47  template<typename MatrixT1, typename MatrixT2, typename KernelT>
48  void inplace_solve_impl(MatrixT1 const & A, MatrixT2 & B, KernelT & k)
49  {
50  viennacl::ocl::enqueue(k(viennacl::traits::opencl_handle(A),
51  cl_uint(viennacl::traits::start1(A)), cl_uint(viennacl::traits::start2(A)),
53  cl_uint(viennacl::traits::size1(A)), cl_uint(viennacl::traits::size2(A)),
55  viennacl::traits::opencl_handle(B),
56  cl_uint(viennacl::traits::start1(B)), cl_uint(viennacl::traits::start2(B)),
58  cl_uint(viennacl::traits::size1(B)), cl_uint(viennacl::traits::size2(B)),
60  )
61  );
62  }
63 }
64 
65 
66 //
67 // Note: By convention, all size checks are performed in the calling frontend. No need to double-check here.
68 //
69 
71 
76 template<typename NumericT, typename SolverTagT>
79  SolverTagT)
80 {
81  viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(A).context());
82 
83  std::string program_name;
84  if (A.row_major() && B.row_major())
85  {
87  KernelClass::init(ctx);
88  program_name = KernelClass::program_name();
89  }
90  else if (A.row_major() && !B.row_major())
91  {
93  KernelClass::init(ctx);
94  program_name = KernelClass::program_name();
95  }
96  else if (!A.row_major() && B.row_major())
97  {
99  KernelClass::init(ctx);
100  program_name = KernelClass::program_name();
101  }
102  else
103  {
105  KernelClass::init(ctx);
106  program_name = KernelClass::program_name();
107  }
108 
109  std::stringstream ss;
110  ss << SolverTagT::name();
111  ss << "_solve";
112 
113  viennacl::ocl::kernel & k = ctx.get_kernel(program_name, ss.str());
114 
115  k.global_work_size(0, B.size2() * k.local_work_size());
117 }
118 
119 
120 
121 //
122 // Solve on vector
123 //
124 
125 template<typename NumericT, typename SOLVERTAG>
128  SOLVERTAG)
129 {
130  cl_uint options = detail::get_option_for_solver_tag(SOLVERTAG());
131 
132  viennacl::ocl::kernel & k = detail::legacy_kernel_for_matrix(A, "triangular_substitute_inplace");
133 
135  viennacl::ocl::enqueue(k(viennacl::traits::opencl_handle(A),
136  cl_uint(viennacl::traits::start1(A)), cl_uint(viennacl::traits::start2(A)),
137  cl_uint(viennacl::traits::stride1(A)), cl_uint(viennacl::traits::stride2(A)),
138  cl_uint(viennacl::traits::size1(A)), cl_uint(viennacl::traits::size2(A)),
140  viennacl::traits::opencl_handle(x),
141  cl_uint(viennacl::traits::start(x)),
142  cl_uint(viennacl::traits::stride(x)),
143  cl_uint(viennacl::traits::size(x)),
144  options
145  )
146  );
147 }
148 
149 } //namespace opencl
150 } //namespace linalg
151 } //namespace viennacl
152 
153 #endif
Represents an OpenCL device within ViennaCL.
result_of::size_type< matrix_base< NumericT > >::type stride1(matrix_base< NumericT > const &s)
Definition: stride.hpp:55
Represents an OpenCL kernel within ViennaCL.
Definition: kernel.hpp:58
Implementation of the dense matrix class.
vcl_size_t internal_size1(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
Definition: size.hpp:386
size_type local_work_size(int index=0) const
Returns the local work size at the respective dimension.
Definition: kernel.hpp:742
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:163
A tag class representing a lower triangular matrix.
Definition: forwards.h:849
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
vcl_size_t internal_size2(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
Definition: size.hpp:394
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
Definition: stride.hpp:45
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:65
cl_uint get_option_for_solver_tag(viennacl::linalg::upper_tag)
OpenCL kernel file for dense matrix solves with multiple right hand side (BLAS level 3) ...
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
Definition: size.hpp:201
void inplace_solve_impl(MatrixT1 const &A, MatrixT2 &B, KernelT &k)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:84
viennacl::ocl::kernel & get_kernel(std::string const &program_name, std::string const &kernel_name)
Convenience function for retrieving the kernel of a program directly from the context.
Definition: context.hpp:605
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
Implementation of a smart-pointer-like class for handling OpenCL handles.
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:44
Main kernel class for the generation of matrix solve kernels.
size_type size2() const
Returns the number of columns.
Definition: matrix_def.hpp:226
result_of::size_type< matrix_base< NumericT > >::type stride2(matrix_base< NumericT > const &s)
Definition: stride.hpp:65
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for dense triangular systems. Matlab notation: A \ B.
viennacl::ocl::kernel & legacy_kernel_for_matrix(matrix_base< NumericT > const &M, std::string const &kernel_name)
void enqueue(KernelType &k, viennacl::ocl::command_queue const &queue)
Enqueues a kernel in the provided queue.
Definition: enqueue.hpp:50
Representation of an OpenCL kernel in ViennaCL.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
bool row_major() const
Definition: matrix_def.hpp:248
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:859
size_type global_work_size(int index=0) const
Returns the global work size at the respective dimension.
Definition: kernel.hpp:751
A tag class representing an upper triangular matrix with unit diagonal.
Definition: forwards.h:864
Runtime generation of OpenCL kernels for matrix operations.