Skip to content

Commit

Permalink
Allow input files to include multiple rows of parameters and select a…
Browse files Browse the repository at this point in the history
…t runtime
  • Loading branch information
ptheywood committed Oct 31, 2024
1 parent 931251d commit 7f58c84
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/exateppabm/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ void setup(CLI::App& app, std::shared_ptr<exateppabm::cli::params> params) {
app.add_option("-d, --device", params->device, "CUDA Device ordinal (GPU) to use (0 indexed)");
app.add_flag("-v, --verbose", params->verbosity, "Verbosity of simulation output, forwarded to FLAME GPU 2");
app.add_option("-i, --input-file", params->inputParamFile, "Path to input parameters file");
app.add_option("-n, --param-number", params->inputParamLine, "The line from the parameters file to use. 1 indexed (assuming there is a header)");

app.add_option("-o, --output-dir", params->outputDir, "Path to output directory");
}

Expand Down
4 changes: 4 additions & 0 deletions src/exateppabm/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct params {
* Path to the input parameter file to read model parameters from
*/
std::string inputParamFile;
/**
* Line number from the input paramater file to use. 1 indexed (assuming a header which is discared)
*/
int inputParamLine = 1;
/**
* Path to directory for file output
*/
Expand Down
2 changes: 1 addition & 1 deletion src/exateppabm/exatepp_abm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int entrypoint(int argc, char* argv[]) {
perfFile.timers.configParsing.start();

// Parse the provided path to an input file
auto config = exateppabm::input::read(cli_params->inputParamFile);
auto config = exateppabm::input::read(cli_params->inputParamFile, cli_params->inputParamLine);

// @temp - print the parsed config.
exateppabm::input::print(*config);
Expand Down
16 changes: 10 additions & 6 deletions src/exateppabm/input.cu
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool valueFromCSVLine(std::string& line, T& value) {

} // anon namespace

std::shared_ptr<exateppabm::input::config> read(const std::filesystem::path p) {
std::shared_ptr<exateppabm::input::config> read(const std::filesystem::path p, const int lineNumber) {
// Construct the model parameters / config struct
auto c = std::make_shared<config>();

Expand Down Expand Up @@ -73,7 +73,15 @@ std::shared_ptr<exateppabm::input::config> read(const std::filesystem::path p) {
throw std::runtime_error("failed to read the header line @todo nicer error message");
}

// Read the 2nd line of the file which contains the parameter values
// Discard rows until the line number is the target line number
int currentLine = 1;
for (int currentLine = 0; currentLine < lineNumber; currentLine++) {
if (!std::getline(fs, line)) {
throw std::runtime_error("Bad parameters file lineNumber @todo nicer errors");
}
}

// Read the next line of the file which should contains the parameter values
if (std::getline(fs, line)) {
// Extract values from the line in the expected order, into the params struct
// Error if any were missing / bad
Expand Down Expand Up @@ -126,10 +134,6 @@ std::shared_ptr<exateppabm::input::config> read(const std::filesystem::path p) {
throw std::runtime_error("failed to read the paramameter value line @todo nicer error message");
}





fs.close();
if (!valid_input_file) {
throw std::runtime_error("Bad input file @todo nicer error message");
Expand Down
3 changes: 2 additions & 1 deletion src/exateppabm/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ struct config {
* Read simulation parameters from a CSV file
*
* @param p path to load parameters from
* @param lineNumber the line of CSV to use.
* @return shared pointer to a configuration object
* @todo - support CSVs with multiple simulations, reading a single row
*/
std::shared_ptr<exateppabm::input::config> read(std::filesystem::path p);
std::shared_ptr<exateppabm::input::config> read(std::filesystem::path p, int lineNumber);

/**
* Print the loaded simulation configuration to stdout for validation
Expand Down
2 changes: 1 addition & 1 deletion src/exateppabm/output/PerformanceFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ bool PerformanceFile::write() {
fmt::print(_handle, " \"n_total\": {},\n", this->metadata.n_total);
fmt::print(_handle, " \"totalProgram\": {},\n", this->timers.totalProgram.getElapsedSeconds());
fmt::print(_handle, " \"configParsing\": {},\n", this->timers.configParsing.getElapsedSeconds());
fmt::print(_handle, " \"simulate\": {},\n", this->timers.simulate.getElapsedSeconds());
fmt::print(_handle, " \"preSimulate\": {},\n", this->timers.preSimulate.getElapsedSeconds());
fmt::print(_handle, " \"simulate\": {},\n", this->timers.simulate.getElapsedSeconds());
fmt::print(_handle, " \"postSimulate\": {},\n", this->timers.postSimulate.getElapsedSeconds());
fmt::print(_handle, " \"flamegpuRTCElapsed\": {},\n", this->timers.flamegpuRTCElapsed);
fmt::print(_handle, " \"flamegpuInitElapsed\": {},\n", this->timers.flamegpuInitElapsed);
Expand Down
8 changes: 4 additions & 4 deletions src/exateppabm/output/PerformanceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ class PerformanceFile : public OutputFile {
* Steady clock timer for config parsing
*/
flamegpu::detail::SteadyClockTimer configParsing;
/**
* Steady clock timer for simulate()
*/
flamegpu::detail::SteadyClockTimer simulate;
/**
* Steady clock timer for model construction
*/
flamegpu::detail::SteadyClockTimer preSimulate;
/**x
* Steady clock timer for simulate()
*/
flamegpu::detail::SteadyClockTimer simulate;
/**
* Steady clock timer for post simulation (excluding output of this file)
*/
Expand Down

0 comments on commit 7f58c84

Please sign in to comment.