]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/tracking-ca/MemoryAssignmentHelpers.h
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / MemoryAssignmentHelpers.h
index 4d162c58f6278acb4ea870ea53b04958a6dd809a..0d8912a5042d7212a2a5094b4370cc4dc8d1c077 100644 (file)
 #ifndef MEMORYASSIGNMENTHELPERS_H
 #define MEMORYASSIGNMENTHELPERS_H
 
+#ifndef assert
 #include <assert.h>
+#endif //!assert
 
 template<unsigned int X>
-static inline void AlignTo( char *&mem )
+GPUhd() static inline void AlignTo( char *&mem )
 {
   STATIC_ASSERT( ( X & ( X - 1 ) ) == 0, X_needs_to_be_a_multiple_of_2 );
-  const int offset = reinterpret_cast<unsigned long>( mem ) & ( X - 1 );
+  const int offset = reinterpret_cast<unsigned long long>( mem ) & ( X - 1 );
   if ( offset > 0 ) {
     mem += ( X - offset );
   }
@@ -31,7 +33,7 @@ static inline void AlignTo( char *&mem )
 }
 
 template<unsigned int X>
-static inline unsigned int NextMultipleOf( unsigned int value )
+GPUhd() static inline unsigned int NextMultipleOf( unsigned int value )
 {
   STATIC_ASSERT( ( X & ( X - 1 ) ) == 0, X_needs_to_be_a_multiple_of_2 );
   const int offset = value & ( X - 1 );
@@ -56,18 +58,18 @@ template<typename T, unsigned int Alignment> static inline T *AssignMemory( char
   return AssignMemory<T, Alignment>( mem, stride * count );
 }
 
-template<typename T, unsigned int Alignment> static T *_assignMemory( char *&mem, unsigned int size )
+template<typename T, unsigned int Alignment> GPUhd() static T *_assignMemory( char *&mem, unsigned int size )
 {
   STATIC_ASSERT( ( Alignment & ( Alignment - 1 ) ) == 0, Alignment_needs_to_be_a_multiple_of_2 );
-  AlignTo<Alignment>( mem );
+  AlignTo<Alignment < sizeof( HLTCA_GPU_ROWALIGNMENT ) ? sizeof( HLTCA_GPU_ROWALIGNMENT ) : Alignment>( mem );
   T *r = reinterpret_cast<T *>( mem );
   mem += size * sizeof( T );
   return r;
 }
 
-template<typename T> static inline void AssignMemory( T *&dst, char *&mem, int count )
+template<typename T> GPUhd() static inline void AssignMemory( T *&dst, char *&mem, int count )
 {
-  dst = _assignMemory < T, ( sizeof( T ) & ( sizeof( T ) - 1 ) ) == 0 && sizeof( T ) <= 16 ? sizeof( T ) : sizeof( void * ) > ( mem, count );
+       dst = _assignMemory < T, ( sizeof( T ) & ( sizeof( T ) - 1 ) ) == 0 && sizeof( T ) <= 16 ? sizeof( T ) : sizeof( void * ) > ( mem, count );
 }
 
 #endif // MEMORYASSIGNMENTHELPERS_H