Skip to content

Commit bc00b12

Browse files
author
Scott Zuyderduyn
committed
last minute fix to get naked pointer iterators to work, and remove dep to estd:: library for test/ progs
1 parent df353b4 commit bc00b12

7 files changed

Lines changed: 110 additions & 107 deletions

File tree

include/ecuda/algo/copy.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ __HOST__ __DEVICE__ inline OutputIterator copy(
667667
{
668668
// memory is now guaranteed to be regularly aligned so we can use cudaMemcpy2D
669669
typedef typename ecuda::add_pointer<value_type>::type pointer;
670-
pointer dest = naked_cast<pointer>( result.operator->() );
670+
pointer dest = get_iterator_pointer( result );
671671
typedef typename ecuda::add_pointer<const value_type>::type const_pointer;
672672
const_pointer src = naked_cast<const_pointer>( first.operator->() );
673673

@@ -805,6 +805,7 @@ __HOST__ __DEVICE__ inline OutputIterator copy( InputIterator first, InputIterat
805805
return impl::copy( first, last, result, ecuda::pair<input_memory_type,output_memory_type>() );
806806
}
807807

808+
808809
} // namespace ecuda
809810

810811
#endif

include/ecuda/algo/find_if.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace ecuda {
5252
/// \cond DEVELOPER_DOCUMENTATION
5353
namespace impl {
5454

55+
ECUDA_SUPPRESS_HD_WARNINGS
5556
template<class InputIterator,class UnaryPredicate>
5657
__HOST__ __DEVICE__ InputIterator
5758
find_if( InputIterator first, InputIterator last, UnaryPredicate p, ecuda::true_type ) // device memory

include/ecuda/global.hpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,17 @@ either expressed or implied, of the FreeBSD Project.
7070
#define ECUDA_CPP11_AVAILABLE
7171
#endif
7272

73+
#ifdef __CUDACC__
74+
// Macro function currently throws an ecuda::cuda_error exception containing a
75+
// description of the problem error code.
76+
#define CUDA_CALL(x) do { if((x)!=cudaSuccess) { std::ostringstream oss; oss << __FILE__; oss << ":"; oss << __LINE__; oss << " "; oss << cudaGetErrorString(cudaGetLastError()); throw ::ecuda::cuda_error(x,oss.str()); /*std::runtime_error(oss.str());*/ }} while(0);
77+
#else
7378
///
7479
/// Macro function that captures a CUDA error code and then does something
7580
/// with it. All calls to functions in the CUDA API that return an error code
7681
/// should use this.
7782
///
7883
#define CUDA_CALL(x) x // cannot do CUDA calls when emulating with host only
79-
#ifdef __CUDACC__
80-
// Macro function currently throws an ecuda::cuda_error exception containing a
81-
// description of the problem error code.
82-
#define CUDA_CALL(x) do { if((x)!=cudaSuccess) { std::ostringstream oss; oss << __FILE__; oss << ":"; oss << __LINE__; oss << " "; oss << cudaGetErrorString(cudaGetLastError()); throw ::ecuda::cuda_error(x,oss.str()); /*std::runtime_error(oss.str());*/ }} while(0);
8384
#endif
8485

8586
#define S(x) #x
@@ -90,31 +91,33 @@ either expressed or implied, of the FreeBSD Project.
9091
///
9192
#define EXCEPTION_MSG(x) "" __FILE__ ":" S__LINE__ " " x
9293

94+
#ifdef __CUDACC__
95+
#define CUDA_CHECK_ERRORS() do { cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); } while(0);
96+
#else
9397
///
9498
/// Macro that performs a check for any outstanding CUDA errors. This macro
9599
/// should be declared after any CUDA API calls that do not return an error code
96100
/// (e.g. after calling kernel functions). Calling this when a CUDA API call
97101
/// has not been made is safe.
98102
///
99103
#define CUDA_CHECK_ERRORS() do {} while(0); // cannot check CUDA errors when emulating with host only
100-
#ifdef __CUDACC__
101-
#define CUDA_CHECK_ERRORS() do { cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); } while(0);
102104
#endif
103105

104-
///
105-
/// Macro that calls a CUDA kernel function, waits for completion, and throws
106-
/// an ecuda::cuda_error exception if any errors are reported by cudaGetLastError().
107-
///
108-
#define CUDA_CALL_KERNEL_AND_WAIT(...) do {\
109-
__VA_ARGS__;\
110-
} while( 0 ); // cannot do CUDA calls when emulating with host only
111106
#ifdef __CUDACC__
112107
#define CUDA_CALL_KERNEL_AND_WAIT(...) do {\
113108
__VA_ARGS__;\
114109
{ cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); }\
115110
cudaDeviceSynchronize();\
116111
{ cudaError_t error = cudaGetLastError(); if( error != cudaSuccess ) throw ::ecuda::cuda_error(error,std::string(cudaGetErrorString(error))); }\
117112
} while(0);
113+
#else
114+
///
115+
/// Macro that calls a CUDA kernel function, waits for completion, and throws
116+
/// an ecuda::cuda_error exception if any errors are reported by cudaGetLastError().
117+
///
118+
#define CUDA_CALL_KERNEL_AND_WAIT(...) do {\
119+
__VA_ARGS__;\
120+
} while( 0 ); // cannot do CUDA calls when emulating with host only
118121
#endif
119122

