view TaskManager/kernel/main.cc @ 2069:26aa08c9a1de draft default tip

cuda example fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 12 Feb 2017 10:04:55 +0900
parents e93e115b1903
children
line wrap: on
line source

#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include "TaskManager.h"

/*!
  User が書いた TMmain() (*名前は固定) を実行する
 */

/* User main function */
extern int TMmain(TaskManager* manager, int argc, char *argv[]);

static int profile = 0;

/* Default TMend function */
static void
defaultTMend(TaskManager *manager) {
}

//TaskManager *manager;

/*!
  const char *usr_help_str を User 側で指定する必要がある
  -help で出力される文字列
 */
const char *help_str = "\n\
* Cerium program option *\n\
  -help Print this message \n\
  -cpu   Number of CPU (default 1) \n";

extern const char *usr_help_str;

int
main(int argc, char *argv[])
{
    int machineNum = 1;
    int gpuNum = 0;
    int speIdle = 0;
    int useRefDma = 0;
    int export_task_log = 0;

    for (int i = 1; argv[i]; ++i) {
        if (strcmp(argv[i], "-cpu") == 0) {
            machineNum = atoi(argv[++i]);
        } else if (strcmp(argv[i], "-gpu") == 0) {
            gpuNum = 1;
        } else if (strcmp(argv[i], "-p") == 0) {
            profile = 1;
        } else if (strcmp(argv[i], "-export") == 0) {
            export_task_log = 1;
        } else if (strcmp(argv[i], "-speidle") == 0) { // これなんだよ?
            speIdle = atoi(argv[++i]);
        } else if (strcmp(argv[i], "-copy") == 0) { // force copy DMA in FifoManager
            useRefDma |= 0x01;
        } else if (strcmp(argv[i], "-pre") == 0) {  // deplicated
            useRefDma |= 0x10;
        }
    }

    TaskManager *manager = new TaskManager(machineNum, gpuNum);
    manager->init(speIdle,export_task_log, useRefDma);

    manager->set_TMend(defaultTMend);

    for (int i = 1; argv[i]; ++i) {
        if (strcmp(argv[i], "-help") == 0) {
          if (usr_help_str) {
            manager->get_scheduler()->printf("%s", usr_help_str);
          }
          manager->get_scheduler()->printf("%s", help_str);
          return EXIT_SUCCESS;
        }
    }

    if (profile)
        manager->start_profile();
    if (TMmain(manager, argc, argv) < 0) {
        goto FINISH;
    }

    manager->run();

    (manager->tm_end)(manager);
    if (profile)
        manager->show_profile();
    if (export_task_log)
        manager->export_task_log();

    manager->run(); // tm_end/show_profile may create a Task..

FINISH:
    delete manager;

    return EXIT_SUCCESS;
}

/* end */