// !!! This is a file automatically generated by hipify!!!
#pragma once

#include <assert.h>
#include <rocblas.h>
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
#include <hip/hip_runtime.h>
#include <mma.h>
#include <stdio.h>

int cublas_gemm_ex(rocblas_handle handle,
                   rocblas_operation transa,
                   rocblas_operation transb,
                   int m,
                   int n,
                   int k,
                   const float* alpha,
                   const float* beta,
                   const float* A,
                   const float* B,
                   float* C,
                   cublasGemmAlgo_t algo)
{
    rocblas_status status = rocblas_gemmex(handle,
                                         transa,
                                         transb,
                                         m,
                                         n,
                                         k,
                                         (const void*)alpha,
                                         (const void*)A,
                                         hipR32F,
                                         (transa == rocblas_operation_none) ? m : k,
                                         (const void*)B,
                                         hipR32F,
                                         (transb == rocblas_operation_none) ? k : n,
                                         (const void*)beta,
                                         C,
                                         hipR32F,
                                         m,
                                         hipR32F,
                                         algo);

    if (status != rocblas_status_success) {
        fprintf(stderr,
                "!!!! kernel execution error. (m: %d, n: %d, k: %d, error: %d) \n",
                m,
                n,
                k,
                (int)status);
        return EXIT_FAILURE;
    }
    return 0;
}

int cublas_gemm_ex(rocblas_handle handle,
                   rocblas_operation transa,
                   rocblas_operation transb,
                   int m,
                   int n,
                   int k,
                   const float* alpha,
                   const float* beta,
                   const __half* A,
                   const __half* B,
                   __half* C,
                   cublasGemmAlgo_t algo)
{
    rocblas_status status = rocblas_gemmex(handle,
                                         transa,
                                         transb,
                                         m,
                                         n,
                                         k,
                                         (const void*)alpha,
                                         (const void*)A,
                                         hipR16F,
                                         (transa == rocblas_operation_none) ? m : k,
                                         (const void*)B,
                                         hipR16F,
                                         (transb == rocblas_operation_none) ? k : n,
                                         (const void*)beta,
                                         (void*)C,
                                         hipR16F,
                                         m,
                                         hipR32F,
                                         algo);

    if (status != rocblas_status_success) {
        fprintf(stderr,
                "!!!! kernel execution error. (m: %d, n: %d, k: %d, error: %d) \n",
                m,
                n,
                k,
                (int)status);
        return EXIT_FAILURE;
    }
    return 0;
}

int cublas_strided_batched_gemm(rocblas_handle handle,
                                int m,
                                int n,
                                int k,
                                const float* alpha,
                                const float* beta,
                                const float* A,
                                const float* B,
                                float* C,
                                rocblas_operation op_A,
                                rocblas_operation op_B,
                                int stride_A,
                                int stride_B,
                                int stride_C,
                                int batch,
                                cublasGemmAlgo_t algo)
{
    rocblas_status status = cublasGemmStridedBatchedEx(handle,
                                                       op_A,
                                                       op_B,
                                                       m,
                                                       n,
                                                       k,
                                                       alpha,
                                                       A,
                                                       hipR32F,
                                                       (op_A == rocblas_operation_none) ? m : k,
                                                       stride_A,
                                                       B,
                                                       hipR32F,
                                                       (op_B == rocblas_operation_none) ? k : n,
                                                       stride_B,
                                                       beta,
                                                       C,
                                                       hipR32F,
                                                       m,
                                                       stride_C,
                                                       batch,
                                                       hipR32F,
                                                       algo);

    if (status != rocblas_status_success) {
        fprintf(stderr,
                "!!!! kernel execution error. (batch: %d, m: %d, n: %d, k: %d, error: %d) \n",
                batch,
                m,
                n,
                k,
                (int)status);
        return EXIT_FAILURE;
    }
    return 0;
}

int cublas_strided_batched_gemm(rocblas_handle handle,
                                int m,
                                int n,
                                int k,
                                const float* alpha,
                                const float* beta,
                                const __half* A,
                                const __half* B,
                                __half* C,
                                rocblas_operation op_A,
                                rocblas_operation op_B,
                                int stride_A,
                                int stride_B,
                                int stride_C,
                                int batch,
                                cublasGemmAlgo_t algo)
{
    rocblas_status status = cublasGemmStridedBatchedEx(handle,
                                                       op_A,
                                                       op_B,
                                                       m,
                                                       n,
                                                       k,
                                                       alpha,
                                                       A,
                                                       hipR16F,
                                                       (op_A == rocblas_operation_none) ? m : k,
                                                       stride_A,
                                                       B,
                                                       hipR16F,
                                                       (op_B == rocblas_operation_none) ? k : n,
                                                       stride_B,
                                                       beta,
                                                       C,
                                                       hipR16F,
                                                       m,
                                                       stride_C,
                                                       batch,
                                                       hipR32F,
                                                       algo);

    if (status != rocblas_status_success) {
        fprintf(stderr,
                "!!!! kernel execution error. (m: %d, n: %d, k: %d, error: %d) \n",
                m,
                n,
                k,
                (int)status);
        return EXIT_FAILURE;
    }

    return 0;
}
