1 #ifndef VIENNACL_LINALG_OPENCL_MATRIX_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_OPENCL_MATRIX_OPERATIONS_HPP_
60 template<
typename NumericT>
68 KernelClass::init(ctx);
69 program = &ctx.
get_program(KernelClass::program_name());
74 KernelClass::init(ctx);
75 program = &ctx.
get_program(KernelClass::program_name());
94 template<
typename DestNumericT,
typename SrcNumericT>
97 assert(dest.
row_major() == src.
row_major() && bool(
"Addition/subtraction on mixed matrix layouts not supported yet!"));
99 assert(viennacl::traits::opencl_handle(dest).
context() == viennacl::traits::opencl_handle(src).
context() &&
bool(
"Matrices do not reside in the same OpenCL context. Automatic migration not yet supported!"));
101 std::string kernel_name(
"convert_");
102 kernel_name += dest.
row_major() ?
"row_" :
"col_";
121 assert(A.
row_major() == B.
row_major() && bool(
"Addition/subtraction on mixed matrix layouts not supported yet!"));
123 std::string kernel_name(
"assign_*m_**00");
125 kernel_name[7] = is_scalar_cpu ?
'h' :
'd';
126 kernel_name[10] = flip_sign_alpha ?
'1' :
'0';
127 kernel_name[11] = reciprocal_alpha ?
'1' :
'0';
135 typename ScalarT1,
typename ScalarT2>
142 std::string kernel_name(
"assign_*m*m_****");
145 kernel_name[7] = is_scalar_cpu1 ?
'h' :
'd';
146 kernel_name[9] = is_scalar_cpu2 ?
'h' :
'd';
147 kernel_name[12] = flip_sign_alpha ?
'1' :
'0';
148 kernel_name[13] = reciprocal_alpha ?
'1' :
'0';
149 kernel_name[14] = flip_sign_beta ?
'1' :
'0';
150 kernel_name[15] = reciprocal_beta ?
'1' :
'0';
158 typename ScalarT1,
typename ScalarT2>
165 std::string kernel_name(
"ip_add_*v*v_****");
168 kernel_name[7] = is_scalar_cpu1 ?
'h' :
'd';
169 kernel_name[9] = is_scalar_cpu2 ?
'h' :
'd';
170 kernel_name[12] = flip_sign_alpha ?
'1' :
'0';
171 kernel_name[13] = reciprocal_alpha ?
'1' :
'0';
172 kernel_name[14] = flip_sign_beta ?
'1' :
'0';
173 kernel_name[15] = reciprocal_beta ?
'1' :
'0';
181 typename SizeT,
typename DistanceT>
185 std::string kernel_name(
"trans_kernel");
188 static_cast<cl_uint
>(proxy.lhs().start1()), static_cast<cl_uint>(proxy.lhs().start2()),
189 static_cast<cl_uint>(proxy.lhs().internal_size1()), static_cast<cl_uint>(proxy.lhs().internal_size2()),
190 static_cast<cl_uint>(proxy.lhs().size1()), static_cast<cl_uint>(proxy.lhs().size2()),
191 static_cast<cl_uint>(proxy.lhs().stride1()), static_cast<cl_uint>(proxy.lhs().stride2()),
194 static_cast<cl_uint>(temp_trans.
start1()), static_cast<cl_uint>(temp_trans.
start2()),
196 static_cast<cl_uint>(temp_trans.
stride1()), static_cast<cl_uint>(temp_trans.
stride2())));
199 template<
typename NumericT>
209 template<
typename NumericT>
217 template<
typename NumericT>
224 template<
typename NumericT>
231 template<
typename NumericT>
238 template<
typename NumericT>
256 template<
typename NumericT,
typename OpT>
260 assert(A.
row_major() == proxy.lhs().row_major() && bool(
"Elementwise operations on mixed matrix layouts not supported yet!"));
261 assert(A.
row_major() == proxy.rhs().row_major() && bool(
"Elementwise operations on mixed matrix layouts not supported yet!"));
262 assert(viennacl::traits::opencl_handle(A).
context() == viennacl::traits::opencl_handle(proxy.lhs()).
context() && bool(
"Matrices do not reside in the same OpenCL context. Automatic migration not yet supported!"));
263 assert(viennacl::traits::opencl_handle(A).
context() == viennacl::traits::opencl_handle(proxy.rhs()).
context() && bool(
"Matrices do not reside in the same OpenCL context. Automatic migration not yet supported!"));
278 template<
typename NumericT,
typename OpT>
282 assert(A.
row_major() == proxy.lhs().row_major() && bool(
"Elementwise operations on mixed matrix layouts not supported yet!"));
283 assert(A.
row_major() == proxy.rhs().row_major() && bool(
"Elementwise operations on mixed matrix layouts not supported yet!"));
285 assert(viennacl::traits::opencl_handle(A).
context() == viennacl::traits::opencl_handle(proxy.lhs()).
context() && bool(
"Matrices do not reside in the same OpenCL context. Automatic migration not yet supported!"));
286 assert(viennacl::traits::opencl_handle(A).
context() == viennacl::traits::opencl_handle(proxy.rhs()).
context() && bool(
"Matrices do not reside in the same OpenCL context. Automatic migration not yet supported!"));
304 template<
typename NumericT>
312 std::string kernel_name = std::string(
"mat_vec_") + (trans_A ^ A.
row_major()?
"T":
"N");
325 template<
typename NumericT,
typename ScalarType >
332 bool effective_A_trans = A_trans ^ A.
row_major();
333 bool effective_B_trans = B_trans ^ B.
row_major();
335 char cAt = effective_A_trans ?
'T' :
'N';
336 char cBt = effective_B_trans ?
'T' :
'N';
338 std::string kernel_prefix(
"prod_");
363 template<
typename NumericT,
typename ScalarT1>
365 ScalarT1
const & alpha,
vcl_size_t len_alpha,
bool reciprocal_alpha,
bool flip_sign_alpha,
382 viennacl::traits::opencl_handle(viennacl::tools::promote_if_host_scalar<NumericT>(alpha)),
385 viennacl::traits::opencl_handle(vec1),
390 viennacl::traits::opencl_handle(vec2),
399 template <
typename SCALARTYPE,
typename VectorType>
415 static_cast<cl_uint>(A.
size1()),
416 static_cast<cl_uint>(A.
size2()),
425 template <
typename NumericT>
464 template <
typename NumericT>
478 static_cast<cl_uint>(start + 1),
479 static_cast<cl_uint>(start),
493 static_cast<cl_uint>(start + 1),
494 static_cast<cl_uint>(start),
507 template <
typename NumericT>
521 static_cast<cl_uint>(0),
522 static_cast<cl_uint>(0),
537 static_cast<cl_uint>(0),
538 static_cast<cl_uint>(0),
551 template <
typename NumericT>
589 template<
typename NumericT>
612 static_cast<cl_uint>(l),
613 static_cast<cl_uint>(m - 1)
629 static_cast<cl_uint>(l),
630 static_cast<cl_uint>(m - 1)
637 template <
typename NumericT>
656 static_cast<cl_uint>(row_start),
657 static_cast<cl_uint>(col_start),
671 static_cast<cl_uint>(row_start),
672 static_cast<cl_uint>(col_start),
void matrix_diag_from_vector(const vector_base< NumericT > &vec, int k, matrix_base< NumericT > &A)
void trans(const matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > &proxy, matrix_base< NumericT > &temp_trans)
void am(matrix_base< NumericT > &A, matrix_base< NumericT > const &B, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
void matrix_column(const matrix_base< NumericT > &A, unsigned int j, vector_base< NumericT > &vec)
Represents an OpenCL device within ViennaCL.
result_of::size_type< matrix_base< NumericT > >::type stride1(matrix_base< NumericT > const &s)
const std::string SVD_HOUSEHOLDER_UPDATE_A_LEFT_KERNEL
statement matrix_diag_from_vector(viennacl::vector_base< NumericT > const *x, viennacl::matrix_base< NumericT > const *A, int id)
Generic size and resize functionality for different vector and matrix types.
Represents an OpenCL kernel within ViennaCL.
viennacl::ocl::program & get_program(std::string const &name)
Returns the program with the provided name.
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
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...
size_type local_work_size(int index=0) const
Returns the local work size at the respective dimension.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
const std::string SVD_BIDIAG_PACK_KERNEL
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
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...
Expression template class for representing a tree of expressions which ultimately result in a matrix...
size_type stride2() const
Returns the number of columns.
const std::string SVD_GIVENS_NEXT_KERNEL
const std::string SVD_HOUSEHOLDER_UPDATE_A_RIGHT_KERNEL
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
This file provides the forward declarations for the main types used within ViennaCL.
result_of::size_type< T >::type start1(T const &obj)
static device_specific::execution_handler & execution_handler(viennacl::ocl::context &ctx)
static void init(viennacl::ocl::context &ctx)
Determines row and column increments for matrices and matrix proxies.
void bidiag_pack(matrix_base< NumericT > &A, viennacl::vector< NumericT > &dh, viennacl::vector< NumericT > &sh)
scheduler::statement avbv(scheduler::operation_node_type ASSIGN_OP, NumericT const *x, NumericT const *y, ScalarT1 const *a, bool flip_a, bool reciprocal_a, NumericT const *z, ScalarT2 const *b, bool flip_b, bool reciprocal_b)
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
void scaled_rank_1_update(matrix_base< NumericT > &A, ScalarT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, const vector_base< NumericT > &vec1, const vector_base< NumericT > &vec2)
The implementation of the operation mat += alpha * vec1 * vec2^T, i.e. a scaled rank 1 update...
OpenCL kernel file for singular value decomposition.
const std::string SVD_COPY_ROW_KERNEL
Common implementations shared by OpenCL-based operations.
void copy_vec(matrix_base< NumericT > &A, vector_base< NumericT > &V, vcl_size_t row_start, vcl_size_t col_start, bool copy_col)
void house_update_A_right(matrix_base< NumericT > &A, vector_base< NumericT > &D)
void element_op(matrix_base< NumericT > &A, matrix_expression< const matrix_base< NumericT >, const matrix_base< NumericT >, op_element_binary< OpT > > const &proxy)
Implementation of binary element-wise operations A = OP(B,C)
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
void ambm(matrix_base< NumericT > &A, matrix_base< NumericT > const &B, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &C, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
void house_update_QL(matrix_base< NumericT > &Q, vector_base< NumericT > &D, vcl_size_t A_size1)
static device_specific::execution_handler & execution_handler(bool is_row_major, viennacl::ocl::context &ctx)
statement binary_element_op(NumericT const *x, NumericT const *y, NumericT const *z, scheduler::operation_node_type TYPE)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
result_of::size_type< T >::type start2(T const &obj)
A class representing local (shared) OpenCL memory. Typically used as kernel argument.
Helper struct for checking whether a type is a host scalar type (e.g. float, double) ...
Main kernel class for generating OpenCL kernels for singular value decomposition of dense matrices...
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.
statement mat_vec_prod(viennacl::matrix_base< NumericT > const *A, bool A_trans, viennacl::vector_base< NumericT > const *x, viennacl::vector_base< NumericT > const *y)
Implementation of a smart-pointer-like class for handling OpenCL handles.
result_of::size_type< T >::type start(T const &obj)
cl_uint make_options(vcl_size_t length, bool reciprocal, bool flip_sign)
Main kernel class for generating OpenCL kernels for operations on/with dense matrix objects of type v...
Metafunction for querying type informations.
const std::string SVD_HOUSEHOLDER_UPDATE_QL_KERNEL
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
size_type stride1() const
Returns the number of rows.
statement unary_element_op(NumericT const *x, NumericT const *y, scheduler::operation_node_type TYPE)
scheduler::statement av(scheduler::operation_node_type ASSIGN_OP, NumericT const *x, NumericT const *y, ScalarT1 const *a, bool flip_a, bool reciprocal_a)
size_type size2() const
Returns the number of columns.
void bidiag_pack_svd(viennacl::matrix< SCALARTYPE > &A, VectorType &dh, VectorType &sh)
Wrapper class for an OpenCL program.
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
void execute(template_base const &T, statements_container const &statements, viennacl::ocl::context &ctx=viennacl::ocl::current_context(), bool force_compilation=false)
void house_update_A_left(matrix_base< NumericT > &A, vector_base< NumericT > &D, vcl_size_t start)
size_type size1() const
Returns the number of rows.
Proxy classes for vectors.
result_of::size_type< matrix_base< NumericT > >::type stride2(matrix_base< NumericT > const &s)
operation_node_type
Enumeration for identifying the possible operations.
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
void convert(matrix_base< DestNumericT > &dest, matrix_base< SrcNumericT > const &src)
statement mat_mat_prod(NumericT alpha, viennacl::matrix_base< NumericT > const *A, bool A_trans, viennacl::matrix_base< NumericT > const *B, bool B_trans, NumericT beta, viennacl::matrix_base< NumericT > const *C)
statement matrix_diag_to_vector(viennacl::vector_base< NumericT > const *x, viennacl::matrix_base< NumericT > const *A, int id)
void matrix_diag_to_vector(const matrix_base< NumericT > &A, int k, vector_base< NumericT > &vec)
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
static device_specific::execution_handler & execution_handler(bool is_row_major, viennacl::ocl::context &ctx)
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.
Representation of an OpenCL kernel in ViennaCL.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
void matrix_assign(matrix_base< NumericT > &A, NumericT s, bool up_to_internal_size=false)
scheduler::statement diagonal_assign_cpu(matrix_base< NumericT > const *x, implicit_vector_base< NumericT > const *y)
size_type global_work_size(int index=0) const
Returns the global work size at the respective dimension.
statement matrix_row(viennacl::vector_base< NumericT > const *x, viennacl::matrix_base< NumericT > const *A, unsigned int id)
static device_specific::execution_handler & execution_handler(bool is_row_major, viennacl::ocl::context &ctx)
void givens_next(matrix_base< NumericT > &matrix, vector_base< NumericT > &tmp1, vector_base< NumericT > &tmp2, int l, int m)
A tag class representing transposed matrices.
statement matrix_column(viennacl::vector_base< NumericT > const *x, viennacl::matrix_base< NumericT > const *A, unsigned int id)
size_type start2() const
Returns the number of columns.
void execute(container_type::key_type const &key, statements_container const &statements)
A tag class representing element-wise binary operations (like multiplication) on vectors or matrices...
size_type internal_size2() const
Returns the internal number of columns. Usually required for launching OpenCL kernels only...
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
const std::string SVD_COPY_COL_KERNEL
size_type internal_size1() const
Returns the internal number of rows. Usually required for launching OpenCL kernels only...
void matrix_row(const matrix_base< NumericT > &A, unsigned int i, vector_base< NumericT > &vec)
T min(const T &lhs, const T &rhs)
Minimum.
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
scheduler::statement assign_cpu(vector_base< NumericT > const *x, implicit_vector_base< NumericT > const *y)
viennacl::ocl::kernel & get_kernel(std::string const &name)
Returns the kernel with the provided name.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
const char * operator_string(scheduler::operation_node_type type)
static void init(viennacl::ocl::context &ctx)
Helper class for converting a type to its string representation.
A tag class representing element-wise unary operations (like sin()) on vectors or matrices...
Implementation of the ViennaCL scalar class.
A collection of compile time type deductions.
static std::string program_name()
void prod_impl(const matrix_base< NumericT > &A, bool trans_A, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
void ambm_m(matrix_base< NumericT > &A, matrix_base< NumericT > const &B, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &C, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
void matrix_diagonal_assign(matrix_base< NumericT > &A, NumericT s)
Simple enable-if variant that uses the SFINAE pattern.
size_type start1() const
Returns the number of rows.
Runtime generation of OpenCL kernels for matrix operations.
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)