YAKL
YAKL_Internal.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 namespace yakl {
6 
8  class YAKL_Internal {
9  private:
10  YAKL_Internal() {
11  yakl_is_initialized = false; // Determine if YAKL has been initialized
12  timer_init_func = [] () {
13  yakl_throw("ERROR: attempting to call the yakl::timer_init(); before calling yakl::init()");
14  };
15  timer_finalize_func = [] () {
16  yakl_throw("ERROR: attempting to call the yakl::timer_finalize(); before calling yakl::init()");
17  };
18  timer_start_func = [] (char const *label) {
19  yakl_throw("ERROR: attempting to call the yakl::timer_start(); before calling yakl::init()");
20  };
21  timer_stop_func = [] (char const * label) {
22  yakl_throw("ERROR: attempting to call the yakl::timer_stop(); before calling yakl::init()");
23  };
24  alloc_device_func = [] ( size_t bytes , char const *label ) -> void* {
25  yakl_throw("ERROR: attempting memory alloc before calling yakl::init()");
26  return nullptr;
27  };
28  free_device_func = [] ( void *ptr , char const *label ) {
29  yakl_throw("ERROR: attempting memory free before calling yakl::init()");
30  };
31  device_allocators_are_default = false;
32  pool_enabled = false;
33  }
34  ~YAKL_Internal() = default;
35 
36  public:
37  YAKL_Internal(const YAKL_Internal&) = delete;
38  YAKL_Internal& operator = (const YAKL_Internal&) = delete;
39 
40  Gator pool; // Pool allocator. Constructor and destructor do not depend on ordering
41  Toney timer; // Constructor and destructor do not depend on ordering
42  std::mutex yakl_mtx; // Mutex for YAKL reference counting, allocation, and deallocation in threaded regions
43  std::mutex yakl_final_mtx; // Mutex for YAKL reference counting, allocation, and deallocation in threaded regions
44  bool yakl_is_initialized; // Determine if YAKL has been initialized
45  std::function<void ()> timer_init_func; // Function to init timers
46  std::function<void ()> timer_finalize_func; // Function to finalize timers
47  std::function<void (char const *)> timer_start_func; // Function to start a single timer
48  std::function<void (char const *)> timer_stop_func; // Function to stop a single timer
49  std::function<void *( size_t , char const *)> alloc_device_func; // Function to alloc on device
50  std::function<void ( void * , char const *)> free_device_func; // Funciton to free on device
51  bool device_allocators_are_default; // Are the allocators & deallocators default, or have they been changed?
52  bool pool_enabled; // Is the pool allocator being used?
53  std::vector< std::function<void ()> > finalize_callbacks;
54 
55  static YAKL_Internal & get_instance() {
56  static YAKL_Internal instance;
57  return instance;
58  }
59  };
60 
61 
63  inline YAKL_Internal & get_yakl_instance() { return YAKL_Internal::get_instance(); }
64 }
66 
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
yakl::yakl_throw
YAKL_INLINE void yakl_throw(const char *msg)
Throw an error message. Works from the host or device.
Definition: YAKL_error.h:17
yakl