Skip to content

Commit

Permalink
Fix to guarantee Bypass mode is more accurate (#123)
Browse files Browse the repository at this point in the history
* add barriers before and after bypass for accuracy

* move bypass flag to DrvAPISysControlVariable
  • Loading branch information
ywwu928 authored Jun 26, 2024
1 parent 0f9c3f1 commit 59fd363
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
10 changes: 10 additions & 0 deletions pando-drv/api/DrvAPIInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ inline int64_t getCoreHartsDone(int64_t pxn_id, int8_t pod_id, int8_t core_id) {
return DrvAPISysConfig::Get()->getCoreHartsDone(pxn_id, pod_id, core_id);
}

inline void clearGlobalBypassFlag() {
return DrvAPISysConfig::Get()->clearGlobalBypassFlag();
}
inline void setGlobalBypassFlag() {
return DrvAPISysConfig::Get()->setGlobalBypassFlag();
}
inline bool getGlobalBypassFlag() {
return DrvAPISysConfig::Get()->getGlobalBypassFlag();
}


} // namespace DrvAPI
#endif
14 changes: 14 additions & 0 deletions pando-drv/api/DrvAPISysConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct DrvAPISysControl
std::vector<std::vector<int64_t>> pod_cores_finalized_; //!< number of cores finalized per pod
std::vector<std::vector<std::vector<int8_t>>> core_state_; //!< state for each core
std::vector<std::vector<std::vector<int64_t>>> core_harts_done_; //!< number of harts done per core

int8_t global_bypass_flag_; //!< global flag to detemine whether to bypass or not
};


Expand All @@ -62,6 +64,7 @@ class DrvAPISysConfig
control_.pod_cores_finalized_.resize(data.num_pxn_);
control_.core_state_.resize(data.num_pxn_);
control_.core_harts_done_.resize(data.num_pxn_);
control_.global_bypass_flag_ = 0;
for (int i = 0; i < data_.num_pxn_; i++) {
control_.pxn_cores_initialized_[i] = 0;
control_.pxn_barrier_exit_[i] = 0;
Expand Down Expand Up @@ -185,6 +188,17 @@ class DrvAPISysConfig
return __atomic_load_n(&(control_.core_harts_done_.at(pxn_id).at(pod_id).at(core_id)), static_cast<int>(std::memory_order_relaxed));
}

void clearGlobalBypassFlag() {
__atomic_store_n(&(control_.global_bypass_flag_), 0, static_cast<int>(std::memory_order_relaxed));
}
void setGlobalBypassFlag() {
__atomic_store_n(&(control_.global_bypass_flag_), 1, static_cast<int>(std::memory_order_relaxed));
}
bool getGlobalBypassFlag() {
int8_t value = __atomic_load_n(&(control_.global_bypass_flag_), static_cast<int>(std::memory_order_relaxed));
return value == 1;
}

static DrvAPISysConfig *Get() { return &sysconfig; }
static DrvAPISysConfig sysconfig;
private:
Expand Down
3 changes: 0 additions & 3 deletions pando-rt/include/pando-rt/drv_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#define PANDO_RT_DRV_INFO_HPP_

#ifdef PANDO_RT_USE_BACKEND_DRVX
#include "DrvAPIMemory.hpp"
#include "DrvAPIThread.hpp"

namespace DrvAPI {
void setStageInit();
Expand All @@ -23,7 +21,6 @@ bool isStageInit();
#define PANDO_DRV_SET_STAGE_OTHER() {DrvAPI::setStageOther();}
#define PANDO_DRV_INCREMENT_PHASE() {DrvAPI::incrementPhase();}

extern bool bypass_flag;
void setBypassFlag();
void clearBypassFlag();
bool getBypassFlag();
Expand Down
11 changes: 10 additions & 1 deletion pando-rt/include/pando-rt/sync/wait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,17 @@ void monitorUntilNot(GlobalPtr<T> ptr, T value) {
#endif
}

#ifdef PANDO_RT_USE_BACKEND_DRVX
/**
* @brief Waits for all tasks to finish executing.
* @brief A specific node waits for all tasks to finish executing.
*
* @ingroup ROOT
*/
PANDO_RT_EXPORT void waitAllTasks();
#endif

/**
* @brief All nodes wait for all tasks to finish executing.
*
* @note This is a collective operation and needs to be called by all nodes.
*
Expand Down
9 changes: 6 additions & 3 deletions pando-rt/src/drv_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef PANDO_RT_USE_BACKEND_DRVX
#include "pando-rt/drv_info.hpp"
#include <pando-rt/pando-rt.hpp>
#include "drvx/drvx.hpp"

namespace DrvAPI {

Expand Down Expand Up @@ -137,12 +138,14 @@ void incrementPhase() {

bool bypass_flag = false;
void setBypassFlag() {
bypass_flag = true;
pando::waitAllTasks();
DrvAPI::setGlobalBypassFlag();
}
void clearBypassFlag() {
bypass_flag = false;
pando::waitAllTasks();
DrvAPI::clearGlobalBypassFlag();
}
bool getBypassFlag() {
return bypass_flag;
return DrvAPI::getGlobalBypassFlag();
}
#endif // PANDO_RT_USE_BACKEND_DRVX
24 changes: 17 additions & 7 deletions pando-rt/src/wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ void waitUntil(const Function<bool()>& f) {
#endif
}

#ifdef PANDO_RT_USE_BACKEND_DRVX
void waitAllTasks() {
if (!isOnCP()) {
PANDO_ABORT("Can only be called from the CP");
}

for (std::int64_t i = 0; i < Drvx::getNodeDims().id; i++) {
for (std::int64_t j = 0; j < Drvx::getPodDims().x; j++) {
while (DrvAPI::getPodTasksRemaining(i, j) != 0) {
hartYield(1000);
}
}
}
}
#endif

void waitAll() {
if (!isOnCP()) {
PANDO_ABORT("Can only be called from the CP");
Expand Down Expand Up @@ -89,13 +105,7 @@ void waitAll() {
#endif
#elif defined(PANDO_RT_USE_BACKEND_DRVX)
CommandProcessor::barrier();
for (std::int64_t i = 0; i < Drvx::getNodeDims().id; i++) {
for (std::int64_t j = 0; j < Drvx::getPodDims().x; j++) {
while (DrvAPI::getPodTasksRemaining(i, j) != 0) {
hartYield(1000);
}
}
}
waitAllTasks();
CommandProcessor::barrier();
#endif
}
Expand Down

0 comments on commit 59fd363

Please sign in to comment.