20 #include "../../include/genn/third_party/CLI11.hpp" 29 : m_App{
"Generate run application for '" + projectName +
"' user project"},
30 m_Debug(
false), m_CPUOnly(
false), m_Timing(
false), m_ScalarType(
"float"), m_GPUDevice(-1), m_ProjectName(projectName)
32 m_App.add_flag(
"--debug", m_Debug,
"Whether to run in a debugger");
33 auto *cpuOnly = m_App.add_flag(
"--cpu-only", m_CPUOnly,
"Whether to build against single-threaded CPU backend");
34 m_App.add_flag(
"--timing", m_Timing,
"Whether to use GeNN's timing mechanism to measure performance");
35 m_App.add_set(
"--ftype", m_ScalarType, {
"float",
"double"},
"What floating point type to use",
true);
36 m_App.add_option(
"--gpu-device", m_GPUDevice,
"What GPU device ID to use (-1 = select automatically)",
true)->excludes(cpuOnly);
37 m_App.add_option(
"experimentName", m_ExperimentName,
"Experiment name")->required();
46 std::string upperCaseScalarType;
47 std::transform(m_ScalarType.begin(), m_ScalarType.end(), std::back_inserter(upperCaseScalarType), ::toupper);
49 sizes <<
"#pragma once" << std::endl;
50 sizes <<
"#define _FTYPE " <<
"GENN_" << upperCaseScalarType << std::endl;
51 sizes <<
"#define _TIMING " << m_Timing << std::endl;
53 if(m_GPUDevice != -1) {
54 sizes <<
"#define _GPU_DEVICE " << m_GPUDevice << std::endl;
67 m_App.parse(argc, argv);
70 int buildAndRun(std::initializer_list<std::string> runParams = {})
const 76 if (mkdir(
getOutDir().c_str(), S_IRWXU | S_IRWXG | S_IXOTH) == -1) {
77 std::cerr <<
"Directory cannot be created. It may exist already." << std::endl;
82 const int runToolsRetVal =
runTools();
83 if(runToolsRetVal != EXIT_SUCCESS) {
84 return runToolsRetVal;
89 const std::string buildCmd = getBuildCommandWindows();
91 const std::string buildCmd = getBuildCommandUnix();
94 const int buildRetVal = system(buildCmd.c_str());
95 if (buildRetVal != 0){
96 std::cerr <<
"ERROR: Following call failed with status " << buildRetVal <<
":" << std::endl << buildCmd << std::endl;
97 std::cerr <<
"Exiting..." << std::endl;
102 std::cout <<
"running test..." << std::endl;
104 std::string runCmd = getRunCommandWindows();
106 std::string runCmd = getRunCommandUnix();
109 runCmd += (
" " + m_ExperimentName);
112 for(
const auto &p: runParams) {
116 const int runRetVal = system(runCmd.c_str());
118 std::cerr <<
"ERROR: Following call failed with status " << runRetVal <<
":" << std::endl << runCmd << std::endl;
119 std::cerr <<
"Exiting..." << std::endl;
140 std::string
getOutDir()
const{
return m_ExperimentName +
"_output"; }
147 std::string getBuildCommandUnix()
const 149 std::string cmd =
"cd model && genn-buildmodel.sh ";
150 cmd += m_ProjectName +
".cc";
158 const unsigned int numThreads = std::thread::hardware_concurrency();
159 cmd +=
" && make -j " + std::to_string(numThreads) +
" clean all";
160 const int retval = system(cmd.c_str());
162 std::cerr <<
"ERROR: Following call failed with status " << retval <<
":" << std::endl << cmd << std::endl;
163 std::cerr <<
"Exiting..." << std::endl;
170 std::string getBuildCommandWindows()
const 172 std::string cmd =
"cd model && genn-buildmodel.bat ";
173 cmd += m_ProjectName +
".cc";
181 cmd +=
" && msbuild /verbosity:minimal /m " + m_ProjectName +
".sln /t:" + m_ProjectName +
" /p:Configuration=";
191 std::string getRunCommandUnix()
const 195 return "cd model && gdb -tui --args " + m_ProjectName;
198 return "cd model && ./" + m_ProjectName;
202 std::string getRunCommandWindows()
const 205 return "cd model && devenv /debugexe " + m_ProjectName +
"_Debug.exe";
208 return "cd model && " + m_ProjectName +
"_Release.exe";
219 std::string m_ScalarType;
221 std::string m_ExperimentName;
222 const std::string m_ProjectName;
int buildAndRun(std::initializer_list< std::string > runParams={}) const
Definition: generateRun.h:70
int getExitCode(const CLI::ParseError &e)
Definition: generateRun.h:61
virtual void writeSizes(std::ofstream &sizes) const
Definition: generateRun.h:44
GenerateRunBase(const std::string &projectName)
Definition: generateRun.h:28
virtual int runTools() const
Definition: generateRun.h:130
CLI::App & getApp()
Definition: generateRun.h:138
const std::string & getExperimentName() const
Definition: generateRun.h:141
Definition: generateRun.h:25
void parseCommandLine(int argc, char **argv)
Definition: generateRun.h:65
std::string getOutDir() const
Definition: generateRun.h:140