120123
/** Replace nullptr with NULL if nvcc still doesn't support C++11. */

include/ecuda/iterator.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ class device_contiguous_iterator : public device_iterator<T,typename ecuda::add_
174174
}
175175
#endif
176176

177-
__HOST__ __DEVICE__ inline device_contiguous_iterator operator+( int x ) const { return device_contiguous_iterator( base_type::ptr + x ); }
178-
__HOST__ __DEVICE__ inline device_contiguous_iterator operator-( int x ) const { return device_contiguous_iterator( base_type::ptr - x ); }
177+
__HOST__ __DEVICE__ inline device_contiguous_iterator operator+( difference_type x ) const { return device_contiguous_iterator( base_type::ptr + x ); }
178+
__HOST__ __DEVICE__ inline device_contiguous_iterator operator-( difference_type x ) const { return device_contiguous_iterator( base_type::ptr - x ); }
179179

180-
__HOST__ __DEVICE__ inline device_contiguous_iterator& operator+=( int x ) { base_type::ptr += x; return *this; }
181-
__HOST__ __DEVICE__ inline device_contiguous_iterator& operator-=( int x ) { base_type::ptr -= x; return *this; }
180+
__HOST__ __DEVICE__ inline device_contiguous_iterator& operator+=( difference_type x ) { base_type::ptr += x; return *this; }
181+
__HOST__ __DEVICE__ inline device_contiguous_iterator& operator-=( difference_type x ) { base_type::ptr -= x; return *this; }
182182

183-
__DEVICE__ inline reference operator[]( int x ) const { return *(base_type::ptr+x); }
183+
__DEVICE__ inline reference operator[]( difference_type x ) const { return *(base_type::ptr+x); }
184184

185185
__HOST__ __DEVICE__ inline difference_type operator-( const device_contiguous_iterator& other ) { return base_type::ptr - other.ptr; }
186186

@@ -278,16 +278,16 @@ class device_contiguous_block_iterator : public device_iterator<T,padded_ptr<T,P
278278
return tmp;
279279
}
280280

281-
__HOST__ __DEVICE__ device_contiguous_block_iterator operator+( int x ) const
281+
__HOST__ __DEVICE__ device_contiguous_block_iterator operator+( difference_type x ) const
282282
{
283283
device_contiguous_block_iterator tmp( *this );
284284
tmp += x;
285285
return tmp;
286286
}
287287

288-
__HOST__ __DEVICE__ inline device_contiguous_block_iterator operator-( int x ) const { return operator+(-x); }
288+
__HOST__ __DEVICE__ inline device_contiguous_block_iterator operator-( difference_type x ) const { return operator+(-x); }
289289

290-
__HOST__ __DEVICE__ device_contiguous_block_iterator& operator+=( int x )
290+
__HOST__ __DEVICE__ device_contiguous_block_iterator& operator+=( difference_type x )
291291
{
292292
const int rows = x / width;
293293
base_type::ptr.skip_bytes( rows * base_type::ptr.get_pitch() );
@@ -298,9 +298,9 @@ class device_contiguous_block_iterator : public device_iterator<T,padded_ptr<T,P
298298
if( offset < 0 ) { base_type::ptr.skip_bytes( width*sizeof(value_type) - base_type::ptr.get_pitch() ); offset += width; }
299299
return *this;
300300
}
301-
__HOST__ __DEVICE__ inline device_contiguous_block_iterator& operator-=( int x ) { operator+=(-x); return *this; }
301+
__HOST__ __DEVICE__ inline device_contiguous_block_iterator& operator-=( difference_type x ) { operator+=(-x); return *this; }
302302

