1 #ifndef VIENNACL_VECTOR_HPP_
2 #define VIENNACL_VECTOR_HPP_
48 template <
typename LHS,
typename RHS,
typename OP>
60 LHS &
lhs()
const {
return _lhs; }
63 RHS &
rhs()
const {
return _rhs; }
93 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
161 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
200 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
215 vector() : size_(0) { viennacl::linalg::kernels::vector<SCALARTYPE, ALIGNMENT>::init(); }
223 viennacl::linalg::kernels::vector<SCALARTYPE, ALIGNMENT>::init();
246 explicit vector(cl_mem existing_mem,
size_type vec_size) : size_(vec_size), elements_(existing_mem)
251 template <
typename LHS,
typename RHS,
typename OP>
265 viennacl::linalg::kernels::vector<SCALARTYPE, 1>::init();
296 template <
typename VectorType>
301 resize(proxy.lhs().size());
311 template <
typename VectorType>
316 resize(proxy.lhs().size());
325 template <
typename VectorType>
330 resize(proxy.lhs().size());
340 template <
typename VectorType>
345 resize(proxy.lhs().size());
360 resize(proxy.lhs().size());
375 resize(proxy.lhs().size());
391 template <
typename F,
unsigned int MAT_ALIGNMENT>
400 template <
typename F,
unsigned int MAT_ALIGNMENT>
409 template <
typename F,
unsigned int MAT_ALIGNMENT>
418 template <
typename F,
unsigned int MAT_ALIGNMENT>
427 template <
typename F,
unsigned int MAT_ALIGNMENT>
437 template <
typename F,
unsigned int MAT_ALIGNMENT>
448 template <
typename F,
unsigned int MAT_ALIGNMENT>
459 template <
typename F,
unsigned int MAT_ALIGNMENT>
470 template <
typename F,
unsigned int MAT_ALIGNMENT>
481 template <
typename F,
unsigned int MAT_ALIGNMENT>
496 template <
unsigned int MAT_ALIGNMENT>
505 template <
unsigned int MAT_ALIGNMENT>
514 template <
unsigned int MAT_ALIGNMENT>
523 template <
unsigned int MAT_ALIGNMENT>
532 template <
unsigned int MAT_ALIGNMENT>
544 template <
unsigned int MAT_ALIGNMENT>
553 template <
unsigned int MAT_ALIGNMENT>
562 template <
unsigned int MAT_ALIGNMENT>
571 template <
unsigned int MAT_ALIGNMENT>
580 template <
unsigned int MAT_ALIGNMENT>
592 template <
unsigned int MAT_ALIGNMENT>
601 template <
unsigned int MAT_ALIGNMENT>
610 template <
unsigned int MAT_ALIGNMENT>
619 template <
unsigned int MAT_ALIGNMENT>
628 template <
unsigned int MAT_ALIGNMENT>
641 template <
unsigned int MAT_ALIGNMENT>
650 template <
unsigned int MAT_ALIGNMENT>
659 template <
unsigned int MAT_ALIGNMENT>
668 template <
unsigned int MAT_ALIGNMENT>
677 template <
unsigned int MAT_ALIGNMENT>
689 template <
unsigned int MAT_ALIGNMENT>
698 template <
unsigned int MAT_ALIGNMENT>
707 template <
unsigned int MAT_ALIGNMENT>
716 template <
unsigned int MAT_ALIGNMENT>
725 template <
unsigned int MAT_ALIGNMENT>
738 template <
unsigned int MAT_ALIGNMENT>
747 template <
unsigned int MAT_ALIGNMENT>
756 template <
unsigned int MAT_ALIGNMENT>
765 template <
unsigned int MAT_ALIGNMENT>
774 template <
unsigned int MAT_ALIGNMENT>
791 assert(new_size > 0);
793 if (new_size != size_)
795 std::size_t new_internal_size = viennacl::tools::roundUpToNextMultiple<std::size_t>(new_size, ALIGNMENT);
797 std::vector<SCALARTYPE> temp(size_);
798 if (preserve && size_ > 0)
800 temp.resize(new_size);
801 temp.resize(new_internal_size);
1020 op_prod> & proxy)
const
1031 op_prod> & proxy)
const
1042 op_prod> & proxy)
const
1053 op_prod> & proxy)
const
1075 op_prod> & proxy)
const
1087 op_prod> & proxy)
const
1099 op_prod> & proxy)
const
1111 op_prod> & proxy)
const
1192 assert(this->size_ == other.size_);
1193 this->elements_.
swap(other.elements_);
1205 return (128*1024*1024) /
sizeof(SCALARTYPE);
1251 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1254 CPU_ITERATOR cpu_begin )
1256 assert(gpu_end - gpu_begin >= 0);
1257 if (gpu_end - gpu_begin != 0)
1259 std::vector<SCALARTYPE> temp_buffer(gpu_end - gpu_begin);
1261 gpu_begin.
handle(), CL_TRUE, 0,
1262 sizeof(SCALARTYPE)*(gpu_end - gpu_begin),
1263 &(temp_buffer[0]), 0, NULL, NULL);
1268 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_begin);
1278 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1281 CPU_ITERATOR cpu_begin )
1294 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPUVECTOR>
1296 CPUVECTOR & cpu_vec )
1313 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1316 CPU_ITERATOR cpu_begin )
1318 if (gpu_begin != gpu_end)
1321 gpu_begin.
handle(), CL_TRUE, 0,
1322 sizeof(SCALARTYPE)*(gpu_end - gpu_begin),
1323 &(*cpu_begin), 0, NULL, NULL);
1334 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPUVECTOR>
1336 CPUVECTOR & cpu_vec )
1343 #ifdef VIENNACL_HAVE_EIGEN
1344 template <
unsigned int ALIGNMENT>
1345 void copy(vector<float, ALIGNMENT>
const & gpu_vec,
1346 Eigen::VectorXf & eigen_vec)
1351 template <
unsigned int ALIGNMENT>
1352 void copy(vector<double, ALIGNMENT> & gpu_vec,
1353 Eigen::VectorXd & eigen_vec)
1371 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1372 void copy(CPU_ITERATOR
const & cpu_begin,
1373 CPU_ITERATOR
const & cpu_end,
1376 assert(cpu_end - cpu_begin > 0);
1377 if (cpu_begin != cpu_end)
1380 std::vector<SCALARTYPE> temp_buffer(cpu_end - cpu_begin);
1381 std::copy(cpu_begin, cpu_end, temp_buffer.begin());
1383 gpu_begin.
handle(), CL_TRUE,
sizeof(SCALARTYPE)*gpu_begin.
index(),
1384 sizeof(SCALARTYPE)*(cpu_end - cpu_begin),
1385 &(temp_buffer[0]), 0, NULL, NULL);
1391 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1392 void copy(CPU_ITERATOR
const & cpu_begin,
1393 CPU_ITERATOR
const & cpu_end,
1404 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPUVECTOR>
1421 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1423 CPU_ITERATOR
const & cpu_end,
1426 if (cpu_begin != cpu_end)
1430 gpu_begin.
handle(), CL_TRUE, 0,
1431 sizeof(SCALARTYPE)*(cpu_end - cpu_begin), &(*cpu_begin), 0, NULL, NULL);
1442 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPUVECTOR>
1448 #ifdef VIENNACL_HAVE_EIGEN
1449 template <
unsigned int ALIGNMENT>
1450 void copy(Eigen::VectorXf
const & eigen_vec,
1451 vector<float, ALIGNMENT> & gpu_vec)
1453 std::vector<float> entries(eigen_vec.size());
1454 for (
size_t i = 0; i<entries.size(); ++i)
1455 entries[i] = eigen_vec(i);
1459 template <
unsigned int ALIGNMENT>
1460 void copy(Eigen::VectorXd
const & eigen_vec,
1461 vector<double, ALIGNMENT> & gpu_vec)
1463 std::vector<double> entries(eigen_vec.size());
1464 for (
size_t i = 0; i<entries.size(); ++i)
1465 entries[i] = eigen_vec(i);
1481 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1486 assert(gpu_src_end - gpu_src_begin >= 0);
1487 if (gpu_src_begin != gpu_src_end)
1492 sizeof(SCALARTYPE) * gpu_src_begin.
index(),
1493 sizeof(SCALARTYPE) * gpu_dest_begin.
index(),
1494 sizeof(SCALARTYPE) * (gpu_src_end.
index() - gpu_src_begin.
index()),
1507 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1520 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1537 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
1538 std::ostream & operator<<(std::ostream & s, vector<SCALARTYPE,ALIGNMENT>
const & val)
1541 std::vector<SCALARTYPE> tmp(val.size());
1542 copy(val.begin(), val.end(), tmp.begin());
1543 std::cout <<
"[" << val.size() <<
"](";
1544 for (
typename std::vector<SCALARTYPE>::size_type i=0; i<val.size(); ++i)
1559 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
1564 &&
"Incompatible vector sizes in swap()");
1578 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1593 template <
typename SCALARTYPE,
unsigned int A>
1604 template <
typename SCALARTYPE,
unsigned int A>
1617 template <
typename LHS1,
typename RHS1,
typename OP1,
1618 typename LHS2,
typename RHS2,
typename OP2>
1619 typename vector_expression< LHS1, RHS1, OP1>::VectorType
1623 assert(proxy1.
size() == proxy2.
size());
1635 template <
typename LHS1,
typename RHS1,
typename OP1,
1636 typename LHS2,
typename RHS2,
typename OP2>
1637 typename vector_expression< LHS1, RHS1, OP1>::VectorType
1641 assert(proxy1.
size() == proxy2.
size());
1655 template <
typename SCALARTYPE,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
1659 assert(proxy.
size() == vec.
size());
1671 template <
typename SCALARTYPE,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
1675 assert(proxy.
size() == vec.
size());
1688 template <
typename SCALARTYPE,
typename LHS,
typename RHS,
typename OP>
1703 template <
typename SCALARTYPE,
typename LHS,
typename RHS,
typename OP>
1721 template <
typename SCALARTYPE,
typename LHS,
typename RHS,
typename OP>
1736 template <
typename SCALARTYPE,
typename LHS,
typename RHS,
typename OP>