# HG changeset patch # User Takato Matsuoka # Date 1642582267 -32400 # Node ID 3e8d89f271e2771d4a1e16d99d41aad94e716490 # Parent e6778c866876c341332d9ec4e77db65e66e0c71a debugger branch diff -r e6778c866876 -r 3e8d89f271e2 src/parallel_execution/DebugTaskManagerImpl.cbc --- a/src/parallel_execution/DebugTaskManagerImpl.cbc Tue Jan 18 19:54:28 2022 +0900 +++ b/src/parallel_execution/DebugTaskManagerImpl.cbc Wed Jan 19 17:51:07 2022 +0900 @@ -14,7 +14,7 @@ // DebugTaskManagerの作成。enumや変数の初期化を行う。 TaskManager* createDebugTaskManagerImpl(struct Context* context, int numCPU, int numGPU, int numIO) { - printf("[Debug log] createDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] createDebugTaskManagerImpl in DebugTaskManager\n"); // TaskManager構造体の生成および、構造体で定義された関数とenumの紐付け。 struct TaskManager* taskManager = new TaskManager(); taskManager->spawnTasks = C_spawnTasksDebugTaskManagerImpl; @@ -48,7 +48,7 @@ // workerの作成。CPUやGPU, モデル検査など環境によって作成するWorkerを変更する。 void createWorkers(struct Context* context, DebugTaskManagerImpl* taskManager) { - printf("[Debug log] createWorkers in DebugTaskManager\n"); + // printf("[Debug log] createWorkers in DebugTaskManager\n"); int i = 0; taskManager->workers = (Worker**)ALLOCATE_PTR_ARRAY(context, Worker, taskManager->maxCPU); for (;igpu;i++) { @@ -71,13 +71,13 @@ // 一連のspawnTaskの始動関数 __code spawnTasksDebugTaskManagerImpl(struct DebugTaskManagerImpl* taskManager, struct Element* taskList, __code next1(...)) { - printf("[Debug log] spawnTaskDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] spawnTaskDebugTaskManagerImpl in DebugTaskManager\n"); taskManager->taskList = taskList; goto spawnTasksDebugTaskManagerImpl1(); } __code spawnTasksDebugTaskManagerImpl1(struct DebugTaskManagerImpl* taskManagerImpl, struct TaskManager* taskManager) { - printf("[Debug log] spawnTasksDebugTaskManagerImpl1 in DebugTaskManager\n"); + // printf("[Debug log] spawnTasksDebugTaskManagerImpl1 in DebugTaskManager\n"); // TaskListにTaskがない場合 if (taskManagerImpl->taskList == NULL) { goto spawnTasksDebugTaskManagerImpl2(); @@ -95,13 +95,13 @@ } __code spawnTasksDebugTaskManagerImpl2(struct DebugTaskManagerImpl* taskManager, struct Element* taskList, __code next1(...)) { - printf("[Debug log] spawnTasksDebugTaskManagerImpl2 DebugTaskManager\n"); + // printf("[Debug log] spawnTasksDebugTaskManagerImpl2 DebugTaskManager\n"); taskManager->taskList = taskList; goto spawnTasksDebugTaskManagerImpl3(); } __code spawnTasksDebugTaskManagerImpl3(struct DebugTaskManagerImpl* taskManagerImpl, __code next1(...), struct TaskManager* taskManager) { - printf("[Debug log] spawnTasksDebugTaskManagerImpl3 in DebugTaskManager\n"); + // printf("[Debug log] spawnTasksDebugTaskManagerImpl3 in DebugTaskManager\n"); if (taskManagerImpl->taskList == NULL) { // struct Queue* tasks = taskManagerImpl->workers[0]->tasks; // printf("put NULL\n"); @@ -122,7 +122,7 @@ // TaskをQueueにputする __code setWaitTaskDebugTaskManagerImpl(struct DebugTaskManagerImpl* taskManager, struct Context* task, __code next(...)) { - printf("[Debug log] setWaitTaskDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] setWaitTaskDebugTaskManagerImpl in DebugTaskManager\n"); int i = taskManager->loopCounter; if (task->idg+i < task->maxIdg) { struct Queue* queue = GET_WAIT_LIST(task->data[task->idg + i]); @@ -134,19 +134,19 @@ } __code incrementTaskCountDebugTaskManagerImpl(struct DebugTaskManagerImpl* taskManager, __code next(...)) { - printf("[Debug log] incrementTaskCountDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] incrementTaskCountDebugTaskManagerImpl in DebugTaskManager\n"); __sync_fetch_and_add(&taskManager->taskCount, 1); goto next(...); } __code decrementTaskCountDebugTaskManagerImpl(struct DebugTaskManagerImpl* taskManager, __code next(...)) { - printf("[Debug log] decrementTaskCountDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] decrementTaskCountDebugTaskManagerImpl in DebugTaskManager\n"); __sync_fetch_and_sub(&taskManager->taskCount, 1); goto next(...); } __code spawnDebugTaskManagerImpl(struct DebugTaskManagerImpl* taskManagerImpl, struct Context* task, __code next(...), struct TaskManager* taskManager) { - printf("[Debug log] spawnDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] spawnDebugTaskManagerImpl in DebugTaskManager\n"); task->taskManager = taskManager; if (task->idgCount == 0) { // iterator task is normal task until spawned @@ -174,7 +174,7 @@ __code taskSend(struct DebugTaskManagerImpl* taskManager, struct Context* task, __code next(...)) { - printf("[Debug log] taskSend in DebugTaskManager\n"); + // printf("[Debug log] taskSend in DebugTaskManager\n"); // set workerId if (task->gpu) { goto taskSend1(); @@ -195,7 +195,7 @@ } __code taskSend2(struct DebugTaskManagerImpl* taskManager, struct Context* task, __code next(...)) { - printf("[Debug log] taskSend2 in DebugTaskManager\n"); + // printf("[Debug log] taskSend2 in DebugTaskManager\n"); int workerId = taskManager->sendCPUWorkerIndex; if (++taskManager->sendCPUWorkerIndex >= taskManager->maxCPU) { taskManager->sendCPUWorkerIndex = taskManager->cpu; @@ -207,7 +207,7 @@ } __code shutdownDebugTaskManagerImpl(struct DebugTaskManagerImpl* taskManager, __code next(...)) { - printf("[Debug log] shutdownDebugTaskManagerImpl in DebugTaskManager\n"); + // printf("[Debug log] shutdownDebugTaskManagerImpl in DebugTaskManager\n"); if (taskManager->taskCount != 0) { usleep(1000); goto shutdownDebugTaskManagerImpl(); @@ -222,13 +222,13 @@ } __code shutdownDebugTaskManagerImpl1(struct DebugTaskManagerImpl* taskManager, __code next(...)) { - printf("[Debug log] shutdownDebugTaskManagerImpl1 in DebugTaskManager\n"); + // printf("[Debug log] shutdownDebugTaskManagerImpl1 in DebugTaskManager\n"); taskManager->loopCounter++; goto shutdownDebugTaskManagerImpl(); } __code shutdownDebugTaskManagerImpl2(struct DebugTaskManagerImpl* taskManager, __code next(...)) { - printf("[Debug log] shutdownDebugTaskManagerImpl2 in DebugTaskManager\n"); + // printf("[Debug log] shutdownDebugTaskManagerImpl2 in DebugTaskManager\n"); int i = taskManager->loopCounter; if (i < taskManager->numWorker) { pthread_join(taskManager->workers[i]->thread, NULL); diff -r e6778c866876 -r 3e8d89f271e2 src/parallel_execution/DebugWorker/DebugWorker.cbc --- a/src/parallel_execution/DebugWorker/DebugWorker.cbc Tue Jan 18 19:54:28 2022 +0900 +++ b/src/parallel_execution/DebugWorker/DebugWorker.cbc Wed Jan 19 17:51:07 2022 +0900 @@ -8,16 +8,18 @@ #interface "Worker.h" #interface "Iterator.h" #interface "Queue.h" - +#interface "SingleLinkedQueue.h" static void startWorker(Worker* worker); +static int dump = 1; + #define INPUT_BUFFER_SIZE 256 #define NUM_OF_COMMAND 2 // workerの作成、初期化、スレッド作成 Worker* createDebugWorker(struct Context* context, int id, Queue* queue) { - printf("[Debug log] createDebugWorker in DebugWorker\n"); + // printf("[Debug log] createDebugWorker in DebugWorker\n"); struct Worker* worker = new Worker(); struct DebugWorker* debugWorker = new DebugWorker(); worker->worker = (union Data*)debugWorker; @@ -35,25 +37,39 @@ worker->taskReceive = C_taskReceiveDebugWorker; worker->shutdown = C_shutdownDebugWorker; pthread_create(&worker->thread, NULL, (void*)&startWorker, worker); + + // context->worker = worker; return worker; } // スレッド用Contextの作成 static void startWorker(struct Worker* worker) { - printf("[Debug log] startWorker in DebugWorker\n"); + // printf("[Debug log] startWorker in DebugWorker\n"); struct DebugWorker* debugWorker = &worker->worker->DebugWorker; debugWorker->context = NEW(struct Context); initContext(debugWorker->context); debugWorker->context->worker = worker; Gearef(debugWorker->context, Worker)->worker = (union Data*)worker; Gearef(debugWorker->context, Worker)->tasks = worker->tasks; - printf("[Debug log] finished startWorker in DebugWorker\n"); + + // init state DB + struct DebugTaskManagerImpl* debugTaskManagerImpl = (struct DebugTaskManagerImpl *)debugWorker->taskManager->taskManager; + StateNode st ; + StateDB out = &st; + out->memory = debugTaskManagerImpl->mem; + out->hash = get_memory_hash(debugTaskManagerImpl->mem,0); + lookup_StateDB(out, &debugTaskManagerImpl->state_db, &out); + if (dump) { + dump_memory(debugTaskManagerImpl->mem); + printf(" flag %0x %p -> %p hash %0x \n", out->flag, debugWorker->parent, out, out->hash); + } + goto meta(debugWorker->context, worker->taskReceive); } // task Queueからtaskの取得 __code taskReceiveDebugWorker(struct DebugWorker* worker, struct Queue* tasks) { - printf("[Debug log] taskReceiveDebugWorker in debug worker\n"); + // printf("[Debug log] taskReceiveDebugWorker in debug worker\n"); goto tasks->take(getTaskDebugWorker); } @@ -83,23 +99,32 @@ goto debugMeta(context, context->next); } +__ncode printTrace(struct Context* context, enum Code next) { + printf("[Debug log] print trace\n"); + + context->next = next; // remember next Code + + // TODO: stateDBに保存したメモリ状態をトレースとして表示させる + struct DebugWorker* debugWorker = (struct DebugWorker*) context->worker->worker; + struct DebugTaskManagerImpl* debugTaskManagerImpl = (struct DebugTaskManagerImpl *)debugWorker->taskManager->taskManager; + + goto debugMeta(context, context->next); +} + __ncode debugMeta(struct Context* context, enum Code next) { - printf("[Debug log] debugMeta in DebugWorker\n"); + // printf("[Debug log] debugMeta in DebugWorker\n"); context->next = next; // remember next Code Gear - printf("start get debugWorker\n"); - struct DebugWorker* debugWorker = (struct DebugWorker*) Gearef(context, Worker); - // struct DebugWorker* debugWorker = (struct DebugWorker*) context->worker->worker; - printf("finish get debugWorker\n"); + struct DebugWorker* debugWorker = (struct DebugWorker*) context->worker->worker; StateNode st; StateDB out = &st; struct Element* list = NULL; struct DebugTaskManagerImpl* debugTaskManagerImpl = (struct DebugTaskManagerImpl *)debugWorker->taskManager->taskManager; out->memory = debugTaskManagerImpl->mem; out->hash = get_memory_hash(debugTaskManagerImpl->mem,0); + int found = visit_StateDB(out, &debugTaskManagerImpl->state_db, &out,debugWorker->visit); // debugTaskManagerImpl->statefunc(debugTaskManagerImpl, debugWorker, debugWorker->parent, out, debugWorker->checking); char command_arr[NUM_OF_COMMAND][INPUT_BUFFER_SIZE]; - while(1) { printf("\n(Gears Debugger) "); // ユーザーインプット処理 @@ -116,15 +141,15 @@ } // checking for input + /* for (i = 0; i < NUM_OF_COMMAND; i++) { printf("command_arr[%d] : %s\n", i, command_arr[i]); } + */ // next // nextする前にstateDBへ保存する処理を書きたい if (strcmp(command_arr[0], "next") == 0 || strcmp(command_arr[0], "n") == 0) { - dump_memory(debugTaskManagerImpl->mem); - // printf(" flag %0x %p -> %p hash %0x \n", out->flag, debugWorker->parent, out, out->hash); goto meta(context, context->next); // quit } else if (strcmp(command_arr[0], "quit") == 0 || strcmp(command_arr[0], "q") == 0) { @@ -140,6 +165,10 @@ // pd(print DataGear) } else if (strcmp(command_arr[0], "pd") == 0){ goto printDataGear(context, context->next, &command_arr[1]); + } else if (strcmp(command_arr[0], "pt") == 0){ + goto printTrace(context, context->next); + } else if (strcmp(command_arr[0], "dump") == 0){ + dump_memory(debugTaskManagerImpl->mem); //others } else { printf("invalid input. Please enter correct debugger commands.\n"); @@ -148,9 +177,9 @@ } __code getTaskDebugWorker(struct DebugWorker* debugWorker, struct Context* task, struct Worker* worker) { - printf("[Debug log] getTaskDebugWorker in DebugWorker\n"); + // printf("[Debug log] getTaskDebugWorker in DebugWorker\n"); if (!task) { - printf("debug worker take task finished\n"); + // printf("debug worker take task finished\n"); goto worker->shutdown(); } printf("debug worker get task\n"); @@ -168,7 +197,7 @@ } __code odgCommitDebugWorker(struct DebugWorker* worker, struct Context* task) { - printf("[Debug log] odgCommitDebugWorker in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker in DebugWorker\n"); if (task->iterate) { struct Iterator* iterator = task->iterator; goto iterator->barrier(task, odgCommitDebugWorker1, odgCommitDebugWorker6); @@ -189,7 +218,7 @@ } __code odgCommitDebugWorker1(struct DebugWorker* worker, struct Context* task) { - printf("[Debug log] odgCommitDebugWorker1 in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker1 in DebugWorker\n"); int i = worker->loopCounter; if (task->odg+i < task->maxOdg) { goto odgCommitDebugWorker2(); @@ -200,21 +229,21 @@ } __code odgCommitDebugWorker2(struct DebugWorker* worker, struct Context* task) { - printf("[Debug log] odgCommitDebugWorker2 in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker2 in DebugWorker\n"); int i = worker->loopCounter; struct Queue* queue = GET_WAIT_LIST(task->data[task->odg+i]); goto queue->isEmpty(odgCommitDebugWorker3, odgCommitDebugWorker5); } __code odgCommitDebugWorker3(struct DebugWorker* worker, struct Context* task) { - printf("[Debug log] odgCommitDebugWorker3 in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker3 in DebugWorker\n"); int i = worker->loopCounter; struct Queue* queue = GET_WAIT_LIST(task->data[task->odg+i]); goto queue->take(odgCommitDebugWorker4); } __code odgCommitDebugWorker4(struct DebugWorker* worker, struct Context* task, struct Context* waitTask) { - printf("[Debug log] odgCommitDebugWorker4 in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker4 in DebugWorker\n"); if (__sync_fetch_and_sub(&waitTask->idgCount, 1) == 1) { // atomic decrement idg counter(__sync_fetch_and_sub function return initial value of waitTask->idgCount point) struct TaskManager* taskManager = waitTask->taskManager; goto taskManager->spawn(waitTask, odgCommitDebugWorker2); @@ -233,18 +262,18 @@ } __code odgCommitDebugWorker5(struct DebugWorker* worker, struct Context* task) { - printf("[Debug log] odgCommitDebugWorker5 in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker5 in DebugWorker\n"); worker->loopCounter++; goto odgCommitDebugWorker1(); } __code odgCommitDebugWorker6(struct DebugWorker* worker, struct Context* task) { - printf("[Debug log] odgCommitDebugWorker6 in DebugWorker\n"); + // printf("[Debug log] odgCommitDebugWorker6 in DebugWorker\n"); struct Worker* taskWorker = task->worker; goto taskWorker->taskReceive(taskWorker->tasks); } __code shutdownDebugWorker(struct DebugWorker* worker) { - printf("[Debug log] shutdownDebugWorker in DebugWorker\n"); + // printf("[Debug log] shutdownDebugWorker in DebugWorker\n"); goto exit_code(); } diff -r e6778c866876 -r 3e8d89f271e2 src/parallel_execution/examples/DebughelloWorld/HelloImpl.cbc --- a/src/parallel_execution/examples/DebughelloWorld/HelloImpl.cbc Tue Jan 18 19:54:28 2022 +0900 +++ b/src/parallel_execution/examples/DebughelloWorld/HelloImpl.cbc Wed Jan 19 17:51:07 2022 +0900 @@ -15,7 +15,6 @@ // ---- Hello* createHelloImpl(struct Context* context) { - printf("[Debug log] createHelloImpl in HelloImpl\n"); struct Hello* hello = new Hello(); struct HelloImpl* hello_impl = new HelloImpl(); hello->hello = (union Data*)hello_impl; @@ -27,14 +26,12 @@ return hello; } __code h(struct HelloImpl* hello, __code next(...)) { - printf("[Debug log] h in HelloImpl\n"); hello->hString = "Hello, "; //createImpl部分では_implなのだが動く printf("%s", hello->hString); goto w(hello, next); } __code w(struct HelloImpl* hello, __code next(...)) { - printf("[Debug log] w in HelloImpl\n"); hello->wString = "World.\n"; printf("%s", hello->wString); goto next(...); diff -r e6778c866876 -r 3e8d89f271e2 src/parallel_execution/examples/DebughelloWorld/main.cbc --- a/src/parallel_execution/examples/DebughelloWorld/main.cbc Tue Jan 18 19:54:28 2022 +0900 +++ b/src/parallel_execution/examples/DebughelloWorld/main.cbc Wed Jan 19 17:51:07 2022 +0900 @@ -17,7 +17,7 @@ int CPU_CUDA = -1; __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { - printf("[Debug log] initDataGears in main\n"); + // printf("[Debug log] initDataGears in main\n"); // loopCounter->tree = createRedBlackTree(context); loopCounter->i = 0; taskManager->taskManager = (union Data*)createDebugTaskManagerImpl(context, cpu_num, gpu_num, 0); @@ -25,7 +25,7 @@ } __code code1(struct LoopCounter* loopCounter) { - printf("[Debug log] code1 in main\n"); + // printf("[Debug log] code1 in main\n"); printf("cpus:\t\t%d\n", cpu_num); printf("gpus:\t\t%d\n", gpu_num); printf("length:\t\t%d\n", length); @@ -35,14 +35,17 @@ __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { - printf("[Debug log] createTask1 in main\n"); + // printf("[Debug log] createTask1 in main\n"); Hello* hello = createHelloImpl(context); - goto hello->h(code2); + struct DebugTaskManagerImpl *debugTaskManagerImpl = (struct DebugTaskManagerImpl *)context->taskManager->taskManager; + add_memory_range((void *)hello, sizeof(Hello), &debugTaskManagerImpl->mem); + par goto hello->h(code2); + goto code2(); } __code code2(struct TaskManager* taskManager) { - printf("[Debug log] code2 in main\n"); + // printf("[Debug log] code2 in main\n"); goto taskManager->shutdown(exit_code); } @@ -51,7 +54,7 @@ } void init(int argc, char** argv) { - printf("[Debug log] init in main\n"); + // printf("[Debug log] init in main\n"); for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-cpu") == 0) cpu_num = (int)atoi(argv[i+1]); @@ -67,7 +70,7 @@ } int main(int argc, char** argv) { - printf("[Debug log] main in main\n"); + // printf("[Debug log] main in main\n"); init(argc, argv); goto initDataGears(); }