Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:01

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
0012 #define BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
0013 
0014 #include <Eigen/Core>
0015 
0016 #include <boost/compute/command_queue.hpp>
0017 #include <boost/compute/algorithm/copy_n.hpp>
0018 #include <boost/compute/iterator/buffer_iterator.hpp>
0019 #include <boost/compute/type_traits/type_name.hpp>
0020 
0021 namespace boost {
0022 namespace compute {
0023 
0024 /// Copies \p matrix to \p buffer.
0025 template<class Derived>
0026 inline void eigen_copy_matrix_to_buffer(const Eigen::PlainObjectBase<Derived> &matrix,
0027                                         buffer_iterator<typename Derived::Scalar> buffer,
0028                                         command_queue &queue = system::default_queue())
0029 {
0030     ::boost::compute::copy_n(matrix.data(), matrix.size(), buffer, queue);
0031 }
0032 
0033 /// Copies \p buffer to \p matrix.
0034 template<class Derived>
0035 inline void eigen_copy_buffer_to_matrix(const buffer_iterator<typename Derived::Scalar> buffer,
0036                                         Eigen::PlainObjectBase<Derived> &matrix,
0037                                         command_queue &queue = system::default_queue())
0038 {
0039     ::boost::compute::copy_n(buffer, matrix.size(), matrix.data(), queue);
0040 }
0041 
0042 /// Converts an \c Eigen::Matrix4f to a \c float16_.
0043 inline float16_ eigen_matrix4f_to_float16(const Eigen::Matrix4f &matrix)
0044 {
0045     float16_ result;
0046     std::memcpy(&result, matrix.data(), 16 * sizeof(float));
0047     return result;
0048 }
0049 
0050 /// Converts an \c Eigen::Matrix4d to a \c double16_.
0051 inline double16_ eigen_matrix4d_to_double16(const Eigen::Matrix4d &matrix)
0052 {
0053     double16_ result;
0054     std::memcpy(&result, matrix.data(), 16 * sizeof(double));
0055     return result;
0056 }
0057 
0058 } // end compute namespace
0059 } // end boost namespace
0060 
0061 BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2i, int2)
0062 BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4i, int4)
0063 BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2f, float2)
0064 BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4f, float4)
0065 BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2f, float8)
0066 BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4f, float16)
0067 BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2d, double2)
0068 BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4d, double4)
0069 BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2d, double8)
0070 BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4d, double16)
0071 
0072 #endif // BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP