1#ifndef STAN_MATH_OPENCL_PINNED_MATRIX_HPP
2#define STAN_MATH_OPENCL_PINNED_MATRIX_HPP
7#include <CL/opencl.hpp>
23template <
typename MatrixType>
27 using Base = Eigen::Map<MatrixType>;
38 catch (
const cl::Error&
e) {
45 catch (
const cl::Error&
e) {
51 b,
true, CL_MAP_WRITE_INVALIDATE_REGION, 0,
sizeof(
Scalar) *
size));
55 if (this->data() !=
nullptr) {
58 }
catch (
const cl::Error&
e) {
81 CL_MEM_ALLOC_HOST_PTR,
85 }
catch (
const cl::Error&
e) {
96 CL_MEM_ALLOC_HOST_PTR,
100 }
catch (
const cl::Error&
e) {
108 template <
typename T, require_eigen_t<T>* =
nullptr>
111 Base::operator=(other);
120 Base::operator=(other);
140 using Base::operator=;
148 if (this->
rows() != other.rows() || this->cols() != other.cols()) {
150 if (other.size() == 0) {
151 new (
this)
Base(
nullptr, other.rows(), other.cols());
154 sizeof(
Scalar) * other.size());
159 buffer_,
true, CL_MAP_WRITE_INVALIDATE_REGION, 0,
160 sizeof(
Scalar) * other.size())),
161 other.rows(), other.cols());
164 Base::operator=(other);
177 Base(
const_cast<Scalar*
>(other.data()), other.rows(), other.cols());
178 buffer_ = std::move(other.buffer_);
188 template <
typename T>
190 if (this->
rows() != other.rows() || this->cols() != other.cols()) {
193 sizeof(
Scalar) * other.size());
198 buffer_,
true, CL_MAP_WRITE_INVALIDATE_REGION, 0,
199 sizeof(
Scalar) * other.size())),
200 other.rows(), other.cols());
202 Base::operator=(other);
214struct traits<
stan::math::pinned_matrix<T>> {
215 using base = traits<Eigen::Map<T>>;
218 PlainObjectTypeInnerSize = base::PlainObjectTypeInnerSize,
219 InnerStrideAtCompileTime = base::InnerStrideAtCompileTime,
220 OuterStrideAtCompileTime = base::OuterStrideAtCompileTime,
221 Alignment = base::Alignment,
The API to access the methods and values in opencl_context_base.
pinned_matrix(Eigen::Index rows, Eigen::Index cols)
Constructs pinned_matrix with given number of rows and columns.
pinned_matrix(cl::Buffer &&b, Eigen::Index size)
std::decay_t< MatrixType > PlainObject
pinned_matrix(cl::Buffer &&b, Eigen::Index rows, Eigen::Index cols)
Eigen::Map< MatrixType > Base
pinned_matrix & operator=(const T &other)
Assignment operator for assigning an expression.
pinned_matrix(Eigen::Index size)
Constructs pinned_matrix with given size.
pinned_matrix & operator=(const pinned_matrix< MatrixType > &other)
Copy assignment operator.
pinned_matrix & operator=(pinned_matrix< MatrixType > &&other)
Move assignment operator.
static constexpr int ColsAtCompileTime
pinned_matrix()
Default constructor.
value_type_t< MatrixType > Scalar
pinned_matrix(const pinned_matrix< MatrixType > &other)
Copy constructor.
Scalar * map_memory(cl::Buffer &b, Eigen::Index size)
static constexpr int RowsAtCompileTime
void unmap_memory(const char *function)
pinned_matrix(pinned_matrix< MatrixType > &&other)
Move constructor.
~pinned_matrix()
Destructor unmaps the memory.
pinned_matrix(const T &other)
Constructs pinned_matrix from an expression.
Equivalent to Eigen::Matrix, except that the data is stored in (hopefully pinned) memory,...
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occurred.
cl::Context & context() noexcept
Returns the reference to the OpenCL context.
cl::CommandQueue & queue() noexcept
Returns the reference to the active OpenCL command queue for the device.
int64_t cols(const T_x &x)
Returns the number of columns in the specified kernel generator expression.
int64_t rows(const T_x &x)
Returns the number of rows in the specified kernel generator expression.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
(Expert) Numerical traits for algorithmic differentiation variables.
static constexpr double e()
Return the base of the natural logarithm.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
traits< Eigen::Map< T > > base
typename base::XprKind XprKind