/** * \brief main function to run fix Inferencer * \author Mingzhe Jiang * \copyright 2020 Kneron Inc. All right reserved. */ #include "KL730Inferencer.h" #include #include #include #include //example code, in case users want to use dump and parser functions in this header //#include "run_fix_inferencer.h" #include "iostream" using namespace std; using std::string; using std::vector; using std::unordered_map; using std::unique_ptr; using std::shared_ptr; using namespace dynasty::inferencer; using namespace dynasty::inferencer::fix_point; /** * This is an example of how to use dynamic fixed point inference. * The inferencer output will contain all layer dump if dump level >0, else only the output layer * user might need to write his own dump function for different dump purpose, can take run_fix_reference as an example * configration parser is also up to user's choice. Can be json or command line params. * @param argc * @param argv * @return */ int main(int argc, char *argv[]) { { bool cuda_en = false; //enable cuda if cuda library is installed. don't enable if no cuda ata ll string model_file_730 = "res/KL730/Mul/output/00011_Mul_inputFM1_1x8x4x4x0x0_inputFM2_1x8x4x4x0x0_1inputs_B0_v0.5.kdp730.scaled.bie"; //get only output node with dump_level = 0; get all layer dump with dump_level = 2 int dump_level = 0; const float EPSILON = 0.8; // Max difference tolerance between 520 result and 720 result unordered_map inference_input_730; string input_name_730 = "0"; string input_path_730 = "res/KL730/Mul/input/simulator_input/test_input.txt"; inference_input_730[input_name_730] = input_path_730; // Inference with 730: cuda disabled auto builder = kl730::Inferencer::GetBuilder(); auto inferencer_730 = kl730::createInferencer(builder.get(), model_file_730,cuda_en, 0); unordered_map> float_outputs_730 = inferencer_730->Inference(inference_input_730, dump_level); unordered_map> fix_outputs_730 = inferencer_730->ConvertFloatToInt(float_outputs_730, dump_level); auto input_dim_730 = builder->GetInputDimensions(); for(auto& item: input_dim_730) { cout << "input node name: " << item.first << ", shape: "; for(auto num: item.second) cout<< num <<", "; cout << endl; } cout << "inference with 730 completed" << endl; cout << "Done!" << endl; return 0; } }