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

[pnnl/SHAD#23] moved all object-id logic into AbstractDataStructure #182

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 14 additions & 23 deletions include/shad/core/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ class array : public AbstractDataStructure<array<T, N>> {
/// @return an ::iterator to the beginning of the sequence.
constexpr iterator begin() noexcept {
if (rt::thisLocality() == rt::Locality(0)) {
return iterator{rt::Locality(0), 0, oid_, chunk_.get()};
return iterator{rt::Locality(0), 0, this->oid_, chunk_.get()};
}
return iterator{rt::Locality(0), 0, oid_, nullptr};
return iterator{rt::Locality(0), 0, this->oid_, nullptr};
}

/// @brief The iterator to the beginning of the sequence.
Expand All @@ -155,15 +155,15 @@ class array : public AbstractDataStructure<array<T, N>> {
if (N < rt::numLocalities()) {
rt::Locality last(uint32_t(N - 1));
pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr;
return iterator{std::forward<rt::Locality>(last), 1, oid_, chunk};
return iterator{std::forward<rt::Locality>(last), 1, this->oid_, chunk};
}

difference_type pos = chunk_size();
if (pivot_locality() != rt::Locality(0)) --pos;

rt::Locality last(rt::numLocalities() - 1);
pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr;
return iterator{std::forward<rt::Locality>(last), pos, oid_, chunk};
return iterator{std::forward<rt::Locality>(last), pos, this->oid_, chunk};
}

/// @brief The iterator to the end of the sequence.
Expand All @@ -174,7 +174,7 @@ class array : public AbstractDataStructure<array<T, N>> {
/// @return a ::const_iterator to the beginning of the sequence.
constexpr const_iterator cbegin() const noexcept {
if (rt::thisLocality() == rt::Locality(0)) {
return const_iterator{rt::Locality(0), 0, oid_, chunk_.get()};
return const_iterator{rt::Locality(0), 0, this->oid_, chunk_.get()};
}

pointer chunk = nullptr;
Expand All @@ -183,8 +183,8 @@ class array : public AbstractDataStructure<array<T, N>> {
auto This = array<T, N>::GetPtr(ID);
*result = This->chunk_.get();
},
GetGlobalID(), &chunk);
return const_iterator{rt::Locality(0), 0, oid_, chunk};
this->GetGlobalID(), &chunk);
return const_iterator{rt::Locality(0), 0, this->oid_, chunk};
}

/// @brief The iterator to the end of the sequence.
Expand All @@ -193,15 +193,15 @@ class array : public AbstractDataStructure<array<T, N>> {
if (N < rt::numLocalities()) {
rt::Locality last(uint32_t(N - 1));
pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr;
return const_iterator{std::forward<rt::Locality>(last), 1, oid_, chunk};
return const_iterator{std::forward<rt::Locality>(last), 1, this->oid_, chunk};
}

difference_type pos = chunk_size();
if (pivot_locality() != rt::Locality(0)) --pos;

rt::Locality last(rt::numLocalities() - 1);
pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr;
return const_iterator{std::forward<rt::Locality>(last), pos, oid_, chunk};
return const_iterator{std::forward<rt::Locality>(last), pos, this->oid_, chunk};
}

/// @}
Expand Down Expand Up @@ -240,13 +240,13 @@ class array : public AbstractDataStructure<array<T, N>> {

if (n < chunk) {
difference_type position(n);
return reference{l, position, oid_, nullptr};
return reference{l, position, this->oid_, nullptr};
}

n -= chunk;
}
difference_type position(n);
return reference{rt::Locality(rt::numLocalities() - 1), position, oid_,
return reference{rt::Locality(rt::numLocalities() - 1), position, this->oid_,
nullptr};
}

Expand All @@ -265,14 +265,14 @@ class array : public AbstractDataStructure<array<T, N>> {

if (n < chunk) {
difference_type position(n);
return const_reference{l, position, oid_, nullptr};
return const_reference{l, position, this->oid_, nullptr};
}

n -= chunk;
}
difference_type position(n);
return const_reference{rt::Locality(rt::numLocalities() - 1), position,
oid_, nullptr};
this->oid_, nullptr};
}

/// @brief Checked element access operator.
Expand Down Expand Up @@ -305,14 +305,6 @@ class array : public AbstractDataStructure<array<T, N>> {

/// @}

/// @brief DataStructure identifier getter.
///
/// Returns the global object identifier associated to a DataStructure
/// instance.
///
/// @warning It must be implemented in the inheriting DataStructure.
ObjectID GetGlobalID() const { return oid_; }

friend bool operator!=(const array<T, N> &LHS, const array<T, N> &RHS) {
bool result[rt::numLocalities()];

Expand Down Expand Up @@ -408,11 +400,10 @@ class array : public AbstractDataStructure<array<T, N>> {
}

/// @brief Constructor.
explicit array(ObjectID oid) : chunk_{new T[chunk_size()]}, oid_{oid} {}
explicit array(ObjectID oid) : chunk_{new T[chunk_size()]}, AbstractDataStructure<array<T, N>>(oid) {}

private:
std::unique_ptr<T[]> chunk_;
ObjectID oid_;
};

template <typename T, std::size_t N>
Expand Down
10 changes: 5 additions & 5 deletions include/shad/data_structures/abstract_data_structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class AbstractDataStructure {
/// SharedPtr to DataStructure
using SharedPtr = std::shared_ptr<DataStructure>;

/// @brief Default constructor
AbstractDataStructure() = default;
/// @brief Constructor.
explicit AbstractDataStructure(ObjectID oid) : oid_(oid) {}

/// @brief Create method.
///
Expand Down Expand Up @@ -125,11 +125,11 @@ class AbstractDataStructure {
///
/// Returns the global object identifier associated to a DataStructure
/// instance.
///
/// @warning It must be implemented in the inheriting DataStructure.
virtual ObjectID GetGlobalID() const = 0;
ObjectID GetGlobalID() const { return oid_; }

protected:
const ObjectID oid_;

template <typename... Args>
static void UpdateCatalogAndConstruct(const ObjectID &oid, Args &&... args) {
// Get a local instance on the remote node.
Expand Down
46 changes: 20 additions & 26 deletions include/shad/data_structures/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ class Array : public AbstractDataStructure<Array<T>> {
using BuffersVector = impl::BuffersVector<std::tuple<size_t, T>, Array<T>>;
using ShadArrayPtr = typename AbstractDataStructure<Array<T>>::SharedPtr;

/// @brief Retrieve the Global Identifier.
///
/// @return The global identifier associated with the array instance.
ObjectID GetGlobalID() const { return oid_; }

/// @brief Return the size of the shad::Array.
/// @return The size of the shad::Array.
size_t Size() const noexcept { return size_; }
Expand Down Expand Up @@ -460,7 +455,7 @@ class Array : public AbstractDataStructure<Array<T>> {

protected:
Array(ObjectID oid, size_t size, const T &initValue)
: oid_(oid),
: AbstractDataStructure<Array<T>>(oid),
size_(size),
pivot_((size % rt::numLocalities() == 0)
? rt::numLocalities()
Expand Down Expand Up @@ -492,7 +487,6 @@ class Array : public AbstractDataStructure<Array<T>> {
}

private:
ObjectID oid_;
size_t size_;
uint32_t pivot_;
std::vector<T> data_;
Expand Down Expand Up @@ -711,7 +705,7 @@ void Array<T>::InsertAt(const size_t pos, const T &value) {
if (target.first == rt::thisLocality()) {
data_[target.second] = value;
} else {
InsertAtArgs args = {oid_, target.second, value};
InsertAtArgs args = {this->oid_, target.second, value};
rt::executeAt(target.first, InsertAtFun, args);
}
}
Expand All @@ -723,7 +717,7 @@ void Array<T>::AsyncInsertAt(rt::Handle &handle, const size_t pos,
if (target.first == rt::thisLocality()) {
data_[target.second] = value;
} else {
InsertAtArgs args = {oid_, target.second, value};
InsertAtArgs args = {this->oid_, target.second, value};
rt::asyncExecuteAt(handle, target.first, AsyncInsertAtFun, args);
}
}
Expand Down Expand Up @@ -758,12 +752,12 @@ void Array<T>::InsertAt(const size_t pos, const T *values,
} else {
chunkSize = constants::min(chunkSize, kMaxChunkSize);
size_t argsSize =
sizeof(oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize;
sizeof(this->oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize;
std::shared_ptr<uint8_t> args(new uint8_t[argsSize],
std::default_delete<uint8_t[]>());
uint8_t *argsPtr = args.get();
memcpy(argsPtr, &oid_, sizeof(oid_));
argsPtr += sizeof(oid_);
memcpy(argsPtr, &this->oid_, sizeof(this->oid_));
argsPtr += sizeof(this->oid_);
memcpy(argsPtr, &tgtPos, sizeof(size_t));
argsPtr += sizeof(size_t);
memcpy(argsPtr, &chunkSize, sizeof(size_t));
Expand All @@ -789,13 +783,13 @@ void Array<T>::InsertAt(const size_t pos, const T *values,
} else {
chunkSize = constants::min(chunkSize, kMaxChunkSize);
size_t argsSize =
sizeof(oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize;
sizeof(this->oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize;
// FIXME(SHAD-125)
std::shared_ptr<uint8_t> args(new uint8_t[argsSize],
std::default_delete<uint8_t[]>());
uint8_t *argsPtr = args.get();
memcpy(argsPtr, &oid_, sizeof(oid_));
argsPtr += sizeof(oid_);
memcpy(argsPtr, &this->oid_, sizeof(this->oid_));
argsPtr += sizeof(this->oid_);
memcpy(argsPtr, &tgtPos, sizeof(size_t));
argsPtr += sizeof(size_t);
memcpy(argsPtr, &chunkSize, sizeof(size_t));
Expand Down Expand Up @@ -839,14 +833,14 @@ void Array<T>::AsyncInsertAt(rt::Handle &handle, const size_t pos,
} else {
chunkSize = constants::min(chunkSize, kMaxChunkSize);
size_t argsSize =
sizeof(oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize;
sizeof(this->oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize;
// FIXME(SHAD-125)
std::shared_ptr<uint8_t> args(new uint8_t[argsSize],
std::default_delete<uint8_t[]>());
;
uint8_t *argsPtr = args.get();
memcpy(argsPtr, &oid_, sizeof(oid_));
argsPtr += sizeof(oid_);
memcpy(argsPtr, &this->oid_, sizeof(this->oid_));
argsPtr += sizeof(this->oid_);
memcpy(argsPtr, &tgtPos, sizeof(size_t));
argsPtr += sizeof(size_t);
memcpy(argsPtr, &chunkSize, sizeof(size_t));
Expand Down Expand Up @@ -885,7 +879,7 @@ T Array<T>::At(const size_t pos) {
if (target.first == rt::thisLocality()) {
retValue = data_[target.second];
} else {
AtArgs args{oid_, target.second};
AtArgs args{this->oid_, target.second};
rt::executeAtWithRet(target.first, AtFun, args, &retValue);
}
return retValue;
Expand All @@ -897,7 +891,7 @@ void Array<T>::AsyncAt(rt::Handle &handle, const size_t pos, T *result) {
if (target.first == rt::thisLocality()) {
*result = data_[target.second];
} else {
AtArgs args = {oid_, target.second};
AtArgs args = {this->oid_, target.second};
rt::asyncExecuteAtWithRet(handle, target.first, AsyncAtFun, args, result);
}
}
Expand All @@ -914,7 +908,7 @@ void Array<T>::Apply(const size_t pos, ApplyFunT &&function, Args &... args) {
FunctionTy fn = std::forward<decltype(function)>(function);
using ArgsTuple =
std::tuple<ObjectID, size_t, size_t, FunctionTy, std::tuple<Args...>>;
ArgsTuple argsTuple{oid_, pos, target.second, fn,
ArgsTuple argsTuple{this->oid_, pos, target.second, fn,
std::tuple<Args...>(args...)};

rt::executeAt(target.first, ApplyFunWrapper<ArgsTuple, Args...>, argsTuple);
Expand All @@ -930,7 +924,7 @@ void Array<T>::AsyncApply(rt::Handle &handle, const size_t pos,
FunctionTy fn = std::forward<decltype(function)>(function);
using ArgsTuple =
std::tuple<ObjectID, size_t, size_t, FunctionTy, std::tuple<Args...>>;
ArgsTuple argsTuple{oid_, pos, target.second, fn,
ArgsTuple argsTuple{this->oid_, pos, target.second, fn,
std::tuple<Args...>(args...)};

rt::asyncExecuteAt(handle, target.first,
Expand All @@ -951,7 +945,7 @@ void Array<T>::ForEachInRange(const size_t first, const size_t last,
size_t remainingValues = last - first;
size_t chunkSize = 0;

ArgsTuple argsTuple{oid_, firstPos, tgtPos, fn, std::tuple<Args...>(args...)};
ArgsTuple argsTuple{this->oid_, firstPos, tgtPos, fn, std::tuple<Args...>(args...)};
while (remainingValues > 0) {
if (firstPos < pivot_ * (size_ / rt::numLocalities())) {
tgtLoc = rt::Locality(firstPos / (size_ / rt::numLocalities()));
Expand Down Expand Up @@ -993,7 +987,7 @@ void Array<T>::AsyncForEachInRange(rt::Handle &handle, const size_t first,
size_t remainingValues = last - first;
size_t chunkSize = 0;
// first it
ArgsTuple argsTuple{oid_, firstPos, tgtPos, fn, std::tuple<Args...>(args...)};
ArgsTuple argsTuple{this->oid_, firstPos, tgtPos, fn, std::tuple<Args...>(args...)};

while (remainingValues > 0) {
if (firstPos < pivot_ * (size_ / rt::numLocalities())) {
Expand Down Expand Up @@ -1032,7 +1026,7 @@ void Array<T>::AsyncForEach(rt::Handle &handle, ApplyFunT &&function,
using feArgs = std::tuple<ObjectID, FunctionTy, std::tuple<Args...>>;
using ArgsTuple = std::tuple<T *, FunctionTy, size_t, std::tuple<Args...>>;

feArgs arguments{oid_, fn, std::tuple<Args...>(args...)};
feArgs arguments{this->oid_, fn, std::tuple<Args...>(args...)};

auto feLambda = [](rt::Handle &handle, const feArgs &args) {
auto arrayPtr = Array<T>::GetPtr(std::get<0>(args));
Expand All @@ -1058,7 +1052,7 @@ void Array<T>::ForEach(ApplyFunT &&function, Args &... args) {
using feArgs = std::tuple<ObjectID, FunctionTy, std::tuple<Args...>>;
using ArgsTuple = std::tuple<T *, FunctionTy, size_t, std::tuple<Args...>>;

feArgs arguments{oid_, fn, std::tuple<Args...>(args...)};
feArgs arguments{this->oid_, fn, std::tuple<Args...>(args...)};

auto feLambda = [](const feArgs &args) {
auto arrayPtr = Array<T>::GetPtr(std::get<0>(args));
Expand Down
Loading