// File: yuang-chen[P]paraGCN/src/gcn.cpp
// Function: GCN::run()
void GCN::run() {
     int epoch = 1;
     float total_time = 0.0;
     vector<float> loss_history;

     for(; epoch <= params.epochs; epoch++) {
        float train_loss, train_acc, val_loss, val_acc;
        timer_start(TMR_TRAIN);
        tie(train_loss, train_acc) = train_epoch();
        tie(val_loss, val_acc) = eval(2);
        printf("epoch=%d train_loss=%.5f train_acc=%.5f val_loss=%.5f val_acc=%.5f time=%.5f\n",
            epoch, train_loss, train_acc, val_loss, val_acc, timer_stop(TMR_TRAIN));
        loss_history.emplace_back(val_loss);
        if(params.early_stopping > 0 && epoch >= params.early_stopping) {
            float recent_loss = 0.0;
            for(int i = epoch - params.early_stopping; i < epoch; i++) {
                recent_loss += loss_history[i];
            }
            if(val_loss > recent_loss / params.early_stopping) {
                printf("early stopping...\n");
                break;
            }
        }
    }
    PRINT_TIMER_AVERAGE(TMR_TRAIN, epoch);


    float test_loss, test_acc;
    timer_start(TMR_TEST);
    tie(test_loss, test_acc) = eval(3);
    printf("test_loss=%.5f test_acc=%.5f time=%.5f\n", test_loss, test_acc, timer_stop(TMR_TEST));
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x1, -0xc(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x55f0
movq -0xa8(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0xb4(%rcx), %eax
jg 0x4a6a
xorl %edi, %edi
callq 0xeaa0
jmp 0x4851
movq -0xa8(%rbp), %rdi
callq 0x45f0
movaps %xmm0, -0xc0(%rbp)
jmp 0x4866
movaps -0xc0(%rbp), %xmm0
movlpd %xmm0, -0x4c(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x5610
movq -0xd8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x5650
movq -0xa8(%rbp), %rdi
movl $0x2, %esi
callq 0x4720
movaps %xmm0, -0xd0(%rbp)
jmp 0x48b4
movaps -0xd0(%rbp), %xmm0
movlpd %xmm0, -0x68(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0x110(%rbp)
leaq -0x34(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x5610
movq -0x110(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x5650
movl -0xc(%rbp), %eax
movl %eax, -0x104(%rbp)
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xf8(%rbp)
movss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xf0(%rbp)
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xe8(%rbp)
xorl %edi, %edi
callq 0xead0
movss %xmm0, -0xdc(%rbp)
jmp 0x4946
movsd -0xe8(%rbp), %xmm3
movsd -0xf0(%rbp), %xmm2
movsd -0xf8(%rbp), %xmm1
movsd -0x100(%rbp), %xmm0
movl -0x104(%rbp), %esi
movss -0xdc(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
leaq 0xb699(%rip), %rdi      # 0x10018
movb $0x5, %al
callq 0x3050
jmp 0x4988
leaq -0x28(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x56c0
jmp 0x4997
movq -0xa8(%rbp), %rax
cmpl $0x0, 0xb8(%rax)
jle 0x4a5a
movq -0xa8(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0xb8(%rcx), %eax
jl 0x4a5a
movq -0xa8(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, -0x7c(%rbp)
movl -0xc(%rbp), %eax
subl 0xb8(%rcx), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4a24
movslq -0x80(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x5520
movss (%rax), %xmm0
addss -0x7c(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x49dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5740
jmp 0x4b8f
movq -0xa8(%rbp), %rax
movss -0x34(%rbp), %xmm0
movss -0x7c(%rbp), %xmm1
cvtsi2ssl 0xb8(%rax), %xmm2
divss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x4a58
leaq 0xb619(%rip), %rdi      # 0x10066
xorl %eax, %eax
callq 0x3050
jmp 0x4a56
jmp 0x4a6a
jmp 0x4a5a
jmp 0x4a5c
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4832
xorl %edi, %edi
callq 0xeb50
movss %xmm0, -0x114(%rbp)
jmp 0x4a7b
movss -0x114(%rbp), %xmm0
movss 0xb589(%rip), %xmm1     # 0x10014
mulss %xmm1, %xmm0
cvtsi2ssl -0xc(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0xb5d6(%rip), %rdi      # 0x10079
movb $0x1, %al
callq 0x3050
jmp 0x4aac
movl $0x1, %edi
callq 0xeaa0
jmp 0x4ab8
movq -0xa8(%rbp), %rdi
movl $0x3, %esi
callq 0x4720
movaps %xmm0, -0x130(%rbp)
jmp 0x4ad2
movaps -0x130(%rbp), %xmm0
movlpd %xmm0, -0x90(%rbp)
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x150(%rbp)
leaq -0x84(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x5610
movq -0x150(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x5650
movss -0x84(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x148(%rbp)
movss -0x88(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x140(%rbp)
movl $0x1, %edi
callq 0xead0
movss %xmm0, -0x134(%rbp)
jmp 0x4b51
movsd -0x140(%rbp), %xmm1
movsd -0x148(%rbp), %xmm0
movss -0x134(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0xb525(%rip), %rdi      # 0x10099
movb $0x3, %al
callq 0x3050
jmp 0x4b7d
leaq -0x28(%rbp), %rdi
callq 0x5740
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3420
nopl (%rax,%rax)