/* **************************************************************************
 * Copyright (C) 2019-2025 Advanced Micro Devices, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * *************************************************************************/

#include "roclapack_gemm_specialized_kernels.hpp"

ROCSOLVER_BEGIN_NAMESPACE

/*************************************************************
    Instantiate template methods using macros
*************************************************************/

INSTANTIATE_GEMM(float, rocblas_int, float*, float*, float*);
INSTANTIATE_GEMM(float, rocblas_int, float* const*, float* const*, float* const*);

INSTANTIATE_GEMM(float, rocblas_int, float*, float* const*, float* const*);
INSTANTIATE_GEMM(float, rocblas_int, float* const*, float*, float* const*);
INSTANTIATE_GEMM(float, rocblas_int, float* const*, float* const*, float*);

INSTANTIATE_GEMM(float, rocblas_int, float* const*, float*, float*);
INSTANTIATE_GEMM(float, rocblas_int, float*, float* const*, float*);
INSTANTIATE_GEMM(float, rocblas_int, float*, float*, float* const*);

#ifdef HAVE_ROCBLAS_64
// 64-bit APIs
INSTANTIATE_GEMM(float, int64_t, float*, float*, float*);
INSTANTIATE_GEMM(float, int64_t, float* const*, float* const*, float* const*);

INSTANTIATE_GEMM(float, int64_t, float*, float* const*, float* const*);
INSTANTIATE_GEMM(float, int64_t, float* const*, float*, float* const*);
INSTANTIATE_GEMM(float, int64_t, float* const*, float* const*, float*);

INSTANTIATE_GEMM(float, int64_t, float* const*, float*, float*);
INSTANTIATE_GEMM(float, int64_t, float*, float* const*, float*);
INSTANTIATE_GEMM(float, int64_t, float*, float*, float* const*);
#endif /* HAVE_ROCBLAS_64 */

/*************************************************************
    Export methods for testing
*************************************************************/

extern "C" {

ROCSOLVER_EXPORT rocblas_status rocsolver_sgemm(rocblas_handle handle,
                                                rocblas_operation transA,
                                                rocblas_operation transB,
                                                rocblas_int m,
                                                rocblas_int n,
                                                rocblas_int k,
                                                const float* alpha,
                                                float* A,
                                                rocblas_int inca,
                                                rocblas_int lda,
                                                float* B,
                                                rocblas_int incb,
                                                rocblas_int ldb,
                                                const float* beta,
                                                float* C,
                                                rocblas_int incc,
                                                rocblas_int ldc)
{
    rocblas_int batch_count = 1;
    float** work = nullptr;
    return rocsolver_gemm<float>(handle, transA, transB, m, n, k, alpha, A, 0, inca, lda, 0, B, 0,
                                 incb, ldb, 0, beta, C, 0, incc, ldc, 0, batch_count, work);
}

ROCSOLVER_EXPORT rocblas_status rocsolver_sgemm_batched(rocblas_handle handle,
                                                        rocblas_operation transA,
                                                        rocblas_operation transB,
                                                        rocblas_int m,
                                                        rocblas_int n,
                                                        rocblas_int k,
                                                        const float* alpha,
                                                        float* const* A,
                                                        rocblas_int inca,
                                                        rocblas_int lda,
                                                        float* const* B,
                                                        rocblas_int incb,
                                                        rocblas_int ldb,
                                                        const float* beta,
                                                        float* const* C,
                                                        rocblas_int incc,
                                                        rocblas_int ldc,
                                                        rocblas_int batch_count)
{
    float** work = nullptr;
    return rocsolver_gemm<float>(handle, transA, transB, m, n, k, alpha, A, 0, inca, lda, 0, B, 0,
                                 incb, ldb, 0, beta, C, 0, incc, ldc, 0, batch_count, work);
}

ROCSOLVER_EXPORT rocblas_status rocsolver_sgemm_strided_batched(rocblas_handle handle,
                                                                rocblas_operation transA,
                                                                rocblas_operation transB,
                                                                rocblas_int m,
                                                                rocblas_int n,
                                                                rocblas_int k,
                                                                const float* alpha,
                                                                float* A,
                                                                rocblas_int inca,
                                                                rocblas_int lda,
                                                                rocblas_stride strideA,
                                                                float* B,
                                                                rocblas_int incb,
                                                                rocblas_int ldb,
                                                                rocblas_stride strideB,
                                                                const float* beta,
                                                                float* C,
                                                                rocblas_int incc,
                                                                rocblas_int ldc,
                                                                rocblas_stride strideC,
                                                                rocblas_int batch_count)
{
    float** work = nullptr;
    return rocsolver_gemm<float>(handle, transA, transB, m, n, k, alpha, A, 0, inca, lda, strideA,
                                 B, 0, incb, ldb, strideB, beta, C, 0, incc, ldc, strideC,
                                 batch_count, work);
}

} // extern C

ROCSOLVER_END_NAMESPACE
