40 #include <viennacl/matrix.hpp>
52 CGPUMatrix<T>::CGPUMatrix()
58 CGPUMatrix<T>::CGPUMatrix(
index_t nrows,
index_t ncols) : matrix(new VCLMemoryArray())
65 viennacl::backend::memory_create(*matrix,
sizeof(T)*num_rows*num_cols,
70 CGPUMatrix<T>::CGPUMatrix(std::shared_ptr<VCLMemoryArray> mem,
index_t nrows,
index_t ncols,
82 CGPUMatrix<T>::CGPUMatrix(
const SGMatrix< T >& cpu_mat) : matrix(new VCLMemoryArray())
86 num_rows = cpu_mat.num_rows;
87 num_cols = cpu_mat.num_cols;
89 viennacl::backend::memory_create(*matrix,
sizeof(T)*num_rows*num_cols,
92 viennacl::backend::memory_write(*matrix, 0, num_rows*num_cols*
sizeof(T),
98 CGPUMatrix<T>::CGPUMatrix(
const EigenMatrixXt& cpu_mat)
99 : matrix(new VCLMemoryArray())
103 num_rows = cpu_mat.rows();
104 num_cols = cpu_mat.cols();
106 viennacl::backend::memory_create(*matrix,
sizeof(T)*num_rows*num_cols,
107 viennacl::context());
109 viennacl::backend::memory_write(*matrix, 0, num_rows*num_cols*
sizeof(T),
114 CGPUMatrix<T>::operator EigenMatrixXt()
const
116 EigenMatrixXt cpu_mat(num_rows, num_cols);
118 viennacl::backend::memory_read(*matrix, offset*
sizeof(T), num_rows*num_cols*
sizeof(T),
126 CGPUMatrix<T>::operator SGMatrix<T>()
const
128 SGMatrix<T> cpu_mat(num_rows, num_cols);
130 viennacl::backend::memory_read(*matrix, offset*
sizeof(T), num_rows*num_cols*
sizeof(T),
137 typename CGPUMatrix<T>::VCLMatrixBase CGPUMatrix<T>::vcl_matrix()
139 return VCLMatrixBase(*matrix,num_rows, offset, 1, num_rows, num_cols, 0, 1, num_cols);
143 void CGPUMatrix<T>::display_matrix(
const char* name)
const
145 ((SGMatrix<T>)*
this).display_matrix(name);
149 void CGPUMatrix<T>::zero()
151 vcl_matrix().clear();
155 void CGPUMatrix<T>::set_const(T value)
157 VCLMatrixBase m = vcl_matrix();
158 viennacl::linalg::matrix_assign(m, value);
162 viennacl::const_entry_proxy<T> CGPUMatrix<T>::operator()(
index_t i,
index_t j)
const
164 return viennacl::const_entry_proxy<T>(offset+i+j*num_rows, *matrix);
168 viennacl::entry_proxy< T > CGPUMatrix<T>::operator()(
index_t i,
index_t j)
170 return viennacl::entry_proxy<T>(offset+i+j*num_rows, *matrix);
174 viennacl::const_entry_proxy< T > CGPUMatrix<T>::operator[](
index_t index)
const
176 return viennacl::const_entry_proxy<T>(offset+index, *matrix);
180 viennacl::entry_proxy< T > CGPUMatrix<T>::operator[](
index_t index)
182 return viennacl::entry_proxy<T>(offset+index, *matrix);
186 void CGPUMatrix<T>::init()
193 template class CGPUMatrix<char>;
194 template class CGPUMatrix<uint8_t>;
195 template class CGPUMatrix<int16_t>;
196 template class CGPUMatrix<uint16_t>;
197 template class CGPUMatrix<int32_t>;
198 template class CGPUMatrix<uint32_t>;
199 template class CGPUMatrix<int64_t>;
200 template class CGPUMatrix<uint64_t>;
201 template class CGPUMatrix<float32_t>;
202 template class CGPUMatrix<float64_t>;
206 #endif // HAVE_VIENNACL
all of classes and functions are contained in the shogun namespace