cadmium-dynamic-devstone.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Copyright (c) 2019, Juan Lanuza
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * 1. Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  17. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. * POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <iostream>
  26. #include <chrono>
  27. #include <algorithm>
  28. #include <boost/program_options.hpp>
  29. #include <cadmium/engine/pdevs_dynamic_runner.hpp>
  30. #include "dynamic/LI_generator.cpp"
  31. #include "dynamic/HI_generator.cpp"
  32. #include "dynamic/HO_generator.cpp"
  33. #include "dynamic/HOmod_generator.cpp"
  34. namespace po=boost::program_options;
  35. using hclock=std::chrono::high_resolution_clock;
  36. using Time=float;
  37. int main(int argc, char* argv[]){
  38. // Declare the supported options.
  39. po::options_description desc("Allowed options");
  40. desc.add_options()
  41. ("help", "produce help message")
  42. ("kind", po::value<std::string>()->required(), "set kind of devstone: LI, HI, HO or HOmod")
  43. ("width", po::value<int>()->required(), "set width of the DEVStone: integer value")
  44. ("depth", po::value<int>()->required(), "set depth of the DEVStone: integer value")
  45. ("int-cycles", po::value<int>()->required(), "set the Dhrystone cycles to expend in internal transtions: integer value")
  46. ("ext-cycles", po::value<int>()->required(), "set the Dhrystone cycles to expend in external transtions: integer value")
  47. ("time-advance", po::value<int>()->default_value(0), "set the time expend in external transtions by the Dhrystone in miliseconds: integer value")
  48. #ifdef CADMIUM_EXECUTE_CONCURRENT
  49. ("threads", po::value<int>()->required(), "amount of threads to use")
  50. #endif //CADMIUM_EXECUTE_CONCURRENT
  51. ;
  52. po::variables_map vm;
  53. try {
  54. po::store(po::parse_command_line(argc, argv, desc), vm);
  55. po::notify(vm);
  56. } catch ( boost::program_options::required_option be ){
  57. if (vm.count("help")) {
  58. std::cout << desc << "\n";
  59. return 0;
  60. } else {
  61. std::cout << be.what() << std::endl;
  62. std::cout << std::endl;
  63. std::cout << "for mode information run: " << argv[0] << " --help" << std::endl;
  64. return 1;
  65. }
  66. }
  67. std::string kind = vm["kind"].as<std::string>();
  68. if (kind.compare("LI") != 0 && kind.compare("HI") != 0 &&
  69. kind.compare("HO") != 0 && kind.compare("HOmod") != 0) {
  70. std::cout << "The kind needs to be LI, HI, HO or HOmod and received value was: " << kind << std::endl;
  71. std::cout << "for mode information run: " << argv[0] << " --help" << std::endl;
  72. return 1;
  73. }
  74. int width = vm["width"].as<int>();
  75. int depth = vm["depth"].as<int>();
  76. int int_cycles = vm["int-cycles"].as<int>();
  77. int ext_cycles = vm["ext-cycles"].as<int>();
  78. int time_advance = vm["time-advance"].as<int>();
  79. #ifdef CADMIUM_EXECUTE_CONCURRENT
  80. int threads = vm["threads"].as<int>();
  81. #endif //CADMIUM_EXECUTE_CONCURRENT
  82. //finished processing input
  83. auto processed_parameters = hclock::now();
  84. std::shared_ptr<cadmium::dynamic::modeling::coupled<Time>> TOP_coupled;
  85. if (kind == "LI"){
  86. TOP_coupled = create_LI_model(width,depth, ext_cycles, int_cycles, time_advance);
  87. } else if (kind == "HI") {
  88. TOP_coupled = create_HI_model(width, depth, ext_cycles, int_cycles, time_advance);
  89. } else if (kind == "HO") {
  90. TOP_coupled = create_HO_model(width,depth, ext_cycles, int_cycles, time_advance);
  91. } else if (kind == "HOmod") {
  92. TOP_coupled = create_HOmod_model(width,depth, ext_cycles, int_cycles, time_advance);
  93. } else {
  94. abort();
  95. }
  96. auto model_init = hclock::now();
  97. std::cout << "Model creation time: " << std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>( model_init - processed_parameters).count() << " seconds" << std::endl;
  98. #ifdef CADMIUM_EXECUTE_CONCURRENT
  99. cadmium::dynamic::engine::runner<Time, cadmium::logger::not_logger> r(TOP_coupled, 0.0, threads);
  100. #else
  101. cadmium::dynamic::engine::runner<TIME, cadmium::logger::not_logger> r(TOP_coupled, 0.0);
  102. #endif //CADMIUM_EXECUTE_CONCURRENT
  103. auto runner_init = hclock::now();
  104. std::cout << "Engine setup time: " << std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>(runner_init - model_init).count() << " seconds" << std::endl;
  105. r.run_until(1000000);
  106. auto finished_simulation = hclock::now();
  107. std::cout << "Simulation time: " << std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>(finished_simulation - runner_init).count() << " seconds" << std::endl;
  108. }