Add --parallelism option for crossgen2
authorWoongsuk Cho <ws77.cho@samsung.com>
Mon, 18 Nov 2024 22:55:52 +0000 (07:55 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Tue, 19 Nov 2024 04:22:28 +0000 (13:22 +0900)
To control thread number of crossgen2, add --parallelism option
the default value is logical cpu number and it should be bigger than 1

NativeLauncher/inc/ni_common.h
NativeLauncher/tool/dotnettool.cc
NativeLauncher/tool/ni_common.cc

index 1fdbf3323edbc76cd599c28a1e97ed28d6816de5..7189b345f86298e9661be7e5624f73594fd6fce1 100644 (file)
@@ -41,6 +41,7 @@
 #define NI_FLAGS_SKIP_RO_APP            0x0400
 #define NI_FLAGS_RM_ORIGIN_AFTER_NI     0x0800
 #define NI_FLAGS_SET_PRIORITY           0x1000
+#define NI_FLAGS_PARALLELISM            0x2000
 
 typedef std::function<void (std::string)> afterCreate;
 
@@ -63,6 +64,7 @@ typedef struct NIOption{
        std::vector<std::string> inputBubbleRefFiles;
        std::vector<std::string> mibcPath;
        int priority;
+       std::string threadNum;
 } NIOption;
 
 /**
index d65454a96e3a86201004279c4a0701a23ce52538..baaa2ec27b9a6e8d6fdf7da63106e4af1d8e5878 100644 (file)
@@ -80,6 +80,7 @@ void DisplayUsage() {
                "                                   Note!: App ATOC options(--ni-pkg, --ni-regen-all-app, --tac-regen-all) cannot be used with --rm-origin-after-ni option.\n"
                "                                   (Use only for assemblies that will not be AOTed again afterward.)\n"
                "       --set-priority            - Sets the priority of the process to the specified values from -20(highest priority) to 19(lowest priority).(default : 0)\n"
+               "       --parallelism             - Sets the maximum number of threads to use in AOTC (default = logical processor count)\n"
 
                "\n"
                "Usage: dotnettool [options] [command] [arguments]\n"
@@ -399,6 +400,27 @@ int main(int argc, char* argv[])
                                DisplayUsage();
                                return -1;
                        }
+               } else if (arg == "--parallelism") {
+                       ++i;
+                       if (i >= argc) {
+                               _SOUT("Number of threads (minimum 1) should be followed for --parallelism option");
+                               DisplayUsage();
+                               return -1;
+                       }
+
+                       opt->flags |= NI_FLAGS_PARALLELISM;
+                       try {
+                               opt->threadNum = argv[i];
+                               if (std::stoi(argv[i]) < 1) {
+                                       _SERR("Number of threads should be bigger than 1 (input : %s)", argv[i]);
+                                       DisplayUsage();
+                                       return -1;
+                               }
+                       } catch (...) {
+                               _SERR("Invalid argument: %s", argv[i]);
+                               DisplayUsage();
+                               return -1;
+                       }
                } else if (arg == "--mibc") {
                        ++i;
                        if (i >= argc) {
index f5a00da7a549eebdf7077c2afee922724397cf35..5deb65b2a6a4c35f96e80c723fb0e73bd1d03a1a 100644 (file)
@@ -73,8 +73,7 @@ static const char* CROSSGEN_OPT_JITPATH = "--jitpath";
 static const char* CROSSGEN_OPT_TARGET_ARCH = "--targetarch";
 static const char* CROSSGEN_OPT_OUT_NEAR_INPUT = "--out-near-input";
 static const char* CROSSGEN_OPT_SINGLE_FILE_COMPILATION = "--single-file-compilation";
-//static const char* CROSSGEN_OPT_PARALLELISM = "--parallelism";
-//static const char* CROSSGEN_OPT_PARALLELISM_COUNT = "5";
+static const char* CROSSGEN_OPT_PARALLELISM = "--parallelism";
 static const char* CROSSGEN_OPT_RESILIENT = "--resilient";
 //static const char* CROSSGEN_OPT_OPTIMIZE = "-O";
 static const char* CROSSGEN_OPT_OPTIMIZE_TIME = "--Ot";
@@ -341,8 +340,10 @@ static void makeArgs(std::vector<const char*>& args, const std::vector<std::stri
        args.push_back(CROSSGEN_OPT_TARGET_ARCH);
        args.push_back(ARCHITECTURE_IDENTIFIER);
 
-       //args.push_back(OPT_PARALLELISM);
-       //args.push_back(OPT_PARALLELISM_COUNT);
+       if (opt->flags & NI_FLAGS_PARALLELISM) {
+               args.push_back(CROSSGEN_OPT_PARALLELISM);
+               args.push_back(opt->threadNum.c_str());
+       }
        args.push_back(CROSSGEN_OPT_RESILIENT);
 
        args.push_back(CROSSGEN_OPT_OPTIMIZE_TIME);