Пример #1
0
  void attach( const ValueType * const arg_ptr, AllocationTracker const & tracker )
  {
    typedef char const * const byte;

    m_alloc_ptr = reinterpret_cast<ValueType *>(tracker.alloc_ptr());

    size_t byte_offset = reinterpret_cast<byte>(arg_ptr) - reinterpret_cast<byte>(m_alloc_ptr);
    const bool ok_aligned = 0 == byte_offset % sizeof(ValueType);

    const size_t count = tracker.alloc_size() / sizeof(ValueType);
    const bool ok_contains = (m_alloc_ptr <= arg_ptr) && (arg_ptr < (m_alloc_ptr + count));

    if (ok_aligned && ok_contains) {
      if (tracker.attribute() == NULL ) {
        MemorySpace::texture_object_attach(
            tracker
            , sizeof(ValueType)
            , cudaCreateChannelDesc< AliasType >()
            );
      }
      m_obj = dynamic_cast<TextureAttribute*>(tracker.attribute())->m_tex_obj;
      m_offset = arg_ptr - m_alloc_ptr;
    }
    else if( !ok_contains ) {
      throw_runtime_exception("Error: cannot attach a texture object to a tracker which does not bound the pointer.");
    }
    else {
      throw_runtime_exception("Error: cannot attach a texture object to an incorrectly aligned pointer.");
    }
  }
TEST_F( alocation_tracker, simple)
{

#if ! defined( KOKKOS_USING_EXPERIMENTAL_VIEW )

  using namespace Kokkos::Impl;

  {
    AllocationTracker tracker;
    EXPECT_FALSE( tracker.is_valid() );
  }

  // test ref count and label
  {
    int size = 100;
    std::vector<AllocationTracker> trackers(size);

    trackers[0] = AllocationTracker( MallocAllocator(), 128,"Test");

    for (int i=0; i<size; ++i) {
      trackers[i] = trackers[0];
    }

    EXPECT_EQ(100u, trackers[0].ref_count());
    EXPECT_EQ(std::string("Test"), std::string(trackers[0].label()));
  }


  // test circular list
  {
    int num_allocs = 3000;
    unsigned ref_count = 100;

    std::vector<AllocationTracker> trackers(num_allocs);

    for (int i=0; i<num_allocs; ++i) {
      trackers[i] = AllocationTracker( MallocAllocator(), 128, "Test");
      std::vector<AllocationTracker> ref_trackers(ref_count);
      for (unsigned j=0; j<ref_count; ++j) {
        ref_trackers[j] = trackers[i];
      }
      EXPECT_EQ( ref_count + 1u, trackers[i].ref_count() );
    }

    for (int i=0; i<num_allocs; ++i) {
      EXPECT_EQ( 1u, trackers[i].ref_count() );
    }
  }

#endif /* #if ! defined( KOKKOS_USING_EXPERIMENTAL_VIEW ) */

}
Пример #3
0
 KOKKOS_INLINE_FUNCTION explicit
 CudaTextureFetch( const ValueType * const arg_ptr, AllocationTracker const & tracker )
   : m_obj( 0 ) , m_alloc_ptr(0) , m_offset(0)
   {
     #if defined( KOKKOS_USE_LDG_INTRINSIC )
       m_alloc_ptr(arg_ptr);
     #elif defined( __CUDACC__ ) && ! defined( __CUDA_ARCH__ )
       if ( arg_ptr != NULL ) {
         if ( tracker.is_valid() ) {
           attach( arg_ptr, tracker );
         }
         else {
           AllocationTracker found_tracker = AllocationTracker::find<typename MemorySpace::allocator>(arg_ptr);
           if ( found_tracker.is_valid() ) {
             attach( arg_ptr, found_tracker );
           } else {
             throw_runtime_exception("Error: cannot attach a texture object to an untracked pointer!");
           }
         }
       }
     #endif
   }
Пример #4
0
 static void decrement_ref_count( AllocationTracker const & tracker )
 {
   tracker.decrement_ref_count();
 }