Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
44 changes: 22 additions & 22 deletions include/osp/auxiliary/io/arch_file_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ limitations under the License.

#pragma once

#include "osp/bsp/model/BspArchitecture.hpp"
#include <fstream>
#include <iostream>
#include <sstream>
#include "osp/bsp/model/BspArchitecture.hpp"

namespace osp { namespace file_reader {

Expand All @@ -31,7 +31,8 @@ bool readBspArchitecture(std::ifstream &infile, BspArchitecture<Graph_t> &archit

// Skip comment lines
while (std::getline(infile, line)) {
if (!line.empty() && line[0] != '%') break;
if (!line.empty() && line[0] != '%')
break;
}

// Parse architecture parameters
Expand All @@ -58,24 +59,24 @@ bool readBspArchitecture(std::ifstream &infile, BspArchitecture<Graph_t> &archit
if (0 <= mem_type && mem_type <= 3) {
using memw_t = v_memw_t<Graph_t>;
switch (mem_type) {
case 0:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::NONE);
break;
case 1:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::LOCAL);
architecture.setMemoryBound(static_cast<memw_t>(M));
break;
case 2:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::GLOBAL);
architecture.setMemoryBound(static_cast<memw_t>(M));
break;
case 3:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::PERSISTENT_AND_TRANSIENT);
architecture.setMemoryBound(static_cast<memw_t>(M));
break;
default:
std::cerr << "Invalid memory type.\n";
return false;
case 0:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::NONE);
break;
case 1:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::LOCAL);
architecture.setMemoryBound(static_cast<memw_t>(M));
break;
case 2:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::GLOBAL);
architecture.setMemoryBound(static_cast<memw_t>(M));
break;
case 3:
architecture.setMemoryConstraintType(MEMORY_CONSTRAINT_TYPE::PERSISTENT_AND_TRANSIENT);
architecture.setMemoryBound(static_cast<memw_t>(M));
break;
default:
std::cerr << "Invalid memory type.\n";
return false;
}
} else if (mem_type == -1) {
std::cout << "No memory type specified. Assuming \"NONE\".\n";
Expand Down Expand Up @@ -116,7 +117,7 @@ bool readBspArchitecture(std::ifstream &infile, BspArchitecture<Graph_t> &archit
return false;
}

architecture.setSendCosts(fromProc, toProc, static_cast<v_commw_t<Graph_t>>(value));
architecture.SetSendCosts(fromProc, toProc, static_cast<v_commw_t<Graph_t>>(value));
}

// Ensure there are no remaining non-comment lines
Expand All @@ -127,7 +128,6 @@ bool readBspArchitecture(std::ifstream &infile, BspArchitecture<Graph_t> &archit
}
}

architecture.computeCommAverage();
return true;
}

Expand Down
794 changes: 429 additions & 365 deletions include/osp/bsp/model/BspArchitecture.hpp

Large diffs are not rendered by default.

76 changes: 49 additions & 27 deletions include/osp/bsp/model/BspInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ limitations under the License.

