From 8d67c81132fdf90090c888b53f51b3729805fbc4 Mon Sep 17 00:00:00 2001 From: Adriano Garcia Date: Tue, 27 Sep 2022 17:13:09 -0300 Subject: [PATCH 1/2] Adding v.04.3-alpha --- Changelog.txt | 6 + benchmarks/benchmarks_registry.json | 16 +- .../bzip2/grppi/bzip2_grppi_farm/bzip2.hpp | 36 ++ .../bzip2_grppi_farm/bzip2_grppi_farm.cpp | 87 ++++ .../bzip2/grppi/bzip2_grppi_farm/config.json | 32 ++ .../operators/include/compress_op.hpp | 24 + .../operators/include/decompress_op.hpp | 24 + .../bzip2_grppi_farm/operators/operators.json | 4 + .../operators/src/compress_op.cpp | 26 + .../operators/src/decompress_op.cpp | 64 +++ .../grppi/ferret_grppi_farm-pipe/config.json | 33 ++ .../grppi/ferret_grppi_farm-pipe/ferret.hpp | 95 ++++ .../ferret_grppi_farm-pipe.cpp | 75 +++ .../operators/include/extract_op.hpp | 27 + .../operators/include/rank_op.hpp | 24 + .../operators/include/segmentation_op.hpp | 24 + .../operators/include/vectorization_op.hpp | 24 + .../operators/operators.json | 6 + .../operators/src/extract_op.cpp | 15 + .../operators/src/rank_op.cpp | 37 ++ .../operators/src/segmentation_op.cpp | 15 + .../operators/src/vectorization_op.cpp | 31 ++ .../grppi/ferret_grppi_farm/config.json | 33 ++ .../ferret/grppi/ferret_grppi_farm/ferret.hpp | 95 ++++ .../ferret_grppi_farm/ferret_grppi_farm.cpp | 63 +++ .../operators/include/extract_op.hpp | 27 + .../operators/include/rank_op.hpp | 24 + .../operators/include/segmentation_op.hpp | 24 + .../operators/include/vectorization_op.hpp | 24 + .../operators/operators.json | 6 + .../operators/src/extract_op.cpp | 15 + .../operators/src/rank_op.cpp | 37 ++ .../operators/src/segmentation_op.cpp | 15 + .../operators/src/vectorization_op.cpp | 31 ++ .../grppi/ferret_grppi_pipe-farm/config.json | 33 ++ .../grppi/ferret_grppi_pipe-farm/ferret.hpp | 95 ++++ .../ferret_grppi_pipe-farm.cpp | 75 +++ .../operators/include/extract_op.hpp | 27 + .../operators/include/rank_op.hpp | 24 + .../operators/include/segmentation_op.hpp | 24 + .../operators/include/vectorization_op.hpp | 24 + .../operators/operators.json | 6 + .../operators/src/extract_op.cpp | 15 + .../operators/src/rank_op.cpp | 37 ++ .../operators/src/segmentation_op.cpp | 15 + .../operators/src/vectorization_op.cpp | 31 ++ .../grppi/ferret_grppi_pipeline/config.json | 33 ++ .../grppi/ferret_grppi_pipeline/ferret.hpp | 95 ++++ .../ferret_grppi_pipeline.cpp | 70 +++ .../operators/include/extract_op.hpp | 27 + .../operators/include/rank_op.hpp | 24 + .../operators/include/segmentation_op.hpp | 24 + .../operators/include/vectorization_op.hpp | 24 + .../operators/operators.json | 6 + .../operators/src/extract_op.cpp | 15 + .../operators/src/rank_op.cpp | 37 ++ .../operators/src/segmentation_op.cpp | 15 + .../operators/src/vectorization_op.cpp | 31 ++ benchmarks/global_config.json | 11 +- .../grppi/lane_grppi_farm/config.json | 32 ++ .../grppi/lane_grppi_farm/lane_detection.hpp | 155 ++++++ .../grppi/lane_grppi_farm/lane_grppi_farm.cpp | 69 +++ .../operators/include/bitwise_op.hpp | 26 + .../operators/include/canny1_op.hpp | 25 + .../operators/include/canny2_op.hpp | 24 + .../operators/include/houghP_op.hpp | 25 + .../operators/include/houghT_op.hpp | 24 + .../operators/include/overlap_op.hpp | 25 + .../operators/include/segment_op.hpp | 26 + .../lane_grppi_farm/operators/operators.json | 9 + .../operators/src/bitwise_op.cpp | 13 + .../operators/src/canny1_op.cpp | 8 + .../operators/src/canny2_op.cpp | 7 + .../operators/src/houghP_op.cpp | 16 + .../operators/src/houghT_op.cpp | 56 ++ .../operators/src/overlap_op.cpp | 24 + .../operators/src/segment_op.cpp | 25 + .../grppi/person_grppi_farm/config.json | 31 ++ .../operators/include/detect_op.hpp | 25 + .../operators/include/recognize_op.hpp | 26 + .../operators/operators.json | 4 + .../operators/src/detect_op.cpp | 35 ++ .../operators/src/recognize_op.cpp | 72 +++ .../person_grppi_farm/person_grppi_farm.cpp | 62 +++ .../person_grppi_farm/person_recognition.hpp | 49 ++ ppis/fastflow/setup_fastflow.sh | 3 + ppis/install_ppis.sh | 14 +- ppis/tbb/setup_tbb.sh | 3 + spbench | 11 +- src/compile_option.py | 2 +- src/download_inputs_option.py | 6 +- src/exec_option.py | 483 +++++++++++------- src/install_option.py | 36 +- src/utils.py | 12 +- sys/errors_test_spbench.sh | 2 +- 95 files changed, 3180 insertions(+), 222 deletions(-) create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2.hpp create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2_grppi_farm.cpp create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/config.json create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/compress_op.hpp create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/decompress_op.hpp create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/operators.json create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/compress_op.cpp create mode 100644 benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/decompress_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/config.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret_grppi_farm-pipe.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/extract_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/rank_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/segmentation_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/vectorization_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/operators.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/extract_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/rank_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/segmentation_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/vectorization_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/config.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/ferret.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/ferret_grppi_farm.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/extract_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/rank_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/segmentation_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/vectorization_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/operators.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/extract_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/rank_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/segmentation_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/vectorization_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/config.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret_grppi_pipe-farm.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/extract_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/rank_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/segmentation_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/vectorization_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/operators.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/extract_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/rank_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/segmentation_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/vectorization_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/config.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret_grppi_pipeline.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/extract_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/rank_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/segmentation_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/vectorization_op.hpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/operators.json create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/extract_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/rank_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/segmentation_op.cpp create mode 100644 benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/vectorization_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/config.json create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/lane_detection.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/lane_grppi_farm.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/bitwise_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny1_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny2_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghP_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghT_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/overlap_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/segment_op.hpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/operators.json create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/bitwise_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny1_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny2_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghP_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghT_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/overlap_op.cpp create mode 100644 benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/segment_op.cpp create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/config.json create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/detect_op.hpp create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/recognize_op.hpp create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/operators/operators.json create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/detect_op.cpp create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/recognize_op.cpp create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/person_grppi_farm.cpp create mode 100644 benchmarks/person_recognition/grppi/person_grppi_farm/person_recognition.hpp diff --git a/Changelog.txt b/Changelog.txt index 5ac2f50..a525fae 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,9 @@ +* v0.4.3-alpha + - [CLI update] Exec command now allows users to set a range for nthreads. It will execute the benchmark in loop iterating throughout the range. + - [New benchmarks] SPBench now includes benchmarks using GrPPI. + - [CLI update] Exec command now hava a "quiet" option. It will run the benchmarks showing less information on the screen. + - [New feature] If repetitions and nthreads range are used together in the exec command, a specific resulting log will be automatically generated inside the log folder. This log file will store average latency, throughput, and exec. time, with their respective std. deviationls side by side. + * v0.4.2-alpha - [New feature] Now, all the benchmark set can be moved to another place just by moving the "benchmarks" folder and replacing it in the new place. - [New feature] SPBench now keeps a persistent execution log in a log.csv file inside the 'logs' folder. This general log contains some results and parameters of each execution. diff --git a/benchmarks/benchmarks_registry.json b/benchmarks/benchmarks_registry.json index d4034b9..52237df 100644 --- a/benchmarks/benchmarks_registry.json +++ b/benchmarks/benchmarks_registry.json @@ -12,6 +12,9 @@ }, "fastflow": { "bzip2_ff_farm": "simple" + }, + "grppi": { + "bzip2_grppi_farm": "single" } }, "lane_detection": { @@ -27,6 +30,9 @@ }, "fastflow": { "lane_ff_farm": "simple" + }, + "grppi": { + "lane_grppi_farm": "simple" } }, "ferret": { @@ -48,6 +54,12 @@ "ferret_ff_farm": "simple", "ferret_ff_pipeline": "simple", "ferret_ff_a2a_pipe-farm": "single" + }, + "grppi": { + "ferret_grppi_pipe-farm": "single", + "ferret_grppi_pipeline": "single", + "ferret_grppi_farm": "simple", + "ferret_grppi_farm-pipe": "single" } }, "person_recognition": { @@ -64,6 +76,8 @@ "fastflow": { "person_ff_farm": "simple" }, - "mpi": {} + "grppi": { + "person_grppi_farm": "single" + } } } \ No newline at end of file diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2.hpp b/benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2.hpp new file mode 100644 index 0000000..7419cf8 --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2.hpp @@ -0,0 +1,36 @@ +#ifndef BZIP2_H +#define BZIP2_H + +#include + +namespace spb{ +class Compress; +class Decompress; + +class Compress{ +private: + static inline void compress_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Compress(spb::Item &item){ + op(item); + } + Compress(){}; + + virtual ~Compress(){} +}; + +class Decompress{ +private: + static inline void decompress_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Decompress(spb::Item &item){ + op(item); + } + Decompress(){}; + virtual ~Decompress(){} +}; + +} // end of namespace spb +#endif diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2_grppi_farm.cpp b/benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2_grppi_farm.cpp new file mode 100644 index 0000000..8ece940 --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/bzip2_grppi_farm.cpp @@ -0,0 +1,87 @@ +#include +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run_compress(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + } + return item; + }, + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Compress::op(item); + return item; + }), + [](spb::Item item) {spb::Sink::op(item); } + ); +} + +void run_decompress(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source_d::op(item)) { + return {}; + } else { + return item; + } + }, + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Decompress::op(item); + return item; + }), + [](spb::Item item) {spb::Sink_d::op(item); } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, true); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +void compress(){ + spb::Metrics::init(); + auto ex = execution_mode(); + run_compress(ex); + spb::Metrics::stop(); +} + +void decompress(){ + spb::Metrics::init(); + auto ex = execution_mode(); + run_decompress(ex); + spb::Metrics::stop(); +} + +int main (int argc, char* argv[]){ + spb::bzip2_main(argc, argv); + return 0; +} diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/config.json b/benchmarks/bzip2/grppi/bzip2_grppi_farm/config.json new file mode 100644 index 0000000..a22f90a --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/config.json @@ -0,0 +1,32 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-O3 -finline-functions", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-O3 -finline-functions", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DNO_CMAKE_CONFIG -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff":"-I $SPB_HOME/ppis/grppi/fastflow-2.2.0", + "grppi":"-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_":"-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb": "-I $SPB_HOME/ppis/tbb/tbb/include/", + "bzlib":"-I $SPB_HOME/libs/bzlib/include/" + }, + "LIBS": { + "myLIB_1": "", + "myLIB_2": "", + "myLIB_N": "", + "tbb" : "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb", + "bzlib" : "-L $SPB_HOME/libs/bzlib/lib/ -lbz2" + }, + "LDFLAGS": "-lpthread -fopenmp" +} diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/compress_op.hpp b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/compress_op.hpp new file mode 100644 index 0000000..7a56e3e --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/compress_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Compress::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + compress_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/decompress_op.hpp b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/decompress_op.hpp new file mode 100644 index 0000000..bd22c1c --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/include/decompress_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Decompress::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + decompress_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/operators.json b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/operators.json new file mode 100644 index 0000000..2fc41de --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/operators.json @@ -0,0 +1,4 @@ +{ + "compress" : "", + "decompress" : "" +} \ No newline at end of file diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/compress_op.cpp b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/compress_op.cpp new file mode 100644 index 0000000..5e61fdd --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/compress_op.cpp @@ -0,0 +1,26 @@ +#include <../include/compress_op.hpp> + +inline void spb::Compress::compress_op(spb::item_data &item){ + + unsigned int outSize = (int) ((item.buffSize*1.01)+600); + + // allocate memory for compressed data + item.CompDecompData == NULL; + item.CompDecompData = new char[outSize]; + + // make sure memory was allocated properly + if (item.CompDecompData == NULL) + { + fprintf(stderr, "Bzip2: *ERROR: Could not allocate memory (CompressedData)! Skipping...\n"); + exit(-1); + } + + // compress the memory buffer (blocksize=9*100k, verbose=0, worklevel=30) + int ret = BZ2_bzBuffToBuffCompress(item.CompDecompData, &outSize, item.FileData, item.buffSize, BWTblockSize, Verbosity, 30); + + if (ret != BZ_OK) + fprintf(stderr, "Bzip2: *ERROR during compression: %d\n", ret); + + item.buffSize = outSize; + +} \ No newline at end of file diff --git a/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/decompress_op.cpp b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/decompress_op.cpp new file mode 100644 index 0000000..a74ab82 --- /dev/null +++ b/benchmarks/bzip2/grppi/bzip2_grppi_farm/operators/src/decompress_op.cpp @@ -0,0 +1,64 @@ +#include <../include/decompress_op.hpp> + +inline void spb::Decompress::decompress_op(spb::item_data &item){ + + //int blockNum = 0; +#ifdef PBZIP_DEBUG + fprintf(stderr, "consumer: Buffer: %x Size: %u Block: %d\n", item.FileData, item.buffSize, blockNum); +#endif + +#ifdef PBZIP_DEBUG + printf ("consumer: recieved %d.\n", blockNum); +#endif + + unsigned int outSize = 900000; + + // allocate memory for decompressed data (start with default 900k block size) + item.CompDecompData = new char[outSize]; + // make sure memory was allocated properly + if (item.CompDecompData == NULL) + { + fprintf(stderr, " *ERROR: Could not allocate memory (DecompressedData)! Skipping...\n"); + exit(-1); + } + + // decompress the memory buffer (verbose=0) + int ret = BZ2_bzBuffToBuffDecompress(item.CompDecompData, &outSize, item.FileData, item.buffSize, 0, Verbosity); + + while (ret == BZ_OUTBUFF_FULL) + { +#ifdef PBZIP_DEBUG + fprintf(stderr, "Increasing DecompressedData buffer size: %d -> %d\n", outSize, outSize*4); +#endif + + if (item.CompDecompData != NULL) + delete [] item.CompDecompData; + item.CompDecompData = NULL; + // increase buffer space + outSize = outSize * 4; + // allocate memory for decompressed data (start with default 900k block size) + item.CompDecompData = new char[outSize]; + // make sure memory was allocated properly + if (item.CompDecompData == NULL) + { + fprintf(stderr, "Bzip2: *ERROR: Could not allocate memory (DecompressedData)! Skipping...\n"); + exit(-1); + } + + // decompress the memory buffer (verbose=0) + ret = BZ2_bzBuffToBuffDecompress(item.CompDecompData, &outSize, item.FileData, item.buffSize, 0, Verbosity); + + } // while + + if ((ret != BZ_OK) && (ret != BZ_OUTBUFF_FULL)) + fprintf(stderr, "Bzip2: *ERROR during decompression: %d\n", ret); + +#ifdef PBZIP_DEBUG + fprintf(stderr, "\n Compressed Block Size: %u\n", item.buffSize); + fprintf(stderr, " Original Block Size: %u\n", outSize); +#endif + + blockNum++; + item.buffSize = outSize; + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/config.json b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/config.json new file mode 100644 index 0000000..612a993 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/config.json @@ -0,0 +1,33 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-no-pie -O3", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-no-pie -O3", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "", + "gsl": "pkg-config --cflags --libs gsl", + "jpeg": "pkg-config --cflags --libs libjpeg" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff": "-I $SPB_HOME/ppis/grppi/fastflow-2.2.0/", + "grppi": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb": "-I $SPB_HOME/ppis/tbb/tbb/include/", + "gsl": "-L $SPB_HOME/libs/gsl/gsl-2.6/include/", + "jpeg": "-L $SPB_HOME/libs/jpeg/libjpeg-turbo-1.5.2/include/" + }, + "LIBS": { + "myLIB_1": "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb", + "myLIB_2": "", + "myLIB_N": "" + }, + "LDFLAGS": "-ljpeg -lgsl -lgslcblas -lpthread -fopenmp" + } diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret.hpp new file mode 100644 index 0000000..5513d55 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret.hpp @@ -0,0 +1,95 @@ +/** + * ************************************************************************ + * File : ferret.hpp + * + * Title : SPBench version of the Ferret application + * + * Author: Adriano Marques Garcia + * + * Date : July 06, 2021 + * + * ************************************************************************ +**/ + +/** + * Copyright (C) 2007 Princeton University + * + * This file is part of Ferret Toolkit. + * + * Ferret Toolkit is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +#ifndef FERRET_H +#define FERRET_H + +#include + +namespace spb{ +class Segmentation; +class Extract; +class Vectorization; +class Rank; + +class Segmentation{ +private: + static inline void segmentation_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Segmentation(spb::Item &item){ + op(item); + } + Segmentation(){}; + virtual ~Segmentation(){} +}; + +class Extract{ +private: + static inline void extract_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Extract(spb::Item &item){ + op(item); + } + Extract(){}; + virtual ~Extract(){} +}; + +class Vectorization{ +private: + static inline void vectorization_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Vectorization(spb::Item &item){ + op(item); + } + Vectorization(){}; + virtual ~Vectorization(){} +}; + +class Rank{ +private: + static inline void rank_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Rank(spb::Item &item){ + op(item); + } + Rank(){}; + virtual ~Rank(){} +}; + +} // end of namespace spb +#endif \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret_grppi_farm-pipe.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret_grppi_farm-pipe.cpp new file mode 100644 index 0000000..91df4ad --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/ferret_grppi_farm-pipe.cpp @@ -0,0 +1,75 @@ +#include + +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + } else { return item; } + }, + grppi::farm(spb::nthreads, + grppi::pipeline( + [](spb::Item item) { + spb::Segmentation::op(item); + return item; + }, + [](spb::Item item) { + spb::Extract::op(item); + return item; + }, + [](spb::Item item) { + spb::Vectorization::op(item); + return item; + }, + [](spb::Item item) { + spb::Rank::op(item); + return item; + } + ) + ), + [](spb::Item item) { + spb::Sink::op(item); + } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, false); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +int main (int argc, char* argv[]){ + spb::init_bench(argc, argv); //Initializations + spb::Metrics::init(); + auto ex = execution_mode(); + run(ex); + spb::Metrics::stop(); + spb::end_bench(); + return 0; +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/extract_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/extract_op.hpp new file mode 100644 index 0000000..4a0fed9 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/extract_op.hpp @@ -0,0 +1,27 @@ +#include + +namespace spb{ + +void Extract::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + extract_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} + + diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/rank_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/rank_op.hpp new file mode 100644 index 0000000..3adbc98 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/rank_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Rank::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + rank_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/segmentation_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/segmentation_op.hpp new file mode 100644 index 0000000..05c8241 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/segmentation_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Segmentation::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + segmentation_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/vectorization_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/vectorization_op.hpp new file mode 100644 index 0000000..b9f1d0b --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/include/vectorization_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Vectorization::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + vectorization_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/operators.json b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/operators.json new file mode 100644 index 0000000..90d8527 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/operators.json @@ -0,0 +1,6 @@ +{ + "extract" : "", + "rank" : "", + "segmentation" : "", + "vectorization" : "" +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/extract_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/extract_op.cpp new file mode 100644 index 0000000..aa49cd3 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/extract_op.cpp @@ -0,0 +1,15 @@ +#include <../include/extract_op.hpp> + +inline void spb::Extract::extract_op(spb::item_data &item){ + + item.extract.name = item.second.seg.name; + image_extract_helper(item.second.seg.HSV, + item.second.seg.mask, + item.second.seg.width, + item.second.seg.height, + item.second.seg.nrgn, + &item.extract.ds); + free(item.second.seg.mask); + free(item.second.seg.HSV); + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/rank_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/rank_op.cpp new file mode 100644 index 0000000..6e75bbc --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/rank_op.cpp @@ -0,0 +1,37 @@ +#include <../include/rank_op.hpp> + +inline void spb::Rank::rank_op(spb::item_data &item){ + cass_query_t query; + query = item.first.rank.query; + + cass_result_t *candidate; + + item.first.rank.name = item.second.vec.name; + + query.flags = CASS_RESULT_LIST | CASS_RESULT_USERMEM | CASS_RESULT_SORT; + query.dataset = item.second.vec.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = top_K; + + query.extra_params = NULL; + + candidate = cass_result_merge_lists(&item.second.vec.result, + (cass_dataset_t *)query_table->__private, + 0); + query.candidate = candidate; + + cass_result_alloc_list(&item.first.rank.result, + 0, top_K); + cass_table_query(query_table, &query, + &item.first.rank.result); + + cass_result_free(&item.second.vec.result); + cass_result_free(candidate); + free(candidate); + cass_dataset_release(item.second.vec.ds); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/segmentation_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/segmentation_op.cpp new file mode 100644 index 0000000..7d926ff --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/segmentation_op.cpp @@ -0,0 +1,15 @@ +#include <../include/segmentation_op.hpp> + +inline void spb::Segmentation::segmentation_op(spb::item_data &item){ + + item.second.seg.name = item.first.load.name; + item.second.seg.width = item.first.load.width; + item.second.seg.height = item.first.load.height; + item.second.seg.HSV = item.first.load.HSV; + image_segment((void**)&item.second.seg.mask, + &item.second.seg.nrgn, + item.first.load.RGB, + item.first.load.width, + item.first.load.height); + free(item.first.load.RGB); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/vectorization_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/vectorization_op.cpp new file mode 100644 index 0000000..c335b74 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm-pipe/operators/src/vectorization_op.cpp @@ -0,0 +1,31 @@ +#include <../include/vectorization_op.hpp> + +inline void spb::Vectorization::vectorization_op(spb::item_data &item){ + + cass_query_t query; + query = item.second.vec.query; + + item.second.vec.name = item.extract.name; + + memset(&query, 0, sizeof query); + query.flags = CASS_RESULT_LISTS | CASS_RESULT_USERMEM; + + item.second.vec.ds = query.dataset = &item.extract.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = 2*top_K; + + query.extra_params = extra_params; + + cass_result_alloc_list(&item.second.vec.result, + item.second.vec.ds->vecset[0].num_regions, + query.topk); + + cass_table_query(table, &query, &item.second.vec.result); + + item.second.vec.query = query; +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/config.json b/benchmarks/ferret/grppi/ferret_grppi_farm/config.json new file mode 100644 index 0000000..d4286b7 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/config.json @@ -0,0 +1,33 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-no-pie -O3", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-no-pie -O3", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "", + "gsl": "pkg-config --cflags --libs gsl", + "jpeg": "pkg-config --cflags --libs libjpeg" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff":"-I $SPB_HOME/ppis/grppi/fastflow-2.2.0", + "grppi": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb": "-I $SPB_HOME/ppis/tbb/tbb/include/", + "gsl": "-L $SPB_HOME/libs/gsl/gsl-2.6/include/", + "jpeg": "-L $SPB_HOME/libs/jpeg/libjpeg-turbo-1.5.2/include/" + }, + "LIBS": { + "myLIB_1": "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb", + "myLIB_2": "", + "myLIB_N": "" + }, + "LDFLAGS": "-ljpeg -lgsl -lgslcblas -lpthread -fopenmp" + } diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/ferret.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm/ferret.hpp new file mode 100644 index 0000000..5513d55 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/ferret.hpp @@ -0,0 +1,95 @@ +/** + * ************************************************************************ + * File : ferret.hpp + * + * Title : SPBench version of the Ferret application + * + * Author: Adriano Marques Garcia + * + * Date : July 06, 2021 + * + * ************************************************************************ +**/ + +/** + * Copyright (C) 2007 Princeton University + * + * This file is part of Ferret Toolkit. + * + * Ferret Toolkit is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +#ifndef FERRET_H +#define FERRET_H + +#include + +namespace spb{ +class Segmentation; +class Extract; +class Vectorization; +class Rank; + +class Segmentation{ +private: + static inline void segmentation_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Segmentation(spb::Item &item){ + op(item); + } + Segmentation(){}; + virtual ~Segmentation(){} +}; + +class Extract{ +private: + static inline void extract_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Extract(spb::Item &item){ + op(item); + } + Extract(){}; + virtual ~Extract(){} +}; + +class Vectorization{ +private: + static inline void vectorization_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Vectorization(spb::Item &item){ + op(item); + } + Vectorization(){}; + virtual ~Vectorization(){} +}; + +class Rank{ +private: + static inline void rank_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Rank(spb::Item &item){ + op(item); + } + Rank(){}; + virtual ~Rank(){} +}; + +} // end of namespace spb +#endif \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/ferret_grppi_farm.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm/ferret_grppi_farm.cpp new file mode 100644 index 0000000..7ac3802 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/ferret_grppi_farm.cpp @@ -0,0 +1,63 @@ +#include + +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + } else { return item; } + }, + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Segmentation::op(item); + spb::Extract::op(item); + spb::Vectorization::op(item); + spb::Rank::op(item); + return item; + }), + [](spb::Item item) { + spb::Sink::op(item); + } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, false); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +int main (int argc, char* argv[]){ + spb::init_bench(argc, argv); //Initializations + spb::Metrics::init(); + auto ex = execution_mode(); + run(ex); + spb::Metrics::stop(); + spb::end_bench(); + return 0; +} diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/extract_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/extract_op.hpp new file mode 100644 index 0000000..4a0fed9 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/extract_op.hpp @@ -0,0 +1,27 @@ +#include + +namespace spb{ + +void Extract::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + extract_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} + + diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/rank_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/rank_op.hpp new file mode 100644 index 0000000..3adbc98 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/rank_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Rank::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + rank_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/segmentation_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/segmentation_op.hpp new file mode 100644 index 0000000..05c8241 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/segmentation_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Segmentation::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + segmentation_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/vectorization_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/vectorization_op.hpp new file mode 100644 index 0000000..b9f1d0b --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/include/vectorization_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Vectorization::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + vectorization_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/operators.json b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/operators.json new file mode 100644 index 0000000..90d8527 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/operators.json @@ -0,0 +1,6 @@ +{ + "extract" : "", + "rank" : "", + "segmentation" : "", + "vectorization" : "" +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/extract_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/extract_op.cpp new file mode 100644 index 0000000..aa49cd3 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/extract_op.cpp @@ -0,0 +1,15 @@ +#include <../include/extract_op.hpp> + +inline void spb::Extract::extract_op(spb::item_data &item){ + + item.extract.name = item.second.seg.name; + image_extract_helper(item.second.seg.HSV, + item.second.seg.mask, + item.second.seg.width, + item.second.seg.height, + item.second.seg.nrgn, + &item.extract.ds); + free(item.second.seg.mask); + free(item.second.seg.HSV); + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/rank_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/rank_op.cpp new file mode 100644 index 0000000..6e75bbc --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/rank_op.cpp @@ -0,0 +1,37 @@ +#include <../include/rank_op.hpp> + +inline void spb::Rank::rank_op(spb::item_data &item){ + cass_query_t query; + query = item.first.rank.query; + + cass_result_t *candidate; + + item.first.rank.name = item.second.vec.name; + + query.flags = CASS_RESULT_LIST | CASS_RESULT_USERMEM | CASS_RESULT_SORT; + query.dataset = item.second.vec.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = top_K; + + query.extra_params = NULL; + + candidate = cass_result_merge_lists(&item.second.vec.result, + (cass_dataset_t *)query_table->__private, + 0); + query.candidate = candidate; + + cass_result_alloc_list(&item.first.rank.result, + 0, top_K); + cass_table_query(query_table, &query, + &item.first.rank.result); + + cass_result_free(&item.second.vec.result); + cass_result_free(candidate); + free(candidate); + cass_dataset_release(item.second.vec.ds); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/segmentation_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/segmentation_op.cpp new file mode 100644 index 0000000..7d926ff --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/segmentation_op.cpp @@ -0,0 +1,15 @@ +#include <../include/segmentation_op.hpp> + +inline void spb::Segmentation::segmentation_op(spb::item_data &item){ + + item.second.seg.name = item.first.load.name; + item.second.seg.width = item.first.load.width; + item.second.seg.height = item.first.load.height; + item.second.seg.HSV = item.first.load.HSV; + image_segment((void**)&item.second.seg.mask, + &item.second.seg.nrgn, + item.first.load.RGB, + item.first.load.width, + item.first.load.height); + free(item.first.load.RGB); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/vectorization_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/vectorization_op.cpp new file mode 100644 index 0000000..c335b74 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_farm/operators/src/vectorization_op.cpp @@ -0,0 +1,31 @@ +#include <../include/vectorization_op.hpp> + +inline void spb::Vectorization::vectorization_op(spb::item_data &item){ + + cass_query_t query; + query = item.second.vec.query; + + item.second.vec.name = item.extract.name; + + memset(&query, 0, sizeof query); + query.flags = CASS_RESULT_LISTS | CASS_RESULT_USERMEM; + + item.second.vec.ds = query.dataset = &item.extract.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = 2*top_K; + + query.extra_params = extra_params; + + cass_result_alloc_list(&item.second.vec.result, + item.second.vec.ds->vecset[0].num_regions, + query.topk); + + cass_table_query(table, &query, &item.second.vec.result); + + item.second.vec.query = query; +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/config.json b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/config.json new file mode 100644 index 0000000..d4286b7 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/config.json @@ -0,0 +1,33 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-no-pie -O3", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-no-pie -O3", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "", + "gsl": "pkg-config --cflags --libs gsl", + "jpeg": "pkg-config --cflags --libs libjpeg" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff":"-I $SPB_HOME/ppis/grppi/fastflow-2.2.0", + "grppi": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb": "-I $SPB_HOME/ppis/tbb/tbb/include/", + "gsl": "-L $SPB_HOME/libs/gsl/gsl-2.6/include/", + "jpeg": "-L $SPB_HOME/libs/jpeg/libjpeg-turbo-1.5.2/include/" + }, + "LIBS": { + "myLIB_1": "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb", + "myLIB_2": "", + "myLIB_N": "" + }, + "LDFLAGS": "-ljpeg -lgsl -lgslcblas -lpthread -fopenmp" + } diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret.hpp new file mode 100644 index 0000000..5513d55 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret.hpp @@ -0,0 +1,95 @@ +/** + * ************************************************************************ + * File : ferret.hpp + * + * Title : SPBench version of the Ferret application + * + * Author: Adriano Marques Garcia + * + * Date : July 06, 2021 + * + * ************************************************************************ +**/ + +/** + * Copyright (C) 2007 Princeton University + * + * This file is part of Ferret Toolkit. + * + * Ferret Toolkit is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +#ifndef FERRET_H +#define FERRET_H + +#include + +namespace spb{ +class Segmentation; +class Extract; +class Vectorization; +class Rank; + +class Segmentation{ +private: + static inline void segmentation_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Segmentation(spb::Item &item){ + op(item); + } + Segmentation(){}; + virtual ~Segmentation(){} +}; + +class Extract{ +private: + static inline void extract_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Extract(spb::Item &item){ + op(item); + } + Extract(){}; + virtual ~Extract(){} +}; + +class Vectorization{ +private: + static inline void vectorization_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Vectorization(spb::Item &item){ + op(item); + } + Vectorization(){}; + virtual ~Vectorization(){} +}; + +class Rank{ +private: + static inline void rank_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Rank(spb::Item &item){ + op(item); + } + Rank(){}; + virtual ~Rank(){} +}; + +} // end of namespace spb +#endif \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret_grppi_pipe-farm.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret_grppi_pipe-farm.cpp new file mode 100644 index 0000000..bbe5bc6 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/ferret_grppi_pipe-farm.cpp @@ -0,0 +1,75 @@ +#include + +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + } else { return item; } + }, + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Segmentation::op(item); + return item; + }), + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Extract::op(item); + return item; + }), + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Vectorization::op(item); + return item; + }), + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Rank::op(item); + return item; + }), + [](spb::Item item) { + spb::Sink::op(item); + } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, false); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +int main (int argc, char* argv[]){ + spb::init_bench(argc, argv); //Initializations + spb::Metrics::init(); + auto ex = execution_mode(); + run(ex); + spb::Metrics::stop(); + spb::end_bench(); + return 0; +} diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/extract_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/extract_op.hpp new file mode 100644 index 0000000..4a0fed9 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/extract_op.hpp @@ -0,0 +1,27 @@ +#include + +namespace spb{ + +void Extract::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + extract_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} + + diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/rank_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/rank_op.hpp new file mode 100644 index 0000000..3adbc98 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/rank_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Rank::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + rank_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/segmentation_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/segmentation_op.hpp new file mode 100644 index 0000000..05c8241 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/segmentation_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Segmentation::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + segmentation_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/vectorization_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/vectorization_op.hpp new file mode 100644 index 0000000..b9f1d0b --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/include/vectorization_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Vectorization::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + vectorization_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/operators.json b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/operators.json new file mode 100644 index 0000000..90d8527 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/operators.json @@ -0,0 +1,6 @@ +{ + "extract" : "", + "rank" : "", + "segmentation" : "", + "vectorization" : "" +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/extract_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/extract_op.cpp new file mode 100644 index 0000000..aa49cd3 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/extract_op.cpp @@ -0,0 +1,15 @@ +#include <../include/extract_op.hpp> + +inline void spb::Extract::extract_op(spb::item_data &item){ + + item.extract.name = item.second.seg.name; + image_extract_helper(item.second.seg.HSV, + item.second.seg.mask, + item.second.seg.width, + item.second.seg.height, + item.second.seg.nrgn, + &item.extract.ds); + free(item.second.seg.mask); + free(item.second.seg.HSV); + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/rank_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/rank_op.cpp new file mode 100644 index 0000000..6e75bbc --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/rank_op.cpp @@ -0,0 +1,37 @@ +#include <../include/rank_op.hpp> + +inline void spb::Rank::rank_op(spb::item_data &item){ + cass_query_t query; + query = item.first.rank.query; + + cass_result_t *candidate; + + item.first.rank.name = item.second.vec.name; + + query.flags = CASS_RESULT_LIST | CASS_RESULT_USERMEM | CASS_RESULT_SORT; + query.dataset = item.second.vec.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = top_K; + + query.extra_params = NULL; + + candidate = cass_result_merge_lists(&item.second.vec.result, + (cass_dataset_t *)query_table->__private, + 0); + query.candidate = candidate; + + cass_result_alloc_list(&item.first.rank.result, + 0, top_K); + cass_table_query(query_table, &query, + &item.first.rank.result); + + cass_result_free(&item.second.vec.result); + cass_result_free(candidate); + free(candidate); + cass_dataset_release(item.second.vec.ds); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/segmentation_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/segmentation_op.cpp new file mode 100644 index 0000000..7d926ff --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/segmentation_op.cpp @@ -0,0 +1,15 @@ +#include <../include/segmentation_op.hpp> + +inline void spb::Segmentation::segmentation_op(spb::item_data &item){ + + item.second.seg.name = item.first.load.name; + item.second.seg.width = item.first.load.width; + item.second.seg.height = item.first.load.height; + item.second.seg.HSV = item.first.load.HSV; + image_segment((void**)&item.second.seg.mask, + &item.second.seg.nrgn, + item.first.load.RGB, + item.first.load.width, + item.first.load.height); + free(item.first.load.RGB); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/vectorization_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/vectorization_op.cpp new file mode 100644 index 0000000..c335b74 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipe-farm/operators/src/vectorization_op.cpp @@ -0,0 +1,31 @@ +#include <../include/vectorization_op.hpp> + +inline void spb::Vectorization::vectorization_op(spb::item_data &item){ + + cass_query_t query; + query = item.second.vec.query; + + item.second.vec.name = item.extract.name; + + memset(&query, 0, sizeof query); + query.flags = CASS_RESULT_LISTS | CASS_RESULT_USERMEM; + + item.second.vec.ds = query.dataset = &item.extract.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = 2*top_K; + + query.extra_params = extra_params; + + cass_result_alloc_list(&item.second.vec.result, + item.second.vec.ds->vecset[0].num_regions, + query.topk); + + cass_table_query(table, &query, &item.second.vec.result); + + item.second.vec.query = query; +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/config.json b/benchmarks/ferret/grppi/ferret_grppi_pipeline/config.json new file mode 100644 index 0000000..612a993 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/config.json @@ -0,0 +1,33 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-no-pie -O3", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-no-pie -O3", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "", + "gsl": "pkg-config --cflags --libs gsl", + "jpeg": "pkg-config --cflags --libs libjpeg" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff": "-I $SPB_HOME/ppis/grppi/fastflow-2.2.0/", + "grppi": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb": "-I $SPB_HOME/ppis/tbb/tbb/include/", + "gsl": "-L $SPB_HOME/libs/gsl/gsl-2.6/include/", + "jpeg": "-L $SPB_HOME/libs/jpeg/libjpeg-turbo-1.5.2/include/" + }, + "LIBS": { + "myLIB_1": "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb", + "myLIB_2": "", + "myLIB_N": "" + }, + "LDFLAGS": "-ljpeg -lgsl -lgslcblas -lpthread -fopenmp" + } diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret.hpp new file mode 100644 index 0000000..5513d55 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret.hpp @@ -0,0 +1,95 @@ +/** + * ************************************************************************ + * File : ferret.hpp + * + * Title : SPBench version of the Ferret application + * + * Author: Adriano Marques Garcia + * + * Date : July 06, 2021 + * + * ************************************************************************ +**/ + +/** + * Copyright (C) 2007 Princeton University + * + * This file is part of Ferret Toolkit. + * + * Ferret Toolkit is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +#ifndef FERRET_H +#define FERRET_H + +#include + +namespace spb{ +class Segmentation; +class Extract; +class Vectorization; +class Rank; + +class Segmentation{ +private: + static inline void segmentation_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Segmentation(spb::Item &item){ + op(item); + } + Segmentation(){}; + virtual ~Segmentation(){} +}; + +class Extract{ +private: + static inline void extract_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Extract(spb::Item &item){ + op(item); + } + Extract(){}; + virtual ~Extract(){} +}; + +class Vectorization{ +private: + static inline void vectorization_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Vectorization(spb::Item &item){ + op(item); + } + Vectorization(){}; + virtual ~Vectorization(){} +}; + +class Rank{ +private: + static inline void rank_op(spb::item_data &item); +public: + static void op(spb::Item &item); + Rank(spb::Item &item){ + op(item); + } + Rank(){}; + virtual ~Rank(){} +}; + +} // end of namespace spb +#endif \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret_grppi_pipeline.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret_grppi_pipeline.cpp new file mode 100644 index 0000000..8d719c4 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/ferret_grppi_pipeline.cpp @@ -0,0 +1,70 @@ +#include +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + }else { return item; } + }, + [](spb::Item item) { + spb::Segmentation::op(item); + return item; + }, + [](spb::Item item) { + spb::Extract::op(item); + return item; + }, + [](spb::Item item) { + spb::Vectorization::op(item); + return item; + }, + [](spb::Item item) { + spb::Rank::op(item); + return item; + }, + [](spb::Item item) { + spb::Sink::op(item); + } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, false); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, false); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +int main (int argc, char* argv[]){ + spb::init_bench(argc, argv); //Initializations + spb::Metrics::init(); + auto ex = execution_mode(); + run(ex); + spb::Metrics::stop(); + spb::end_bench(); + return 0; +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/extract_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/extract_op.hpp new file mode 100644 index 0000000..4a0fed9 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/extract_op.hpp @@ -0,0 +1,27 @@ +#include + +namespace spb{ + +void Extract::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + extract_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} + + diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/rank_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/rank_op.hpp new file mode 100644 index 0000000..3adbc98 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/rank_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Rank::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + rank_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/segmentation_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/segmentation_op.hpp new file mode 100644 index 0000000..05c8241 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/segmentation_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Segmentation::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + segmentation_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/vectorization_op.hpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/vectorization_op.hpp new file mode 100644 index 0000000..b9f1d0b --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/include/vectorization_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Vectorization::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + vectorization_op(*item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/operators.json b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/operators.json new file mode 100644 index 0000000..90d8527 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/operators.json @@ -0,0 +1,6 @@ +{ + "extract" : "", + "rank" : "", + "segmentation" : "", + "vectorization" : "" +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/extract_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/extract_op.cpp new file mode 100644 index 0000000..aa49cd3 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/extract_op.cpp @@ -0,0 +1,15 @@ +#include <../include/extract_op.hpp> + +inline void spb::Extract::extract_op(spb::item_data &item){ + + item.extract.name = item.second.seg.name; + image_extract_helper(item.second.seg.HSV, + item.second.seg.mask, + item.second.seg.width, + item.second.seg.height, + item.second.seg.nrgn, + &item.extract.ds); + free(item.second.seg.mask); + free(item.second.seg.HSV); + +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/rank_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/rank_op.cpp new file mode 100644 index 0000000..6e75bbc --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/rank_op.cpp @@ -0,0 +1,37 @@ +#include <../include/rank_op.hpp> + +inline void spb::Rank::rank_op(spb::item_data &item){ + cass_query_t query; + query = item.first.rank.query; + + cass_result_t *candidate; + + item.first.rank.name = item.second.vec.name; + + query.flags = CASS_RESULT_LIST | CASS_RESULT_USERMEM | CASS_RESULT_SORT; + query.dataset = item.second.vec.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = top_K; + + query.extra_params = NULL; + + candidate = cass_result_merge_lists(&item.second.vec.result, + (cass_dataset_t *)query_table->__private, + 0); + query.candidate = candidate; + + cass_result_alloc_list(&item.first.rank.result, + 0, top_K); + cass_table_query(query_table, &query, + &item.first.rank.result); + + cass_result_free(&item.second.vec.result); + cass_result_free(candidate); + free(candidate); + cass_dataset_release(item.second.vec.ds); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/segmentation_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/segmentation_op.cpp new file mode 100644 index 0000000..7d926ff --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/segmentation_op.cpp @@ -0,0 +1,15 @@ +#include <../include/segmentation_op.hpp> + +inline void spb::Segmentation::segmentation_op(spb::item_data &item){ + + item.second.seg.name = item.first.load.name; + item.second.seg.width = item.first.load.width; + item.second.seg.height = item.first.load.height; + item.second.seg.HSV = item.first.load.HSV; + image_segment((void**)&item.second.seg.mask, + &item.second.seg.nrgn, + item.first.load.RGB, + item.first.load.width, + item.first.load.height); + free(item.first.load.RGB); +} \ No newline at end of file diff --git a/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/vectorization_op.cpp b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/vectorization_op.cpp new file mode 100644 index 0000000..c335b74 --- /dev/null +++ b/benchmarks/ferret/grppi/ferret_grppi_pipeline/operators/src/vectorization_op.cpp @@ -0,0 +1,31 @@ +#include <../include/vectorization_op.hpp> + +inline void spb::Vectorization::vectorization_op(spb::item_data &item){ + + cass_query_t query; + query = item.second.vec.query; + + item.second.vec.name = item.extract.name; + + memset(&query, 0, sizeof query); + query.flags = CASS_RESULT_LISTS | CASS_RESULT_USERMEM; + + item.second.vec.ds = query.dataset = &item.extract.ds; + query.vecset_id = 0; + + query.vec_dist_id = vec_dist_id; + + query.vecset_dist_id = vecset_dist_id; + + query.topk = 2*top_K; + + query.extra_params = extra_params; + + cass_result_alloc_list(&item.second.vec.result, + item.second.vec.ds->vecset[0].num_regions, + query.topk); + + cass_table_query(table, &query, &item.second.vec.result); + + item.second.vec.query = query; +} \ No newline at end of file diff --git a/benchmarks/global_config.json b/benchmarks/global_config.json index da30d16..46186b1 100644 --- a/benchmarks/global_config.json +++ b/benchmarks/global_config.json @@ -10,19 +10,12 @@ "MACROS": "", "EXTRA_MACROS": "", "PKG-CONFIG": { - "myPKG_1": "", - "myPKG_2": "", - "myPKG_N": "" + "myPKG": "" }, "INCLUDES": { - "myINC_1": "", - "myINC_2": "", - "myINC_N": "" + "UPL": "-I $SPB_HOME/libs/upl/include/upl/" }, "LIBS": { - "myLIB_1": "", - "myLIB_2": "", - "myLIB_N": "", "UPL" : "-L $SPB_HOME/libs/upl/lib/x86 -lupl" }, "LDFLAGS": "", diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/config.json b/benchmarks/lane_detection/grppi/lane_grppi_farm/config.json new file mode 100644 index 0000000..35f4c5a --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/config.json @@ -0,0 +1,32 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-O3", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-O3", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "", + "opencv": "pkg-config --cflags --libs opencv" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff":"-I $SPB_HOME/ppis/grppi/fastflow-2.2.0", + "grppi": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_" : "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb" : "-I $SPB_HOME/ppis/tbb/tbb/include/", + "opencv": "-I $SPB_HOME/libs/opencv/opencv-2.4.13.6/include/" + }, + "LIBS": { + "myLIB_1": "", + "myLIB_2": "", + "myLIB_N": "", + "tbb" : "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb" + }, + "LDFLAGS": "-lpthread -fopenmp" + } diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/lane_detection.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/lane_detection.hpp new file mode 100644 index 0000000..db4a3c9 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/lane_detection.hpp @@ -0,0 +1,155 @@ +/** + * ************************************************************************ + * File : lane_detection.hpp + * + * Title : SPBench version of the Lane Detection + * + * Author: Adriano Marques Garcia + * + * Date : July 06, 2021 + * + * ************************************************************************ +**/ + +/** + * ------------------------------------------------------------------------------------------ + * Lane Detection: + * + * General idea and some code modified from: + * chapter 7 of Computer Vision Programming using the OpenCV Library. + * by Robert Laganiere, Packt Publishing, 2011. + * This program is free software; permission is hereby granted to use, copy, modify, + * and distribute this source code, or portions thereof, for any purpose, without fee, + * subject to the restriction that the copyright notice may not be removed + * or altered from any source or altered source distribution. + * The software is released on an as-is basis and without any warranties of any kind. + * In particular, the software is not guaranteed to be fault-tolerant or free from failure. + * The author disclaims all warranties with regard to this software, any use, + * and any consequent failure, is purely the responsibility of the user. + * + * Copyright (C) 2013 Jason Dorweiler, www.transistor.io + * ------------------------------------------------------------------------------------------ + * Source: + * + * http://www.transistor.io/revisiting-lane-detection-using-opencv.html + * https://github.com/jdorweiler/lane-detection + * ------------------------------------------------------------------------------------------ + * Notes: + * + * Add up number on lines that are found within a threshold of a given rho,theta and + * use that to determine a score. Only lines with a good enough score are kept. + * + * Calculation for the distance of the car from the center. This should also determine + * if the road in turning. We might not want to be in the center of the road for a turn. + * + * Several other parameters can be played with: min vote on houghp, line distance and gap. Some + * type of feed back loop might be good to self tune these parameters. + * + * We are still finding the Road, i.e. both left and right lanes. we Need to set it up to find the + * yellow divider line in the middle. + * + * Added filter on theta angle to reduce horizontal and vertical lines. + * + * Added image ROI to reduce false lines from things like trees/powerlines + * ------------------------------------------------------------------------------------------ + */ +#ifndef LANE_H +#define LANE_H + +#include + +namespace spb{ +class Segment; +class Canny1; +class HoughT; +class HoughP; +class Bitwise; +class Canny2; +class Overlap; + +class Segment{ +private: + static inline void segment_op(item_data &item); +public: + static void op(Item &item); + Segment(Item &item){ + op(item); + } + Segment(){}; + virtual ~Segment(){} +}; + +class Canny1{ +private: + static inline void canny1_op(item_data &item); +public: + static void op(Item &item); + Canny1(Item &item){ + op(item); + } + Canny1(){}; + virtual ~Canny1(){} +}; + +class HoughT{ +private: + static inline void houghT_op(item_data &item); +public: + static void op(Item &item); + HoughT(Item &item){ + op(item); + } + HoughT(){}; + virtual ~HoughT(){} +}; + +class HoughP{ +private: + static inline void houghP_op(item_data &item); +public: + static void op(Item &item); + HoughP(Item &item){ + op(item); + } + HoughP(){}; + virtual ~HoughP(){} +}; + +class Bitwise{ +private: + static inline void bitwise_op(item_data &item); +public: + static void op(Item &item); + Bitwise(Item &item){ + op(item); + } + Bitwise(){}; + virtual ~Bitwise(){} +}; + +class Canny2{ +private: + static inline void canny2_op(item_data &item); +public: + static void op(Item &item); + Canny2(Item &item){ + op(item); + } + Canny2(){}; + virtual ~Canny2(){} +}; + +class Overlap{ +private: + static inline void overlap_op(item_data &item); +public: + static void op(Item &item); + Overlap(Item &item){ + op(item); + } + Overlap(){}; + virtual ~Overlap(){} +}; + +} // end of namespace spb +#endif \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/lane_grppi_farm.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/lane_grppi_farm.cpp new file mode 100644 index 0000000..09fc95a --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/lane_grppi_farm.cpp @@ -0,0 +1,69 @@ +#include +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + }else { return item; } + }, + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Segment::op(item); + spb::Canny1::op(item); + spb::HoughT::op(item); + spb::HoughP::op(item); + spb::Bitwise::op(item); + spb::Canny2::op(item); + spb::Overlap::op(item); + return item; + }), + [](spb::Item item) { + spb::Sink::op(item); + } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, true); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +int main (int argc, char* argv[]){ + // Disabling internal OpenCV's support for multithreading. + cv::setNumThreads(0); + spb::init_bench(argc, argv); //Initializations + spb::Metrics::init(); + auto ex = execution_mode(); + run(ex); + spb::Metrics::stop(); + spb::end_bench(); + return 0; +} + + diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/bitwise_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/bitwise_op.hpp new file mode 100644 index 0000000..8086642 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/bitwise_op.hpp @@ -0,0 +1,26 @@ +#include + +namespace spb{ + +void Bitwise::op(Item &item){ + + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + bitwise_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny1_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny1_op.hpp new file mode 100644 index 0000000..21c2ab4 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny1_op.hpp @@ -0,0 +1,25 @@ +#include + +namespace spb{ + +void Canny1::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + canny1_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny2_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny2_op.hpp new file mode 100644 index 0000000..2f79033 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/canny2_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void Canny2::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + canny2_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghP_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghP_op.hpp new file mode 100644 index 0000000..0fafa06 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghP_op.hpp @@ -0,0 +1,25 @@ +#include + +namespace spb{ + +void HoughP::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + houghP_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghT_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghT_op.hpp new file mode 100644 index 0000000..bac8911 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/houghT_op.hpp @@ -0,0 +1,24 @@ +#include + +namespace spb{ + +void HoughT::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + houghT_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/overlap_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/overlap_op.hpp new file mode 100644 index 0000000..2317198 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/overlap_op.hpp @@ -0,0 +1,25 @@ +#include + +namespace spb{ + +void Overlap::op(Item &item){ + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + overlap_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/segment_op.hpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/segment_op.hpp new file mode 100644 index 0000000..5161ed5 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/include/segment_op.hpp @@ -0,0 +1,26 @@ +#include + +namespace spb{ + +void Segment::op(Item &item){ Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + segment_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} + + diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/operators.json b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/operators.json new file mode 100644 index 0000000..573096d --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/operators.json @@ -0,0 +1,9 @@ +{ + "bitwise" : "", + "canny1" : "", + "canny2" : "", + "houghP" : "", + "houghT" : "", + "overlap" : "", + "segment" : "" +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/bitwise_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/bitwise_op.cpp new file mode 100644 index 0000000..290d7fe --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/bitwise_op.cpp @@ -0,0 +1,13 @@ +#include <../include/bitwise_op.hpp> + +inline void spb::Bitwise::bitwise_op(spb::item_data &item){ + + //bitwise AND of the two hough images + cv::bitwise_and(item.houghP, item.hough, item.houghP); + cv::Mat houghPinv(item.imgROI.size(), CV_8U, cv::Scalar(0)); + //threshold and invert to black lines + cv::threshold(item.houghP, houghPinv, 150, 255, cv::THRESH_BINARY_INV); + + item.houghPinv = houghPinv; + +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny1_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny1_op.cpp new file mode 100644 index 0000000..c5dd4a8 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny1_op.cpp @@ -0,0 +1,8 @@ +#include <../include/canny1_op.hpp> + +inline void spb::Canny1::canny1_op(spb::item_data &item){ + //Mat contours; + cv::Canny(item.imgROI, item.contours,50,250); + cv::Mat contoursInv; + cv::threshold(item.contours, contoursInv, 128, 255, cv::THRESH_BINARY_INV); +} diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny2_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny2_op.cpp new file mode 100644 index 0000000..1160d09 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/canny2_op.cpp @@ -0,0 +1,7 @@ +#include <../include/canny2_op.hpp> + +inline void spb::Canny2::canny2_op(spb::item_data &item){ + + cv::Canny(item.houghPinv, item.contours, 100, 350); + item.li = item.ld.findLines(item.contours); +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghP_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghP_op.cpp new file mode 100644 index 0000000..23bfbdf --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghP_op.cpp @@ -0,0 +1,16 @@ +#include <../include/houghP_op.hpp> + +inline void spb::HoughP::houghP_op(spb::item_data &item){ + + //set probabilistic Hough parameters + item.ld.setLineLengthAndGap(60,10); + item.ld.setMinVote(4); + + //detect lines + item.li = item.ld.findLines(item.contours); + cv::Mat houghP(item.imgROI.size(), CV_8U, cv::Scalar(0)); + item.ld.setShift(0); + item.ld.drawDetectedLines(houghP); + + item.houghP = houghP; +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghT_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghT_op.cpp new file mode 100644 index 0000000..26cf330 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/houghT_op.cpp @@ -0,0 +1,56 @@ +#include <../include/houghT_op.hpp> + +inline void spb::HoughT::houghT_op(spb::item_data &item){ + + //Hough tranform for line detection with feedback + //Increase by 25 for the next frame if we found some lines. + //This is so we don't miss other lines that may crop up in the next frame + //but at the same time we don't want to start the feed back loop from scratch. + + int houghVote = 200; + + //we lost all lines. reset + if (houghVote < 1 || item.lines.size() > 2) + { + houghVote = 200; + } + else + { + houghVote += 25; + } + + while(item.lines.size() < 5 && houghVote > 0) + { + cv::HoughLines(item.contours, item.lines,1,PI/180, houghVote); + houghVote -= 5; + } + + cv::Mat result(item.imgROI.size(), CV_8U, cv::Scalar(255)); + item.imgROI.copyTo(result); + + //draw the limes + std::vector::const_iterator it; + cv::Mat hough(item.imgROI.size(), CV_8U, cv::Scalar(0)); + it = item.lines.begin(); + + while(it!=item.lines.end()) + { + //first element is distance rho + float rho= (*it)[0]; + //second element is angle theta + float theta= (*it)[1]; + if( (theta > 0.09 && theta < 1.48) || (theta < 3.14 && theta > 1.66) ) + { + //filter to remove vertical and horizontal lines + //point of intersection of the line with first row + cv::Point pt1(rho/cos(theta),0); + //point of intersection of the line with last row + cv::Point pt2((rho-result.rows*sin(theta))/cos(theta), result.rows); + //draw a white line + cv::line(result, pt1, pt2, cv::Scalar(255), 8); + cv::line(hough, pt1, pt2, cv::Scalar(255), 8); + } + ++it; + } + item.hough = hough; +} diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/overlap_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/overlap_op.cpp new file mode 100644 index 0000000..d495999 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/overlap_op.cpp @@ -0,0 +1,24 @@ +#include <../include/overlap_op.hpp> + +inline void spb::Overlap::overlap_op(spb::item_data &item){ + + //set probabilistic Hough parameters + item.ld.setLineLengthAndGap(5,2); + item.ld.setMinVote(1); + if(SPBench::memory_source_is_enabled()){ + item.ld.setShift(item.image_p->cols/3); + item.ld.drawDetectedLines(*(item.image_p)); + } else { + item.ld.setShift(item.image.cols/3); + item.ld.drawDetectedLines(item.image); + } + std::stringstream stream; + stream << "Line Segments: " << item.lines.size(); + + if(SPBench::memory_source_is_enabled()) { + cv::putText(*(item.image_p), stream.str(), cv::Point(10, item.image_p->rows-10), 2, 0.8, cv::Scalar(0,0,255),0); + } else { + cv::putText(item.image, stream.str(), cv::Point(10, item.image.rows-10), 2, 0.8, cv::Scalar(0,0,255),0); + } + item.lines.clear(); +} \ No newline at end of file diff --git a/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/segment_op.cpp b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/segment_op.cpp new file mode 100644 index 0000000..9d04338 --- /dev/null +++ b/benchmarks/lane_detection/grppi/lane_grppi_farm/operators/src/segment_op.cpp @@ -0,0 +1,25 @@ +#include <../include/segment_op.hpp> + +inline void spb::Segment::segment_op(spb::item_data &item){ + + cv::Mat gray; + if(SPBench::memory_source_is_enabled()){ + cv::cvtColor(*(item.image_p), gray, CV_RGB2GRAY); + } else { + cv::cvtColor(item.image, gray, CV_RGB2GRAY); + } + std::vector codes; + cv::Mat corners; + cv::findDataMatrix(gray, codes, corners); + if(SPBench::memory_source_is_enabled()){ + cv::drawDataMatrixCodes(*(item.image_p), codes, corners); + cv::Rect roi(0, item.image_p->cols/3, item.image_p->cols-1, item.image_p->rows - item.image_p->cols/3); + cv::Mat aux = *(item.image_p); + item.imgROI = aux(roi); + } else { + cv::drawDataMatrixCodes(item.image, codes, corners); + cv::Rect roi(0, item.image.cols/3, item.image.cols-1, item.image.rows - item.image.cols/3); + item.imgROI = item.image(roi); + } +} + diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/config.json b/benchmarks/person_recognition/grppi/person_grppi_farm/config.json new file mode 100644 index 0000000..b131a7c --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/config.json @@ -0,0 +1,31 @@ +{ + "CXX": "g++ -std=c++1y", + "CXX_FLAGS":"-O3", + "PPI_CXX": "g++ -std=c++1y", + "PPI_CXX_FLAGS":"-O3", + "PRE_SRC_CMD": "", + "POST_SRC_CMD": "", + "MACROS": "-DGRPPI_TBB -DGRPPI_FF -DGRPPI_OMP", + "PKG-CONFIG": { + "myPKG_1": "", + "myPKG_2": "", + "myPKG_N": "", + "opencv": "pkg-config --cflags --libs opencv" + }, + "INCLUDES": { + "myINC_1": "", + "myINC_2": "", + "myINC_N": "", + "ff":"-I $SPB_HOME/ppis/grppi/fastflow-2.2.0", + "grppi": "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/include/", + "grppi_" : "-I $SPB_HOME/ppis/grppi/grppi-0.4.0/grppi/include/", + "tbb" : "-I $SPB_HOME/ppis/tbb/tbb/include/", + "opencv": "-I $SPB_HOME/libs/opencv/opencv-2.4.13.6/include/" + }, + "LIBS": { + "myLIB_1": "", + "tbb": "-L $SPB_HOME/ppis/tbb/tbb/ -ltbb", + "myLIB_N": "" + }, + "LDFLAGS": "-lpthread -fopenmp" +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/detect_op.hpp b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/detect_op.hpp new file mode 100644 index 0000000..487efec --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/detect_op.hpp @@ -0,0 +1,25 @@ +#include + +namespace spb{ +void Detect::op(Item &item){ + + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + detect_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/recognize_op.hpp b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/recognize_op.hpp new file mode 100644 index 0000000..accd2a7 --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/include/recognize_op.hpp @@ -0,0 +1,26 @@ +#include + +namespace spb{ + +void Recognize::op(Item &item){ + + Metrics metrics; + volatile unsigned long latency_op; + if(metrics.latency_is_enabled()){ + latency_op = current_time_usecs(); + } + unsigned int num_item = 0; + + while(num_item < item.batch_size){ //batch loop + + recognize_op(item.item_batch[num_item]); + + num_item++; + } + + if(metrics.latency_is_enabled()){ + item.latency_op.push_back(current_time_usecs() - latency_op); + } +} + +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/operators/operators.json b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/operators.json new file mode 100644 index 0000000..04bad45 --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/operators.json @@ -0,0 +1,4 @@ +{ + "detect" : "", + "recognize" : "" +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/detect_op.cpp b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/detect_op.cpp new file mode 100644 index 0000000..ecc655c --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/detect_op.cpp @@ -0,0 +1,35 @@ +#include <../include/detect_op.hpp> + +inline void spb::Detect::detect_op(spb::item_data &item){ + + cv::CascadeClassifier _cascade; + _cascade.load(std::string(input_data.cascade_path)); + + cv::Mat tmp; + int width, height; + if(SPBench::memory_source_is_enabled()){ + width = item.image_p->size().width; + height = item.image_p->size().height; + } else { + width = item.image.size().width; + height = item.image.size().height; + } + + cv::Size minScaleSize = cv::Size(DET_MIN_SIZE_RATIO * width, DET_MIN_SIZE_RATIO * height), + maxScaleSize = cv::Size(DET_MAX_SIZE_RATIO * width, DET_MAX_SIZE_RATIO * height); + + if(SPBench::memory_source_is_enabled()){ + cv::cvtColor(*(item.image_p), tmp, CV_BGR2GRAY); + } else { + cv::cvtColor(item.image, tmp, CV_BGR2GRAY); + } + //convert the image to grayscale and normalize histogram: + cv::equalizeHist(tmp, tmp); + + //clear the vector: + item.faces.clear(); + + //detect faces: + _cascade.detectMultiScale(tmp, item.faces, DET_SCALE_FACTOR, DET_MIN_NEIGHBORS, 0, minScaleSize, maxScaleSize); + +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/recognize_op.cpp b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/recognize_op.cpp new file mode 100644 index 0000000..2fd7a8a --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/operators/src/recognize_op.cpp @@ -0,0 +1,72 @@ +#include <../include/recognize_op.hpp> + +inline void spb::Recognize::recognize_op(spb::item_data &item){ + //analyze each detected face: + bool has_match = false; + double match_conf = 0; + int index = 0; + for (std::vector::const_iterator face = item.faces.begin() ; face != item.faces.end() ; face++, index++){ + cv::Scalar color = cv::NO_MATCH_COLOR; + + double confidence = 0; + bool face_match = false; + + //try to recognize the face: + cv::Ptr _model = model; + + cv::Mat gray, aux; + if(SPBench::memory_source_is_enabled()){ + cv::Mat tmp = *(item.image_p); + cv::Mat face_img = tmp(*face); + aux = tmp(item.faces[index]); + } else { + cv::Mat face_img = item.image(*face); + aux = item.image(item.faces[index]); + } + + int label; + cv::cvtColor(aux, gray, CV_BGR2GRAY); + cv::resize(gray, gray, _faceSize); + _model->predict(gray, label, confidence); + + bool verify; + label == 10 ? verify = true : verify = false; + + if (verify){ + color = cv::MATCH_COLOR; + has_match = true; + face_match = true; + match_conf = confidence; + } + + cv::Point center(face->x + face->width * 0.5, face->y + face->height * 0.5); + if(SPBench::memory_source_is_enabled()){ + cv::circle(*(item.image_p), center, FACE_RADIUS_RATIO * face->width, color, CIRCLE_THICKNESS, LINE_TYPE, 0); + } else { + cv::circle(item.image, center, FACE_RADIUS_RATIO * face->width, color, CIRCLE_THICKNESS, LINE_TYPE, 0); + } + } + if(SPBench::memory_source_is_enabled()){ + cv::putText(*(item.image_p), cv::format("Frame: %d", (item.index +1)), cvPoint(10, item.image_p->rows - 105), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(*(item.image_p), cv::format("FPS: %d", 15), cvPoint(10, item.image_p->rows - 80), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(*(item.image_p), cv::format("Faces: %d", item.faces.size()), cvPoint(10, item.image_p->rows - 55), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(*(item.image_p), cv::format("Match: %s", has_match ? "True" : "False"), cvPoint(10, item.image_p->rows - 30), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(*(item.image_p), cv::format("Confidence: %f", has_match ? match_conf : 0), cvPoint(10, item.image_p->rows - 5), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + } else { + cv::putText(item.image, cv::format("Frame: %d", (item.index +1)), cvPoint(10, item.image.rows - 105), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(item.image, cv::format("FPS: %d", 15), cvPoint(10, item.image.rows - 80), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(item.image, cv::format("Faces: %d", item.faces.size()), cvPoint(10, item.image.rows - 55), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(item.image, cv::format("Match: %s", has_match ? "True" : "False"), cvPoint(10, item.image.rows - 30), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + cv::putText(item.image, cv::format("Confidence: %f", has_match ? match_conf : 0), cvPoint(10, item.image.rows - 5), + cv::FONT, 2, cv::FONT_COLOR, 1, LINE_TYPE); + } +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/person_grppi_farm.cpp b/benchmarks/person_recognition/grppi/person_grppi_farm/person_grppi_farm.cpp new file mode 100644 index 0000000..4e30036 --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/person_grppi_farm.cpp @@ -0,0 +1,62 @@ +#include +#include "grppi/grppi.h" +#include "dyn/dynamic_execution.h" + +using namespace std; +using namespace experimental; + +void run(grppi::dynamic_execution & ex) { + tbb::task_scheduler_init init(spb::nthreads); + grppi::pipeline(ex, + []() mutable -> optional { + spb::Item item; + if(!spb::Source::op(item)) { + return {}; + } else { + return item; + } + }, + grppi::farm(spb::nthreads, + [](spb::Item item) { + spb::Detect::op(item); //detect faces in the image: + spb::Recognize::op(item); //analyze each detected face: + return item; + }), + [](spb::Item item) { spb::Sink::op(item); } + ); +} + +grppi::dynamic_execution execution_mode(){ + string backend = spb::SPBench::getArg(0); + if(backend == "tbb"){ + auto ex = grppi::parallel_execution_tbb(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking, spb::nthreads*10); + return ex; + } else if (backend == "ff"){ + auto ex = grppi::parallel_execution_ff(spb::nthreads, true); + return ex; + } else if (backend == "omp"){ + auto ex = grppi::parallel_execution_omp(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else if (backend == "thr"){ + auto ex = grppi::parallel_execution_native(spb::nthreads, true); + ex.set_queue_attributes(1, grppi::queue_mode::blocking); + return ex; + } else { + cout << "No backend selected" << endl; + exit(1); + } +} + +int main (int argc, char* argv[]){ + // Disabling internal OpenCV's support for multithreading. + cv::setNumThreads(0); + spb::init_bench(argc, argv); //Initializations + spb::Metrics::init(); + auto ex = execution_mode(); + run(ex); + spb::Metrics::stop(); + spb::end_bench(); + return 0; +} \ No newline at end of file diff --git a/benchmarks/person_recognition/grppi/person_grppi_farm/person_recognition.hpp b/benchmarks/person_recognition/grppi/person_grppi_farm/person_recognition.hpp new file mode 100644 index 0000000..52f21dc --- /dev/null +++ b/benchmarks/person_recognition/grppi/person_grppi_farm/person_recognition.hpp @@ -0,0 +1,49 @@ +/** + * ************************************************************************ + * File : person_recognition.hpp + * + * Title : SPBench version of the Person Recognition + * + * Author: Adriano Marques Garcia + * + * Date : July 06, 2021 + * + * ************************************************************************ +**/ + +#ifndef PERSON_H +#define PERSON_H + +#include + +namespace spb{ +class Detect; +class Recognize; + +class Detect{ +private: + static inline void detect_op(item_data &item); +public: + static void op(Item &item); + Detect(Item &item){ + op(item); + } + Detect(){}; + + virtual ~Detect(){} +}; + +class Recognize{ +private: + static inline void recognize_op(item_data &item); +public: + static void op(Item &item); + Recognize(Item &item){ + op(item); + } + Recognize(){}; + virtual ~Recognize(){} +}; + +} // end of namespace spb +#endif \ No newline at end of file diff --git a/ppis/fastflow/setup_fastflow.sh b/ppis/fastflow/setup_fastflow.sh index acb8b21..3d643d3 100644 --- a/ppis/fastflow/setup_fastflow.sh +++ b/ppis/fastflow/setup_fastflow.sh @@ -1,5 +1,8 @@ #!/bin/bash +THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +cd $THIS_DIR + wget -c --read-timeout=5 --tries=10 https://gmap.pucrs.br/public_data/spbench/libs/fastflow/fastflow.tar.gz tar -xf fastflow.tar.gz diff --git a/ppis/install_ppis.sh b/ppis/install_ppis.sh index 5384d7c..4977b5e 100644 --- a/ppis/install_ppis.sh +++ b/ppis/install_ppis.sh @@ -7,20 +7,30 @@ echo " Installing FastFlow..." echo "---------------------------------------" cd fastflow bash setup_fastflow.sh +cd .. echo "DONE!" echo "---------------------------------------" echo " Installing SPAR..." echo "---------------------------------------" -cd ../SPar +cd SPar bash setup_spar.sh make +cd .. echo "DONE!" echo "---------------------------------------" echo " Installing TBB..." echo "---------------------------------------" -cd ../tbb +cd tbb bash setup_tbb.sh cd .. +echo "DONE!" + +echo "---------------------------------------" +echo " Installing GrPPI..." +echo "---------------------------------------" +cd grppi +bash setup_grppi.sh +cd .. echo "DONE!" \ No newline at end of file diff --git a/ppis/tbb/setup_tbb.sh b/ppis/tbb/setup_tbb.sh index 5039979..3381398 100644 --- a/ppis/tbb/setup_tbb.sh +++ b/ppis/tbb/setup_tbb.sh @@ -1,5 +1,8 @@ #!/bin/bash +THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +cd $THIS_DIR + FILE=tbb.tar.gz if [ ! -f "$FILE" ]; then diff --git a/spbench b/spbench index 04e0c2a..48adade 100755 --- a/spbench +++ b/spbench @@ -64,7 +64,7 @@ from src.utils import * from argparse import ArgumentParser,SUPPRESS -spbench_version="v0.4.2-alpha" +spbench_version="v0.4.3-alpha" spbench_path = os.path.dirname(os.path.realpath(__file__))#os.path.dirname(sys.argv[0]) @@ -574,7 +574,7 @@ parser_exec.add_argument('-nthreads', dest='nthreads', required=False, default='', - help='Number of threads. It can be used inside the parallel benchmarks. Default value: 1. (Optional)') + help='Number of threads. It can be used inside the benchmarks as a global variable. You can insert a single number or a range using the \':\' character (e.g. -nthreads 1:10). You can also define iteration step of the range (e.g. -nthreads 4:4:16 would run the benchmarks with 4, 8, 12, and 16 threads). Default value: 1. (Optional)') parser_exec.add_argument('-batch', action='store', @@ -704,6 +704,13 @@ parser_exec.add_argument('-print', required=False, help='(Optional) When this parameter is added, the exec command will only print on the screen the execution command it would use to run the benchmark. You may use it to manually change some aspect of the execution.') +parser_exec.add_argument('-quiet', + action='store_true', + default=False, + dest='quiet', + required=False, + help='Run it in quiet mode. Results can be retrieved from the \'log/general_log.csv\' file (optional)') + parser_exec.add_argument('-d', action='append_const', const='-d', diff --git a/src/compile_option.py b/src/compile_option.py index afd79a9..d977ddf 100644 --- a/src/compile_option.py +++ b/src/compile_option.py @@ -94,7 +94,7 @@ def compile_func(spbench_path, args): print(" Version: " + bench_id) print("\n Common problems regarding SPBench:") print(" - Required library not installed.") - print(" See libs/README.md and ppis/README.md \n and make sure everything is setup.\n") + print(" See libs/README.md and ppis/README.md \n and make sure everything is setted up.\n") print(" - Required library is installed but not loaded.") print(" Run \'source setup_vars.sh\'\n") print(" - Missing or wrong compiling parameters.") diff --git a/src/download_inputs_option.py b/src/download_inputs_option.py index 4b3c0d6..e9b24d8 100644 --- a/src/download_inputs_option.py +++ b/src/download_inputs_option.py @@ -31,7 +31,7 @@ from src.utils import * # download the inputs for the SPBench applications -def download_inputs_func(spbench_path, args): +def download_inputs_func(spbench_path, args, skip = False): # Check if the chosen app exists if args.app_id: @@ -45,7 +45,7 @@ def download_inputs_func(spbench_path, args): if args.force: overwrite_files = "force" - if args.app_id == "all" and args.class_id == "all": + if args.app_id == "all" and args.class_id == "all" and skip == False: print("\n Warning: No specific application selected.") print(" It will download all the inputs for all SPBench applications.") print("\n Aproximate size of all inputs: 1.3 GB.") @@ -53,7 +53,7 @@ def download_inputs_func(spbench_path, args): sys.exit() print("\n >> It may take a while to finish <<\n") - + if args.app_id == "lane_detection" or args.app_id == "all": get_input_cmd = spbench_path + "/inputs/get_inputs.sh " + "lane_detection " + args.class_id + " " + overwrite_files runShellCmd("bash " + get_input_cmd) diff --git a/src/exec_option.py b/src/exec_option.py index ec3d611..652850e 100644 --- a/src/exec_option.py +++ b/src/exec_option.py @@ -26,8 +26,6 @@ ############################################################################## ## -#from __future__ import print_function - import sys import os import datetime @@ -40,6 +38,9 @@ def execute_func(spbench_path, args): + is_range = False + nthreads = ["1"] + inputs_registry_dic = getInputsRegistry(spbench_path) # get list of selected benchmarks to run @@ -102,6 +103,43 @@ def execute_func(spbench_path, args): else: # generate a '-i input_id_list' argument input_id += " -i " + os.path.abspath(input) + # Check for errors in nthreads + if args.nthreads: + # check if it is a range or not + if args.nthreads.isdigit(): + nthreads[0] = args.nthreads + else: + # check format and get the range values + nthreads = args.nthreads.replace(" ", "").lower() + # check if it the range number of parameters + if len(nthreads.split(':')) < 2 or len(nthreads.split(':')) > 3: + raise ArgumentTypeError("Argument error! Invalid format for nthreads range: " + nthreads + "\n Expected: -nthreads start:end or start:step:end\n\n") + + range_arg = nthreads.split(':') + for value in range_arg: + if not value.isdigit(): + raise ArgumentTypeError("Argument error! Values in the range must be integer numbers higher than or equal to one: " + args.nthreads) + + range_start = int(range_arg[0]) + if len(range_arg) == 2: + range_step = 1 + range_end = int(range_arg[1]) + elif len(range_arg) == 3: + range_step = int(range_arg[1]) + range_end = int(range_arg[2]) + else: + raise ArgumentTypeError("Argument error! Invalid format for nthreads range: " + nthreads + "\n Expected: -nthreads start:end or start:step:end\n\n") + + if range_start < 1 or range_end < 1: + raise ArgumentTypeError("Argument error! Values in the range must be integer numbers higher than or equal to one: " + args.nthreads) + + if range_start <= range_end: + nthreads = range((range_start), (range_end)+1, (range_step)) + if range_start > range_end: + nthreads = range((range_start), (range_end)-1, -abs((range_step))) + + is_range = True + # Check for errors in frequency pattern frequency_pattern = '' isPositiveFloat = lambda x: x.replace('.','',1).isdigit() @@ -153,11 +191,6 @@ def execute_func(spbench_path, args): if args.batch_interval: if not isPositiveFloat(args.batch_interval): raise ArgumentTypeError("Argument error! Batch interval window must be a number higher than or equal to zero: " + args.batch_interval) - - # Check for errors in nthreads - if args.nthreads: - if not args.nthreads.isdigit(): - raise ArgumentTypeError("Argument error! Number of threads must be a integer number higher than or equal to one: " + args.nthreads) if nsources and args.time_interval_thr: raise ArgumentTypeError("Argument error! -monitor-thread feature is not available for multi-source benchmarks. You can use the -monitor instead!") @@ -186,8 +219,8 @@ def execute_func(spbench_path, args): user_args = '' num_threads = '' if app_id == 'bzip2': - if args.nthreads: - num_threads = " -t" + args.nthreads + #if args.nthreads: + # num_threads = " -t" + args.nthreads batch_size = '' if args.batch_size: @@ -219,8 +252,8 @@ def execute_func(spbench_path, args): other_args = ' --force --keep' else: - if args.nthreads: - num_threads = " -t " + args.nthreads + #if args.nthreads: + # num_threads = " -t " + args.nthreads batch_size = '' if args.batch_size: @@ -252,7 +285,7 @@ def execute_func(spbench_path, args): if args.exec_arguments: exec_arguments = exec_arguments.join(args.exec_arguments) # join the input argument with the remaining arguments - exec_arguments = input_id + num_threads + batch_size + batch_interval + time_interval + items_frequency + frequency_pattern + " " + exec_arguments + other_args + exec_arguments = input_id + batch_size + batch_interval + time_interval + items_frequency + frequency_pattern + " " + exec_arguments + other_args # build the execution command line and run it cmd_line = spbench_path + "/bin/" + app_id + "/" + ppi_id + "/" + bench_id + exec_arguments + user_args @@ -261,12 +294,23 @@ def execute_func(spbench_path, args): cmd_line = args.executor + " " + cmd_line if(args.print_exec_line): - print(cmd_line) + if app_id == 'bzip2': + if is_range: + num_threads = " -t" + str(range_end) + else: + num_threads = " -t" + args.nthreads + else: + if is_range: + num_threads = " -t " + str(range_end) + else: + num_threads = " -t " + args.nthreads + + print(cmd_line + num_threads) continue - print("Execution string >> " + cmd_line) + #print("Execution string >> " + cmd_line) print("\n Running benchmark: " + bench_id) - if not nsources: + if not nsources and not args.quiet: print(" Selected input: " + inputs_ID_list[0]) if batch_size: print(" Batch size: " + args.batch_size + " items per batch") @@ -319,205 +363,264 @@ def execute_func(spbench_path, args): elif args.items_frequency: print(" Target frequency: " + args.items_frequency) else: - print(" Selected inputs: ") - for input_key in inputs_ID_list: - print(" -> " + input_key) - - # Try to execute the benchmark - print('\n') + if not args.quiet: + print(" Selected inputs: ") + for input_key in inputs_ID_list: + print(" -> " + input_key) + #print('\n') latencies = [] throughputs = [] exec_times = [] - for n in range (0, int(args.repetitions)): + # prepare the performance log + log_dir = spbench_path + "/log" + if is_range and (int(args.repetitions) > 1): + range_log_file = log_dir + "/" + bench_id + "_" + str(range_start) + "-" + str(range_step) + "-" + str(range_end) + ".dat" + nth_log_header = ("Thread Average_latency Std_dev_latency Average_throughput Std_dev_throughput Average_exec_time Std_dev_exec_time\n") + + #if(not fileExists(range_log_file)): + with open(range_log_file, 'w') as nth_log_file: + nth_log_file.write(nth_log_header) + + # prepare the general execution log + log_header = ("Time;Benchmark;Latency;Throughput;Exec. time;Max lat.;Min lat.;Input;N threads;Batch size;Batch int.;Frequency;Freq. patt.\n") + log_file = log_dir + "/general_log.csv" + + if(not dirExists(log_dir)): + try: + os.mkdir(log_dir) + except OSError as error: + print(error) + + if(not fileExists(log_file)): + with open(log_file, 'w') as general_log_file: + general_log_file.write(log_header) - if(int(args.repetitions) > 1): - print("\n ~~~> Execution " + str(n+1) + " from " + args.repetitions) + # run the benchmark for n threads + for nthread in nthreads: - # run the command line - output = runShellWithReturn(cmd_line) + # add nthread parameter to the execution line + if app_id == 'bzip2': + num_threads = " -t" + str(nthread) + else: + num_threads = " -t " + str(nthread) + + exec_line = cmd_line + num_threads - print(output) + if is_range: + print("\n ~~~> Running " + bench_id + " with " + str(nthread) + " threads!") - end_latency = 0 - max_latency = 0 - min_latency = 0 - exec_time = 0 - throughput = 0 + latencies = [] + exec_times = [] + throughputs = [] - output_lines = output.splitlines() - for line in output_lines: - - if("End-to-end latency" in line): - end_latency = line.split()[4] - if(isPositiveFloat(end_latency)): - latencies.append(float(end_latency)) + # run the benchmark n times + for n in range(0, int(args.repetitions)): - if("Maximum latency" in line): - max_latency = line.split()[4] + if(int(args.repetitions) > 1): + print("\n ~~~~~~> Execution " + str(n+1) + " from " + args.repetitions) - if("Minimum latency" in line): - min_latency = line.split()[4] - - if("Execution time" in line): - exec_time = line.split()[4] - if(isPositiveFloat(exec_time)): - exec_times.append(float(exec_time)) - - if("Items-per-second" in line): - throughput = line.split()[2] - if(isPositiveFloat(throughput)): - throughputs.append(float(throughput)) + # run the command line + output = runShellWithReturn(exec_line) - ## - # Writing results to the general log file - ## - time_now = datetime.datetime.now() - print_time = time_now.strftime("%d/%m/%y %H:%M:%S") - log_line = [] - log_line.append(str(print_time)) - log_line.append(bench_id) - log_line.append(str((round(float(end_latency), 3)))) - log_line.append(str(round(float(throughput), 3))) - log_line.append(str(round(float(exec_time), 3))) - log_line.append(str(round(float(max_latency), 3))) - log_line.append(str(round(float(min_latency), 3))) - log_line.append(','.join(inputs_ID_list)) - log_line.append(args.nthreads) - log_line.append(args.batch_size) - log_line.append(args.batch_interval) - log_line.append(args.items_frequency) - log_line.append(args.frequency_pattern + "\n") - - log_header = ("Time;Benchmark;Latency;Throughput;Exec. time;Max lat.;Min lat.;Input;N threads;Batch size;Batch int.;Frequency;Freq. patt.\n") - - log_file = spbench_path + "/log/general_log.csv" - - log_dir = spbench_path + "/log" - - if(not dirExists(log_dir)): - try: - os.mkdir(log_dir) - except OSError as error: - print(error) - - if(not fileExists(log_file)): - with open(log_file, 'w') as general_log_file: - general_log_file.write(log_header) + if not args.quiet: + print(output) - with open(log_file, 'r+') as general_log_file: - general_log_file.seek(0) - current_header = general_log_file.readline() + end_latency = 0 + max_latency = 0 + min_latency = 0 + exec_time = 0 + throughput = 0 - if(log_header not in current_header): - general_log_file.seek(0) - general_log_file.write(log_header) + output_lines = output.splitlines() + for line in output_lines: + + if("End-to-end latency" in line): + end_latency = line.split()[4] + if(isPositiveFloat(end_latency)): + latencies.append(float(end_latency)) - general_log_file.seek(0, 2) - general_log_file.write(';'.join(log_line)) - general_log_file.truncate() - - ## - # result correctness checking - ## - if args.test_result: - print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - for input in inputs_ID_list: - print("\n Checking result correctness for input \'" + input + '\'...\n') - - # check if there is a md5 hash associated to this input - if not bool(inputs_registry_dic[app_id][input].get('md5_test')): - print(" -> Result checking unavailable for this input!") - print("\n - Make sure that input \'" + input + "\' has an expected\n md5 hash associated to it.") - print(" Run \'./spbench list-inputs\' to check it.") - print("\n - Check the documentation for more info on how\n to fix it (link)(forthcoming).") - print("\n - Or run \'./spbench edit_input -h\' to associate\n an verification hash (forthcoming feature).") - print("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - continue + if("Maximum latency" in line): + max_latency = line.split()[4] + + if("Minimum latency" in line): + min_latency = line.split()[4] - checking_file = '' - - if app_id == 'bzip2': - # bzip2 output files can alse be used as workload for decompression. - # this way, the output files are in the same directory as input files and we must address this special case here - bzip2_out_file = (inputs_registry_dic[app_id][input]['input'].replace('$SPB_HOME', spbench_path)) - if '-d' in exec_arguments: - # if decompress is selected, remove the '.bz2' - checking_file = os.path.splitext(bzip2_out_file)[0] - else: # else, add a '.bz2' - checking_file = bzip2_out_file + ".bz2" + if("Execution time" in line): + exec_time = line.split()[4] + if(isPositiveFloat(exec_time)): + exec_times.append(float(exec_time)) - elif app_id == 'ferret': - # ferret output is disordered, so it requires sorting the output - output_file = spbench_path + "/outputs/" + bench_id + '_' + input + ".out" + if("Items-per-second" in line): + throughput = line.split()[2] + if(isPositiveFloat(throughput)): + throughputs.append(float(throughput)) + + if args.quiet: + if '-l' in args.exec_arguments: + print(" Average latency (ms) = " + str((round(float(end_latency), 3)))) + if '-x' in args.exec_arguments: + print(" Items per second = " + str((round(float(throughput), 3)))) + print(" Execution time (sec) = " + str((round(float(exec_time), 3)))) + ## + # Writing results to the general log file + ## + time_now = datetime.datetime.now() + print_time = time_now.strftime("%d/%m/%y %H:%M:%S") + log_line = [] + log_line.append(str(print_time)) + log_line.append(bench_id) + log_line.append(str((round(float(end_latency), 3)))) + log_line.append(str(round(float(throughput), 3))) + log_line.append(str(round(float(exec_time), 3))) + log_line.append(str(round(float(max_latency), 3))) + log_line.append(str(round(float(min_latency), 3))) + log_line.append(','.join(inputs_ID_list)) + log_line.append(str(nthread)) + log_line.append(args.batch_size) + log_line.append(args.batch_interval) + log_line.append(args.items_frequency) + log_line.append(args.frequency_pattern + "\n") + + with open(log_file, 'r+') as general_log_file: + general_log_file.seek(0) + current_header = general_log_file.readline() - # check if output exists before sorting it - if not outputExists(output_file): continue + if(log_header not in current_header): + general_log_file.seek(0) + general_log_file.write(log_header) - checking_file = spbench_path + "/outputs/" + bench_id + '_' + input + "_sorted.out" - sorting_cmd = "sort " + output_file + " > " + checking_file - os.system(sorting_cmd) + general_log_file.seek(0, 2) + general_log_file.write(';'.join(log_line)) + general_log_file.truncate() + + ## + # result correctness checking + ## + if args.test_result: + print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + for input in inputs_ID_list: + if not args.quiet: + print("\n Checking result correctness for input \'" + input + '\'...\n') + + # check if there is a md5 hash associated to this input + if not bool(inputs_registry_dic[app_id][input].get('md5_test')): + print(" -> Result checking unavailable for this input!") + if not args.quiet: + print("\n - Make sure that input \'" + input + "\' has an expected\n md5 hash associated to it.") + print(" Run \'./spbench list-inputs\' to check it.") + print("\n - Check the documentation for more info on how\n to fix it (link)(forthcoming).") + print("\n - Or run \'./spbench edit_input -h\' to associate\n an verification hash (forthcoming feature).") + print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + continue + + checking_file = '' + + if app_id == 'bzip2': + # bzip2 output files can alse be used as workload for decompression. + # this way, the output files are in the same directory as input files and we must address this special case here + bzip2_out_file = (inputs_registry_dic[app_id][input]['input'].replace('$SPB_HOME', spbench_path)) + if '-d' in exec_arguments: + # if decompress is selected, remove the '.bz2' + checking_file = os.path.splitext(bzip2_out_file)[0] + else: # else, add a '.bz2' + checking_file = bzip2_out_file + ".bz2" + + elif app_id == 'ferret': + # ferret output is disordered, so it requires sorting the output + output_file = spbench_path + "/outputs/" + bench_id + '_' + input + ".out" + + # check if output exists before sorting it + if not outputExists(output_file): continue + + checking_file = spbench_path + "/outputs/" + bench_id + '_' + input + "_sorted.out" + sorting_cmd = "sort " + output_file + " > " + checking_file + os.system(sorting_cmd) + + else: # lane and person + checking_file = spbench_path + "/outputs/" + bench_id + '_' + input + ".avi" + + # also check the ouput for bzip2, person, and lane + if not outputExists(checking_file): continue + + # compute md5 hash for the output file + resulting_md5 = md5(checking_file) + + if app_id == 'ferret': # deleting ferret's sorted output + os.system('rm ' + checking_file) + + # compare the computed hash to the one stored in the inputs database + if resulting_md5 == inputs_registry_dic[app_id][input]['md5_test']: + print(" -> SUCCESS!") + else: + print(" -> UNSUCCESSFUL!\n") + if not args.quiet: + print(" Incorrect output") + print(" - Expected md5 hash: " + inputs_registry_dic[app_id][input]['md5_test']) + print(" - Resulting md5 hash: " + resulting_md5) + print("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + print("") + # end of the correcteness checking - else: # lane and person - checking_file = spbench_path + "/outputs/" + bench_id + '_' + input + ".avi" + ## + # Compute and print the metrics sumary + ## + if(int(args.repetitions) > 1): - # also check the ouput for bzip2, person, and lane - if not outputExists(checking_file): continue + if(latencies): + latency_average = sum(latencies)/len(latencies) + latency_error = stdev(latencies) - # compute md5 hash for the output file - resulting_md5 = md5(checking_file) + if(exec_times): + exec_time_average = sum(exec_times)/len(exec_times) + exec_time_error = stdev(exec_times) - if app_id == 'ferret': # deleting ferret's sorted output - os.system('rm ' + checking_file) - - # compare the computed hash to the one stored in the inputs database - if resulting_md5 == inputs_registry_dic[app_id][input]['md5_test']: - print(" -> SUCCESS!") - else: - print(" -> UNSUCCESSFUL!\n") - print(" Incorrect output") - print(" - Expected md5 hash: " + inputs_registry_dic[app_id][input]['md5_test']) - print(" - Resulting md5 hash: " + resulting_md5) - print("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - print("") - # end of the correcteness checking - - ## - # Compute and print the metrics sumary - ## - if(int(args.repetitions) > 1): - - if(latencies): - latency_average = sum(latencies)/len(latencies) - latency_error = stdev(latencies) - - if(exec_times): - exec_time_average = sum(exec_times)/len(exec_times) - exec_time_error = stdev(exec_times) - - if(throughputs): - thr_average = sum(throughputs)/len(throughputs) - thr_error = stdev(throughputs) - - if(latencies or exec_times or throughputs): - print("*************** RESULTS SUMARY ***************\n") - print(" Benchmark:", bench_id) - print(" Repetitions:", args.repetitions) - if(latencies): - print("\n Average latency:", latency_average) - print(" Latency std. dev.:", latency_error) if(throughputs): - print("\n Average throughput:", thr_average) - print(" Throughput std. dev.:", thr_error) - if(exec_times): - print("\n Average exec. time:", exec_time_average) - print(" Exec. time std. dev.:", exec_time_error) - - if nsources: - print("\n CAUTION: This is a multi-source benchmark.") - print(" This summary includes all different") - print(" sources and may not be accurate.") - print("\n********************************************") + thr_average = sum(throughputs)/len(throughputs) + thr_error = stdev(throughputs) + + if (latencies or exec_times or throughputs) and not args.quiet: + print("*************** RESULTS SUMARY ***************\n") + print(" Benchmark:", bench_id) + print(" Repetitions:", args.repetitions) + if(latencies): + print("\n Average latency:", latency_average) + print(" Latency std. dev.:", latency_error) + if(throughputs): + print("\n Average throughput:", thr_average) + print(" Throughput std. dev.:", thr_error) + if(exec_times): + print("\n Average exec. time:", exec_time_average) + print(" Exec. time std. dev.:", exec_time_error) + + if nsources: + print("\n CAUTION: This is a multi-source benchmark.") + print(" This summary includes all different") + print(" sources and may not be accurate.") + print("\n********************************************") + + ## + # Generate a specific performance log if repetitions and nthreads range are enabled + ## + if is_range: + with open(range_log_file, 'r+') as nth_log_file: + nth_log_file.seek(0) + current_header = nth_log_file.readline() + + if(nth_log_header not in current_header): + nth_log_file.seek(0) + nth_log_file.write(nth_log_header) + + nth_log_file.seek(0, 2) + nth_log_file.write( + str(nthread) + " " + + str(latency_average) + " " + + str(latency_error) + " " + + str(thr_average) + " " + + str(thr_error) + " " + + str(exec_time_average) + " " + + str(exec_time_error) + "\n") + nth_log_file.truncate() sys.exit() diff --git a/src/install_option.py b/src/install_option.py index fe6703e..d0ea9f4 100644 --- a/src/install_option.py +++ b/src/install_option.py @@ -30,6 +30,7 @@ import os from src.utils import * +from src.download_inputs_option import * from sys import version_info python_3 = version_info[0] @@ -46,7 +47,7 @@ def install_func(spbench_path, args): print(" To install them, you can run:\n") print(" sudo apt-get install -y build-essential cmake python3.\n") print(" Or ask a system admin if you don't have sudo access.") - print("---------------------------------------------\n") + print(" ---------------------------------------------------------------\n") print(" You are installing dependencies for the following\n application:") print("\n -> " + args.app_id + "\n") @@ -65,22 +66,43 @@ def install_func(spbench_path, args): # user input support for python 2 and 3 if(python_3 == 3): - answer = input("\nDo you want to proceed with the installation? [yes/no]\n") + answer = input(color.BOLD + "\n Do you want to proceed with the installation? [yes/no]\n" + color.END) else: - answer = raw_input("\nDo you want to proceed with the installation? [yes/no]\n") + answer = raw_input(color.BOLD + "\n Do you want to proceed with the installation? [yes/no]\n" + color.END) if(answer.lower() not in ["y","yes"]): print("Installation canceled!\n") sys.exit() - runShellCmd('bash ' + spbench_path + '/ppis/install_ppis.sh') - runShellCmd('bash ' + spbench_path + '/libs/install_libs.sh ' + args.app_id) + print(" For running the benchmarks you can use the inputs provided by SPBench.") + print(" Otherwise, you can use your own inputs.") + + print(" You can download them now or later, using the command \'./spbench download-inputs\'") + print("\n Aproximated size of all inputs: 1.3 GB.") + + download_inputs_flag = True + # user input support for python 2 and 3 + if(python_3 == 3): + answer = input(color.BOLD + "\n Do you want to download all benchmark inputs now? [yes/no]\n" + color.END) + else: + answer = raw_input(color.BOLD + "\n Do you want to download all benchmark inputs now? [yes/no]\n" + color.END) + + if(answer.lower() not in ["y","yes"]): + download_inputs_flag = False + + #runShellCmd('bash ' + spbench_path + '/ppis/install_ppis.sh') + #runShellCmd('bash ' + spbench_path + '/libs/install_libs.sh ' + args.app_id) print(" ---------------------------------------------------------------") print(color.BOLD + " >> IMPORTANT << " + color.END) print(" ---------------------------------------------------------------\n") print(" Now you must run \'source setup_vars.sh\'\n to load the libraries.\n") - print(" Obs: You must load the libraries before using\n SPBench every time you star a new session!") - print(" ---------------------------------------------------------------\n") + print(" Obs: You must load the libraries before using\n SPBench every time you star a new session!\n") + + if download_inputs_flag: + args.app_id = "all" + args.class_id = "all" + args.force = True + download_inputs_func(spbench_path, args, True) sys.exit() \ No newline at end of file diff --git a/src/utils.py b/src/utils.py index e6f0842..97920df 100644 --- a/src/utils.py +++ b/src/utils.py @@ -161,14 +161,14 @@ def runShellWithReturn(shell_cmd_line): output = subprocess.check_output(shell_cmd_line, stderr=subprocess.STDOUT, shell=True).decode() #success = True except subprocess.CalledProcessError as e: - output = e.output.decode() - print(output) - print("\n Unsuccessful execution\n") + output = e.output.decode() + "\n Unsuccessful execution\n" + #print(output) + #print("\n Unsuccessful execution\n") except Exception as e: # check_call can raise other exceptions, such as FileNotFoundError - output = str(e) - print(output) - print("\n Unsuccessful execution\n") + output = str(e) + "\n Unsuccessful execution\n" + #print(output) + #print("\n Unsuccessful execution\n") except KeyboardInterrupt as e: print(" KeyboardInterrupt") print("\n Unsuccessful execution\n") diff --git a/sys/errors_test_spbench.sh b/sys/errors_test_spbench.sh index e0bede8..eb1cf6c 100644 --- a/sys/errors_test_spbench.sh +++ b/sys/errors_test_spbench.sh @@ -17,7 +17,7 @@ ../spbench global-config -editor cat ../spbench update -bench teste ../spbench compile -bench teste -../spbench new-input -id teste -app lane_detection -input-string "$BENCH_DIR/my_test/string" -md5 "myasdasdtestjfaksdmd5" +../spbench new-input -id teste -app lane_detection -input-string "$SPB_HOME/my_test/string" -md5 "myasdasdtestjfaksdmd5" ../spbench delete-input -id teste -app lane_detection ../spbench exec -bench teste -nth 4 -input test -latency -thr -freq-patt spike,10,5,10,100 -batch 2 -monitor 250 -repeat 2 ../spbench clean -bench teste From 6b051be8173da4a112655e3fad1be384855f3878 Mon Sep 17 00:00:00 2001 From: Adriano Garcia Date: Mon, 17 Oct 2022 20:49:38 -0300 Subject: [PATCH 2/2] v0.4.3-alpha --- Changelog.txt | 6 +-- README.md | 2 +- .../fastflow/bzip2_ff_farm/bzip2_ff_farm.cpp | 1 + .../tbb/bzip2_tbb_farm/bzip2_tbb_farm.cpp | 1 + .../ferret_ff_a2a_pipe-farm.cpp | 1 + .../ferret_ff_farm/ferret_ff_farm.cpp | 1 + .../ferret_ff_pipe-farm.cpp | 1 + .../ferret_ff_pipeline/ferret_ff_pipeline.cpp | 1 + .../tbb/ferret_tbb_farm/ferret_tbb_farm.cpp | 1 + .../ferret_tbb_pipe-farm.cpp | 1 + .../ferret_tbb_pipeline.cpp | 1 + .../fastflow/lane_ff_farm/lane_ff_farm.cpp | 2 +- .../sequential/lane_sequential/config.json | 2 +- .../lane_sequential/lane_sequential.cpp | 33 ++----------- .../tbb/lane_tbb_farm/lane_tbb_farm.cpp | 5 +- .../person_ff_farm/person_ff_farm.cpp | 1 + .../tbb/person_tbb_farm/person_tbb_farm.cpp | 1 + spbench | 2 +- src/exec_option.py | 11 ++++- src/make_gen.py | 6 +-- sys/apps/bzip2/bzip2_utils.cpp | 44 +++++++++-------- sys/errors_test_spbench.sh | 49 +++++++++++-------- 22 files changed, 89 insertions(+), 84 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index a525fae..fb925de 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,8 +1,8 @@ -* v0.4.3-alpha +v0.4.3-alpha - [CLI update] Exec command now allows users to set a range for nthreads. It will execute the benchmark in loop iterating throughout the range. - [New benchmarks] SPBench now includes benchmarks using GrPPI. - - [CLI update] Exec command now hava a "quiet" option. It will run the benchmarks showing less information on the screen. - - [New feature] If repetitions and nthreads range are used together in the exec command, a specific resulting log will be automatically generated inside the log folder. This log file will store average latency, throughput, and exec. time, with their respective std. deviationls side by side. + - [CLI update] Exec command now have a "quiet" option. It will run the benchmarks showing less information on the screen. + - [New feature] If repetitions and nthreads range are used together in the exec command, a specific resulting log will be automatically generated inside the log folder. This log file will store average latency, throughput, and exec. time, with their respective std. deviation side by side. * v0.4.2-alpha - [New feature] Now, all the benchmark set can be moved to another place just by moving the "benchmarks" folder and replacing it in the new place. diff --git a/README.md b/README.md index c0cf2c7..14b7a11 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ The main goal of SPBench is to enable users to easily create custom benchmarks f - Intel TBB - FastFlow - SPar - - GrPPI (forthcoming) + - GrPPI (backends: Intel TBB, FastFlow, OpenMP, and C++11 threads) - Standard C++ Threads (forthcoming) - OpenMP (forthcoming) diff --git a/benchmarks/bzip2/fastflow/bzip2_ff_farm/bzip2_ff_farm.cpp b/benchmarks/bzip2/fastflow/bzip2_ff_farm/bzip2_ff_farm.cpp index 4bf7e19..3f7f82d 100644 --- a/benchmarks/bzip2/fastflow/bzip2_ff_farm/bzip2_ff_farm.cpp +++ b/benchmarks/bzip2/fastflow/bzip2_ff_farm/bzip2_ff_farm.cpp @@ -22,6 +22,7 @@ struct Worker_comp: ff::ff_node_t{ struct Collector_comp: ff::ff_node_t{ spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }Collector_comp; diff --git a/benchmarks/bzip2/tbb/bzip2_tbb_farm/bzip2_tbb_farm.cpp b/benchmarks/bzip2/tbb/bzip2_tbb_farm/bzip2_tbb_farm.cpp index a466061..b4ad617 100644 --- a/benchmarks/bzip2/tbb/bzip2_tbb_farm/bzip2_tbb_farm.cpp +++ b/benchmarks/bzip2/tbb/bzip2_tbb_farm/bzip2_tbb_farm.cpp @@ -31,6 +31,7 @@ class stage3_comp : public tbb::filter{ void* operator() (void* new_item){ spb::Item * item = static_cast (new_item); spb::Sink::op(*item); + delete item; return NULL; } }; diff --git a/benchmarks/ferret/fastflow/ferret_ff_a2a_pipe-farm/ferret_ff_a2a_pipe-farm.cpp b/benchmarks/ferret/fastflow/ferret_ff_a2a_pipe-farm/ferret_ff_a2a_pipe-farm.cpp index 89b4536..ca09496 100644 --- a/benchmarks/ferret/fastflow/ferret_ff_a2a_pipe-farm/ferret_ff_a2a_pipe-farm.cpp +++ b/benchmarks/ferret/fastflow/ferret_ff_a2a_pipe-farm/ferret_ff_a2a_pipe-farm.cpp @@ -61,6 +61,7 @@ struct Sink: ff::ff_minode_t{ Sink(){} spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }; diff --git a/benchmarks/ferret/fastflow/ferret_ff_farm/ferret_ff_farm.cpp b/benchmarks/ferret/fastflow/ferret_ff_farm/ferret_ff_farm.cpp index 9dee16f..ea29b2e 100644 --- a/benchmarks/ferret/fastflow/ferret_ff_farm/ferret_ff_farm.cpp +++ b/benchmarks/ferret/fastflow/ferret_ff_farm/ferret_ff_farm.cpp @@ -27,6 +27,7 @@ struct Worker: ff::ff_node_t{ struct Collector: ff::ff_node_t{ spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }Collector; diff --git a/benchmarks/ferret/fastflow/ferret_ff_pipe-farm/ferret_ff_pipe-farm.cpp b/benchmarks/ferret/fastflow/ferret_ff_pipe-farm/ferret_ff_pipe-farm.cpp index f250a5f..5a4db41 100644 --- a/benchmarks/ferret/fastflow/ferret_ff_pipe-farm/ferret_ff_pipe-farm.cpp +++ b/benchmarks/ferret/fastflow/ferret_ff_pipe-farm/ferret_ff_pipe-farm.cpp @@ -60,6 +60,7 @@ struct Sink: ff::ff_minode_t{ Sink(){} spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }; diff --git a/benchmarks/ferret/fastflow/ferret_ff_pipeline/ferret_ff_pipeline.cpp b/benchmarks/ferret/fastflow/ferret_ff_pipeline/ferret_ff_pipeline.cpp index 46462a7..375471b 100644 --- a/benchmarks/ferret/fastflow/ferret_ff_pipeline/ferret_ff_pipeline.cpp +++ b/benchmarks/ferret/fastflow/ferret_ff_pipeline/ferret_ff_pipeline.cpp @@ -44,6 +44,7 @@ struct Rank: ff::ff_node_t{ struct Sink: ff::ff_node_t{ spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }; diff --git a/benchmarks/ferret/tbb/ferret_tbb_farm/ferret_tbb_farm.cpp b/benchmarks/ferret/tbb/ferret_tbb_farm/ferret_tbb_farm.cpp index 28ca104..febd677 100644 --- a/benchmarks/ferret/tbb/ferret_tbb_farm/ferret_tbb_farm.cpp +++ b/benchmarks/ferret/tbb/ferret_tbb_farm/ferret_tbb_farm.cpp @@ -34,6 +34,7 @@ class Sink : public tbb::filter{ void* operator() (void* new_item){ spb::Item * item = static_cast (new_item); spb::Sink::op(*item); + delete item; return NULL; } }; diff --git a/benchmarks/ferret/tbb/ferret_tbb_pipe-farm/ferret_tbb_pipe-farm.cpp b/benchmarks/ferret/tbb/ferret_tbb_pipe-farm/ferret_tbb_pipe-farm.cpp index 555c16f..6c3e640 100644 --- a/benchmarks/ferret/tbb/ferret_tbb_pipe-farm/ferret_tbb_pipe-farm.cpp +++ b/benchmarks/ferret/tbb/ferret_tbb_pipe-farm/ferret_tbb_pipe-farm.cpp @@ -62,6 +62,7 @@ class Sink : public tbb::filter{ //Token* operator()(Token* t)const{ spb::Item * item = static_cast (new_item); spb::Sink::op(*item); + delete item; return NULL; } }; diff --git a/benchmarks/ferret/tbb/ferret_tbb_pipeline/ferret_tbb_pipeline.cpp b/benchmarks/ferret/tbb/ferret_tbb_pipeline/ferret_tbb_pipeline.cpp index 6e23ecc..44365e8 100644 --- a/benchmarks/ferret/tbb/ferret_tbb_pipeline/ferret_tbb_pipeline.cpp +++ b/benchmarks/ferret/tbb/ferret_tbb_pipeline/ferret_tbb_pipeline.cpp @@ -62,6 +62,7 @@ class Sink : public tbb::filter{ //Token* operator()(Token* t)const{ spb::Item * item = static_cast (new_item); spb::Sink::op(*item); + delete item; return NULL; } }; diff --git a/benchmarks/lane_detection/fastflow/lane_ff_farm/lane_ff_farm.cpp b/benchmarks/lane_detection/fastflow/lane_ff_farm/lane_ff_farm.cpp index 888d276..7270be9 100644 --- a/benchmarks/lane_detection/fastflow/lane_ff_farm/lane_ff_farm.cpp +++ b/benchmarks/lane_detection/fastflow/lane_ff_farm/lane_ff_farm.cpp @@ -3,7 +3,6 @@ #include struct Emitter: ff::ff_node_t{ - spb::Item * svc(spb::Item * task){ while (1){ spb::Item * item = new spb::Item(); @@ -30,6 +29,7 @@ struct Worker: ff::ff_node_t{ struct Collector: ff::ff_node_t{ spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }Collector; diff --git a/benchmarks/lane_detection/sequential/lane_sequential/config.json b/benchmarks/lane_detection/sequential/lane_sequential/config.json index 3648977..3021e21 100644 --- a/benchmarks/lane_detection/sequential/lane_sequential/config.json +++ b/benchmarks/lane_detection/sequential/lane_sequential/config.json @@ -5,7 +5,7 @@ "PPI_CXX_FLAGS":"", "PRE_SRC_CMD": "", "POST_SRC_CMD": "", - "MACROS": "-DNO_UPL", + "MACROS": "", "PKG-CONFIG": { "myPKG_1": "", "myPKG_2": "", diff --git a/benchmarks/lane_detection/sequential/lane_sequential/lane_sequential.cpp b/benchmarks/lane_detection/sequential/lane_sequential/lane_sequential.cpp index 30e46d5..bc229de 100644 --- a/benchmarks/lane_detection/sequential/lane_sequential/lane_sequential.cpp +++ b/benchmarks/lane_detection/sequential/lane_sequential/lane_sequential.cpp @@ -1,8 +1,11 @@ #include -std::atomic done(false); +int main (int argc, char* argv[]){ + // Disabling internal OpenCV's support for multithreading + cv::setNumThreads(0); + spb::init_bench(argc, argv); // Initializations -void stream_region(){ + spb::Metrics::init(); while(1){ spb::Item item; if (!spb::Source::op(item)) break; @@ -15,32 +18,6 @@ void stream_region(){ spb::Overlap::op(item); spb::Sink::op(item); } - done = true; - return; -} - -int main (int argc, char* argv[]){ - // Disabling internal OpenCV's support for multithreading - cv::setNumThreads(0); - spb::init_bench(argc, argv); // Initializations - - spb::Metrics::init(); - - std::thread stream_thread(stream_region); - - while(!done){ - sleep(1); - std::cout << spb::Metrics::getAverageLatency() - << " " << spb::Metrics::getInstantThroughput(2) - << std::endl; - } - - if (stream_thread.joinable()){ - stream_thread.join(); - } - - - spb::Metrics::stop(); spb::end_bench(); return 0; diff --git a/benchmarks/lane_detection/tbb/lane_tbb_farm/lane_tbb_farm.cpp b/benchmarks/lane_detection/tbb/lane_tbb_farm/lane_tbb_farm.cpp index b1b03b2..7bcb7bb 100644 --- a/benchmarks/lane_detection/tbb/lane_tbb_farm/lane_tbb_farm.cpp +++ b/benchmarks/lane_detection/tbb/lane_tbb_farm/lane_tbb_farm.cpp @@ -37,6 +37,7 @@ class stage3 : public tbb::filter{ void* operator() (void* new_item){ spb::Item * item = static_cast (new_item); spb::Sink::op(*item); + delete item; return NULL; } }; @@ -47,8 +48,6 @@ int main (int argc, char* argv[]){ cv::setNumThreads(0); spb::init_bench(argc, argv); //Initializations - - spb::Metrics::init(); //TBB code: tbb::task_scheduler_init init_parallel(spb::nthreads); @@ -62,6 +61,8 @@ int main (int argc, char* argv[]){ stage3 write; pipeline.add_filter(write); + spb::Metrics::init(); + pipeline.run(spb::nthreads*10); spb::Metrics::stop(); diff --git a/benchmarks/person_recognition/fastflow/person_ff_farm/person_ff_farm.cpp b/benchmarks/person_recognition/fastflow/person_ff_farm/person_ff_farm.cpp index 7be16b6..291394f 100644 --- a/benchmarks/person_recognition/fastflow/person_ff_farm/person_ff_farm.cpp +++ b/benchmarks/person_recognition/fastflow/person_ff_farm/person_ff_farm.cpp @@ -27,6 +27,7 @@ struct Worker: ff::ff_node_t{ struct Collector: ff::ff_node_t{ spb::Item * svc(spb::Item * item){ spb::Sink::op(*item); + delete item; return GO_ON; } }Collector; diff --git a/benchmarks/person_recognition/tbb/person_tbb_farm/person_tbb_farm.cpp b/benchmarks/person_recognition/tbb/person_tbb_farm/person_tbb_farm.cpp index a5b4838..9c8de96 100644 --- a/benchmarks/person_recognition/tbb/person_tbb_farm/person_tbb_farm.cpp +++ b/benchmarks/person_recognition/tbb/person_tbb_farm/person_tbb_farm.cpp @@ -35,6 +35,7 @@ class stage3 : public tbb::filter{ void* operator() (void* new_item){ spb::Item * item = static_cast (new_item); spb::Sink::op(*item); + delete item; return NULL; } }; diff --git a/spbench b/spbench index 48adade..9f4af78 100755 --- a/spbench +++ b/spbench @@ -622,7 +622,7 @@ parser_exec.add_argument('-freq-pattern', dest='frequency_pattern', required=False, default='', - help='(Optional) Usage example: [-freq-pattern wave,10,5,80] (pattern,period,max,min). This argument overwrites the -frequency command and sets a varying frequency for the input stream. You can select and set a frequency variation pattern. For this argument you need to supply a tuple string: , where pattern can be "wave", "spike", "binary", "increasing" or "decreasing". Period is the duration in seconds of one cycle of the pattern. And min is the minimum frequency and max the maximum frequency, defined in items per second. For the spike pattern you can also set the duration of the spikes as percentage of the period (0-100) (e.g. ). The default spike duration is 10 percent of the period.') + help='(Optional) Usage example: [-freq-pattern wave,10,5,80] (pattern,period,min,max). This argument overwrites the -frequency command and sets a varying frequency for the input stream. You can select and set a frequency variation pattern. For this argument you need to supply a tuple string: , where pattern can be "wave", "spike", "binary", "increasing" or "decreasing". Period is the duration in seconds of one cycle of the pattern. And min is the minimum frequency and max the maximum frequency, defined in items per second. For the spike pattern you can also set the duration of the spikes as percentage of the period (0-100) (e.g. ). The default spike duration is 10 percent of the period.') parser_exec.add_argument('-in-memory', action='append_const', diff --git a/src/exec_option.py b/src/exec_option.py index 652850e..0a85999 100644 --- a/src/exec_option.py +++ b/src/exec_option.py @@ -432,6 +432,13 @@ def execute_func(spbench_path, args): min_latency = 0 exec_time = 0 throughput = 0 + + latency_average = 0 + thr_average = 0 + exec_time_average = 0 + exec_time_error = 0 + latency_error = 0 + thr_error = 0 output_lines = output.splitlines() for line in output_lines: @@ -458,9 +465,9 @@ def execute_func(spbench_path, args): throughputs.append(float(throughput)) if args.quiet: - if '-l' in args.exec_arguments: + if args.exec_arguments and "-l" in args.exec_arguments: print(" Average latency (ms) = " + str((round(float(end_latency), 3)))) - if '-x' in args.exec_arguments: + if args.exec_arguments and "-x" in args.exec_arguments: print(" Items per second = " + str((round(float(throughput), 3)))) print(" Execution time (sec) = " + str((round(float(exec_time), 3)))) ## diff --git a/src/make_gen.py b/src/make_gen.py index 8071d45..53a62c4 100644 --- a/src/make_gen.py +++ b/src/make_gen.py @@ -97,7 +97,7 @@ def make_gen(stream_path, selected_benchmark): compiler = json_data["CXX"] compiler = compiler.replace('$SPB_HOME', stream_path) - if(json_data["CXX_FLAGS"]): + if(global_json_data["CXX_FLAGS"]): compiler_flags = global_json_data["CXX_FLAGS"] else: compiler_flags = json_data["CXX_FLAGS"] @@ -117,14 +117,14 @@ def make_gen(stream_path, selected_benchmark): ppi_compiler = compiler ppi_compiler = ppi_compiler.replace('$SPB_HOME', stream_path) - - if(json_data["PPI_CXX_FLAGS"]): + if(global_json_data["PPI_CXX_FLAGS"]): ppi_compiler_flags = global_json_data["PPI_CXX_FLAGS"] else: ppi_compiler_flags = json_data["PPI_CXX_FLAGS"] if(global_json_data["EXTRA_PPI_CXX_FLAGS"]): ppi_compiler_flags += " " + global_json_data["EXTRA_PPI_CXX_FLAGS"] + ppi_compiler_flags = ppi_compiler_flags.replace('$SPB_HOME', stream_path) if(global_json_data["PRE_SRC_CMD"]): diff --git a/sys/apps/bzip2/bzip2_utils.cpp b/sys/apps/bzip2/bzip2_utils.cpp index 75ed1a9..77428ac 100644 --- a/sys/apps/bzip2/bzip2_utils.cpp +++ b/sys/apps/bzip2/bzip2_utils.cpp @@ -1563,8 +1563,8 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -P argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - numCPU = atoi(cmdLineTemp); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + numCPU = atoi(argv[i] + j + 1); if (numCPU > 4096) { fprintf(stderr, "Bzip2: *ERROR: Maximal number of supported processors is 4096! Aborting...\n"); @@ -1591,8 +1591,10 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -t argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - nthreads = atoi(cmdLineTemp); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + + nthreads = atoi(argv[i] + j + 1); + if (nthreads < 1) { fprintf(stderr, "Bzip2: *ERROR: Minimum number of supported processors is 1! Aborting...\n"); @@ -1615,14 +1617,15 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -b argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - SPBench::setBatchSize(atoi(cmdLineTemp)); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + SPBench::setBatchSize(atoi(argv[i] + j + 1)); if (SPBench::getBatchSize() < 1) { fprintf(stderr, "Bzip2: *ERROR: Minimum batch size is 1! Aborting...\n"); return 1; } j += cmdLineTempCount; + #ifdef PBZIP_DEBUG fprintf(stderr, "-b%d\n", batch_size); #endif @@ -1639,8 +1642,8 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -B argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - SPBench::setBatchInterval(atoi(cmdLineTemp)); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + SPBench::setBatchInterval(atoi(argv[i] + j + 1)); if (SPBench::getBatchInterval() <= 0) { fprintf(stderr, "Bzip2: *ERROR: Minimum batch time size is 0! Aborting...\n"); @@ -1663,8 +1666,8 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -F argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - SPBench::setFrequency(atoi(cmdLineTemp)); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + SPBench::setFrequency(atoi(argv[i] + j + 1)); //SPBench::enable_memory_source(); if (SPBench::getFrequency() < 0) @@ -1685,9 +1688,9 @@ int bzip2_main(int argc, char* argv[]) cmdLineTempCount++; } - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount + 1); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount + 1); try { - input_freq_pattern_parser(cmdLineTemp); + input_freq_pattern_parser(argv[i] + j + 1); } catch (const std::invalid_argument& e) { std::cerr << "exception: " << e.what() << std::endl; @@ -1708,8 +1711,8 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse file block size"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - blockSize = atoi(cmdLineTemp) * 100000; + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + blockSize = atoi(argv[i] + j + 1) * 100000; if ((blockSize < 100000) || (blockSize > 1000000000)) { fprintf(stderr, "Bzip2: *ERROR: File block size Min: 100k and Max: 10000k! Aborting...\n"); @@ -1731,8 +1734,8 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -m argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - Metrics::set_monitoring_time_interval(atoi(cmdLineTemp)); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + Metrics::set_monitoring_time_interval(atoi(argv[i] + j + 1)); if (Metrics::monitoring_thread_is_enabled()) { fprintf(stderr, " *ERROR: You can not use both -m and -M parameters. You must select only one at once. Aborting...\n"); @@ -1755,8 +1758,8 @@ int bzip2_main(int argc, char* argv[]) } if (cmdLineTempCount == 0) usage(argv[0], "Cannot parse -M argument"); - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); - Metrics::set_monitoring_time_interval(atoi(cmdLineTemp)); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount); + Metrics::set_monitoring_time_interval(atoi(argv[i] + j + 1)); if (Metrics::monitoring_is_enabled()) { fprintf(stderr, " *ERROR: You can not use both -m and -M parameters. You must select only one at once. Aborting...\n"); @@ -1774,9 +1777,8 @@ int bzip2_main(int argc, char* argv[]) k++; cmdLineTempCount++; } - - strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount + 1); - SPBench::setArg(cmdLineTemp); + //strncpy(cmdLineTemp, argv[i] + j + 1, cmdLineTempCount + 1); + SPBench::setArg(argv[i] + j + 1); j += cmdLineTempCount; break; diff --git a/sys/errors_test_spbench.sh b/sys/errors_test_spbench.sh index eb1cf6c..a91ef35 100644 --- a/sys/errors_test_spbench.sh +++ b/sys/errors_test_spbench.sh @@ -1,24 +1,31 @@ # This script runs some basic operations in SPbench # for looking for errors -../spbench -h -../spbench list -../spbench list-inputs -../spbench list-op -bench lane_sequential -../spbench new -bench teste -ppi teste -app lane_detection -../spbench new -bench teste2 -ppi teste -app lane_detection -from teste -../spbench list-op -bench teste2 -../spbench delete -bench teste -../spbench rename -old-name teste2 -new-name teste -../spbench clean -bench teste -../spbench compile -bench teste -../spbench edit -bench teste -editor cat -../spbench configure -bench teste -editor cat -../spbench global-config -editor cat -../spbench update -bench teste -../spbench compile -bench teste -../spbench new-input -id teste -app lane_detection -input-string "$SPB_HOME/my_test/string" -md5 "myasdasdtestjfaksdmd5" -../spbench delete-input -id teste -app lane_detection -../spbench exec -bench teste -nth 4 -input test -latency -thr -freq-patt spike,10,5,10,100 -batch 2 -monitor 250 -repeat 2 -../spbench clean -bench teste -../spbench delete -bench teste +cd .. + +./spbench -h +./spbench list +./spbench list-inputs +./spbench list-op -bench lane_sequential +./spbench new -bench teste -ppi teste -app lane_detection +./spbench new -bench teste2 -ppi teste -app lane_detection -from teste +./spbench list-op -bench teste2 +./spbench delete -bench teste +./spbench rename -old-name teste2 -new-name teste +./spbench clean -bench teste +./spbench compile -bench teste +./spbench edit -bench teste -editor cat +./spbench configure -bench teste -editor cat +./spbench global-config -editor cat +./spbench update -bench teste +./spbench compile -bench teste +./spbench new-input -id teste -app lane_detection -input-string "$SPB_HOME/my_test/string" -md5 "myasdasdtestjfaksdmd5" +./spbench delete-input -id teste -app lane_detection +./spbench exec -bench teste -nth 4 -input test -thr -freq-patt spike,10,5,10,100 -batch 2 -monitor 250 -repeat 2 -quiet +./spbench exec -bench teste -nth 4 -input test -latency -freq-patt wave,2,10,50 -batch 2 -batch-interval 0.2 -monitor 250 -repeat 2 -test +./spbench exec -bench teste -nth 3:4 -input test -thr -freq-patt binary,1,20,100 -monitor 500 -test -in-mem +./spbench clean -bench teste +./spbench delete -bench teste +./spbench exec -bench lane_grppi_farm -nth 2:4 -input small -latency -thr -freq-patt increasing,10,10,20 -batch-interval 0.3 -repeat 3 -user thr +cat log/lane_grppi_farm_2-1-4.dat +cd sys