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 ) */

}
Пример #2
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
   }