Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for different data types in arrays, also on GPU #324

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CarpetX: correct count in AnyTypeVector::alloc()
  • Loading branch information
rhaas80 committed Jan 1, 2025
commit f73cdf3aa3c79399e53013226427dd4290667334
21 changes: 11 additions & 10 deletions CarpetX/src/driver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ struct GHExt {
class AnyTypeVector {
private:
int _type, _typesize;
void *_data;
size_t _count;
void *_data;

public:
AnyTypeVector() : _type(-1), _typesize(-1), _data(nullptr), _count(0){};
AnyTypeVector() : _type(-1), _typesize(-1), _count(0), _data(nullptr){};
AnyTypeVector(int type_, size_t count_) : _type(type_), _count(count_) {
assert(type_ == CCTK_VARIABLE_INT || type_ == CCTK_VARIABLE_REAL ||
type_ == CCTK_VARIABLE_COMPLEX);
Expand All @@ -174,17 +174,17 @@ struct GHExt {
swap(other);
return *this;
}
AnyTypeVector(AnyTypeVector &&other) : _type(other._type), _typesize(other._typesize), _data(other._data), _count(other._count) {
AnyTypeVector(AnyTypeVector &&other) : _type(other._type), _typesize(other._typesize), _count(other._count), _data(other._data) {
other._type = -1;
other._typesize = -1;
other._data = nullptr;
other._count = 0;
other._data = nullptr;
}
void swap(AnyTypeVector &other) {
std::swap(this->_type, other._type);
std::swap(this->_typesize, other._typesize);
std::swap(this->_data, other._data);
std::swap(this->_count, other._count);
std::swap(this->_data, other._data);
}

~AnyTypeVector() {
Expand All @@ -194,12 +194,13 @@ struct GHExt {
amrex::The_Arena()->free(_data);
_type = -1;
_typesize = -1;
_data = nullptr;
_count = 0;
_data = nullptr;
}
assert(_data == nullptr);
assert(_type == -1);
assert(_typesize == -1);
assert(_count == 0);
assert(_data == nullptr);
};

void alloc(int type_, size_t count_) {
Expand All @@ -208,14 +209,14 @@ struct GHExt {

assert(_type == -1);
assert(_typesize == -1);
assert(_data == nullptr);
assert(_count == 0);
assert(_data == nullptr);

_type = type_;
_typesize = CCTK_VarTypeSize(_type);
assert(_typesize > 0);
_data = amrex::The_Arena()->alloc(_typesize * _count);
_count = count_;
_data = amrex::The_Arena()->alloc(_typesize * _count);
}

void free() {
Expand All @@ -225,8 +226,8 @@ struct GHExt {
amrex::The_Arena()->free(_data);
_type = -1;
_typesize = -1;
_data = nullptr;
_count = 0;
_data = nullptr;
}

int type() const { return _type; };
Expand Down