diff --git a/onnxruntime/core/providers/cuda/tensor/cast_op.cc b/onnxruntime/core/providers/cuda/tensor/cast_op.cc index 75290533b7..8f4015f6b5 100644 --- a/onnxruntime/core/providers/cuda/tensor/cast_op.cc +++ b/onnxruntime/core/providers/cuda/tensor/cast_op.cc @@ -9,8 +9,12 @@ using namespace onnxruntime::common; namespace onnxruntime { namespace cuda { -const std::vector castOpTypeConstraints{ - DataTypeImpl::GetTensorType(), +const std::vector& CastOpTypeConstraints() { + // Must be done as a local static for a shared provider, to avoid the prefast warning: + // Global initializer calls a non-constexpr function 'onnxruntime::DataTypeImpl::GetTensorType' + // In a shared provider, GetTensorType is a function call into Onnxruntime and isn't constexpr + static std::vector types{ + DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType(), @@ -22,8 +26,9 @@ const std::vector castOpTypeConstraints{ DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType() -}; + DataTypeImpl::GetTensorType()}; + return types; +} #define REGISTER_KERNEL_TYPED(T) \ ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_EX( \ @@ -34,7 +39,7 @@ const std::vector castOpTypeConstraints{ kCudaExecutionProvider, \ (*KernelDefBuilder::Create()) \ .TypeConstraint("T1", DataTypeImpl::GetTensorType()) \ - .TypeConstraint("T2", castOpTypeConstraints), \ + .TypeConstraint("T2", CastOpTypeConstraints()), \ Cast); \ ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_EX( \ Cast, \ @@ -44,7 +49,7 @@ const std::vector castOpTypeConstraints{ kCudaExecutionProvider, \ (*KernelDefBuilder::Create()) \ .TypeConstraint("T1", DataTypeImpl::GetTensorType()) \ - .TypeConstraint("T2", castOpTypeConstraints), \ + .TypeConstraint("T2", CastOpTypeConstraints()), \ Cast); \ ONNX_OPERATOR_TYPED_KERNEL_EX( \ Cast, \ @@ -54,7 +59,7 @@ const std::vector castOpTypeConstraints{ kCudaExecutionProvider, \ (*KernelDefBuilder::Create()) \ .TypeConstraint("T1", DataTypeImpl::GetTensorType()) \ - .TypeConstraint("T2", castOpTypeConstraints), \ + .TypeConstraint("T2", CastOpTypeConstraints()), \ Cast); template