Commit fc81a152 authored by CARDOSI Paul's avatar CARDOSI Paul
Browse files

Change sendWorkersTo signature so that it takes a reference to the other...

Change sendWorkersTo signature so that it takes a reference to the other compute engine. Renamings in comments.
parent a3a176d6
......@@ -222,9 +222,11 @@ public:
addWorkersInternal<true>(std::move(inWorkers));
}
void sendWorkersTo(SpComputeEngine* otherCe, const SpWorker::SpWorkerType wt, const size_t maxCount, const bool allowBusyWorkersToBeDetached) {
if(otherCe && otherCe != this) {
otherCe->addWorkersInternal<false>(sendWorkersToInternal(otherCe, wt, maxCount, allowBusyWorkersToBeDetached));
void sendWorkersTo(SpComputeEngine& otherCe, const SpWorker::SpWorkerType wt, const size_t maxCount, const bool allowBusyWorkersToBeDetached) {
SpComputeEngine* otherCePtr = std::addressof(otherCe);
if(otherCePtr && otherCePtr != this) {
otherCePtr->addWorkersInternal<false>(sendWorkersToInternal(otherCePtr, wt, maxCount, allowBusyWorkersToBeDetached));
}
}
......
......@@ -179,14 +179,14 @@ constexpr SpScalarDataMode<SpDataAccessMode::PARALLEL_WRITE, DepType&> SpParalle
template <class DepType>
constexpr SpScalarDataMode<SpDataAccessMode::COMMUTATIVE_WRITE, DepType&> SpCommutativeWrite(DepType& inDep){
static_assert(std::is_const<DepType>::value == false, "Commute Write cannot be done on const value");
static_assert(std::is_const<DepType>::value == false, "Commutative Write cannot be done on const value");
return SpScalarDataMode<SpDataAccessMode::COMMUTATIVE_WRITE, DepType&>(inDep);
}
template <class DepType>
constexpr SpScalarDataMode<SpDataAccessMode::POTENTIAL_WRITE, DepType&> SpPotentialWrite(DepType& inDep){
static_assert(std::is_const<DepType>::value == false, "Maybe Write cannot be done on const value");
static_assert(SpDataCanBeDuplicate<DepType>::value, "Maybe write data must be duplicatable");
static_assert(std::is_const<DepType>::value == false, "Potential write cannot be done on const value");
static_assert(SpDataCanBeDuplicate<DepType>::value, "Potentially written to data must be duplicatable");
return SpScalarDataMode<SpDataAccessMode::POTENTIAL_WRITE, DepType&>(inDep);
}
......
......@@ -73,11 +73,11 @@ public:
assert(idTaskWrite == useTaskId);
return true;
}
// If it is commute
// If it is commutative
else if(accessMode == SpDataAccessMode::COMMUTATIVE_WRITE){
// The number of already user tasks must be less than the number of register tasks
assert(nbTasksInUsed < static_cast<long int>(idTasksMultiple.size()));
// In commute their must be only 0 or 1 usage at a time
// In commutative mode there must be only 0 or 1 usage at a time
assert(nbTasksInUsed-nbTasksReleased >= 0 && nbTasksInUsed-nbTasksReleased <= 1);
// The given task must exist in the list
assert(std::find(idTasksMultiple.begin(), idTasksMultiple.end(), useTaskId) != idTasksMultiple.end());
......@@ -87,13 +87,13 @@ public:
// Return true if no task uses the data
return nbTasksInUsed-nbTasksReleased == 0;
}
// If it is not write and not commute
// If it is not write and not commutative
else {
// The number of already user tasks must be less than the number of register tasks
assert(nbTasksInUsed < static_cast<long int>(idTasksMultiple.size()));
// The given task must exist in the list
assert(std::find(idTasksMultiple.begin(), idTasksMultiple.end(), useTaskId) != idTasksMultiple.end());
SpDebugPrint() << "[SpDependence]Is not in commute and not in write, test existence among " << idTasksMultiple.size() << " tasks";
SpDebugPrint() << "[SpDependence]Is not in commutative and not in write, test existence among " << idTasksMultiple.size() << " tasks";
SpDebugPrint() << "[SpDependence]Found " << (std::find(idTasksMultiple.begin(), idTasksMultiple.end(), useTaskId) != idTasksMultiple.end());
return true;
}
......
......@@ -50,8 +50,8 @@ class SpTaskManager{
//! Number of finished tasks
std::atomic<int> nbFinishedTasks;
//! To protect commute locking
std::mutex mutexCommute;
//! To protect commutative data accesses
std::mutex mutexCommutative;
small_vector<SpAbstractTask*> readyTasks;
......@@ -61,14 +61,14 @@ class SpTaskManager{
aTask->takeControl();
if(aTask->isState(SpTaskState::WAITING_TO_BE_READY)){
SpDebugPrint() << "Is waiting to be ready " << aTask->getId();
const bool useCommute = aTask->hasMode(SpDataAccessMode::COMMUTATIVE_WRITE);
if(useCommute){
mutexCommute.lock();
const bool hasCommutativeAccessMode = aTask->hasMode(SpDataAccessMode::COMMUTATIVE_WRITE);
if(hasCommutativeAccessMode){
mutexCommutative.lock();
}
if(aTask->dependencesAreReady()){
aTask->useDependences();
if(useCommute){
mutexCommute.unlock();
if(hasCommutativeAccessMode){
mutexCommutative.unlock();
}
SpDebugPrint() << "Was not in ready list " << aTask->getId();
......@@ -92,8 +92,8 @@ class SpTaskManager{
else{
SpDebugPrint() << " not ready yet " << aTask->getId();
aTask->releaseControl();
if(useCommute){
mutexCommute.unlock();
if(hasCommutativeAccessMode){
mutexCommutative.unlock();
}
}
}
......
......@@ -98,10 +98,10 @@ protected:
inline static constexpr bool is_data_dependency_v = is_data_dependency<T>::value;
template <class... ParamsTy>
using contains_maybe_write_dependencies = std::disjunction<access_modes_are_equal<SpDataAccessMode::POTENTIAL_WRITE, ParamsTy>...>;
using contains_potential_write_dependencies = std::disjunction<access_modes_are_equal<SpDataAccessMode::POTENTIAL_WRITE, ParamsTy>...>;
template <class... ParamsTy>
inline static constexpr bool contains_maybe_write_dependencies_v = contains_maybe_write_dependencies<ParamsTy...>::value;
inline static constexpr bool contains_potential_write_dependencies_v = contains_potential_write_dependencies<ParamsTy...>::value;
template <typename Func, class T0, class T1, class... ParamsTy,
typename=std::enable_if_t<
......@@ -218,9 +218,9 @@ protected:
static_assert(std::is_invocable_v<decltype(t2.getCallableRef()), decltype(params.getView())...>,
"SpTaskGraph::task Cpu callable is not invocable with data dependencies.");
constexpr bool isPotentialTask = contains_maybe_write_dependencies_v<ParamsTy...>;
constexpr bool isPotentialTask = contains_potential_write_dependencies_v<ParamsTy...>;
static_assert(isSpeculativeTaskGraph || !isPotentialTask, "SpTaskGraph::task of non speculative task graph should not be given maybe-write data dependencies.");
static_assert(isSpeculativeTaskGraph || !isPotentialTask, "SpTaskGraph::task of non speculative task graph should not be given potential-write data dependencies.");
static_assert(!(probabilityArgWasGivenByUser && !isPotentialTask),
"SpTaskGraph::task no probability should be specified for normal tasks.");
......@@ -255,9 +255,9 @@ protected:
static_assert(std::is_invocable_v<decltype(t2.getCallableRef()), decltype(params.getView())...>,
"SpTaskGraph::task callable is not invocable with data dependencies.");
constexpr bool isPotentialTask = contains_maybe_write_dependencies_v<ParamsTy...>;
constexpr bool isPotentialTask = contains_potential_write_dependencies_v<ParamsTy...>;
static_assert(isSpeculativeTaskGraph || !isPotentialTask, "SpTaskGraph::task of non speculative task graph should not be given maybe-write data dependencies.");
static_assert(isSpeculativeTaskGraph || !isPotentialTask, "SpTaskGraph::task of non speculative task graph should not be given potential-write data dependencies.");
static_assert(!(probabilityArgWasGivenByUser && !isPotentialTask),
"SpTaskGraph::task no probability should be specified for normal tasks.");
......@@ -592,13 +592,13 @@ private:
small_vector<const void *> originalAddresses;
constexpr const unsigned char maybeWriteFlags = 1 << static_cast<unsigned char>(SpDataAccessMode::POTENTIAL_WRITE);
constexpr const unsigned char potentialWriteFlags = 1 << static_cast<unsigned char>(SpDataAccessMode::POTENTIAL_WRITE);
constexpr const unsigned char writeFlags = 1 << static_cast<unsigned char>(SpDataAccessMode::WRITE)
| 1 << static_cast<unsigned char>(SpDataAccessMode::COMMUTATIVE_WRITE)
| 1 << static_cast<unsigned char>(SpDataAccessMode::PARALLEL_WRITE);
auto originalAddressesOfMaybeWrittenHandles = getOriginalAddressesOfHandlesWithAccessModes<maybeWriteFlags>(std::forward<DataDependencyTupleTy>(dataDepTuple));
auto originalAddressesOfPotentiallyWrittenHandles = getOriginalAddressesOfHandlesWithAccessModes<potentialWriteFlags>(std::forward<DataDependencyTupleTy>(dataDepTuple));
auto originalAddressesOfWrittenHandles = getOriginalAddressesOfHandlesWithAccessModes<writeFlags>(std::forward<DataDependencyTupleTy>(dataDepTuple));
if(executionPaths.empty()) {
......@@ -685,7 +685,7 @@ private:
std::forward<DataDependencyTupleTy>(dataDepTuple), std::forward<CallableTupleTy>(callableTuple));
if constexpr(isPotentialTask) {
setExecutionPathForOriginalAddressesInHashMap(e, originalAddressesOfMaybeWrittenHandles);
setExecutionPathForOriginalAddressesInHashMap(e, originalAddressesOfPotentiallyWrittenHandles);
}
if constexpr(SpecModel == SpSpeculativeModel::SP_MODEL_1) {
......@@ -783,7 +783,7 @@ private:
if constexpr(isPotentialTask) {
specGroupSpecTask->setProbability(inProbability);
currentSpecGroup = specGroupSpecTask.get();
l1 = copyIfMaybeWriteAndNotDuplicateOrUsedInRead(std::array<CopyMapPtrTy, 1>{std::addressof(*it)},
l1 = copyIfPotentialWriteAndNotDuplicateOrUsedInRead(std::array<CopyMapPtrTy, 1>{std::addressof(*it)},
specGroupSpecTask->getActivationStateForCopyTasks(),
inPriority,
std::forward<DataDependencyTupleTy>(dataDepTuple));
......@@ -800,7 +800,7 @@ private:
if constexpr(isPotentialTask && SpecModel != SpSpeculativeModel::SP_MODEL_2) {
currentSpecGroup = specGroupSpecTask.get();
l1p = copyIfMaybeWriteAndDuplicate(std::array<CopyMapPtrTy, 3>{std::addressof(l1), std::addressof(l2), std::addressof(*it)},
l1p = copyIfPotentialWriteAndDuplicate(std::array<CopyMapPtrTy, 3>{std::addressof(l1), std::addressof(l2), std::addressof(*it)},
specGroupSpecTask->getActivationStateForCopyTasks(),
inPriority, std::forward<DataDependencyTupleTy>(dataDepTuple));
currentSpecGroup = nullptr;
......@@ -876,14 +876,14 @@ private:
currentSpecGroup = specGroupNormalTask.get();
if constexpr(SpecModel == SpSpeculativeModel::SP_MODEL_1) {
if(speculativeTasks.empty()) {
l1p = copyIfMaybeWriteAndDuplicate(std::array<CopyMapPtrTy, 1>{std::addressof(emptyCopyMap)},
l1p = copyIfPotentialWriteAndDuplicate(std::array<CopyMapPtrTy, 1>{std::addressof(emptyCopyMap)},
specGroupNormalTask->getActivationStateForCopyTasks(),
inPriority,
std::forward<DataDependencyTupleTy>(dataDepTuple));
it->merge(l1p);
}
}else{
l1p = copyIfMaybeWriteAndDuplicate(std::array<CopyMapPtrTy, 1>{std::addressof(emptyCopyMap)},
l1p = copyIfPotentialWriteAndDuplicate(std::array<CopyMapPtrTy, 1>{std::addressof(emptyCopyMap)},
specGroupNormalTask->getActivationStateForCopyTasks(),
inPriority,
std::forward<DataDependencyTupleTy>(dataDepTuple));
......@@ -1039,7 +1039,7 @@ private:
using TargetParamType = typename std::remove_reference<ObjectType>::type;
static_assert(std::is_default_constructible<TargetParamType>::value && std::is_copy_assignable<TargetParamType>::value,
"Maybewrite data must be copiable");
"Potentially written to data must be copiable");
TargetParamType* ptr = new TargetParamType();
const TargetParamType* originPtr = &objectToCopy;
......@@ -1154,7 +1154,7 @@ private:
}
template <class Tuple, std::size_t N>
inline auto copyIfMaybeWriteAndNotDuplicateOrUsedInRead(const std::array<CopyMapPtrTy, N>& copyMapsToLookInto,
inline auto copyIfPotentialWriteAndNotDuplicateOrUsedInRead(const std::array<CopyMapPtrTy, N>& copyMapsToLookInto,
const SpTaskActivation initialActivationState,
const SpPriority& inPriority,
Tuple& args){
......@@ -1162,7 +1162,7 @@ private:
}
template <class Tuple, std::size_t N>
inline auto copyIfMaybeWriteAndDuplicate(const std::array<CopyMapPtrTy, N>& copyMapsToLookInto,
inline auto copyIfPotentialWriteAndDuplicate(const std::array<CopyMapPtrTy, N>& copyMapsToLookInto,
const SpTaskActivation initialActivationState,
const SpPriority& inPriority,
Tuple& args){
......
......@@ -89,7 +89,7 @@ class ComputeEngineTest : public UTester< ComputeEngineTest > {
tg2.waitAllTasks();
ce2.sendWorkersTo(std::addressof(ce1), SpWorker::SpWorkerType::CPU_WORKER, 3, true);
ce2.sendWorkersTo(ce1, SpWorker::SpWorkerType::CPU_WORKER, 3, true);
tg1.waitAllTasks();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment