30 #include <thrust/host_vector.h>
31 #include <thrust/device_vector.h>
34 #include <cuda_runtime.h>
45 virtual void fill(
const T val) {}
47 virtual const T*
host_ptr()
const {
return NULL; }
69 m_hvec.resize( size );
72 cudaError_t error = cudaHostRegister( &m_hvec[0],
sizeof(T) * size, cudaHostRegisterMapped );
75 log_error(stderr,
"host_device_buffer_zero_copy::resize(): failed locking %llu bytes\n %s\n",
sizeof(T)*size, cudaGetErrorString(error));
82 thrust::fill( m_hvec.begin(), m_hvec.end(), val );
87 virtual const T*
host_ptr()
const {
return thrust::raw_pointer_cast( &m_hvec.front() ); }
92 cudaError_t error = cudaHostGetDevicePointer( &ptr_d, const_cast<T*>(
host_ptr()), 0u );
95 log_error(stderr,
"host_device_buffer_zero_copy::device_ptr(): failed mapping %llu bytes\n %s\n",
sizeof(T)*m_hvec.size(), cudaGetErrorString(error));
100 virtual T*
host_ptr() {
return thrust::raw_pointer_cast( &m_hvec.front() ); }
105 cudaError_t error = cudaHostGetDevicePointer( &ptr_d,
host_ptr(), 0u );
108 log_error(stderr,
"host_device_buffer_zero_copy::device_ptr(): failed mapping %llu bytes\n %s\n",
sizeof(T)*m_hvec.size(), cudaGetErrorString(error));
115 thrust::host_vector<T> m_hvec;
118 template <
typename T>
129 m_hvec.resize( size );
130 m_dvec.resize( size );
135 thrust::fill( m_dvec.begin(), m_dvec.end(), val );
140 thrust_copy_vector(m_hvec, m_dvec);
143 virtual const T*
host_ptr()
const {
return thrust::raw_pointer_cast( &m_hvec.front() ); }
144 virtual const T*
device_ptr()
const {
return thrust::raw_pointer_cast( &m_dvec.front() ); }
146 virtual T*
host_ptr() {
return thrust::raw_pointer_cast( &m_hvec.front() ); }
147 virtual T*
device_ptr() {
return thrust::raw_pointer_cast( &m_dvec.front() ); }
150 thrust::host_vector<T> m_hvec;
151 thrust::device_vector<T> m_dvec;
154 template <
typename T>
156 const thrust::device_vector<T>& dvec,
157 thrust::host_vector<T>& hvec)
162 template <
typename T>
165 thrust::host_vector<T>& hvec)
168 hvec.resize( dvec.
size() );
175 template <
typename T>
178 return thrust::raw_pointer_cast( &dvec.front() );
181 template <
typename T>
184 return thrust::raw_pointer_cast( &dvec.front() );
187 template <
typename T>
193 template <
typename T>