1 #ifndef STAN_MATH_OPENCL_COPY_HPP 2 #define STAN_MATH_OPENCL_COPY_HPP 21 #include <type_traits> 36 template <
int R,
int C>
39 if (src.size() == 0) {
52 queue.enqueueWriteBuffer(dst.buffer(), CL_FALSE, 0,
53 sizeof(double) * dst.size(), src.data(),
54 &dst.write_events(), ©_event);
55 dst.add_write_event(copy_event);
56 }
catch (
const cl::Error&
e) {
72 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> dst(src.
rows(),
74 if (src.
size() == 0) {
88 queue.enqueueReadBuffer(src.
buffer(), CL_FALSE, 0,
89 sizeof(double) * dst.size(), dst.data(),
93 }
catch (
const cl::Error&
e) {
107 template <TriangularViewCL triangular_view>
109 const int packed_size = src.
rows() * (src.
rows() + 1) / 2;
110 std::vector<double> dst(packed_size);
111 if (dst.size() == 0) {
118 packed, src, src.
rows(), src.
rows(),
120 const std::vector<cl::Event> mat_events
122 cl::Event copy_event;
123 queue.enqueueReadBuffer(packed.
buffer(), CL_FALSE, 0,
124 sizeof(double) * packed_size, dst.data(),
125 &mat_events, ©_event);
128 }
catch (
const cl::Error&
e) {
147 template <TriangularViewCL triangular_view>
149 const int packed_size = rows * (rows + 1) / 2;
151 src.size(),
"rows * (rows + 1) / 2", packed_size);
153 if (dst.size() == 0) {
158 cl::Event packed_event;
160 queue.enqueueWriteBuffer(packed.
buffer(), CL_FALSE, 0,
161 sizeof(double) * packed_size, src.data(), NULL,
165 packed, dst.
rows(), dst.rows(),
167 }
catch (
const cl::Error&
e) {
185 if (src.
size() == 0) {
195 const std::vector<cl::Event> mat_events
197 cl::Event copy_event;
198 queue.enqueueCopyBuffer(src.
buffer(), dst.buffer(), 0, 0,
199 sizeof(double) * src.
size(), &mat_events,
201 dst.add_write_event(copy_event);
203 }
catch (
const cl::Error&
e) {
215 template <typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
223 cl::Event copy_event;
225 queue.enqueueReadBuffer(src.
buffer(), CL_FALSE, 0,
sizeof(T), &dst,
229 }
catch (
const cl::Error&
e) {
241 template <typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
249 cl::Event copy_event;
251 queue.enqueueWriteBuffer(dst.
buffer(), CL_FALSE, 0,
sizeof(T), &src,
254 }
catch (
const cl::Error&
e) {
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > from_matrix_cl(const matrix_cl &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix...
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
const std::vector< T > & vec_concat(const std::vector< T > &v1)
Ends the recursion to extract the event stack.
const kernel_cl< out_buffer, in_buffer, int, int, TriangularViewCL > unpack("unpack", {indexing_helpers, unpack_kernel_code})
See the docs for unpack() .
const kernel_cl< out_buffer, in_buffer, int, int, TriangularViewCL > pack("pack", {indexing_helpers, pack_kernel_code})
See the docs for pack() .
const cl::Buffer & buffer() const
void clear_write_events() const
Clear the write events from the event stacks.
matrix_cl copy_cl(const matrix_cl &src)
Copies the source matrix to the destination matrix.
The API to access the methods and values in opencl_context_base.
The matrix_cl class - allocates memory space on the OpenCL device, functions for transfering matrices...
void add_write_event(cl::Event new_event) const
Add an event to the write event stack.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
void add_read_event(cl::Event new_event) const
Add an event to the read event stack.
Represents a matrix on the OpenCL device.
checking OpenCL error numbers
Initialization for OpenCL:
const std::vector< cl::Event > read_write_events() const
Get the events from the event stacks.
double e()
Return the base of the natural logarithm.
matrix_cl to_matrix_cl(const Eigen::Matrix< double, R, C > &src)
Copies the source Eigen matrix to the destination matrix that is stored on the OpenCL device...
std::vector< double > packed_copy(const matrix_cl &src)
Packs the flat triagnular matrix on the OpenCL device and copies it to the std::vector.
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occured.
const std::vector< cl::Event > & write_events() const
Get the events from the event stacks.
cl::CommandQueue & queue()
Returns the reference to the active OpenCL command queue for the device.