X-Git-Url: https://git.ti.com/gitweb?p=tidl%2Ftidl-api.git;a=blobdiff_plain;f=examples%2Fone_eo_per_frame%2Fmain.cpp;h=8872c06438d3aed18c54d8ebbcbd0bcf6fa320cd;hp=f79500ad8417054a4aa3dac9818ac2b1fd6b0087;hb=a7b7ea7175e0d46193d54e7f5d899f9a169e3ccc;hpb=fe305413f04e84268989599dd98fa2fe8a4296dc diff --git a/examples/one_eo_per_frame/main.cpp b/examples/one_eo_per_frame/main.cpp index f79500a..8872c06 100644 --- a/examples/one_eo_per_frame/main.cpp +++ b/examples/one_eo_per_frame/main.cpp @@ -33,41 +33,26 @@ // #include #include -#include #include #include #include -#include #include "executor.h" #include "execution_object.h" #include "configuration.h" -#include +#include "utils.h" using namespace tidl; using std::string; using std::unique_ptr; using std::vector; -using boost::format; bool Run(const string& config_file, int num_eve,int num_dsp, const char* ref_output); -bool ReadFrame(ExecutionObject* eo, - int frame_idx, - const Configuration& configuration, - std::istream& input_file); -bool CheckFrame(const ExecutionObject *eo, const char *ref_output); - -const char* ReadReferenceOutput(const string& name); -void ReportTime(const ExecutionObject* eo); - Executor* CreateExecutor(DeviceType dt, int num, const Configuration& c); void CollectEOs(const Executor *e, vector& EOs); -void AllocateMemory(const vector& EOs); -void FreeMemory (const vector& EOs); - int main(int argc, char *argv[]) { @@ -89,6 +74,11 @@ int main(int argc, char *argv[]) unique_ptr reference_output(ReadReferenceOutput(ref_file)); + // Enable time stamp generation. The timestamp file is post processed + // by execution_graph.py to generate graphical view of frame execution. + // Refer to the User's Guide for details. + EnableTimeStamps("1eo.log"); + bool status = Run(config_file, num_eve, num_dsp, reference_output.get()); if (!status) @@ -108,7 +98,7 @@ bool Run(const string& config_file, int num_eve, int num_dsp, if (!c.ReadFromFile(config_file)) return false; - // heap sizes determined using Configuration::showHeapStats + // Heap sizes for this network determined using Configuration::showHeapStats c.PARAM_HEAP_SIZE = (3 << 20); // 3MB c.NETWORK_HEAP_SIZE = (20 << 20); // 20MB @@ -116,7 +106,6 @@ bool Run(const string& config_file, int num_eve, int num_dsp, // Open input file for reading std::ifstream input_data_file(c.inData, std::ios::binary); - assert (input_data_file.good()); bool status = true; try @@ -187,106 +176,3 @@ void CollectEOs(const Executor *e, vector& EOs) EOs.push_back((*e)[i]); } -// Allocate input and output memory for each EO -void AllocateMemory(const vector& EOs) -{ - // Allocate input and output buffers for each execution object - for (auto eo : EOs) - { - size_t in_size = eo->GetInputBufferSizeInBytes(); - size_t out_size = eo->GetOutputBufferSizeInBytes(); - ArgInfo in = { ArgInfo(malloc(in_size), in_size)}; - ArgInfo out = { ArgInfo(malloc(out_size), out_size)}; - eo->SetInputOutputBuffer(in, out); - } -} - -// Free the input and output memory associated with each EO -void FreeMemory(const vector& EOs) -{ - for (auto eo : EOs) - { - free(eo->GetInputBufferPtr()); - free(eo->GetOutputBufferPtr()); - } - -} - -// Read a frame. Since the sample input has a single frame, read the same -// frame over and over. -bool ReadFrame(ExecutionObject *eo, int frame_idx, - const Configuration& configuration, - std::istream& input_file) -{ - char* frame_buffer = eo->GetInputBufferPtr(); - assert (frame_buffer != nullptr); - - input_file.seekg(0, input_file.beg); - - input_file.read(eo->GetInputBufferPtr(), - eo->GetInputBufferSizeInBytes()); - - if (input_file.eof()) - return false; - - assert (input_file.good()); - - // Note: Frame index is used by the EO for debug messages only - eo->SetFrameIndex(frame_idx); - - if (input_file.good()) - return true; - - return false; -} - -// Compare output against reference output -bool CheckFrame(const ExecutionObject *eo, const char *ref_output) -{ - if (std::memcmp(static_cast(ref_output), - static_cast(eo->GetOutputBufferPtr()), - eo->GetOutputBufferSizeInBytes()) == 0) - return true; - - return false; -} - - -void ReportTime(const ExecutionObject* eo) -{ - double elapsed_host = eo->GetHostProcessTimeInMilliSeconds(); - double elapsed_device = eo->GetProcessTimeInMilliSeconds(); - double overhead = 100 - (elapsed_device/elapsed_host*100); - - std::cout << format("frame[%3d]: Time on %s: %4.2f ms, host: %4.2f ms" - " API overhead: %2.2f %%\n") - % eo->GetFrameIndex() % eo->GetDeviceName() - % elapsed_device % elapsed_host % overhead; -} - -namespace tidl { -std::size_t GetBinaryFileSize (const std::string &F); -bool ReadBinary (const std::string &F, char* buffer, int size); -} - -// Read a file into a buffer. -const char* ReadReferenceOutput(const string& name) -{ - size_t size = GetBinaryFileSize(name); - - if (size == 0) - return nullptr; - - char* buffer = new char[size]; - - if (!buffer) - return nullptr; - - if (!ReadBinary(name, buffer, size)) - { - delete [] buffer; - return nullptr; - } - - return buffer; -}