2021/01/04

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のソースコードに変換するやつ
    • ヒアドキュメントを使うとリストに変換できない問題があるので…
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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

これが

1
2
3
4
5
6
7
8
#interface "Stack.h"
#interface "StackTest.h"

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

こうなる

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#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);
}
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy