40 #include <viennacl/matrix.hpp>
45 #include <type_traits>
51 CGPUMatrix<T>::CGPUMatrix()
57 CGPUMatrix<T>::CGPUMatrix(
index_t nrows,
index_t ncols) : matrix(new VCLMemoryArray())
64 viennacl::backend::memory_create(*matrix,
sizeof(T)*num_rows*num_cols,
69 CGPUMatrix<T>::CGPUMatrix(std::shared_ptr<VCLMemoryArray> mem,
index_t nrows,
index_t ncols,
81 CGPUMatrix<T>::CGPUMatrix(
const SGMatrix< T >& cpu_mat) : matrix(new VCLMemoryArray())
85 num_rows = cpu_mat.num_rows;
86 num_cols = cpu_mat.num_cols;
88 viennacl::backend::memory_create(*matrix,
sizeof(T)*num_rows*num_cols,
91 viennacl::backend::memory_write(*matrix, 0, num_rows*num_cols*
sizeof(T),
96 CGPUMatrix<T>::CGPUMatrix(
const EigenMatrixXt& cpu_mat)
97 : matrix(new VCLMemoryArray())
101 num_rows = cpu_mat.rows();
102 num_cols = cpu_mat.cols();
104 viennacl::backend::memory_create(*matrix,
sizeof(T)*num_rows*num_cols,
105 viennacl::context());
107 viennacl::backend::memory_write(*matrix, 0, num_rows*num_cols*
sizeof(T),
112 CGPUMatrix<T>::operator EigenMatrixXt()
const
114 EigenMatrixXt cpu_mat(num_rows, num_cols);
116 viennacl::backend::memory_read(*matrix, offset*
sizeof(T), num_rows*num_cols*
sizeof(T),
123 CGPUMatrix<T>::operator SGMatrix<T>()
const
125 SGMatrix<T> cpu_mat(num_rows, num_cols);
127 viennacl::backend::memory_read(*matrix, offset*
sizeof(T), num_rows*num_cols*
sizeof(T),
134 typename CGPUMatrix<T>::VCLMatrixBase CGPUMatrix<T>::vcl_matrix()
136 #if VIENNACL_VERSION >= 10600
137 return VCLMatrixBase(*matrix, num_rows, offset, 1, num_rows, num_cols, 0, 1, num_cols,
false);
139 return VCLMatrixBase(*matrix, num_rows, offset, 1, num_rows, num_cols, 0, 1, num_cols);
144 void CGPUMatrix<T>::display_matrix(
const char* name)
const
146 ((SGMatrix<T>)*
this).display_matrix(name);
150 void CGPUMatrix<T>::zero()
152 vcl_matrix().clear();
156 void CGPUMatrix<T>::set_const(T value)
158 VCLMatrixBase m = vcl_matrix();
159 viennacl::linalg::matrix_assign(m, value);
163 viennacl::const_entry_proxy<T> CGPUMatrix<T>::operator()(
index_t i,
index_t j)
const
165 return viennacl::const_entry_proxy<T>(offset+i+j*num_rows, *matrix);
169 viennacl::entry_proxy< T > CGPUMatrix<T>::operator()(
index_t i,
index_t j)
171 return viennacl::entry_proxy<T>(offset+i+j*num_rows, *matrix);
175 viennacl::const_entry_proxy< T > CGPUMatrix<T>::operator[](
index_t index)
const
177 return viennacl::const_entry_proxy<T>(offset+index, *matrix);
181 viennacl::entry_proxy< T > CGPUMatrix<T>::operator[](
index_t index)
183 return viennacl::entry_proxy<T>(offset+index, *matrix);
187 void CGPUMatrix<T>::init()
194 template<
typename T>
struct dummy {};
195 template<
typename T>
class CGPUMatrix<dummy<T> > {};
197 template class CGPUMatrix<char>;
198 template class CGPUMatrix<uint8_t>;
199 template class CGPUMatrix<int16_t>;
200 template class CGPUMatrix<uint16_t>;
201 template class CGPUMatrix<int32_t>;
202 template class CGPUMatrix<uint32_t>;
203 template class CGPUMatrix<std::conditional<viennacl::is_primitive_type<int64_t>::value, int64_t, dummy<int64_t> >::type>;
204 template class CGPUMatrix<std::conditional<viennacl::is_primitive_type<uint64_t>::value, uint64_t, dummy<uint64_t> >::type>;
205 template class CGPUMatrix<float32_t>;
206 template class CGPUMatrix<float64_t>;
210 #endif // HAVE_VIENNACL
all of classes and functions are contained in the shogun namespace