1 #ifndef VIENNACL_ELL_MATRIX_HPP_ 
    2 #define VIENNACL_ELL_MATRIX_HPP_ 
   52 template<
typename NumericT, 
unsigned int AlignmentV >
 
   67 #ifdef VIENNACL_WITH_OPENCL 
   70       coords_.opencl_handle().context(ctx.opencl_context());
 
   71       elements_.opencl_handle().context(ctx.opencl_context());
 
  106 #if defined(_MSC_VER) && _MSC_VER < 1500          //Visual Studio 2005 needs special treatment 
  107   template<
typename CPUMatrixT>
 
  108   friend void copy(
const CPUMatrixT & cpu_matrix, 
ell_matrix & gpu_matrix );
 
  110   template<
typename CPUMatrixT, 
typename T, 
unsigned int ALIGN>
 
  123 template<
typename CPUMatrixT, 
typename NumericT, 
unsigned int AlignmentV>
 
  129   if (cpu_matrix.size1() > 0 && cpu_matrix.size2() > 0)
 
  133     for (
typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1(); row_it != cpu_matrix.end1(); ++row_it)
 
  136       for (
typename CPUMatrixT::const_iterator2 col_it = row_it.begin(); col_it != row_it.end(); ++col_it)
 
  139       max_entries_per_row = 
std::max(max_entries_per_row, num_entries);
 
  143     gpu_matrix.maxnnz_ = max_entries_per_row;
 
  144     gpu_matrix.rows_ = cpu_matrix.size1();
 
  145     gpu_matrix.cols_ = cpu_matrix.size2();
 
  150     std::vector<NumericT> elements(nnz, 0);
 
  155     for (
typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1(); row_it != cpu_matrix.end1(); ++row_it)
 
  159       for (
typename CPUMatrixT::const_iterator2 col_it = row_it.begin(); col_it != row_it.end(); ++col_it)
 
  161         coords.set(gpu_matrix.
internal_size1() * data_index + col_it.index1(), col_it.index2());
 
  162         elements[gpu_matrix.
internal_size1() * data_index + col_it.index1()] = *col_it;
 
  180 template<
typename IndexT, 
typename NumericT, 
unsigned int AlignmentV>
 
  181 void copy(std::vector< std::map<IndexT, NumericT> > 
const & cpu_matrix,
 
  185   for (
vcl_size_t i=0; i<cpu_matrix.size(); ++i)
 
  187     if (cpu_matrix[i].
size() > 0)
 
  188       max_col = std::max<vcl_size_t>(max_col, (cpu_matrix[i].rbegin())->first);
 
  199 template<
typename CPUMatrixT, 
typename NumericT, 
unsigned int AlignmentV>
 
  205   if (gpu_matrix.
size1() > 0 && gpu_matrix.
size2() > 0)
 
  207     std::vector<NumericT> elements(gpu_matrix.
internal_nnz());
 
  220         if (val <= 0 && val >= 0) 
 
  223         if (coords[offset] >= gpu_matrix.
size2())
 
  225           std::cerr << 
"ViennaCL encountered invalid data " << offset << 
" " << ind << 
" " << row << 
" " << coords[offset] << 
" " << gpu_matrix.
size2() << std::endl;
 
  229         cpu_matrix(row, coords[offset]) = val;
 
  241 template<
typename NumericT, 
unsigned int AlignmentV, 
typename IndexT>
 
  243           std::vector< std::map<IndexT, NumericT> > & cpu_matrix)
 
  245   if (cpu_matrix.size() == 0)
 
  246     cpu_matrix.resize(gpu_matrix.
size1());
 
  248   assert(cpu_matrix.size() == gpu_matrix.
size1() && bool(
"Matrix dimension mismatch!"));
 
  265   template<
typename T, 
unsigned int A>
 
  266   struct op_executor<vector_base<T>, 
op_assign, vector_expression<const ell_matrix<T, A>, const vector_base<T>, op_prod> >
 
  268     static void apply(vector_base<T> & lhs, vector_expression<
const ell_matrix<T, A>, 
const vector_base<T>, op_prod> 
const & rhs)
 
  282   template<
typename T, 
unsigned int A>
 
  283   struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const ell_matrix<T, A>, const vector_base<T>, op_prod> >
 
  285     static void apply(vector_base<T> & lhs, vector_expression<
const ell_matrix<T, A>, 
const vector_base<T>, op_prod> 
const & rhs)
 
  299   template<
typename T, 
unsigned int A>
 
  300   struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const ell_matrix<T, A>, const vector_base<T>, op_prod> >
 
  302     static void apply(vector_base<T> & lhs, vector_expression<
const ell_matrix<T, A>, 
const vector_base<T>, op_prod> 
const & rhs)
 
  318   template<
typename T, 
unsigned int A, 
typename LHS, 
typename RHS, 
typename OP>
 
  319   struct op_executor<vector_base<T>, 
op_assign, vector_expression<const ell_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
 
  321     static void apply(vector_base<T> & lhs, vector_expression<
const ell_matrix<T, A>, 
const vector_expression<const LHS, const RHS, OP>, op_prod> 
const & rhs)
 
  329   template<
typename T, 
unsigned int A, 
typename LHS, 
typename RHS, 
typename OP>
 
  330   struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const ell_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
 
  332     static void apply(vector_base<T> & lhs, vector_expression<
const ell_matrix<T, A>, 
const vector_expression<const LHS, const RHS, OP>, op_prod> 
const & rhs)
 
  342   template<
typename T, 
unsigned int A, 
typename LHS, 
typename RHS, 
typename OP>
 
  343   struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const ell_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
 
  345     static void apply(vector_base<T> & lhs, vector_expression<
const ell_matrix<T, A>, 
const vector_expression<const LHS, const RHS, OP>, op_prod> 
const & rhs)
 
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
Helper class implementing an array on the host. Default case: No conversion necessary. 
vcl_size_t element_size() const 
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
const handle_type & handle2() const 
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.) 
This file provides the forward declarations for the main types used within ViennaCL. 
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM. 
T max(const T &lhs, const T &rhs)
Maximum. 
viennacl::backend::mem_handle handle_type
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
vcl_size_t internal_size1() const 
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
const handle_type & handle() const 
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.) 
vcl_size_t internal_nnz() const 
Sparse matrix class using the ELLPACK format for storing the nonzeros. 
friend void copy(const CPUMatrixT &cpu_matrix, ell_matrix< T, ALIGN > &gpu_matrix)
Implementations of operations using sparse matrices. 
vcl_size_t maxnnz() const 
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
viennacl::memory_types memory_type() const 
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object. 
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
vcl_size_t raw_size() const 
Returns the number of bytes of the currently active buffer. 
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
vcl_size_t internal_size2() const 
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication. 
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version. 
vcl_size_t internal_maxnnz() const 
ell_matrix(viennacl::context ctx)