From a91417a7a5a210f424b8cfec4b2bc1e00aa340be Mon Sep 17 00:00:00 2001 From: Luke Iwanski Date: Mon, 20 Mar 2017 14:48:54 +0000 Subject: Introduces align allocator for SYCL buffer --- .../Eigen/CXX11/src/Tensor/TensorDeviceSycl.h | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h index e9c3dc0a0..c5142b7c9 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h @@ -15,6 +15,17 @@ #if defined(EIGEN_USE_SYCL) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H) #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H +template > +struct SyclAllocator { + typedef Scalar value_type; + typedef typename std::allocator_traits::pointer pointer; + typedef typename std::allocator_traits::size_type size_type; + + SyclAllocator( ){}; + Scalar* allocate(std::size_t elements) { return static_cast(aligned_alloc(Align, elements)); } + void deallocate(Scalar * p, std::size_t size) { EIGEN_UNUSED_VARIABLE(size); free(p); } +}; + namespace Eigen { #define ConvertToActualTypeSycl(Scalar, buf_acc) reinterpret_cast::pointer_t>((&(*buf_acc.get_pointer()))) @@ -56,11 +67,11 @@ template }; struct memsetCghFunctor{ - cl::sycl::buffer& m_buf; + cl::sycl::buffer >& m_buf; const ptrdiff_t& buff_offset; const size_t& rng , GRange, tileSize; const int &c; - memsetCghFunctor(cl::sycl::buffer& buff, const ptrdiff_t& buff_offset_, const size_t& rng_, const size_t& GRange_, const size_t& tileSize_, const int& c_) + memsetCghFunctor(cl::sycl::buffer >& buff, const ptrdiff_t& buff_offset_, const size_t& rng_, const size_t& GRange_, const size_t& tileSize_, const int& c_) :m_buf(buff), buff_offset(buff_offset_), rng(rng_), GRange(GRange_), tileSize(tileSize_), c(c_){} void operator()(cl::sycl::handler &cgh) const { @@ -124,6 +135,7 @@ m_queue(cl::sycl::queue(s, [&](cl::sycl::exception_list l) { })) #endif {} + /// Allocating device pointer. This pointer is actually an 8 bytes host pointer used as key to access the sycl device buffer. /// The reason is that we cannot use device buffer as a pointer as a m_data in Eigen leafNode expressions. So we create a key /// pointer to be used in Eigen expression construction. When we convert the Eigen construction into the sycl construction we @@ -131,10 +143,10 @@ m_queue(cl::sycl::queue(s, [&](cl::sycl::exception_list l) { /// The device pointer would be deleted by calling deallocate function. EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const { std::lock_guard lock(mutex_); - auto buf = cl::sycl::buffer(cl::sycl::range<1>(num_bytes)); + auto buf = cl::sycl::buffer >(cl::sycl::range<1>(num_bytes)); auto ptr =buf.get_access().get_pointer(); buf.set_final_data(nullptr); - buffer_map.insert(std::pair>(static_cast(ptr),buf)); + buffer_map.insert(std::pair > >(static_cast(ptr),buf)); return static_cast(ptr); } @@ -235,7 +247,7 @@ m_queue(cl::sycl::queue(s, [&](cl::sycl::exception_list l) { } /// Accessing the created sycl device buffer for the device pointer - EIGEN_STRONG_INLINE cl::sycl::buffer& get_sycl_buffer(const void * ptr) const { + EIGEN_STRONG_INLINE cl::sycl::buffer >& get_sycl_buffer(const void * ptr) const { return find_buffer(ptr)->second; } @@ -380,18 +392,18 @@ private: /// std::map is the container used to make sure that we create only one buffer /// per pointer. The lifespan of the buffer now depends on the lifespan of SyclDevice. /// If a non-read-only pointer is needed to be accessed on the host we should manually deallocate it. - mutable std::map> buffer_map; + mutable std::map > > buffer_map; /// sycl queue mutable cl::sycl::queue m_queue; - EIGEN_STRONG_INLINE std::map>::iterator find_buffer(const void* ptr) const { + EIGEN_STRONG_INLINE std::map > >::iterator find_buffer(const void* ptr) const { std::lock_guard lock(mutex_); auto it1 = buffer_map.find(static_cast(ptr)); if (it1 != buffer_map.end()){ return it1; } else{ - for(std::map>::iterator it=buffer_map.begin(); it!=buffer_map.end(); ++it){ + for(std::map > >::iterator it=buffer_map.begin(); it!=buffer_map.end(); ++it){ auto size = it->second.get_size(); if((it->first < (static_cast(ptr))) && ((static_cast(ptr)) < (it->first + size)) ) return it; } @@ -416,7 +428,7 @@ struct SyclDevice { } /// Accessing the created sycl device buffer for the device pointer - EIGEN_STRONG_INLINE cl::sycl::buffer& get_sycl_buffer(const void * ptr) const { + EIGEN_STRONG_INLINE cl::sycl::buffer >& get_sycl_buffer(const void * ptr) const { return m_queue_stream->get_sycl_buffer(ptr); } -- cgit v1.2.3