ViennaCL - The Vienna Computing Library  1.6.1
Free open-source GPU-accelerated linear algebra and solver library.
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-2014, 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 PDF 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"
31 
32 namespace viennacl
33 {
34 namespace linalg
35 {
36 namespace opencl
37 {
38 
39 namespace detail
40 {
42  inline cl_uint get_option_for_solver_tag(viennacl::linalg::unit_upper_tag) { return (1 << 0); }
43  inline cl_uint get_option_for_solver_tag(viennacl::linalg::lower_tag) { return (1 << 2); }
44  inline cl_uint get_option_for_solver_tag(viennacl::linalg::unit_lower_tag) { return (1 << 2) | (1 << 0); }
45 
46  template<typename MatrixT1, typename MatrixT2, typename KernelT>
47  void inplace_solve_impl(MatrixT1 const & A, MatrixT2 & B, KernelT & k)
48  {
49  viennacl::ocl::enqueue(k(viennacl::traits::opencl_handle(A),
50  cl_uint(viennacl::traits::start1(A)), cl_uint(viennacl::traits::start2(A)),
52  cl_uint(viennacl::traits::size1(A)), cl_uint(viennacl::traits::size2(A)),
54  viennacl::traits::opencl_handle(B),
55  cl_uint(viennacl::traits::start1(B)), cl_uint(viennacl::traits::start2(B)),
57  cl_uint(viennacl::traits::size1(B)), cl_uint(viennacl::traits::size2(B)),
59  )
60  );
61  }
62 }
63 
64 
65 //
66 // Note: By convention, all size checks are performed in the calling frontend. No need to double-check here.
67 //
68 
70 
75 template<typename NumericT, typename SolverTagT>
78  SolverTagT)
79 {
80  viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(A).context());
81 
82  std::string program_name;
83  if (A.row_major() && B.row_major())
84  {
86  KernelClass::init(ctx);
87  program_name = KernelClass::program_name();
88  }
89  else if (A.row_major() && !B.row_major())
90  {
92  KernelClass::init(ctx);
93  program_name = KernelClass::program_name();
94  }
95  else if (!A.row_major() && B.row_major())
96  {
98  KernelClass::init(ctx);
99  program_name = KernelClass::program_name();
100  }
101  else
102  {
104  KernelClass::init(ctx);
105  program_name = KernelClass::program_name();
106  }
107 
108  std::stringstream ss;
109  ss << SolverTagT::name();
110  ss << "_solve";
111 
112  viennacl::ocl::kernel & k = ctx.get_kernel(program_name, ss.str());
113 
114  k.local_work_size(0, 128);
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 
134  k.local_work_size(0, 128);
136  viennacl::ocl::enqueue(k(viennacl::traits::opencl_handle(A),
137  cl_uint(viennacl::traits::start1(A)), cl_uint(viennacl::traits::start2(A)),
138  cl_uint(viennacl::traits::stride1(A)), cl_uint(viennacl::traits::stride2(A)),
139  cl_uint(viennacl::traits::size1(A)), cl_uint(viennacl::traits::size2(A)),
141  viennacl::traits::opencl_handle(x),
142  cl_uint(viennacl::traits::start(x)),
143  cl_uint(viennacl::traits::stride(x)),
144  cl_uint(viennacl::traits::size(x)),
145  options
146  )
147  );
148 }
149 
150 } //namespace opencl
151 } //namespace linalg
152 } //namespace viennacl
153 
154 #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:279
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:216
A tag class representing a lower triangular matrix.
Definition: forwards.h:809
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:54
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:287
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
ocl::kernel & legacy_kernel_for_matrix(matrix_base< NumericT > const &M, std::string const &kernel_name)
Definition: common.hpp:43
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:245
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
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:144
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:84
Definition: blas3.hpp:36
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:607
A tag class representing an upper triangular matrix.
Definition: forwards.h:814
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:217
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.
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:239
void init()
Definition: Random.hpp:25
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:819
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:824