// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include #include "core/providers/cuda/math/gemm.h" #include "core/providers/cuda/cuda_common.h" #include "core/providers/cuda/shared_inc/fpgeneric.h" #include "core/providers/cpu/math/gemm_helper.h" #include "contrib_ops/cuda/math/gemm_float8.h" using namespace ONNX_NAMESPACE; namespace onnxruntime { namespace contrib { namespace cuda { #if !defined(DISABLE_FLOAT8_TYPES) #define GEMM_FLOAT8_CONSTRAINTS BuildKernelDefConstraints() #else #define GEMM_FLOAT8_CONSTRAINTS BuildKernelDefConstraints() #endif #define GEMM_FLOAT8_C_CONSTRAINTS BuildKernelDefConstraints() #define REGISTER_KERNEL() \ ONNX_OPERATOR_KERNEL_EX( \ GemmFloat8, \ kMSDomain, \ 1, \ kCudaExecutionProvider, \ (*KernelDefBuilder::Create()) \ .TypeConstraint("TA", GEMM_FLOAT8_CONSTRAINTS) \ .TypeConstraint("TB", GEMM_FLOAT8_CONSTRAINTS) \ .TypeConstraint("TC", GEMM_FLOAT8_C_CONSTRAINTS) \ .TypeConstraint("TR", GEMM_FLOAT8_CONSTRAINTS) \ .TypeConstraint("TS", BuildKernelDefConstraints()), \ GemmFloat8); REGISTER_KERNEL() GemmFloat8::GemmFloat8(const OpKernelInfo& info) : CudaKernel(info) { transA_ = info.GetAttrOrDefault("transA", 0); transB_ = info.GetAttrOrDefault("transB", 0); dtype_ = info.GetAttrOrDefault("dtype", ONNX_NAMESPACE::TensorProto_DataType_FLOAT); auto& device_prop = GetDeviceProp(); sm_count_ = device_prop.multiProcessorCount; alpha_ = info.GetAttrOrDefault("alpha", 1); beta_ = info.GetAttrOrDefault("beta", 0); std::string stemp = info.GetAttrOrDefault("activation", "NONE"); if (stemp == "NONE") { epilogue_ = CUBLASLT_EPILOGUE_DEFAULT; } else if (stemp == "RELU") { epilogue_ = CUBLASLT_EPILOGUE_RELU; } else if (stemp == "GELU") { epilogue_ = CUBLASLT_EPILOGUE_GELU; } else { ORT_THROW("Unexpected value for activation: '", stemp, "'."); } } Status GemmFloat8::SetCheck(const TensorShape& a_shape, const TensorShape& b_shape, int& M, int& N, int& K) const { GemmHelper helper(a_shape, transA_, b_shape, transB_, TensorShape({})); if (!helper.State().IsOK()) return helper.State(); M = gsl::narrow_cast(helper.M()); N = gsl::narrow_cast(helper.N()); K = gsl::narrow_cast(helper.K()); return helper.State(); } } // namespace cuda } // namespace contrib } // namespace onnxruntime