303-
__DEVICE__ inline reference operator[]( int x ) const { return *operator+(x); }
303+
__DEVICE__ inline reference operator[]( difference_type x ) const { return *operator+(x); }
304304

305305
__HOST__ __DEVICE__ inline difference_type operator-( const device_contiguous_block_iterator& other ) const
306306
{
@@ -399,18 +399,18 @@ class reverse_device_iterator //: public std::iterator<device_iterator_tag,typen
399399

400400
__HOST__ __DEVICE__ inline difference_type operator-( const reverse_device_iterator& other ) { return parentIterator - other.parentIterator; }
401401

402-
__HOST__ __DEVICE__ inline reverse_device_iterator operator+( int x ) const { return reverse_device_iterator( parentIterator-x ); }
403-
__HOST__ __DEVICE__ inline reverse_device_iterator operator-( int x ) const { return reverse_device_iterator( parentIterator+x ); }
402+
__HOST__ __DEVICE__ inline reverse_device_iterator operator+( difference_type x ) const { return reverse_device_iterator( parentIterator-x ); }
403+
__HOST__ __DEVICE__ inline reverse_device_iterator operator-( difference_type x ) const { return reverse_device_iterator( parentIterator+x ); }
404404

405405
__HOST__ __DEVICE__ inline bool operator<( const reverse_device_iterator& other ) const { return parentIterator < other.parentIterator; }
406406
__HOST__ __DEVICE__ inline bool operator>( const reverse_device_iterator& other ) const { return parentIterator > other.parentIterator; }
407407
__HOST__ __DEVICE__ inline bool operator<=( const reverse_device_iterator& other ) const { return operator<(other) || operator==(other); }
408408
__HOST__ __DEVICE__ inline bool operator>=( const reverse_device_iterator& other ) const { return operator>(other) || operator==(other); }
409409

410-
__HOST__ __DEVICE__ inline reverse_device_iterator& operator+=( int x ) { parentIterator -= x; return *this; }
411-
__HOST__ __DEVICE__ inline reverse_device_iterator& operator-=( int x ) { parentIterator += x; return *this; }
410+
__HOST__ __DEVICE__ inline reverse_device_iterator& operator+=( difference_type x ) { parentIterator -= x; return *this; }
411+
__HOST__ __DEVICE__ inline reverse_device_iterator& operator-=( difference_type x ) { parentIterator += x; return *this; }
412412

413-
__DEVICE__ reference operator[]( int x ) const { return parentIterator.operator[]( -x-1 ); }
413+
__DEVICE__ reference operator[]( difference_type x ) const { return parentIterator.operator[]( -x-1 ); }
414414

415415
__HOST__ __DEVICE__ reverse_device_iterator& operator=( const reverse_device_iterator& other )
416416
{

include/ecuda/type_traits.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ template<typename T,typename P> class striding_padded_ptr; // forward declaratio
199199
/// so that a cast to a naked pointer T* is achieved by reinterpret_cast<T*>(ptr.get().get()).
200200
///
201201
template<typename T,typename U> __HOST__ __DEVICE__ T naked_cast( U* ptr ) { return reinterpret_cast<T>(ptr); }
202+
template<typename T> __HOST__ __DEVICE__ T naked_cast( T* ptr ) { return ptr; }
202203
//template<typename T,typename U> __HOST__ __DEVICE__ T naked_cast( const naked_ptr<U>& ptr ) { return naked_cast<T>(ptr.get()); }
203204
template<typename T,typename U,typename V> __HOST__ __DEVICE__ T naked_cast( const unique_ptr<U,V>& ptr ) { return naked_cast<T>(ptr.get()); }
204205
template<typename T,typename U> __HOST__ __DEVICE__ T naked_cast( const shared_ptr<U>& ptr ) { return naked_cast<T>(ptr.get()); }

0 commit comments

Comments
 (0)