All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compressed_compressed_matrix.hpp
Go to the documentation of this file.
#ifndef VIENNACL_COMPRESSED_compressed_compressed_matrix_HPP_
#define VIENNACL_COMPRESSED_compressed_compressed_matrix_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 <vector>
#include <list>
#include <map>
#include "viennacl/forwards.h"
#include "viennacl/vector.hpp"
#include "viennacl/linalg/sparse_matrix_operations.hpp"
#include "viennacl/tools/tools.hpp"
#include "viennacl/tools/entry_proxy.hpp"
namespace viennacl
{
namespace detail
{
template<typename CPUMatrixT, typename NumericT>
void copy_impl(const CPUMatrixT & cpu_matrix,
compressed_compressed_matrix<NumericT> & gpu_matrix,
vcl_size_t nonzero_rows,
vcl_size_t nonzeros)
{
assert( (gpu_matrix.size1() == 0 || viennacl::traits::size1(cpu_matrix) == gpu_matrix.size1()) && bool("Size mismatch") );
assert( (gpu_matrix.size2() == 0 || viennacl::traits::size2(cpu_matrix) == gpu_matrix.size2()) && bool("Size mismatch") );
viennacl::backend::typesafe_host_array<unsigned int> row_buffer(gpu_matrix.handle1(), nonzero_rows + 1);
viennacl::backend::typesafe_host_array<unsigned int> row_indices(gpu_matrix.handle3(), nonzero_rows);
viennacl::backend::typesafe_host_array<unsigned int> col_buffer(gpu_matrix.handle2(), nonzeros);
std::vector<NumericT> elements(nonzeros);
vcl_size_t row_index = 0;
vcl_size_t data_index = 0;
for (typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1();
row_it != cpu_matrix.end1();
++row_it)
{
bool row_empty = true;
for (typename CPUMatrixT::const_iterator2 col_it = row_it.begin();
col_it != row_it.end();
++col_it)
{
NumericT entry = *col_it;
if (entry < 0 || entry > 0) // entry != 0 without compiler warnings
{
if (row_empty)
{
assert(row_index < nonzero_rows && bool("Provided count of nonzero rows exceeded!"));
row_empty = false;
row_buffer.set(row_index, data_index);
row_indices.set(row_index, col_it.index1());
++row_index;
}
col_buffer.set(data_index, col_it.index2());
elements[data_index] = entry;
++data_index;
}
}
}
row_buffer.set(row_index, data_index);
gpu_matrix.set(row_buffer.get(),
row_indices.get(),
col_buffer.get(),
&elements[0],
cpu_matrix.size1(),
cpu_matrix.size2(),
nonzero_rows,
nonzeros);
}
}
//provide copy-operation:
template<typename CPUMatrixT, typename NumericT>
void copy(const CPUMatrixT & cpu_matrix,
compressed_compressed_matrix<NumericT> & gpu_matrix )
{
//std::cout << "copy for (" << cpu_matrix.size1() << ", " << cpu_matrix.size2() << ", " << cpu_matrix.nnz() << ")" << std::endl;
if ( cpu_matrix.size1() > 0 && cpu_matrix.size2() > 0 )
{
//determine nonzero rows and total nonzeros:
vcl_size_t num_entries = 0;
vcl_size_t nonzero_rows = 0;
for (typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1();
row_it != cpu_matrix.end1();
++row_it)
{
bool row_empty = true;
for (typename CPUMatrixT::const_iterator2 col_it = row_it.begin();
col_it != row_it.end();
++col_it)
{
NumericT val = *col_it;
if (val < 0 || val > 0) // val != 0 without compiler warnings
{
++num_entries;
if (row_empty)
{
row_empty = false;
++nonzero_rows;
}
}
}
}
if (num_entries == 0) //we copy an empty matrix
num_entries = 1;
//set up matrix entries:
viennacl::detail::copy_impl(cpu_matrix, gpu_matrix, nonzero_rows, num_entries);
}
}
//adapted for std::vector< std::map < > > argument:
template<typename SizeT, typename NumericT>
void copy(const std::vector< std::map<SizeT, NumericT> > & cpu_matrix,
compressed_compressed_matrix<NumericT> & gpu_matrix )
{
vcl_size_t nonzero_rows = 0;
vcl_size_t nonzeros = 0;
vcl_size_t max_col = 0;
for (vcl_size_t i=0; i<cpu_matrix.size(); ++i)
{
if (cpu_matrix[i].size() > 0)
++nonzero_rows;
nonzeros += cpu_matrix[i].size();
if (cpu_matrix[i].size() > 0)
max_col = std::max<vcl_size_t>(max_col, (cpu_matrix[i].rbegin())->first);
}
viennacl::detail::copy_impl(tools::const_sparse_matrix_adapter<NumericT, SizeT>(cpu_matrix, cpu_matrix.size(), max_col + 1),
gpu_matrix,
nonzero_rows,
nonzeros);
}
//
// gpu to cpu:
//
template<typename CPUMatrixT, typename NumericT>
void copy(const compressed_compressed_matrix<NumericT> & gpu_matrix,
CPUMatrixT & cpu_matrix )
{
assert( (cpu_matrix.size1() == gpu_matrix.size1()) && bool("Size mismatch") );
assert( (cpu_matrix.size2() == gpu_matrix.size2()) && bool("Size mismatch") );
if ( gpu_matrix.size1() > 0 && gpu_matrix.size2() > 0 )
{
//get raw data from memory:
viennacl::backend::typesafe_host_array<unsigned int> row_buffer(gpu_matrix.handle1(), gpu_matrix.nnz1() + 1);
viennacl::backend::typesafe_host_array<unsigned int> row_indices(gpu_matrix.handle1(), gpu_matrix.nnz1());
viennacl::backend::typesafe_host_array<unsigned int> col_buffer(gpu_matrix.handle2(), gpu_matrix.nnz());
std::vector<NumericT> elements(gpu_matrix.nnz());
//std::cout << "GPU->CPU, nonzeros: " << gpu_matrix.nnz() << std::endl;
viennacl::backend::memory_read(gpu_matrix.handle1(), 0, row_buffer.raw_size(), row_buffer.get());
viennacl::backend::memory_read(gpu_matrix.handle3(), 0, row_indices.raw_size(), row_indices.get());
viennacl::backend::memory_read(gpu_matrix.handle2(), 0, col_buffer.raw_size(), col_buffer.get());
viennacl::backend::memory_read(gpu_matrix.handle(), 0, sizeof(NumericT)* gpu_matrix.nnz(), &(elements[0]));
//fill the cpu_matrix:
vcl_size_t data_index = 0;
for (vcl_size_t i = 1; i < row_buffer.size(); ++i)
{
while (data_index < row_buffer[i])
{
if (col_buffer[data_index] >= gpu_matrix.size2())
{
std::cerr << "ViennaCL encountered invalid data at colbuffer[" << data_index << "]: " << col_buffer[data_index] << std::endl;
return;
}
NumericT val = elements[data_index];
if (val < 0 || val > 0) // val != 0 without compiler warning
cpu_matrix(row_indices[i-1], col_buffer[data_index]) = val;
++data_index;
}
}
}
}
template<typename NumericT>
void copy(const compressed_compressed_matrix<NumericT> & gpu_matrix,
std::vector< std::map<unsigned int, NumericT> > & cpu_matrix)
{
tools::sparse_matrix_adapter<NumericT> temp(cpu_matrix, cpu_matrix.size(), cpu_matrix.size());
copy(gpu_matrix, temp);
}
template<class NumericT>
class compressed_compressed_matrix
{
public:
typedef viennacl::backend::mem_handle handle_type;
typedef scalar<typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT<NumericT>::ResultType> value_type;
typedef vcl_size_t size_type;
compressed_compressed_matrix() : rows_(0), cols_(0), nonzero_rows_(0), nonzeros_(0) {}
explicit compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows = 0, vcl_size_t nonzeros = 0, viennacl::context ctx = viennacl::context())
: rows_(rows), cols_(cols), nonzero_rows_(nonzero_rows), nonzeros_(nonzeros)
{
row_buffer_.switch_active_handle_id(ctx.memory_type());
row_indices_.switch_active_handle_id(ctx.memory_type());
col_buffer_.switch_active_handle_id(ctx.memory_type());
elements_.switch_active_handle_id(ctx.memory_type());
#ifdef VIENNACL_WITH_OPENCL
if (ctx.memory_type() == OPENCL_MEMORY)
{
row_buffer_.opencl_handle().context(ctx.opencl_context());
row_indices_.opencl_handle().context(ctx.opencl_context());
col_buffer_.opencl_handle().context(ctx.opencl_context());
elements_.opencl_handle().context(ctx.opencl_context());
}
#endif
if (rows > 0)
{
viennacl::backend::memory_create(row_buffer_, viennacl::backend::typesafe_host_array<unsigned int>().element_size() * (rows + 1), ctx);
}
if (nonzeros > 0)
{
viennacl::backend::memory_create(col_buffer_, viennacl::backend::typesafe_host_array<unsigned int>().element_size() * nonzeros, ctx);
viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, ctx);
}
}
explicit compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, viennacl::context ctx)
: rows_(rows), cols_(cols), nonzeros_(0)
{
row_buffer_.switch_active_handle_id(ctx.memory_type());
col_buffer_.switch_active_handle_id(ctx.memory_type());
elements_.switch_active_handle_id(ctx.memory_type());
#ifdef VIENNACL_WITH_OPENCL
if (ctx.memory_type() == OPENCL_MEMORY)
{
row_buffer_.opencl_handle().context(ctx.opencl_context());
col_buffer_.opencl_handle().context(ctx.opencl_context());
elements_.opencl_handle().context(ctx.opencl_context());
}
#endif
if (rows > 0)
{
viennacl::backend::memory_create(row_buffer_, viennacl::backend::typesafe_host_array<unsigned int>().element_size() * (rows + 1), ctx);
}
}
explicit compressed_compressed_matrix(viennacl::context ctx) : rows_(0), cols_(0), nonzero_rows_(0), nonzeros_(0)
{
row_buffer_.switch_active_handle_id(ctx.memory_type());
row_indices_.switch_active_handle_id(ctx.memory_type());
col_buffer_.switch_active_handle_id(ctx.memory_type());
elements_.switch_active_handle_id(ctx.memory_type());
#ifdef VIENNACL_WITH_OPENCL
if (ctx.memory_type() == OPENCL_MEMORY)
{
row_buffer_.opencl_handle().context(ctx.opencl_context());
row_indices_.opencl_handle().context(ctx.opencl_context());
col_buffer_.opencl_handle().context(ctx.opencl_context());
elements_.opencl_handle().context(ctx.opencl_context());
}
#endif
}
#ifdef VIENNACL_WITH_OPENCL
explicit compressed_compressed_matrix(cl_mem mem_row_buffer, cl_mem mem_row_indices, cl_mem mem_col_buffer, cl_mem mem_elements,
vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows, vcl_size_t nonzeros) :
rows_(rows), cols_(cols), nonzero_rows_(nonzero_rows), nonzeros_(nonzeros)
{
row_buffer_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
row_buffer_.opencl_handle() = mem_row_buffer;
row_buffer_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
row_buffer_.raw_size(sizeof(cl_uint) * (nonzero_rows + 1));
row_indices_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
row_indices_.opencl_handle() = mem_row_indices;
row_indices_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
row_indices_.raw_size(sizeof(cl_uint) * nonzero_rows);
col_buffer_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
col_buffer_.opencl_handle() = mem_col_buffer;
col_buffer_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
col_buffer_.raw_size(sizeof(cl_uint) * nonzeros);
elements_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
elements_.opencl_handle() = mem_elements;
elements_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
elements_.raw_size(sizeof(NumericT) * nonzeros);
}
#endif
compressed_compressed_matrix & operator=(compressed_compressed_matrix const & other)
{
assert( (rows_ == 0 || rows_ == other.size1()) && bool("Size mismatch") );
assert( (cols_ == 0 || cols_ == other.size2()) && bool("Size mismatch") );
rows_ = other.size1();
cols_ = other.size2();
nonzero_rows_ = other.nnz1();
nonzeros_ = other.nnz();
viennacl::backend::typesafe_memory_copy<unsigned int>(other.row_buffer_, row_buffer_);
viennacl::backend::typesafe_memory_copy<unsigned int>(other.row_indices_, row_indices_);
viennacl::backend::typesafe_memory_copy<unsigned int>(other.col_buffer_, col_buffer_);
viennacl::backend::typesafe_memory_copy<NumericT>(other.elements_, elements_);
return *this;
}
void set(const void * row_jumper,
const void * row_indices,
const void * col_buffer,
const NumericT * elements,
vcl_size_t rows,
vcl_size_t cols,
vcl_size_t nonzero_rows,
vcl_size_t nonzeros)
{
assert( (rows > 0) && bool("Error in compressed_compressed_matrix::set(): Number of rows must be larger than zero!"));
assert( (cols > 0) && bool("Error in compressed_compressed_matrix::set(): Number of columns must be larger than zero!"));
assert( (nonzero_rows > 0) && bool("Error in compressed_compressed_matrix::set(): Number of nonzero rows must be larger than zero!"));
assert( (nonzeros > 0) && bool("Error in compressed_compressed_matrix::set(): Number of nonzeros must be larger than zero!"));
//std::cout << "Setting memory: " << cols + 1 << ", " << nonzeros << std::endl;
viennacl::backend::memory_create(row_buffer_, viennacl::backend::typesafe_host_array<unsigned int>(row_buffer_).element_size() * (nonzero_rows + 1), viennacl::traits::context(row_buffer_), row_jumper);
viennacl::backend::memory_create(row_indices_, viennacl::backend::typesafe_host_array<unsigned int>(row_indices_).element_size() * nonzero_rows, viennacl::traits::context(row_indices_), row_indices);
viennacl::backend::memory_create(col_buffer_, viennacl::backend::typesafe_host_array<unsigned int>(col_buffer_).element_size() * nonzeros, viennacl::traits::context(col_buffer_), col_buffer);
viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, viennacl::traits::context(elements_), elements);
nonzeros_ = nonzeros;
nonzero_rows_ = nonzero_rows;
rows_ = rows;
cols_ = cols;
}
void clear()
{
viennacl::backend::typesafe_host_array<unsigned int> host_row_buffer(row_buffer_, rows_ + 1);
viennacl::backend::typesafe_host_array<unsigned int> host_row_indices(row_indices_, rows_ + 1);
viennacl::backend::typesafe_host_array<unsigned int> host_col_buffer(col_buffer_, 1);
std::vector<NumericT> host_elements(1);
viennacl::backend::memory_create(row_buffer_, host_row_buffer.element_size() * (rows_ + 1), viennacl::traits::context(row_buffer_), host_row_buffer.get());
viennacl::backend::memory_create(row_indices_, host_row_indices.element_size() * (rows_ + 1), viennacl::traits::context(row_indices_), host_row_indices.get());
viennacl::backend::memory_create(col_buffer_, host_col_buffer.element_size() * 1, viennacl::traits::context(col_buffer_), host_col_buffer.get());
viennacl::backend::memory_create(elements_, sizeof(NumericT) * 1, viennacl::traits::context(elements_), &(host_elements[0]));
nonzeros_ = 0;
nonzero_rows_ = 0;
}
const vcl_size_t & size1() const { return rows_; }
const vcl_size_t & size2() const { return cols_; }
const vcl_size_t & nnz1() const { return nonzero_rows_; }
const vcl_size_t & nnz() const { return nonzeros_; }
const handle_type & handle1() const { return row_buffer_; }
const handle_type & handle2() const { return col_buffer_; }
const handle_type & handle3() const { return row_indices_; }
const handle_type & handle() const { return elements_; }
handle_type & handle1() { return row_buffer_; }
handle_type & handle2() { return col_buffer_; }
handle_type & handle3() { return row_indices_; }
handle_type & handle() { return elements_; }
void switch_memory_context(viennacl::context new_ctx)
{
viennacl::backend::switch_memory_context<unsigned int>(row_buffer_, new_ctx);
viennacl::backend::switch_memory_context<unsigned int>(row_indices_, new_ctx);
viennacl::backend::switch_memory_context<unsigned int>(col_buffer_, new_ctx);
viennacl::backend::switch_memory_context<NumericT>(elements_, new_ctx);
}
viennacl::memory_types memory_context() const
{
return row_buffer_.get_active_handle_id();
}
private:
vcl_size_t rows_;
vcl_size_t cols_;
vcl_size_t nonzero_rows_;
vcl_size_t nonzeros_;
handle_type row_buffer_;
handle_type row_indices_;
handle_type col_buffer_;
handle_type elements_;
};
//
// Specify available operations:
//
namespace linalg
{
namespace detail
{
// x = A * y
template<typename T>
struct op_executor<vector_base<T>, op_assign, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
{
static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
{
// check for the special case x = A * x
if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
{
viennacl::vector<T> temp(lhs);
viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
lhs = temp;
}
else
viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), lhs, T(0));
}
};
template<typename T>
struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
{
static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
{
// check for the special case x += A * x
if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
{
viennacl::vector<T> temp(lhs);
viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
lhs += temp;
}
else
viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), lhs, T(1));
}
};
template<typename T>
struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
{
static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
{
// check for the special case x -= A * x
if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
{
viennacl::vector<T> temp(lhs);
viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
lhs -= temp;
}
else
viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(-1), lhs, T(1));
}
};
// x = A * vec_op
template<typename T, typename LHS, typename RHS, typename OP>
struct op_executor<vector_base<T>, op_assign, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
{
static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
{
viennacl::vector<T> temp(rhs.rhs());
viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs);
}
};
// x = A * vec_op
template<typename T, typename LHS, typename RHS, typename OP>
struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const compressed_compressed_matrix<T>, vector_expression<const LHS, const RHS, OP>, op_prod> >
{
static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
{
viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
viennacl::vector<T> temp_result(lhs);
viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
lhs += temp_result;
}
};
// x = A * vec_op
template<typename T, typename LHS, typename RHS, typename OP>
struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
{
static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
{
viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
viennacl::vector<T> temp_result(lhs);
viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
lhs -= temp_result;
}
};
} // namespace detail
} // namespace linalg
}
#endif
viennacl::compressed_compressed_matrix::nnz
const vcl_size_t & nnz() const
Returns the number of nonzero entries.
Definition: compressed_compressed_matrix.hpp:466
viennacl::backend::typesafe_host_array
Helper class implementing an array on the host. Default case: No conversion necessary.
Definition: util.hpp:92
viennacl::backend::typesafe_host_array::element_size
vcl_size_t element_size() const
Definition: util.hpp:112
viennacl::scalar
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:227
viennacl::compressed_compressed_matrix::value_type
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
Definition: compressed_compressed_matrix.hpp:269
viennacl::compressed_compressed_matrix::switch_memory_context
void switch_memory_context(viennacl::context new_ctx)
Definition: compressed_compressed_matrix.hpp:486
viennacl::compressed_compressed_matrix::set
void set(const void *row_jumper, const void *row_indices, const void *col_buffer, const NumericT *elements, vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows, vcl_size_t nonzeros)
Sets the row, column and value arrays of the compressed matrix.
Definition: compressed_compressed_matrix.hpp:416
viennacl::compressed_compressed_matrix::handle2
const handle_type & handle2() const
Returns the OpenCL handle to the column index array.
Definition: compressed_compressed_matrix.hpp:471
viennacl::compressed_compressed_matrix::handle1
const handle_type & handle1() const
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:469
tools.hpp
Various little tools used here and there in ViennaCL.
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
entry_proxy.hpp
A proxy class for entries in a vector.
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::backend::typesafe_host_array::get
void * get()
Definition: util.hpp:110
viennacl::backend::memory_read
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.
Definition: memory.hpp:261
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::compressed_compressed_matrix::handle3
handle_type & handle3()
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:482
viennacl::backend::detail::element_size
vcl_size_t element_size(memory_types)
Definition: memory.hpp:299
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::context
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
viennacl::compressed_compressed_matrix::handle
const handle_type & handle() const
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_compressed_matrix.hpp:475
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::compressed_compressed_matrix::handle
handle_type & handle()
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_compressed_matrix.hpp:484
viennacl::compressed_compressed_matrix::handle3
const handle_type & handle3() const
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:473
viennacl::compressed_compressed_matrix
A sparse square matrix in compressed sparse rows format optimized for the case that only a few rows c...
Definition: compressed_compressed_matrix.hpp:265
sparse_matrix_operations.hpp
Implementations of operations using sparse matrices.
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
compressed_compressed_matrix(viennacl::context ctx)
Definition: compressed_compressed_matrix.hpp:338
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows=0, vcl_size_t nonzeros=0, viennacl::context ctx=viennacl::context())
Construction of a compressed matrix with the supplied number of rows and columns. If the number of no...
Definition: compressed_compressed_matrix.hpp:283
viennacl::compressed_compressed_matrix::operator=
compressed_compressed_matrix & operator=(compressed_compressed_matrix const &other)
Assignment a compressed matrix from possibly another memory domain.
Definition: compressed_compressed_matrix.hpp:386
viennacl::compressed_compressed_matrix::clear
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
Definition: compressed_compressed_matrix.hpp:443
viennacl::tools::const_sparse_matrix_adapter
Adapts a constant sparse matrix type made up from std::vector<std::map<SizeT, NumericT> > to basic ub...
Definition: adapter.hpp:183
viennacl::compressed_compressed_matrix::size2
const vcl_size_t & size2() const
Returns the number of columns.
Definition: compressed_compressed_matrix.hpp:462
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::vector
Definition: forwards.h:266
viennacl::compressed_compressed_matrix::size1
const vcl_size_t & size1() const
Returns the number of rows.
Definition: compressed_compressed_matrix.hpp:460
viennacl::context::memory_type
viennacl::memory_types memory_type() const
Definition: context.hpp:76
viennacl::detail::copy_impl
void copy_impl(const CPUMatrixT &cpu_matrix, compressed_compressed_matrix< NumericT > &gpu_matrix, vcl_size_t nonzero_rows, vcl_size_t nonzeros)
Definition: compressed_compressed_matrix.hpp:41
viennacl::backend::mem_handle::switch_active_handle_id
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...
Definition: mem_handle.hpp:121
viennacl::traits::context
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::compressed_compressed_matrix::handle2
handle_type & handle2()
Returns the OpenCL handle to the column index array.
Definition: compressed_compressed_matrix.hpp:480
viennacl::copy
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) ...
Definition: circulant_matrix.hpp:150
viennacl::compressed_compressed_matrix::nnz1
const vcl_size_t & nnz1() const
Returns the number of nonzero entries.
Definition: compressed_compressed_matrix.hpp:464
viennacl::backend::mem_handle
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
viennacl::backend::mem_handle::raw_size
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:230
viennacl::tools::sparse_matrix_adapter
Adapts a non-const sparse matrix type made up from std::vector<std::map<SizeT, NumericT> > to basic u...
Definition: adapter.hpp:357
viennacl::backend::memory_create
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...
Definition: memory.hpp:87
viennacl::compressed_compressed_matrix::memory_context
viennacl::memory_types memory_context() const
Definition: compressed_compressed_matrix.hpp:494
viennacl::linalg::prod_impl
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Definition: matrix_operations.hpp:438
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
viennacl::memory_types
memory_types
Definition: forwards.h:345
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
compressed_compressed_matrix()
Default construction of a compressed matrix. No memory is allocated.
Definition: compressed_compressed_matrix.hpp:273
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, viennacl::context ctx)
Construction of a compressed matrix with the supplied number of rows and columns. If the number of no...
Definition: compressed_compressed_matrix.hpp:317
op_assign
Definition: self_assign.cpp:132
viennacl::compressed_compressed_matrix::handle_type
viennacl::backend::mem_handle handle_type
Definition: compressed_compressed_matrix.hpp:268
viennacl::compressed_compressed_matrix::size_type
vcl_size_t size_type
Definition: compressed_compressed_matrix.hpp:270
viennacl::backend::mem_handle::get_active_handle_id
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
Definition: mem_handle.hpp:118
viennacl::compressed_compressed_matrix::handle1
handle_type & handle1()
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:478