Skip to content

Instantly share code, notes, and snippets.

@jrhemstad
Last active August 18, 2020 21:26
Show Gist options
  • Save jrhemstad/0369038051650f2c9b9244fcf196e95b to your computer and use it in GitHub Desktop.
Save jrhemstad/0369038051650f2c9b9244fcf196e95b to your computer and use it in GitHub Desktop.
C++ wrappers for NVTX memory annotations
namespace nvtx3{

enum class heap_kind{
   LINEAR,
   3D,
   ARRAY
};

struct heap_type{
   heap_type(heap_kind k){
     switch(k)
        case LINEAR: value_ = NVTX_MEM_TYPE_VIRTUAL_ADDRESS; break; 
        case 3D:     value_ = NVTX_MEM_TYPE_VIRTUAL_ADDRESS_3D; break;
        case ARRAY:  value_ = NVTX_MEM_TYPE_CUDA_ARRAY; break;
   }
   
  auto value(){ return value_; }
  
  private:
   uint32_t value_;
};

template <typename Domain>
struct suballocator{
   suballocator(heap_type type, /* TODO description */ ) :
      handle{nvtxMemHeapRegister(domain::get<Domain>(), NVTX_MEM_HEAP_SUB_ALLOCATOR, type.value(), /* TODO description */ } 
   }
   
   void register(void * p, std::size_t size){
      nvtxMemRegionRegister(domain::get<Domain>(), handle_, p, size);
   }
   
   void unregister(void * p){
      nvtxMemRegionUnregister(domain::get<Domain>(), p);
   }
   private:
      nvtxMemHeapHandle_t handle_;
};

} // namespace nvtx3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment