# HG changeset patch # User autobackup # Date 1609773003 -32400 # Node ID a6fe06ec0cf9297fcbc458a71c79045472f66962 # Parent 7c64665b26bfd8741ecc2933283555f5ec4f8ff4 backup 2021-01-05 diff -r 7c64665b26bf -r a6fe06ec0cf9 user/anatofuz/note/2021/01/04.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user/anatofuz/note/2021/01/04.md Tue Jan 05 00:10:03 2021 +0900 @@ -0,0 +1,227 @@ +# 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 ( ) { + chomp; + print 'push(@list, \'', $_, " ' );\n"; +} + + +__DATA__ +#include +#include +#include +#include + +$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 +#include +#include +#include + +#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); +} +```