diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index fdd4a2f50a..c530301cf2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -446,6 +446,17 @@ endif() #must after OpenMP settings find_package(Threads) +macro(check_nvcc_compiler_flag _FLAG _RESULT) + execute_process(COMMAND ${onnxruntime_CUDA_HOME}/bin/nvcc "${_FLAG}" RESULT_VARIABLE NVCC_OUT ERROR_VARIABLE NVCC_ERROR) + message("NVCC_ERROR = ${NVCC_ERROR}") + message("NVCC_OUT = ${NVCC_OUT}") + if("${NVCC_OUT}" MATCHES "0") + set(${_RESULT} 1) + else() + set(${_RESULT} 0) + endif() +endmacro() + #Set global compile flags for all the source code(including third_party code like protobuf) #This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch if (MSVC) @@ -874,6 +885,7 @@ else() check_cxx_compiler_flag(-Wclass-memaccess HAS_CLASS_MEMACCESS) check_cxx_compiler_flag(-Wmaybe-uninitialized HAS_MAYBE_UNINITIALIZED) check_cxx_compiler_flag(-Wstrict-aliasing HAS_STRICT_ALIASING) + check_nvcc_compiler_flag(-Wstrict-aliasing NVCC_HAS_STRICT_ALIASING) if(HAS_TAUTOLOGICAL_POINTER_COMPARE) #we may have extra null pointer checkings in debug build, it's not an issue @@ -1001,7 +1013,7 @@ function(onnxruntime_set_compile_flags target_name) target_compile_options(${target_name} PRIVATE "$<$:SHELL:--compiler-options -Wno-deprecated-copy>" "$<$:-Wno-deprecated-copy>") endif() if(onnxruntime_USE_CUDA) - if(HAS_STRICT_ALIASING) + if((NVCC_HAS_STRICT_ALIASING AND "${target_name}" MATCHES "cuda") OR (HAS_STRIC_ALIASING AND NOT "${target_name}" MATCHES "cuda")) target_compile_options(${target_name} PRIVATE "$<$:-Wno-strict-aliasing>") endif() endif() diff --git a/include/onnxruntime/core/platform/threadpool.h b/include/onnxruntime/core/platform/threadpool.h index cddf6020eb..48bd681089 100644 --- a/include/onnxruntime/core/platform/threadpool.h +++ b/include/onnxruntime/core/platform/threadpool.h @@ -314,7 +314,7 @@ class ThreadPool { } if (num_batches <= 0) { - num_batches = std::min(total, DegreeOfParallelism(tp)); + num_batches = std::min(total, DegreeOfParallelism(tp)); } if (num_batches <= 1) { diff --git a/onnxruntime/core/providers/cuda/math/clip_impl.cu b/onnxruntime/core/providers/cuda/math/clip_impl.cu index 901b002218..f0ff222690 100644 --- a/onnxruntime/core/providers/cuda/math/clip_impl.cu +++ b/onnxruntime/core/providers/cuda/math/clip_impl.cu @@ -19,13 +19,23 @@ void ClipImpl(cudaStream_t stream, const T* input_data, T* output_data, const T* typedef typename ToCudaType::MappedType CudaT; int blocksPerGrid = (int)(ceil(static_cast(count) / GridDim::maxThreadsPerBlock)); - _Clip<<>>(reinterpret_cast(input_data), - reinterpret_cast(output_data), - reinterpret_cast(min), - reinterpret_cast(max), - *reinterpret_cast(&min_default), - *reinterpret_cast(&max_default), - count); + union ConstAliasUnion { + const T *t; + const CudaT *cudaT; + ConstAliasUnion(const T* _t) { t = _t;} + }; + union AliasUnion { + T *t; + CudaT *cudaT; + AliasUnion(T* _t) { t = _t;} + }; + _Clip<<>>(((union ConstAliasUnion)input_data).cudaT, + ((union AliasUnion)output_data).cudaT, + ((union ConstAliasUnion)min).cudaT, + ((union ConstAliasUnion)max).cudaT, + *((union AliasUnion)&min_default).cudaT, + *((union AliasUnion)&max_default).cudaT, + count); } template void ClipImpl(cudaStream_t stream, const float* input_data, float* output_data, const float* min, const float* max, float min_default, float max_default, size_t count);