Skip to content
Closed
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: 18 additions & 19 deletions apps/test_suite_runner/AbstractTestSuiteRunner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ limitations under the License.
#include <string>
#include <vector>

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include "ConfigParser.hpp"
#include "StatsModules/IStatsModule.hpp"
#include "osp/bsp/model/BspInstance.hpp"
#include "osp/auxiliary/io/arch_file_reader.hpp"
#include "osp/auxiliary/io/general_file_reader.hpp"
#include "osp/auxiliary/return_status.hpp"
#include "osp/bsp/model/BspInstance.hpp"
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

//#define EIGEN_FOUND 1
// #define EIGEN_FOUND 1

#ifdef EIGEN_FOUND
#include <Eigen/Sparse>
Expand Down Expand Up @@ -83,7 +84,7 @@ class AbstractTestSuiteRunner {

if (write_target_object_to_file) {
output_target_object_dir_path = parser.global_params.get_child("scheduleDirectory")
.get_value<std::string>();
.get_value<std::string>();
if (output_target_object_dir_path.substr(0, 1) != "/")
output_target_object_dir_path = executable_dir + output_target_object_dir_path;
if (!output_target_object_dir_path.empty() && !std::filesystem::exists(output_target_object_dir_path)) {
Expand Down Expand Up @@ -167,13 +168,13 @@ class AbstractTestSuiteRunner {
}
}

virtual RETURN_STATUS compute_target_object_impl(const BspInstance<GraphType> &instance, std::unique_ptr<TargetObjectType>& target_object,
const pt::ptree &algo_config,
long long &computation_time_ms) = 0;
virtual RETURN_STATUS compute_target_object_impl(const BspInstance<GraphType> &instance, std::unique_ptr<TargetObjectType> &target_object,
const pt::ptree &algo_config,
long long &computation_time_ms) = 0;

virtual void create_and_register_statistic_modules(const std::string &module_name) = 0;

virtual void write_target_object_hook(const TargetObjectType&, const std::string &, const std::string &,
virtual void write_target_object_hook(const TargetObjectType &, const std::string &, const std::string &,
const std::string &) {
} // default in case TargetObjectType cannot be written to file

Expand Down Expand Up @@ -250,7 +251,7 @@ class AbstractTestSuiteRunner {
log_stream << "Start Graph: " + filename_graph + "\n";

BspInstance<GraphType> bsp_instance;
bsp_instance.setArchitecture(arch);
bsp_instance.getArchitecture() = arch;
bool graph_status = false;
std::string ext;
if (filename_graph.rfind('.') != std::string::npos)
Expand All @@ -268,12 +269,12 @@ class AbstractTestSuiteRunner {
SM_csc_int64 L_csc_int64{};

if constexpr (std::is_same_v<GraphType, sparse_matrix_graph_int32_t> || std::is_same_v<GraphType, sparse_matrix_graph_int64_t>) {
if (ext != "mtx"){
if (ext != "mtx") {
log_stream << "Error: Only .mtx file is accepted for SpTRSV" << std::endl;
return 0;
}
if constexpr (std::is_same_v<GraphType, sparse_matrix_graph_int32_t>){

if constexpr (std::is_same_v<GraphType, sparse_matrix_graph_int32_t>) {
graph_status = Eigen::loadMarket(L_csr_int32, filename_graph);
if (!graph_status) {
std::cerr << "Failed to read matrix from " << filename_graph << std::endl;
Expand All @@ -297,7 +298,7 @@ class AbstractTestSuiteRunner {
}
} else {
#endif
graph_status = file_reader::readGraph(filename_graph, bsp_instance.getComputationalDag());
graph_status = file_reader::readGraph(filename_graph, bsp_instance.getComputationalDag());

#ifdef EIGEN_FOUND
}
Expand All @@ -309,22 +310,20 @@ class AbstractTestSuiteRunner {

for (auto &algorithm_config_pair : parser.scheduler) {
const pt::ptree &algo_config = algorithm_config_pair.second;



std::string current_algo_name = algo_config.get_child("name").get_value<std::string>();
log_stream << "Start Algorithm " + current_algo_name + "\n";

long long computation_time_ms;
std::unique_ptr<TargetObjectType> target_object;
std::unique_ptr<TargetObjectType> target_object;

RETURN_STATUS exec_status = compute_target_object_impl(bsp_instance, target_object, algo_config, computation_time_ms);

if (exec_status != RETURN_STATUS::OSP_SUCCESS && exec_status != RETURN_STATUS::BEST_FOUND) {
if (exec_status == RETURN_STATUS::ERROR)
log_stream << "Error computing with " << current_algo_name << "." << std::endl;
else if (exec_status == RETURN_STATUS::TIMEOUT)
log_stream << "Scheduler " << current_algo_name << " timed out." << std::endl;
log_stream << "Scheduler " << current_algo_name << " timed out." << std::endl;
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ limitations under the License.
namespace osp {

const std::set<std::string> get_available_bsp_scheduler_names() {
return {"Serial", "GreedyBsp", "GrowLocal", "BspLocking", "Cilk", "Etf", "GreedyRandom",
"GreedyChildren", "Variance", "MultiHC", "LocalSearch", "Coarser", "FullILP", "MultiLevel"};
return {"Serial", "GreedyBsp", "GrowLocal", "BspLocking", "Cilk", "Etf", "GreedyRandom",
"GreedyChildren", "Variance", "MultiHC", "LocalSearch", "Coarser", "FullILP", "MultiLevel"};
}

template<typename Graph_t>
Expand Down Expand Up @@ -247,7 +247,7 @@ RETURN_STATUS run_bsp_scheduler(const ConfigParser &parser, const boost::propert
if (!status)
return RETURN_STATUS::ERROR;

instance_coarse.setArchitecture(instance.getArchitecture());
instance_coarse.getArchitecture() = instance.getArchitecture();
instance_coarse.setNodeProcessorCompatibility(instance.getProcessorCompatibilityMatrix());
BspSchedule<boost_graph_t> schedule_coarse(instance_coarse);

Expand Down
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
56 changes: 56 additions & 0 deletions include/osp/auxiliary/return_status.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2024 Huawei Technologies Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
*/

#pragma once

#include <iostream>

namespace osp {

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

/**
* @brief Converts the enum to a string literal.
* Returns const char* to avoid std::string allocation overhead.
*/
inline const char *to_string(const RETURN_STATUS status) {
switch (status) {
case RETURN_STATUS::OSP_SUCCESS:
return "SUCCESS";
case RETURN_STATUS::BEST_FOUND:
return "BEST FOUND";
case RETURN_STATUS::TIMEOUT:
return "TIMEOUT";
case RETURN_STATUS::ERROR:
return "ERROR";
default:
return "UNKNOWN";
}
}

/**
* @brief Stream operator overload using the helper function.
*/
inline std::ostream &operator<<(std::ostream &os, RETURN_STATUS status) {
return os << to_string(status);
}

} // namespace osp
Loading