This contains my bachelors thesis and associated tex files, code snippets and maybe more. Topic: Data Movement in Heterogeneous Memories with Intel Data Streaming Accelerator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

732 lines
26 KiB

  1. #pragma once
  2. #include <iostream>
  3. #include <unordered_map>
  4. #include <shared_mutex>
  5. #include <mutex>
  6. #include <memory>
  7. #include <sched.h>
  8. #include <numa.h>
  9. #include <numaif.h>
  10. #include <dml/dml.hpp>
  11. namespace dml {
  12. inline const std::string StatusCodeToString(const dml::status_code code) {
  13. switch (code) {
  14. case dml::status_code::ok: return "ok";
  15. case dml::status_code::false_predicate: return "false predicate";
  16. case dml::status_code::partial_completion: return "partial completion";
  17. case dml::status_code::nullptr_error: return "nullptr error";
  18. case dml::status_code::bad_size: return "bad size";
  19. case dml::status_code::bad_length: return "bad length";
  20. case dml::status_code::inconsistent_size: return "inconsistent size";
  21. case dml::status_code::dualcast_bad_padding: return "dualcast bad padding";
  22. case dml::status_code::bad_alignment: return "bad alignment";
  23. case dml::status_code::buffers_overlapping: return "buffers overlapping";
  24. case dml::status_code::delta_delta_empty: return "delta delta empty";
  25. case dml::status_code::batch_overflow: return "batch overflow";
  26. case dml::status_code::execution_failed: return "execution failed";
  27. case dml::status_code::unsupported_operation: return "unsupported operation";
  28. case dml::status_code::queue_busy: return "queue busy";
  29. case dml::status_code::error: return "unknown error";
  30. case dml::status_code::config_error: return "config error";
  31. default: return "unhandled error";
  32. }
  33. }
  34. }
  35. namespace dsacache {
  36. constexpr bool WAIT_WEAK = true;
  37. class Cache;
  38. /*
  39. * Class Description:
  40. * Holds all required information on one cache entry and is used
  41. * both internally by the Cache and externally by the user.
  42. *
  43. * Important Usage Notes:
  44. * The pointer is only updated in WaitOnCompletion() which
  45. * therefore must be called by the user at some point in order
  46. * to use the cached data. Using this class as T for
  47. * std::shared_ptr<T> is not recommended as references are
  48. * already counted internally.
  49. *
  50. * Cache Lifetime:
  51. * As long as the instance is referenced, the pointer it stores
  52. * is guaranteed to be either nullptr or pointing to a valid copy.
  53. *
  54. * Implementation Detail:
  55. * Performs self-reference counting with a shared atomic integer.
  56. * Therefore on creating a copy the reference count is increased
  57. * and with the destructor it is deacresed. If the last copy is
  58. * destroyed the actual underlying data is freed and all shared
  59. * variables deleted.
  60. *
  61. * Notes on Thread Safety:
  62. * Class is thread safe in any possible state and performs
  63. * reference counting and deallocation itself entirely atomically.
  64. */
  65. class CacheData {
  66. public:
  67. using dml_handler = dml::handler<dml::mem_copy_operation, std::allocator<uint8_t>>;
  68. private:
  69. static constexpr uint64_t maxptr = 0xffff'ffff'ffff'ffff;
  70. // set to false if we do not own the cache pointer
  71. bool delete_ = false;
  72. // data source and size of the block
  73. uint8_t* src_;
  74. size_t size_;
  75. // global reference counting object
  76. std::atomic<int32_t>* active_;
  77. // global cache-location pointer
  78. std::atomic<uint8_t*>* cache_;
  79. // object-local incomplete cache location pointer
  80. // contract: only access when being in sole posession of handlers
  81. uint8_t** incomplete_cache_;
  82. // dml handler vector pointer which is used
  83. // to wait on caching task completion
  84. std::atomic<std::vector<dml_handler>*>* handlers_;
  85. // deallocates the global cache-location
  86. // and invalidates it
  87. void Deallocate();
  88. size_t GetSize() const { return size_; }
  89. uint8_t* GetSource() const { return src_; }
  90. int32_t GetRefCount() const { return active_->load(); }
  91. void SetTaskHandlersAndCache(uint8_t* cache, std::vector<dml_handler>* handlers);
  92. // initializes the class after which it is thread safe
  93. // but may only be destroyed safely after setting handlers
  94. void Init();
  95. friend Cache;
  96. public:
  97. CacheData(uint8_t* data, const size_t size);
  98. CacheData(const CacheData& other);
  99. ~CacheData();
  100. // waits on completion of caching operations
  101. // for this task and is safe to be called in
  102. // any state of the object
  103. void WaitOnCompletion(const bool weak = false);
  104. // returns the cache data location for this
  105. // instance which is valid as long as the
  106. // instance is alive - !!! this may also
  107. // yield a nullptr !!!
  108. uint8_t* GetDataLocation() const { return cache_->load(); }
  109. };
  110. /*
  111. * Class Description:
  112. * Class will handle access to data through internal copies.
  113. * These are obtained via work submission to the Intel DSA which takes
  114. * care of asynchronously duplicating the data. The user will define
  115. * where these copies lie and which system nodes will perform the copy.
  116. * This is done through policy functions set during initialization.
  117. *
  118. * Placement Policy:
  119. * The Placement Policy Function decides on which node a particular
  120. * entry is to be placed, given the current executing node and the
  121. * data source node and data size. This in turn means that for one
  122. * datum, multiple cached copies may exist at one time.
  123. *
  124. * Cache Lifetime:
  125. * When accessing the cache, a CacheData-object will be returned.
  126. * As long as this object lives, the pointer which it holds is
  127. * guaranteed to be either nullptr or a valid copy. When destroyed
  128. * the entry is marked for deletion which is only carried out
  129. * when system memory pressure drives an automated cache flush.
  130. *
  131. * Restrictions:
  132. * - Overlapping Pointers may lead to undefined behaviour during
  133. * manual cache invalidation which should not be used if you
  134. * intend to have these types of pointers
  135. * - Cache Invalidation may only be performed manually and gives
  136. * no ordering guarantees. Therefore, it is the users responsibility
  137. * to ensure that results after invalidation have been generated
  138. * using the latest state of data. The cache is best suited
  139. * to static data.
  140. *
  141. * Notes on Thread Safety:
  142. * - Cache is completely thread-safe after initialization
  143. * - CacheData-class will handle deallocation of data itself by
  144. * performing self-reference-counting atomically and only
  145. * deallocating if the last reference is destroyed
  146. * - The internal cache state has one lock which is either
  147. * acquired shared for reading the state (upon accessing an already
  148. * cached element) or unique (accessing a new element, flushing, invalidating)
  149. * - Waiting on copy completion is done over an atomic-wait in copies
  150. * of the original CacheData-instance
  151. * - Overall this class may experience performance issues due to the use
  152. * of locking (in any configuration), lock contention (worsens with higher
  153. * core count, node count and utilization) and atomics (worse in the same
  154. * situations as lock contention)
  155. *
  156. * Improving Performance:
  157. * When data is never shared between threads or memory size for the cache is
  158. * not an issue you may consider having one Cache-instance per thread and removing
  159. * the lock in Cache and modifying the reference counting and waiting mechanisms
  160. * of CacheData accordingly (although this is high effort and will yield little due
  161. * to the atomics not being shared among cores/nodes).
  162. * Otherwise, one Cache-instance per node could also be considered. This will allow
  163. * the placement policy function to be barebones and reduces the lock contention and
  164. * synchronization impact of the atomic variables.
  165. */
  166. class Cache {
  167. public:
  168. // cache policy is defined as a type here to allow flexible usage of the cacher
  169. // given a numa destination node (where the data will be needed), the numa source
  170. // node (current location of the data) and the data size, this function should
  171. // return optimal cache placement
  172. // dst node and returned value can differ if the system, for example, has HBM
  173. // attached accessible directly to node n under a different node id m
  174. typedef int (CachePolicy)(const int numa_dst_node, const int numa_src_node, const size_t data_size);
  175. // copy policy specifies the copy-executing nodes for a given task
  176. // which allows flexibility in assignment for optimizing raw throughput
  177. // or choosing a conservative usage policy
  178. typedef std::vector<int> (CopyPolicy)(const int numa_dst_node, const int numa_src_node, const size_t data_size);
  179. private:
  180. // mutex for accessing the cache state map
  181. // map from [dst-numa-node,map2]
  182. // map2 from [data-ptr,cache-structure]
  183. struct LockedNodeCacheState {
  184. std::shared_mutex cache_mutex_;
  185. std::unordered_map<uint8_t*, CacheData> node_cache_state_;
  186. };
  187. std::unordered_map<uint8_t, LockedNodeCacheState*> cache_state_;
  188. CachePolicy* cache_policy_function_ = nullptr;
  189. CopyPolicy* copy_policy_function_ = nullptr;
  190. // function used to submit a copy task on a specific node to the dml
  191. // engine on that node - will change the current threads node assignment
  192. // to achieve this so take care to restore this
  193. dml::handler<dml::mem_copy_operation, std::allocator<uint8_t>> ExecuteCopy(
  194. const uint8_t* src, uint8_t* dst, const size_t size, const int node
  195. ) const;
  196. // allocates the required memory on the destination node
  197. // and then submits task to the dml library for processing
  198. // and attaches the handlers to the cache data structure
  199. void SubmitTask(CacheData* task, const int dst_node, const int src_node);
  200. // querries the policy functions for the given data and size
  201. // to obtain destination cache node, also returns the datas
  202. // source node for further usage
  203. // output may depend on the calling threads node assignment
  204. // as this is set as the "optimal placement" node
  205. void GetCacheNode(uint8_t* src, const size_t size, int* OUT_DST_NODE, int* OUT_SRC_NODE) const;
  206. // allocates memory of size "size" on the numa node "node"
  207. // and returns nullptr if this is not possible, also may
  208. // try to flush the cache of the requested node to
  209. // alleviate encountered shortage
  210. uint8_t* AllocOnNode(const size_t size, const int node);
  211. // checks whether the cache contains an entry for
  212. // the given data in the given memory node and
  213. // returns it, otherwise returns nullptr
  214. std::unique_ptr<CacheData> GetFromCache(uint8_t* src, const size_t size, const int dst_node);
  215. public:
  216. ~Cache();
  217. Cache() = default;
  218. Cache(const Cache& other) = delete;
  219. // initializes the cache with the two policy functions
  220. // only after this is it safe to use in a threaded environment
  221. void Init(CachePolicy* cache_policy_function, CopyPolicy* copy_policy_function);
  222. // function to perform data access through the cache
  223. std::unique_ptr<CacheData> Access(uint8_t* data, const size_t size);
  224. // flushes the cache of inactive entries
  225. // if node is -1 then the whole cache is
  226. // checked and otherwise the specified
  227. // node - no checks on node validity
  228. void Flush(const int node = -1);
  229. // forces out all entries from the
  230. // cache and therefore will also "forget"
  231. // still-in-use entries, these will still
  232. // be properly deleted, but the cache
  233. // will be fresh - use for testing
  234. void Clear();
  235. void Invalidate(uint8_t* data);
  236. };
  237. }
  238. inline void dsacache::Cache::Clear() {
  239. for (auto& nc : cache_state_) {
  240. std::unique_lock<std::shared_mutex> lock(nc.second->cache_mutex_);
  241. nc.second->node_cache_state_.clear();
  242. }
  243. }
  244. inline void dsacache::Cache::Init(CachePolicy* cache_policy_function, CopyPolicy* copy_policy_function) {
  245. cache_policy_function_ = cache_policy_function;
  246. copy_policy_function_ = copy_policy_function;
  247. // initialize numa library
  248. numa_available();
  249. // obtain all available nodes
  250. // and those we may allocate
  251. // memory on
  252. const int nodes_max = numa_num_configured_nodes();
  253. const bitmask* valid_nodes = numa_get_mems_allowed();
  254. // prepare the cache state with entries
  255. // for all given nodes
  256. for (int node = 0; node < nodes_max; node++) {
  257. if (numa_bitmask_isbitset(valid_nodes, node)) {
  258. void* block = numa_alloc_onnode(sizeof(LockedNodeCacheState), node);
  259. auto* state = new(block)LockedNodeCacheState;
  260. cache_state_.insert({node,state});
  261. }
  262. }
  263. }
  264. inline std::unique_ptr<dsacache::CacheData> dsacache::Cache::Access(uint8_t* data, const size_t size) {
  265. // get destination numa node for the cache
  266. int dst_node = -1;
  267. int src_node = -1;
  268. GetCacheNode(data, size, &dst_node, &src_node);
  269. // TODO: at this point it could be beneficial to check whether
  270. // TODO: the given destination node is present as an entry
  271. // TODO: in the cache state to see if it is valid
  272. // check whether the data is already cached
  273. std::unique_ptr<CacheData> task = GetFromCache(data, size, dst_node);
  274. if (task != nullptr) {
  275. return std::move(task);
  276. }
  277. // at this point the requested data is not present in cache
  278. // and we create a caching task for it
  279. task = std::make_unique<CacheData>(data, size);
  280. {
  281. LockedNodeCacheState* local_cache_state = cache_state_[dst_node];
  282. std::unique_lock<std::shared_mutex> lock(local_cache_state->cache_mutex_);
  283. const auto state = local_cache_state->node_cache_state_.emplace(task->GetSource(), *task);
  284. // if state.second is false then no insertion took place
  285. // which means that concurrently whith this thread
  286. // some other thread must have accessed the same
  287. // resource in which case we return the other
  288. // threads data cache structure
  289. if (!state.second) {
  290. return std::move(std::make_unique<CacheData>(state.first->second));
  291. }
  292. // initialize the task now for thread safety
  293. // as we are now sure that we will submit work
  294. // to it and will not delete it beforehand
  295. task->Init();
  296. }
  297. SubmitTask(task.get(), dst_node, src_node);
  298. return std::move(task);
  299. }
  300. inline uint8_t* dsacache::Cache::AllocOnNode(const size_t size, const int node) {
  301. // allocate data on this node and flush the unused parts of the
  302. // cache if the operation fails and retry once
  303. // TODO: smarter flush strategy could keep some stuff cached
  304. // check currently free memory to see if the data fits
  305. long long int free_space = 0;
  306. numa_node_size64(node, &free_space);
  307. if (free_space < size) {
  308. // dst node lacks memory space so we flush the cache for this
  309. // node hoping to free enough currently unused entries to make
  310. // the second allocation attempt successful
  311. Flush(node);
  312. // re-test by getting the free space and checking again
  313. numa_node_size64(node, &free_space);
  314. if (free_space < size) {
  315. return nullptr;
  316. }
  317. }
  318. uint8_t* dst = reinterpret_cast<uint8_t*>(numa_alloc_onnode(size, node));
  319. if (dst == nullptr) {
  320. return nullptr;
  321. }
  322. return dst;
  323. }
  324. inline void dsacache::Cache::SubmitTask(CacheData* task, const int dst_node, const int src_node) {
  325. uint8_t* dst = AllocOnNode(task->GetSize(), dst_node);
  326. if (dst == nullptr) {
  327. return;
  328. }
  329. // querry copy policy function for the nodes to use for the copy
  330. const std::vector<int> executing_nodes = copy_policy_function_(dst_node, src_node, task->GetSize());
  331. const size_t task_count = executing_nodes.size();
  332. // each task will copy one fair part of the total size
  333. // and in case the total size is not a factor of the
  334. // given task count the last node must copy the remainder
  335. const size_t size = task->GetSize() / task_count;
  336. const size_t last_size = size + task->GetSize() % task_count;
  337. // save the current numa node mask to restore later
  338. // as executing the copy task will place this thread
  339. // on a different node
  340. auto handlers = new std::vector<CacheData::dml_handler>();
  341. for (uint32_t i = 0; i < task_count; i++) {
  342. const size_t local_size = i + 1 == task_count ? size : last_size;
  343. const size_t local_offset = i * size;
  344. const uint8_t* local_src = task->GetSource() + local_offset;
  345. uint8_t* local_dst = dst + local_offset;
  346. handlers->emplace_back(ExecuteCopy(local_src, local_dst, local_size, executing_nodes[i]));
  347. }
  348. task->SetTaskHandlersAndCache(dst, handlers);
  349. }
  350. inline dml::handler<dml::mem_copy_operation, std::allocator<uint8_t>> dsacache::Cache::ExecuteCopy(
  351. const uint8_t* src, uint8_t* dst, const size_t size, const int node
  352. ) const {
  353. dml::const_data_view srcv = dml::make_view(src, size);
  354. dml::data_view dstv = dml::make_view(dst, size);
  355. return dml::submit<dml::hardware>(
  356. dml::mem_copy.block_on_fault(), srcv, dstv,
  357. dml::execution_interface<dml::hardware,std::allocator<uint8_t>>(), node
  358. );
  359. }
  360. inline void dsacache::Cache::GetCacheNode(uint8_t* src, const size_t size, int* OUT_DST_NODE, int* OUT_SRC_NODE) const {
  361. // obtain numa node of current thread to determine where the data is needed
  362. const int current_cpu = sched_getcpu();
  363. const int current_node = numa_node_of_cpu(current_cpu);
  364. // obtain node that the given data pointer is allocated on
  365. *OUT_SRC_NODE = -1;
  366. get_mempolicy(OUT_SRC_NODE, NULL, 0, (void*)src, MPOL_F_NODE | MPOL_F_ADDR);
  367. // querry cache policy function for the destination numa node
  368. *OUT_DST_NODE = cache_policy_function_(current_node, *OUT_SRC_NODE, size);
  369. }
  370. inline void dsacache::Cache::Flush(const int node) {
  371. // this lambda is used because below we have two code paths that
  372. // flush nodes, either one single or all successively
  373. const auto FlushNode = [](std::unordered_map<uint8_t*,CacheData>& map) {
  374. // begin at the front of the map
  375. auto it = map.begin();
  376. // loop until we reach the end of the map
  377. while (it != map.end()) {
  378. // if the iterator points to an inactive element
  379. // then we may erase it
  380. if (it->second.GetRefCount() <= 1) {
  381. // erase the iterator from the map
  382. map.erase(it);
  383. // as the erasure invalidated out iterator
  384. // we must start at the beginning again
  385. it = map.begin();
  386. }
  387. else {
  388. // if element is active just move over to the next one
  389. it++;
  390. }
  391. }
  392. };
  393. // we require exclusive lock as we modify the cache state
  394. // node == -1 means that cache on all nodes should be flushed
  395. if (node == -1) {
  396. for (auto& nc : cache_state_) {
  397. std::unique_lock<std::shared_mutex> lock(nc.second->cache_mutex_);
  398. FlushNode(nc.second->node_cache_state_);
  399. }
  400. }
  401. else {
  402. std::unique_lock<std::shared_mutex> lock(cache_state_[node]->cache_mutex_);
  403. FlushNode(cache_state_[node]->node_cache_state_);
  404. }
  405. }
  406. inline std::unique_ptr<dsacache::CacheData> dsacache::Cache::GetFromCache(uint8_t* src, const size_t size, const int dst_node) {
  407. // the best situation is if this data is already cached
  408. // which we check in an unnamed block in which the cache
  409. // is locked for reading to prevent another thread
  410. // from marking the element we may find as unused and
  411. // clearing it
  412. LockedNodeCacheState* local_cache_state = cache_state_[dst_node];
  413. // lock the cache state in shared-mode because we read
  414. std::shared_lock<std::shared_mutex> lock(local_cache_state->cache_mutex_);
  415. // search for the data in our cache state structure at the given node
  416. const auto search = local_cache_state->node_cache_state_.find(src);
  417. // if the data is in our structure we continue
  418. if (search != local_cache_state->node_cache_state_.end()) {
  419. // now check whether the sizes match
  420. if (search->second.GetSize() >= size) {
  421. // return a unique copy of the entry which uses the object
  422. // lifetime and destructor to safely handle deallocation
  423. return std::move(std::make_unique<CacheData>(search->second));
  424. }
  425. else {
  426. // if the sizes missmatch then we clear the current entry from cache
  427. // which will cause its deletion only after the last possible outside
  428. // reference is also destroyed
  429. local_cache_state->node_cache_state_.erase(search);
  430. }
  431. }
  432. return nullptr;
  433. }
  434. void dsacache::Cache::Invalidate(uint8_t* data) {
  435. // as the cache is modified we must obtain a unique writers lock
  436. // loop through all per-node-caches available
  437. for (auto node : cache_state_) {
  438. std::unique_lock<std::shared_mutex> lock(node.second->cache_mutex_);
  439. // search for an entry for the given data pointer
  440. auto search = node.second->node_cache_state_.find(data);
  441. if (search != node.second->node_cache_state_.end()) {
  442. // if the data is represented in-cache
  443. // then it will be erased to re-trigger
  444. // caching on next access
  445. node.second->node_cache_state_.erase(search);
  446. }
  447. }
  448. }
  449. inline dsacache::Cache::~Cache() {
  450. for (auto node : cache_state_) {
  451. node.second->~LockedNodeCacheState();
  452. numa_free(reinterpret_cast<void*>(node.second), sizeof(LockedNodeCacheState));
  453. }
  454. }
  455. inline dsacache::CacheData::CacheData(uint8_t* data, const size_t size) {
  456. src_ = data;
  457. size_ = size;
  458. delete_ = false;
  459. active_ = new std::atomic<int32_t>(1);
  460. cache_ = new std::atomic<uint8_t*>(data);
  461. handlers_ = new std::atomic<std::vector<dml_handler>*>();
  462. incomplete_cache_ = new uint8_t*(nullptr);
  463. }
  464. inline dsacache::CacheData::CacheData(const dsacache::CacheData& other) {
  465. // we copy the ptr to the global atomic reference counter
  466. // and increase the amount of active references
  467. active_ = other.active_;
  468. const int current_active = active_->fetch_add(1);
  469. src_ = other.src_;
  470. size_ = other.size_;
  471. cache_ = other.cache_;
  472. incomplete_cache_ = other.incomplete_cache_;
  473. handlers_ = other.handlers_;
  474. }
  475. inline dsacache::CacheData::~CacheData() {
  476. // due to fetch_sub returning the preivously held value
  477. // we must subtract one locally to get the current value
  478. const int32_t v = active_->fetch_sub(1) - 1;
  479. // if the returned value is zero or lower
  480. // then we must execute proper deletion
  481. // as this was the last reference
  482. if (v == 0) {
  483. // on deletion we must ensure that all offloaded
  484. // operations have completed successfully
  485. WaitOnCompletion();
  486. // only then can we deallocate the memory
  487. Deallocate();
  488. delete active_;
  489. delete cache_;
  490. delete handlers_;
  491. delete incomplete_cache_;
  492. }
  493. }
  494. inline void dsacache::CacheData::Deallocate() {
  495. // although deallocate should only be called from
  496. // a safe context to do so, it can not hurt to
  497. // defensively perform the operation atomically
  498. // and check for incomplete cache if no deallocation
  499. // takes place for the retrieved local cache
  500. uint8_t* cache_local = cache_->exchange(nullptr);
  501. if (cache_local != nullptr && delete_) numa_free(cache_local, size_);
  502. else if (*incomplete_cache_ != nullptr) numa_free(*incomplete_cache_, size_);
  503. else;
  504. }
  505. inline void dsacache::CacheData::WaitOnCompletion(const bool weak) {
  506. // first check if waiting is even neccessary as a valid
  507. // cache pointer signals that no waiting is to be performed
  508. if (cache_->load() != nullptr) {
  509. return;
  510. }
  511. // then check if the handlers are available
  512. handlers_->wait(nullptr);
  513. // exchange the global handlers pointer with nullptr to have a local
  514. // copy - this signals that this thread is the sole owner and therefore
  515. // responsible for waiting for them. we can not set to nullptr here but
  516. // set to maximum of 64-bit in order to prevent deadlocks from the above
  517. // waiting construct
  518. std::vector<dml_handler>* local_handlers = handlers_->exchange(reinterpret_cast<std::vector<dml_handler>*>(maxptr));
  519. // ensure that no other thread snatched the handlers before us
  520. // and in case one did, wait again and then return
  521. if (local_handlers == nullptr || local_handlers == reinterpret_cast<std::vector<dml_handler>*>(maxptr)) {
  522. cache_->wait(nullptr);
  523. return;
  524. }
  525. // at this point we are responsible for waiting for the handlers
  526. // and handling any error that comes through them gracefully
  527. bool error = false;
  528. for (auto& handler : *local_handlers) {
  529. if (weak && !handler.is_finished()) {
  530. handlers_->store(local_handlers);
  531. return;
  532. }
  533. auto result = handler.get();
  534. if (result.status != dml::status_code::ok) {
  535. // if one of the copy tasks failed we abort the whole task
  536. // after all operations are completed on it
  537. error = true;
  538. }
  539. }
  540. // at this point all handlers have been waited for
  541. // and therefore may be decomissioned
  542. delete local_handlers;
  543. // handle errors now by aborting the cache
  544. if (error) {
  545. cache_->store(src_);
  546. numa_free(*incomplete_cache_, size_);
  547. delete_ = false;
  548. *incomplete_cache_ = nullptr;
  549. }
  550. else {
  551. cache_->store(*incomplete_cache_);
  552. }
  553. // notify all waiting threads so they wake up quickly
  554. cache_->notify_all();
  555. handlers_->notify_all();
  556. }
  557. void dsacache::CacheData::SetTaskHandlersAndCache(uint8_t* cache, std::vector<dml_handler>* handlers) {
  558. *incomplete_cache_ = cache;
  559. handlers_->store(handlers);
  560. handlers_->notify_one();
  561. }
  562. void dsacache::CacheData::Init() {
  563. cache_->store(nullptr);
  564. delete_ = true;
  565. }