namespace osp {

enum class RETURN_STATUS { OSP_SUCCESS, BEST_FOUND, TIMEOUT, ERROR };
enum class RETURN_STATUS { OSP_SUCCESS,
BEST_FOUND,
TIMEOUT,
ERROR };

inline std::string to_string(const RETURN_STATUS status) {
switch (status) {
Expand All @@ -44,13 +47,23 @@ inline std::string to_string(const RETURN_STATUS status) {
}
}

inline std::ostream& operator<<(std::ostream& os, RETURN_STATUS status) {
inline std::ostream &operator<<(std::ostream &os, RETURN_STATUS status) {
switch (status) {
case RETURN_STATUS::OSP_SUCCESS: os << "SUCCESS"; break;
case RETURN_STATUS::BEST_FOUND: os << "BEST_FOUND"; break;
case RETURN_STATUS::TIMEOUT: os << "TIMEOUT"; break;
case RETURN_STATUS::ERROR: os << "ERROR"; break;
default: os << "UNKNOWN"; break;
case RETURN_STATUS::OSP_SUCCESS:
os << "SUCCESS";
break;
case RETURN_STATUS::BEST_FOUND:
os << "BEST_FOUND";
break;
case RETURN_STATUS::TIMEOUT:
os << "TIMEOUT";
break;
case RETURN_STATUS::ERROR:
os << "ERROR";
break;
default:
os << "UNKNOWN";
break;
}
return os;
}
Expand Down Expand Up @@ -195,10 +208,24 @@ class BspInstance {
*
* @return A copy of the send costs matrix.
*/
inline const std::vector<std::vector<v_commw_t<Graph_t>>> &sendCostMatrix() const {
/**
* @brief Returns a copy of the send costs matrix.
*
* @return A copy of the send costs matrix.
*/
inline std::vector<std::vector<v_commw_t<Graph_t>>> sendCostMatrix() const {
return architecture.sendCostMatrix();
}

/**
* @brief Returns the flattened send costs vector.
*
* @return The flattened send costs vector.
*/
inline const std::vector<v_commw_t<Graph_t>> &sendCostsVector() const {
return architecture.sendCostsVector();
}

/**
* @brief Returns the communication costs of the BSP architecture.
*
Expand Down Expand Up @@ -389,53 +416,48 @@ class BspInstance {
};

template<typename Graph_t>
class compatible_processor_range {
class CompatibleProcessorRange {

std::vector<std::vector<unsigned>> type_processor_idx;
const BspInstance<Graph_t> *instance = nullptr;

public:
public:
CompatibleProcessorRange() = default;

compatible_processor_range() = default;

compatible_processor_range(const BspInstance<Graph_t> &inst) {
CompatibleProcessorRange(const BspInstance<Graph_t> &inst) {
initialize(inst);
}

inline void initialize(const BspInstance<Graph_t> &inst) {

instance = &inst;

if constexpr (has_typed_vertices_v<Graph_t>) {
if constexpr (has_typed_vertices_v<Graph_t>) {

type_processor_idx = std::vector<std::vector<unsigned>>(inst.getComputationalDag().num_vertex_types());

for (v_type_t<Graph_t> v_type = 0; v_type < inst.getComputationalDag().num_vertex_types(); v_type++) {
for (unsigned proc = 0; proc < inst.numberOfProcessors(); proc++)
if (inst.isCompatibleType(v_type, inst.processorType(proc)))
type_processor_idx[v_type].push_back(proc);

for (unsigned proc = 0; proc < inst.numberOfProcessors(); proc++)
if (inst.isCompatibleType(v_type, inst.processorType(proc)))
type_processor_idx[v_type].push_back(proc);
}
}
}
}

inline const auto & compatible_processors_type(v_type_t<Graph_t> type) const {
inline const auto &compatible_processors_type(v_type_t<Graph_t> type) const {

assert(instance != nullptr);

if constexpr (has_typed_vertices_v<Graph_t>) {
return type_processor_idx[type];
return type_processor_idx[type];
} else {
return instance->processors();
}
}

inline const auto & compatible_processors_vertex(vertex_idx_t<Graph_t> vertex) const {
inline const auto &compatible_processors_vertex(vertex_idx_t<Graph_t> vertex) const {
return compatible_processors_type(instance->getComputationalDag().vertex_type(vertex));
}


};


} // namespace osp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ limitations under the License.

namespace osp {

static constexpr unsigned CacheLineSize = 64;

template<typename vert_t, typename weight_t>
struct GrowLocalAutoCoresParallel_Params {
vert_t minSuperstepSize = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct kl_bsp_comm_cost_function {
constexpr static bool is_max_comm_cost_function = true;

kl_active_schedule<Graph_t, cost_t, MemoryConstraint_t> *active_schedule;
compatible_processor_range<Graph_t> *proc_range;
CompatibleProcessorRange<Graph_t> *proc_range;
const Graph_t *graph;
const BspInstance<Graph_t> *instance;

Expand All @@ -119,7 +119,7 @@ struct kl_bsp_comm_cost_function {
}

void initialize(kl_active_schedule<Graph_t, cost_t, MemoryConstraint_t> &sched,
compatible_processor_range<Graph_t> &p_range) {
CompatibleProcessorRange<Graph_t> &p_range) {
active_schedule = &sched;
proc_range = &p_range;
instance = &sched.getInstance();
Expand Down
Loading