view user/anatofuz/note/2021/01/04.md @ 16:a6fe06ec0cf9

backup 2021-01-05
author autobackup
date Tue, 05 Jan 2021 00:10:03 +0900
parents
children
line wrap: on
line source

# 2021/01/04

# やったこと
- hg-browseの改修
    - linux対応
        - 自分が使いたい
    - コアモジュール対応


# Perlのネタ

- `$^O`で動かしているOSがとれる

>     $OSNAME
>    $^O     The name of the operating system under which this copy of Perl
>            was built, as determined during the configuration process. For
>            examples see "PLATFORMS" in perlport.
>
>            The value is identical to $Config{'osname'}. See also Config and
>            the -V command-line switch documented in perlrun.


# Gmain

- こんな感じのperlを書いた
    - `__DATA__`以下をリストにpushするPerlのソースコードに変換するやつ
    - ヒアドキュメントを使うとリストに変換できない問題があるので...


```perl
while (<DATA> ) {
  chomp;
  print 'push(@list, \'', $_, " ' );\n";
}


__DATA__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

$includes

int cpu_num = 1;
int length = 102400;
int split = 8;
int* array_ptr;
int gpu_num = 0;
int CPU_ANY = -1;
int CPU_CUDA = -1;

__code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
    // loopCounter->tree = createRedBlackTree(context);
    loopCounter->i = 0;
    taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
    goto prevTask();
}

__code prevTask(struct LoopCounter* loopCounter) {
    printf("cpus:\t\t%d\n", cpu_num);
    printf("gpus:\t\t%d\n", gpu_num);
    printf("length:\t\t%d\n", length);
    printf("length/task:\t%d\n", length/split);
    /* puts("queue"); */
    /* print_queue(context->data[ActiveQueue]->queue.first); */
    /* puts("tree"); */
    /* print_tree(context->data[Tree]->tree.root); */
    /* puts("result"); */
    goto createTask();
}


__code createTask(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
  $gmain
}

__code shutdown(struct TaskManager* taskManager) {
    goto taskManager->shutdown(exit_code);
}

__code shutdown_stub(struct Context* context) {
    goto shutdown(context, &Gearef(context, TaskManager)->taskManager->TaskManager);
}



void init(int argc, char** argv) {
    for (int i = 1; argv[i]; ++i) {
        if (strcmp(argv[i], "-cpu") == 0)
            cpu_num = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-l") == 0)
            length = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-s") == 0)
            split = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-cuda") == 0) {
            gpu_num = 1;
            CPU_CUDA = 0;
        }
    }
}

int main(int argc, char** argv) {
    init(argc, argv);
    goto initDataGears();
}
$other
```


# gmain


これが


```c
#interface "Stack.h"
#interface "StackTest.h"

__code gmain(){
    Stack* stack = createSingleLinkedStack(context);
    StackTest* stackTest = createStackTestImpl3(context);
    goto stackTest->insertTest1(stack, shutdown);
}
```

こうなる

```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include "../../../context.h"

int cpu_num = 1;
int length = 102400;
int split = 8;
int* array_ptr;
int gpu_num = 0;
int CPU_ANY = -1;
int CPU_CUDA = -1;

__code initDataGears(struct Context *context,struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
    // loopCounter->tree = createRedBlackTree(context);
    loopCounter->i = 0;
    taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
    goto meta(context, C_prevTask);
}

__code initDataGears_stub(struct Context* context) {
	LoopCounter* loopCounter = Gearef(context, LoopCounter);
	TaskManager* taskManager = Gearef(context, TaskManager);
	goto initDataGears(context, loopCounter, taskManager);
}

__code prevTask(struct Context *context,struct LoopCounter* loopCounter) {
    printf("cpus:\t\t%d\n", cpu_num);
    printf("gpus:\t\t%d\n", gpu_num);
    printf("length:\t\t%d\n", length);
    printf("length/task:\t%d\n", length/split);
    /* puts("queue"); */
    /* print_queue(context->data[ActiveQueue]->queue.first); */
    /* puts("tree"); */
    /* print_tree(context->data[Tree]->tree.root); */
    /* puts("result"); */
    goto meta(context, C_createTask);
}


__code prevTask_stub(struct Context* context) {
	LoopCounter* loopCounter = Gearef(context, LoopCounter);
	goto prevTask(context, loopCounter);
}

__code createTask(struct Context *context,struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
    Stack* stack = createSingleLinkedStack(context);
    StackTest* stackTest = createStackTestImpl3(context);
    Gearef(context, StackTest)->stackTest = (union Data*) stackTest;
    Gearef(context, StackTest)->stack = stack;
    Gearef(context, StackTest)->next = C_shutdown;
    goto meta(context, stackTest->insertTest1);
}

__code createTask_stub(struct Context* context) {
	LoopCounter* loopCounter = Gearef(context, LoopCounter);
	TaskManager* taskManager = Gearef(context, TaskManager);
	goto createTask(context, loopCounter, taskManager);
}

__code shutdown(struct Context *context,struct TaskManager* taskManager) {
    Gearef(context, TaskManager)->taskManager = (union Data*) taskManager;
    Gearef(context, TaskManager)->next = C_exit_code;
    goto meta(context, taskManager->shutdown);
}

__code shutdown_stub(struct Context* context) {
    goto shutdown(context, &Gearef(context, TaskManager)->taskManager->TaskManager);
}



void init(int argc, char** argv) {
    for (int i = 1; argv[i]; ++i) {
        if (strcmp(argv[i], "-cpu") == 0)
            cpu_num = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-l") == 0)
            length = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-s") == 0)
            split = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-cuda") == 0) {
            gpu_num = 1;
            CPU_CUDA = 0;
        }
    }
}

int main(int argc, char** argv) {
    init(argc, argv);
    struct Context* main_context = NEW(struct Context);
    initContext(main_context);
    main_context->next = C_initDataGears;
    goto start_code(main_context);
}
```