All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
direct_solve.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_OPENCL_DIRECT_SOLVE_HPP
#define VIENNACL_LINALG_OPENCL_DIRECT_SOLVE_HPP
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
#include "viennacl/ocl/kernel.hpp"
#include "viennacl/ocl/device.hpp"
#include "viennacl/ocl/handle.hpp"
#include "viennacl/linalg/opencl/kernels/matrix_solve.hpp"
#include "viennacl/linalg/opencl/kernels/matrix.hpp"
namespace viennacl
{
namespace linalg
{
namespace opencl
{
namespace detail
{
inline cl_uint get_option_for_solver_tag(viennacl::linalg::upper_tag) { return 0; }
inline cl_uint get_option_for_solver_tag(viennacl::linalg::unit_upper_tag) { return (1 << 0); }
inline cl_uint get_option_for_solver_tag(viennacl::linalg::lower_tag) { return (1 << 2); }
inline cl_uint get_option_for_solver_tag(viennacl::linalg::unit_lower_tag) { return (1 << 2) | (1 << 0); }
template<typename MatrixT1, typename MatrixT2, typename KernelT>
void inplace_solve_impl(MatrixT1 const & A, MatrixT2 & B, KernelT & k)
{
viennacl::ocl::enqueue(k(viennacl::traits::opencl_handle(A),
cl_uint(viennacl::traits::start1(A)), cl_uint(viennacl::traits::start2(A)),
cl_uint(viennacl::traits::stride1(A)), cl_uint(viennacl::traits::stride2(A)),
cl_uint(viennacl::traits::size1(A)), cl_uint(viennacl::traits::size2(A)),
cl_uint(viennacl::traits::internal_size1(A)), cl_uint(viennacl::traits::internal_size2(A)),
viennacl::traits::opencl_handle(B),
cl_uint(viennacl::traits::start1(B)), cl_uint(viennacl::traits::start2(B)),
cl_uint(viennacl::traits::stride1(B)), cl_uint(viennacl::traits::stride2(B)),
cl_uint(viennacl::traits::size1(B)), cl_uint(viennacl::traits::size2(B)),
cl_uint(viennacl::traits::internal_size1(B)), cl_uint(viennacl::traits::internal_size2(B))
)
);
}
}
//
// Note: By convention, all size checks are performed in the calling frontend. No need to double-check here.
//
template<typename NumericT, typename SolverTagT>
void inplace_solve(matrix_base<NumericT> const & A,
matrix_base<NumericT> & B,
SolverTagT)
{
viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(A).context());
std::string program_name;
if (A.row_major() && B.row_major())
{
typedef viennacl::linalg::opencl::kernels::matrix_solve<NumericT, row_major, row_major> KernelClass;
KernelClass::init(ctx);
program_name = KernelClass::program_name();
}
else if (A.row_major() && !B.row_major())
{
typedef viennacl::linalg::opencl::kernels::matrix_solve<NumericT, row_major, column_major> KernelClass;
KernelClass::init(ctx);
program_name = KernelClass::program_name();
}
else if (!A.row_major() && B.row_major())
{
typedef viennacl::linalg::opencl::kernels::matrix_solve<NumericT, column_major, row_major> KernelClass;
KernelClass::init(ctx);
program_name = KernelClass::program_name();
}
else
{
typedef viennacl::linalg::opencl::kernels::matrix_solve<NumericT, column_major, column_major> KernelClass;
KernelClass::init(ctx);
program_name = KernelClass::program_name();
}
std::stringstream ss;
ss << SolverTagT::name();
ss << "_solve";
viennacl::ocl::kernel & k = ctx.get_kernel(program_name, ss.str());
k.global_work_size(0, B.size2() * k.local_work_size());
detail::inplace_solve_impl(A, B, k);
}
//
// Solve on vector
//
template<typename NumericT, typename SOLVERTAG>
void inplace_solve(matrix_base<NumericT> const & A,
vector_base<NumericT> & x,
SOLVERTAG)
{
cl_uint options = detail::get_option_for_solver_tag(SOLVERTAG());
viennacl::ocl::kernel & k = detail::legacy_kernel_for_matrix(A, "triangular_substitute_inplace");
k.global_work_size(0, k.local_work_size());
viennacl::ocl::enqueue(k(viennacl::traits::opencl_handle(A),
cl_uint(viennacl::traits::start1(A)), cl_uint(viennacl::traits::start2(A)),
cl_uint(viennacl::traits::stride1(A)), cl_uint(viennacl::traits::stride2(A)),
cl_uint(viennacl::traits::size1(A)), cl_uint(viennacl::traits::size2(A)),
cl_uint(viennacl::traits::internal_size1(A)), cl_uint(viennacl::traits::internal_size2(A)),
viennacl::traits::opencl_handle(x),
cl_uint(viennacl::traits::start(x)),
cl_uint(viennacl::traits::stride(x)),
cl_uint(viennacl::traits::size(x)),
options
)
);
}
} //namespace opencl
} //namespace linalg
} //namespace viennacl
#endif
device.hpp
Represents an OpenCL device within ViennaCL.
viennacl::traits::stride1
result_of::size_type< matrix_base< NumericT > >::type stride1(matrix_base< NumericT > const &s)
Definition: stride.hpp:55
viennacl::ocl::kernel
Represents an OpenCL kernel within ViennaCL.
Definition: kernel.hpp:58
matrix.hpp
Implementation of the dense matrix class.
viennacl::traits::internal_size1
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
viennacl::ocl::kernel::local_work_size
size_type local_work_size(int index=0) const
Returns the local work size at the respective dimension.
Definition: kernel.hpp:742
viennacl::traits::size1
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
viennacl::linalg::lower_tag
A tag class representing a lower triangular matrix.
Definition: forwards.h:849
viennacl::ocl::context
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
viennacl::traits::internal_size2
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
viennacl::matrix_base< NumericT >
viennacl::traits::stride
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
Definition: stride.hpp:45
viennacl::traits::start1
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:65
viennacl::linalg::opencl::detail::get_option_for_solver_tag
cl_uint get_option_for_solver_tag(viennacl::linalg::upper_tag)
Definition: direct_solve.hpp:42
matrix_solve.hpp
OpenCL kernel file for dense matrix solves with multiple right hand side (BLAS level 3) ...
viennacl::traits::size2
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
viennacl::linalg::opencl::detail::inplace_solve_impl
void inplace_solve_impl(MatrixT1 const &A, MatrixT2 &B, KernelT &k)
Definition: direct_solve.hpp:48
viennacl::traits::size
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
viennacl::traits::start2
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:84
viennacl::ocl::context::get_kernel
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
viennacl::linalg::upper_tag
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
handle.hpp
Implementation of a smart-pointer-like class for handling OpenCL handles.
viennacl::traits::start
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:44
viennacl::vector_base< NumericT >
viennacl::linalg::opencl::kernels::matrix_solve
Main kernel class for the generation of matrix solve kernels.
Definition: matrix_solve.hpp:130
viennacl::matrix_base::size2
size_type size2() const
Returns the number of columns.
Definition: matrix_def.hpp:226
viennacl::traits::stride2
result_of::size_type< matrix_base< NumericT > >::type stride2(matrix_base< NumericT > const &s)
Definition: stride.hpp:65
viennacl::linalg::opencl::inplace_solve
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for dense triangular systems. Matlab notation: A \ B.
Definition: direct_solve.hpp:77
viennacl::linalg::opencl::detail::legacy_kernel_for_matrix
viennacl::ocl::kernel & legacy_kernel_for_matrix(matrix_base< NumericT > const &M, std::string const &kernel_name)
Definition: matrix_operations.hpp:100
viennacl::ocl::enqueue
void enqueue(KernelType &k, viennacl::ocl::command_queue const &queue)
Enqueues a kernel in the provided queue.
Definition: enqueue.hpp:50
kernel.hpp
Representation of an OpenCL kernel in ViennaCL.
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::matrix_base::row_major
bool row_major() const
Definition: matrix_def.hpp:248
viennacl::linalg::unit_lower_tag
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:859
viennacl::ocl::kernel::global_work_size
size_type global_work_size(int index=0) const
Returns the global work size at the respective dimension.
Definition: kernel.hpp:751
viennacl::linalg::unit_upper_tag
A tag class representing an upper triangular matrix with unit diagonal.
Definition: forwards.h:864
matrix.hpp
Runtime generation of OpenCL kernels for matrix operations.