/*
 *   -- micMAGMA (version 0.1) --
 *      Univ. of Tennessee, Knoxville
 *      Univ. of California, Berkeley
 *      Univ. of Colorado, Denver
 *      April 2012
 *
 *   @author Azzam Haidar
 *   @author Khairul Kabir 
 *
 *   @precisions normal z -> s d c
 */

case magma_mic_ZCOPY:
{
    //printf("copy\n");
    magma_mic_zcopy_param zcopy_param;

    if (mic_recv(&zcopy_param, sizeof(zcopy_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZCOPY\n");
        return;
    }

    mic_time = dsecnd();
    call_zcopy(zcopy_param);
    mic_time = dsecnd() - mic_time;

    break;
}


case magma_mic_ZGEMM:
{
    //printf("gemm\n");
    magma_mic_zgemm_param zgemm_param;

    if (mic_recv(&zgemm_param, sizeof(zgemm_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZGEMM\n");
        return;
    }

    mic_time = dsecnd();
    call_zgemm(zgemm_param);
    mic_time = dsecnd() - mic_time;

    m = zgemm_param.m;
    n = zgemm_param.n;
    k = zgemm_param.k;
    gflops = MICFLOPS_GEMM((double)m, (double)n, (double)k) * 1e-9;
    //printf("zgemm: %d\t%d\t%d\t%8.2lf\t%8.2lf\t%8.2lf\n", m, n, k, mic_time, gflops, gflops/mic_time);
    break;
}

case magma_mic_ZHEMM:
{
    //printf("hemm\n");                                                                                                          
    magma_mic_zhemm_param zhemm_param;

    if (mic_recv(&zhemm_param, sizeof(zhemm_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHEMM\n");
        return;
    }

    mic_time = dsecnd();
    call_zhemm(zhemm_param);
    mic_time = dsecnd() - mic_time;

    m = zhemm_param.m;
    n = zhemm_param.n;
    magma_side_t side = zhemm_param.side;

    //gflops = MICFLOPS_SYMM((magma_side_t)side, (double)m, (double)n ) * 1e-9;
    //printf("zhemm: %d\t%d\t%g\t%g\t%g\n", m, n, mic_time,gflops, gflops/mic_time);
    break;
}

case magma_mic_ZGEMV:
{
    //printf("gemv\n");
    magma_mic_zgemv_param zgemv_param;

    if (mic_recv(&zgemv_param, sizeof(zgemv_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZGEMV\n");
        return;
    }

    mic_time = dsecnd();
    call_zgemv(zgemv_param);
    mic_time = dsecnd() - mic_time;

    m = zgemv_param.m;
    n = zgemv_param.n;
    //gflops = MICFLOPS_GEMV((double)m, (double)n) * 1e-9;
    //printf("zgemv: %d\t%d\t%g\t%g\t%g\n", m, n, mic_time,
    //        gflops, gflops/mic_time);
    break;
}

case magma_mic_ZHEMV:
{
    //printf("hemv\n");
    magma_mic_zhemv_param hemv_param;

    if (mic_recv(&hemv_param, sizeof(hemv_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHEMV\n");
        return;
    }

    mic_time = dsecnd();
    call_zhemv(hemv_param);
    mic_time = dsecnd() - mic_time;

    break;
}

case magma_mic_ZSYMV2:
{
    //printf("symv2\n");
    magma_mic_zsymv2_param symv_param;

    if (mic_recv(&symv_param, sizeof(symv_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHEMV\n");
        return;
    }

    mic_time = dsecnd();
    call_zsymv2(symv_param);
    mic_time = dsecnd() - mic_time;

    break;
}

case magma_mic_ZTRSM:
{
    //printf("ztrsm\n");                                                                                                                                                                                                                          
    magma_mic_ztrsm_param ztrsm_param;
    if (mic_recv(&ztrsm_param, sizeof(ztrsm_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZTRSM\n");
        return;
    }

    mic_time = dsecnd();
    call_ztrsm(ztrsm_param);
    mic_time = dsecnd() - mic_time;

    side = ztrsm_param.side;
    m = ztrsm_param.m;
    n = ztrsm_param.n;

    if(side == MagmaLeft)
        gflops = MICFLOPS_TRSM_L((double)m, (double)n) * 1e-9;
    else
        gflops = MICFLOPS_TRSM_R((double)m, (double)n) * 1e-9;

    //printf("ztrsm: %c\t%d\t%d\t%f\t%f\t%f\n", side, m, n, mic_time,
    //     gflops, gflops/mic_time);
    break;
}

case magma_mic_ZTRSV:
{
   //printf("ztrsv\n");

   magma_mic_ztrsv_param ztrsv_param;
   if (mic_recv(&ztrsv_param, sizeof(ztrsv_param)) == MIC_FAILURE) {
     printf("scif_recv failed for ZTRSV\n");
     return;
   }

   mic_time = dsecnd();
   call_ztrsv(ztrsv_param);
   mic_time = dsecnd() - mic_time;

   break;
}

case magma_mic_ZTRMV:
{
   //printf("ztrmv\n");

   magma_mic_ztrmv_param trmv_param;
   if (mic_recv(&trmv_param, sizeof(trmv_param)) == MIC_FAILURE) {
     printf("scif_recv failed for ZTRMV\n");
     return;
   }

   mic_time = dsecnd();
   call_ztrmv(trmv_param);
   mic_time = dsecnd() - mic_time;

   break;
}

case magma_mic_ZTRMM:
{
    //printf("ztrmm\n");
    magma_mic_ztrmm_param ztrmm_param;
    if (mic_recv(&ztrmm_param, sizeof(ztrmm_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZTRMM\n");
        return;
    }

    mic_time = dsecnd();
    call_ztrmm(ztrmm_param);
    mic_time = dsecnd() - mic_time;

    side = ztrmm_param.side;
    m = ztrmm_param.m;
    n = ztrmm_param.n;

    //if(side == 'L')
    //    gflops = MICFLOPS_TRSM_L((float)m, (float)n) * 1e-9;
    //else
    //    gflops = MICFLOPS_TRSM_R((float)m, (float)n) * 1e-9;

    //printf("ztrmm: %c\t%d\t%d\t%f\t%f\t%f\n", side, m, n, mic_time, gflops, gflops/mic_time);
    break;
}

case magma_mic_ZHERK:
{
    //printf("zherk\n");
    magma_mic_zherk_param zherk_param;
    if (mic_recv(&zherk_param, sizeof(zherk_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHERK\n");
        return;
    }

    mic_time = dsecnd();
    call_zherk(zherk_param);
    mic_time = dsecnd() - mic_time;

    n = zherk_param.n;
    k = zherk_param.k;
    //gflops = MICFLOPS_SYRK((float)n, (float)k) * 1e-9;
    //printf("zherk: %d\t%d\t%f\t%f\t%f\n", n, k, mic_time, gflops, gflops/mic_time);
    break;
}

case magma_mic_ZHERK_MMIC:
{
    //printf("zherk\n");
    magma_mic_zherk_mmic_param zherk_mmic_param;
    if (mic_recv(&zherk_mmic_param, sizeof(zherk_mmic_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHERK_MMIC\n");
        return;
    }

    mic_time = dsecnd();
    call_zherk_mmic(zherk_mmic_param);
    mic_time = dsecnd() - mic_time;

    n = zherk_mmic_param.n;
    k = zherk_mmic_param.k;
    //gflops = MICFLOPS_SYRK((float)n, (float)k) * 1e-9;
    //printf("zherk: %d\t%d\t%f\t%f\t%f\n", n, k, mic_time, gflops, gflops/mic_time);
    break;
}


case magma_mic_ZHER2K:
{
    //printf("zher2k\n");
    magma_mic_zher2k_param zher2k_param;
    if (mic_recv(&zher2k_param, sizeof(zher2k_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHER2K\n");
        return;
    }

    mic_time = dsecnd();
    call_zher2k(zher2k_param);
    mic_time = dsecnd() - mic_time;

    n = zher2k_param.n;
    k = zher2k_param.k;
    //gflops = MICFLOPS_SYR2K((float)n, (float)k) * 1e-9;
    //printf("zher2k: %d\t%d\t%f\t%f\t%f\n", n, k, mic_time, gflops, gflops/mic_time);
    break;
}

case magma_mic_ZHER2K_MMIC:
{
    //printf("zher2k_mmic\n");
    magma_mic_zher2k_mmic_param zher2k_mmic_param;
    if (mic_recv(&zher2k_mmic_param, sizeof(zher2k_mmic_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZHER2K_MMIC\n");
        return;
    }

    //mic_time = dsecnd();
    call_zher2k_mmic(zher2k_mmic_param);
    //mic_time = dsecnd() - mic_time;

    n = zher2k_mmic_param.n;
    k = zher2k_mmic_param.k;
    //gflops = MICFLOPS_SYRK((float)n, (float)k) * 1e-9;
    //printf("zherk: %d\t%d\t%f\t%f\t%f\n", n, k, mic_time, gflops, gflops/mic_time);
    break;
}

case magma_mic_ZLARFT:
{
    //printf("zlarft\n");                                                                                                                                                                                                                         
    magma_mic_zlarft_param zlarft_param;
    if (mic_recv(&zlarft_param, sizeof(zlarft_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZLARFT\n");
        return;
    }

    //mic_time = dsecnd();
    call_zlarft(zlarft_param);
    //mic_time = dsecnd() - mic_time;

    //gflops = MICFLOPS_GEMM((float)m, (float)n, (float)k) * 1e-9;
    //printf("zlarft: %d\t%d\t%d\t%f\t%f\t%f\n", m, n, k, mic_time,                                                                                                                                                                               
    //     gflops, gflops/mic_time);                                                                                                                                                                                                            
    break;
}

case magma_mic_ZLARFB:
{
    //printf("zlarfb\n");                                                                                                                                                                                                                         
    magma_mic_zlarfb_param zlarfb_param;
    if (mic_recv(&zlarfb_param, sizeof(zlarfb_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZLARFB\n");
        return;
    }

    //mic_time = dsecnd();
    call_zlarfb(zlarfb_param);
    //mic_time = dsecnd();

    //gflops = MICFLOPS_GEMM((float)m, (float)n, (float)k) * 1e-9;
    //printf("zlarfb: %d\t%d\t%d\t%f\t%f\t%f\n", m, n, k, mic_time,                                                                                                                                                                               
    //     gflops, gflops/mic_time);                                                                                                                                                                                                            
    break;
}

case magma_mic_ZLARFB_GEMM:
{
    //printf("dlarfb\n");
    

    magma_mic_zlarfb_gemm_param zlarfb_gemm_param;
    if (mic_recv(&zlarfb_gemm_param, sizeof(zlarfb_gemm_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZLARFB_GEMM\n");
        return;
    }

    //mic_time = dsecnd();
    call_zlarfb_gemm(zlarfb_gemm_param);
    //mic_time = dsecnd();

    //gflops = MICFLOPS_GEMM((float)m, (float)n, (float)k) * 1e-9;
    //printf("slarfb: %d\t%d\t%d\t%f\t%f\t%f\n", m, n, k, mic_time,
    //     gflops, gflops/mic_time);
    break;
}

case magma_mic_ZTRSM_GEMM:
{
    //printf("ztrsmgemm\n");
    magma_mic_ztrsmgemm_param ztrsmgemm_param;
    magma_mic_zgemm_param zgemm_param;
    magma_mic_ztrsm_param ztrsm_param;

    if (mic_recv(&ztrsmgemm_param, sizeof(ztrsmgemm_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZTRSM_GEMM\n");
        return;
    }

    mic_time = dsecnd();
    call_ztrsmgemm(ztrsmgemm_param);
    mic_time = dsecnd() - mic_time;

    break;
}    

case magma_mic_ZLASET:
{
    magma_mic_zlaset_param zlaset_param;
    if (mic_recv(&zlaset_param, sizeof(zlaset_param)) == MIC_FAILURE) {
      printf("scif_recv failed for ZLASET\n");
      return;
    }

    call_zlaset(zlaset_param);

    break;
}

case magma_mic_ZLASWP:
{
    magma_mic_zlaswp_param zlaswp_param;
    if (mic_recv(&zlaswp_param, sizeof(zlaswp_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZLASWP\n");
        return;
    }

    call_zlaswp(zlaswp_param);

    break;
}

case magma_mic_ZSWAP:
{
    magma_mic_zswap_param zswap_param;
    if (mic_recv(&zswap_param, sizeof(zswap_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZSWAP\n");
        return;
    }

    call_zswap(zswap_param);

    break;
}

case magma_mic_ZTRANSPOSE:
{
    magma_mic_ztranspose_param ztranspose_param;
    if (mic_recv(&ztranspose_param, sizeof(ztranspose_param)) == MIC_FAILURE) {
        printf("scif_recv failed for ZTRANSPOSE\n");
        return;
    }

    call_ztranspose(ztranspose_param);

    break;
}
