Address some static analysis warnings.

This commit is contained in:
edgchen1 2022-08-25 16:46:34 -07:00 committed by Edward Chen
parent c270ea148a
commit 64e8806148
4 changed files with 32 additions and 16 deletions

View file

@ -273,6 +273,16 @@ std::unique_ptr<profiling::EpProfiler> CUDAExecutionProvider::GetProfiler() {
return std::make_unique<profiling::CudaProfiler>();
}
// Suppressing warning "C26816: The pointer points to memory allocated on the stack." for
// CUDAExecutionProvider::GetPerThreadContext().
// While CUDAExecutionProvider::GetPerThreadContext() does return the result of dereferencing a local
// std::shared_ptr<PerThreadContext>, the underlying PerThreadContext is owned by the CUDA EP and is not local to this
// function.
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 26816)
#endif
CUDAExecutionProvider::PerThreadContext& CUDAExecutionProvider::GetPerThreadContext() const {
const auto& per_thread_context_cache = PerThreadContextCache();
@ -311,6 +321,10 @@ CUDAExecutionProvider::PerThreadContext& CUDAExecutionProvider::GetPerThreadCont
return *context;
}
#ifdef _WIN32
#pragma warning(pop)
#endif
void CUDAExecutionProvider::ReleasePerThreadContext() const {
const auto& per_thread_context_cache = PerThreadContextCache();

View file

@ -2506,8 +2506,8 @@ TEST(QDQTransformerTests, QDQFinalCleanupTransformer_BasicDQQCleanUp) {
auto test_case = [](bool use_matching_qdq_params) {
// input -> Q -> DQ -> Q -> DQ -> output
auto build_test_case = [&](ModelTestBuilder& builder) {
const float scale_1 = 0.05f;
const uint8_t zp_1 = 128;
constexpr float scale_1 = 0.05f;
constexpr uint8_t zp_1 = 128;
auto* const input = builder.MakeInput<float>({1, 2, 4}, -1.0f, 1.0f);
auto* const dq_1_out = AddQDQNodePair<uint8_t>(builder, input, scale_1, zp_1);
@ -2550,8 +2550,8 @@ TEST(QDQTransformerTests, QDQFinalCleanupTransformer_GraphInputToOutput) {
auto test_case = [](bool is_q_dq) {
// create model with input -> Q/DQ pair -> output
auto build_test_case = [&](ModelTestBuilder& builder) {
const float scale = 0.05f;
const uint8_t zp = 128;
constexpr float scale = 0.05f;
constexpr uint8_t zp = 128;
NodeArg* input = is_q_dq ? builder.MakeInput<float>({1, 2, 4}, -1.f, 1.f)
: builder.MakeInput<uint8_t>({1, 2, 4},
std::numeric_limits<uint8_t>::min(),

View file

@ -80,10 +80,10 @@ Status LayerNormGrad<T, U, V, simplified>::ComputeInternal(OpKernelContext* p_op
}
#ifndef USE_ROCM
const int part_size = 16;
constexpr int part_size = 16;
#else
// Optimization for ROCm MI100
const int part_size = 64;
constexpr int part_size = 64;
#endif
auto part_grad_gamma = GetScratchBuffer<CudaU>(part_size * n2);
auto part_grad_beta = GetScratchBuffer<CudaU>(part_size * n2);

View file

@ -4,6 +4,7 @@
#include "orttraining/training_ops/cuda/reduction/reduction_all.h"
#include "orttraining/training_ops/cuda/reduction/reduction_all_impl.h"
#include "core/common/safeint.h"
#include "core/providers/cuda/reduction/reduction_functions.h"
#include "core/providers/cuda/shared_inc/accumulation_type.h"
@ -65,23 +66,24 @@ Status ReduceAllL2<TIn, TOut>::ComputeInternal(OpKernelContext* ctx) const {
typedef AccumulationType_t<CudaTOut> CudaTAcc;
// find reduction buffer size needed by 'reduce_square_sum' for each tensor
size_t reduction_buffer_size = 0;
size_t reduction_buffer_size_in_bytes = 0;
for (int i = 0; i < total_tensor_count; ++i) {
reduction_buffer_size =
std::max(reduction_buffer_size, compute_reduction_buffer_size<CudaTAcc>(tensor_sizes[i]));
reduction_buffer_size_in_bytes =
std::max(reduction_buffer_size_in_bytes, compute_reduction_buffer_size<CudaTAcc>(tensor_sizes[i]));
}
// enlarge reduction buffer size for 'reduce_sum' over tensor square norms
reduction_buffer_size =
std::max(reduction_buffer_size, compute_reduction_buffer_size<CudaTAcc>(total_tensor_count));
reduction_buffer_size_in_bytes =
std::max(reduction_buffer_size_in_bytes, compute_reduction_buffer_size<CudaTAcc>(total_tensor_count));
// create GPU scratch space and zero target for each tensor square norm
auto reduction_buffer = GetScratchBuffer<void>(reduction_buffer_size);
auto reduction_buffer = GetScratchBuffer<void>(reduction_buffer_size_in_bytes);
// buffer for final output and square norms of each tensor
auto results_buffer = GetScratchBuffer<CudaTAcc>(1 + total_tensor_count);
SafeInt<size_t> results_buffer_size = 1 + total_tensor_count;
auto results_buffer = GetScratchBuffer<CudaTAcc>(results_buffer_size);
CUDA_RETURN_IF_ERROR(cudaMemsetAsync(results_buffer.get(), 0, sizeof(CudaTAcc) * (1 + total_tensor_count), Stream()));
CUDA_RETURN_IF_ERROR(cudaMemsetAsync(results_buffer.get(), 0, sizeof(CudaTAcc) * results_buffer_size, Stream()));
CudaTAcc* p_global_sqnorm = results_buffer.get();
CudaTAcc* p_tensor_sqnorm = p_global_sqnorm + 1;
@ -90,10 +92,10 @@ Status ReduceAllL2<TIn, TOut>::ComputeInternal(OpKernelContext* ctx) const {
for (int i = 0; i < total_tensor_count; ++i) {
CudaTIn* p_tensor_i = reinterpret_cast<CudaTIn*>(grouped_tensor_pointers[i][0]);
ORT_RETURN_IF_ERROR(reduce_square_sum(
Stream(), p_tensor_i, p_tensor_sqnorm + i, tensor_sizes[i], reduction_buffer.get(), reduction_buffer_size));
Stream(), p_tensor_i, p_tensor_sqnorm + i, tensor_sizes[i], reduction_buffer.get(), reduction_buffer_size_in_bytes));
}
ORT_RETURN_IF_ERROR(reduce_sum(
Stream(), p_tensor_sqnorm, p_global_sqnorm, total_tensor_count, reduction_buffer.get(), reduction_buffer_size));
Stream(), p_tensor_sqnorm, p_global_sqnorm, total_tensor_count, reduction_buffer.get(), reduction_buffer_size_in_bytes));
ScalarSqrt(Stream(), p_global_sqnorm, p_output);
}