openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
limpet_data.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
4 #ifndef LIMPET_DATA_H
5 #define LIMPET_DATA_H
6 
7 #include "target.h"
8 #ifdef HAS_ROCM_MODEL
9 #include <hip/hip_runtime.h>
10 #endif
11 #ifdef HAS_CUDA_MODEL
12 #include <cuda_runtime.h>
13 #endif
14 #include <iostream>
15 
16 namespace limpet {
17 template<typename T>
18 class LimpetData {
19  public:
20  LimpetData(Target target, std::size_t n) : _target(target), _size(n) {
21  this->_data = allocate_on_target<T>(this->_target, this->_size);
22  this->_count = new std::size_t(0);
23  };
24 
25  LimpetData() : _target(Target::UNKNOWN), _size(0), _data(nullptr) {}
26 
28  if (*this->_count == 0) {
29  deallocate_on_target<T>(this->_target, this->_data);
30  }
31  else {
32  (*this->_count)--;
33  }
34  }
35 
36 #if defined HAS_ROCM_MODEL || HAS_CUDA_MODEL
37  __device__ __host__
38 #endif
39  T *data() const {
40  return this->_data;
41  }
42 
44  if (this != &other) {
45  this->_data = other._data;
46  this->_size = other._size;
47  this->_target = other._target;
48  this->_count = other._count;
49  (*this->_count)++;
50  }
51  return *this;
52  }
53 
54  T operator*() {
55  return *this->_data;
56  }
57  T* operator&() {
58  return this->_data;
59  }
60 
61  private:
62  Target _target;
63  std::size_t _size;
64  T *_data = nullptr;
65  std::size_t *_count = nullptr;
66  bool _copied;
67 };
68 }
69 
70 #endif // LIMPET_DATA_H
T * data() const
Definition: limpet_data.h:39
LimpetData< T > & operator=(const LimpetData< T > &other)
Definition: limpet_data.h:43
LimpetData(Target target, std::size_t n)
Definition: limpet_data.h:20
Target
enum that represents different targets to run ionic models on.
Definition: target.h:30
@ UNKNOWN
special value to handle unknown targets
Definition: target.h:32
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...