Skip to content

Commit ad32f42

Browse files
[CUDA] Fix cuda 12.8 build warnings (#26136)
Fix build warnings using cuda 12.8 in Linux like the following: ``` <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror] gather_block_quantized.cc:95:40: warning: comparison of integer expressions of different signedness: ‘int64_t’ {aka ‘long int’} and ‘long unsigned int’ [-Wsign-compare] 95 | for (int64_t i = gather_axis_ + 1; i < data_rank; ++i) { attention_op_test.cc:304:85: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<float>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 304 | } else if (batch_size * q_num_heads * q_sequence_length * total_sequence_length == attn_mask.size()) { /cast_op_test.cc:1487:24: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare] 1487 | for (size_t i = 0; i < num_pairs; ++i) { | ~~^~~~~~~~~~~ ``` --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 72e56e7 commit ad32f42

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

onnxruntime/contrib_ops/cuda/quantization/gather_block_quantized.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ Status GatherBlockQuantized<T1, T2, Tind>::ComputeInternal(OpKernelContext* ctx)
6464
const Tensor* zero_points = ctx->Input<Tensor>(3);
6565

6666
auto data_shape = data->Shape().GetDims();
67-
auto data_rank = data->Shape().NumDimensions();
67+
int64_t data_rank = data->Shape().NumDimensions();
6868

6969
auto indices_shape = indices->Shape().GetDims();
7070
auto indices_rank = indices->Shape().NumDimensions();
7171

72-
ORT_ENFORCE(quantize_axis_ == data_rank - 1);
72+
ORT_ENFORCE(quantize_axis_ == static_cast<int64_t>(data_rank) - 1);
7373

7474
TensorShapeVector output_shape;
7575
output_shape.reserve(data_rank - 1 + indices_rank);
@@ -92,7 +92,7 @@ Status GatherBlockQuantized<T1, T2, Tind>::ComputeInternal(OpKernelContext* ctx)
9292
}
9393

9494
// 3) dims after gather_axis
95-
for (int64_t i = gather_axis_ + 1; i < data_rank; ++i) {
95+
for (int64_t i = gather_axis_ + 1; i < static_cast<int64_t>(data_rank); ++i) {
9696
output_shape.push_back(data_shape[i]);
9797
after_gather_dim *= data_shape[i];
9898
}

onnxruntime/test/providers/cpu/llm/attention_op_test.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ static void RunTest3D(
220220
std::vector<int64_t> v_shape = {batch_size, kv_sequence_length, v_hidden_size};
221221

222222
std::vector<int64_t> attn_mask_shape = {q_sequence_length, total_sequence_length};
223-
if (q_sequence_length * total_sequence_length != attn_mask.size() && attn_mask.size() > 0) {
224-
if (batch_size * q_sequence_length * total_sequence_length == attn_mask.size()) {
223+
size_t expected_mask_size = static_cast<size_t>(q_sequence_length) * static_cast<size_t>(total_sequence_length);
224+
if (expected_mask_size != attn_mask.size() && attn_mask.size() > 0) {
225+
if (static_cast<size_t>(batch_size) * expected_mask_size == attn_mask.size()) {
225226
attn_mask_shape = {batch_size, 1, q_sequence_length, total_sequence_length};
226-
} else if (batch_size * q_num_heads * q_sequence_length * total_sequence_length == attn_mask.size()) {
227+
} else if (static_cast<size_t>(batch_size) * static_cast<size_t>(q_num_heads) * expected_mask_size == attn_mask.size()) {
227228
attn_mask_shape = {batch_size, q_num_heads, q_sequence_length, total_sequence_length};
228229
} else {
229230
ORT_THROW("Invalid attention mask size: ", attn_mask.size(),
@@ -298,10 +299,11 @@ static void RunTest4D(
298299
std::vector<int64_t> v_shape = {batch_size, kv_num_heads, kv_sequence_length, v_head_size};
299300

300301
std::vector<int64_t> attn_mask_shape = {q_sequence_length, total_sequence_length};
301-
if (q_sequence_length * total_sequence_length != attn_mask.size() && attn_mask.size() > 0) {
302-
if (batch_size * q_sequence_length * total_sequence_length == attn_mask.size()) {
302+
size_t expected_mask_size = static_cast<size_t>(q_sequence_length) * static_cast<size_t>(total_sequence_length);
303+
if (expected_mask_size != attn_mask.size() && attn_mask.size() > 0) {
304+
if (static_cast<size_t>(batch_size) * expected_mask_size == attn_mask.size()) {
303305
attn_mask_shape = {batch_size, 1, q_sequence_length, total_sequence_length};
304-
} else if (batch_size * q_num_heads * q_sequence_length * total_sequence_length == attn_mask.size()) {
306+
} else if (static_cast<size_t>(batch_size) * static_cast<size_t>(q_num_heads) * expected_mask_size == attn_mask.size()) {
305307
attn_mask_shape = {batch_size, q_num_heads, q_sequence_length, total_sequence_length};
306308
} else {
307309
ORT_THROW("Invalid attention mask size: ", attn_mask.size(),

onnxruntime/test/providers/cpu/tensor/cast_op_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ template <typename F4>
14771477
void CastOpTestFloatFloat4(std::vector<int64_t> shape,
14781478
std::vector<float> float_data,
14791479
bool is_fp4_input = false) {
1480-
int num_pairs = static_cast<int>(float_data.size()) / 2;
1480+
size_t num_pairs = float_data.size() / 2;
14811481
int num_fp4_elements = static_cast<int>((float_data.size() + 1) / 2);
14821482
bool is_odd_count = (float_data.size() % 2 != 0);
14831483

@@ -1489,7 +1489,7 @@ void CastOpTestFloatFloat4(std::vector<int64_t> shape,
14891489
}
14901490

14911491
if (is_odd_count) {
1492-
fp4_data.emplace_back(F4(float_data[num_pairs * 2], 0)); // Padding zero
1492+
fp4_data.emplace_back(F4(float_data.back(), 0)); // Padding zero
14931493
}
14941494

14951495
if (!is_fp4_input) {

tools/ci_build/build.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,8 @@ def generate_build_tree(
11831183
if config == "Release":
11841184
cflags = [
11851185
"-DNDEBUG",
1186-
"-Wp,-D_FORTIFY_SOURCE=2",
1186+
"-U_FORTIFY_SOURCE",
1187+
"-D_FORTIFY_SOURCE=2",
11871188
"-Wp,-D_GLIBCXX_ASSERTIONS",
11881189
"-fstack-protector-strong",
11891190
"-O3",
@@ -1194,7 +1195,8 @@ def generate_build_tree(
11941195
elif config == "RelWithDebInfo":
11951196
cflags = [
11961197
"-DNDEBUG",
1197-
"-Wp,-D_FORTIFY_SOURCE=2",
1198+
"-U_FORTIFY_SOURCE",
1199+
"-D_FORTIFY_SOURCE=2",
11981200
"-Wp,-D_GLIBCXX_ASSERTIONS",
11991201
"-fstack-protector-strong",
12001202
"-O3",
@@ -1209,7 +1211,8 @@ def generate_build_tree(
12091211
elif config == "MinSizeRel":
12101212
cflags = [
12111213
"-DNDEBUG",
1212-
"-Wp,-D_FORTIFY_SOURCE=2",
1214+
"-U_FORTIFY_SOURCE",
1215+
"-D_FORTIFY_SOURCE=2",
12131216
"-Wp,-D_GLIBCXX_ASSERTIONS",
12141217
"-fstack-protector-strong",
12151218
"-Os",

tools/python/util/vcpkg_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,12 @@ def generate_triplet_for_posix_platform(
362362
cflags_release = ["-DNDEBUG", "-O3"]
363363

364364
if enable_binskim:
365-
cflags_release += ["-Wp,-D_FORTIFY_SOURCE=2", "-Wp,-D_GLIBCXX_ASSERTIONS", "-fstack-protector-strong"]
365+
cflags_release += [
366+
"-U_FORTIFY_SOURCE",
367+
"-D_FORTIFY_SOURCE=2",
368+
"-Wp,-D_GLIBCXX_ASSERTIONS",
369+
"-fstack-protector-strong",
370+
]
366371
if target_abi == "x64":
367372
cflags_release += ["-fstack-clash-protection", "-fcf-protection"]
368373

0 commit comments

Comments
 (0)