MCPcopy Create free account
hub / github.com/ddsggcs/cv_learning_resnet50 / CompileModule

Function CompileModule

practice/cpp/5th_codegen/resnet_codegen.cc:504–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

502}
503
504void CompileModule() {
505 std::cout << "\033[0;32mBegin Compile Module \033[0m" << std::endl;
506 std::system("rm -rf codegen/*.so codegen/*.o;");
507 std::string cmd_common;
508 std::string cmd;
509 std::string opt_level = " -Ofast ";
510 std::string opencv_install_dir = "/usr/include/opencv4";
511 std::string codegen_dir = "codegen";
512 cmd_common = "g++ -mavx -fPIC " + opt_level + "-I" + opencv_install_dir +
513 " -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs ";
514
515 int compile_step = 1;
516 const int total_steps = 59;
517 auto CompileStepVision = [&](int& step, const std::string& cmd) {
518 float pre = (float)step / (float)total_steps * 100;
519 auto pre_label = "[" + std::to_string((int)pre) + "%]";
520 std::cout << pre_label << " \033[0;32m" << cmd << "\033[0m" << std::endl;
521 step++;
522 };
523
524 // compile .cc to .o
525 std::vector<std::string> obj_list;
526 auto Compile2Obj = [&](const std::string& layer_name) {
527 auto cmd = cmd_common + "-c " + codegen_dir + "/" + layer_name + ".cc" + " -o " + codegen_dir +
528 "/" + layer_name + ".o";
529 CompileStepVision(compile_step, cmd);
530 std::system(cmd.c_str());
531 obj_list.push_back(codegen_dir + "/" + layer_name + ".o");
532 };
533 Compile2Obj("maxpool");
534 Compile2Obj("avgpool");
535 Compile2Obj("bn");
536 Compile2Obj("fc");
537 Compile2Obj("codegen");
538 for (int i = 0; i < 53; i++) {
539 Compile2Obj("conv_" + std::to_string(i));
540 }
541
542 // link .o to libresnet.so
543 cmd = cmd_common + "-shared -o " + codegen_dir + "/libresnet.so ";
544 for (auto it : obj_list) {
545 cmd += it + " ";
546 }
547 CompileStepVision(compile_step, cmd);
548 std::system(cmd.c_str());
549 std::system("rm -f codegen/*.o;");
550 std::cout << "\033[0;32mEnd Compile Module \033[0m" << std::endl;
551}
552
553Module LoadModule() {
554 void* handle = dlopen("./codegen/libresnet.so", RTLD_LAZY);

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected