Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions onnxruntime/test/providers/cpu/tensor/gather_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,10 @@ TEST(GatherOpTest, Gather_axis1_indices2d_string) {
}

TEST(GatherOpTest, Gather_overflow_check) {
// Skip on 32-bit platforms where size_t overflow would truncate the large expected
// output shape and where allocating the full reference tensor is infeasible.
#if SIZE_MAX <= UINT32_MAX
GTEST_SKIP() << "Gather_overflow_check skipped on 32-bit platforms.";
#endif

// The test uses dimensions (65537, 2) and indices of length 65537, which produce an output
// shape of (65537, 65537).
// The test uses dimensions (46341, 2) and indices of length 46341, which produce an output
// shape of (46341, 46341).
//
// 65537 x 65537 = 4,295,098,369 which is greater than the maximum value of a 32-bit integer (2,147,483,647).
// 46341 x 46341 = 2,147,488,281 which is just greater than the maximum value of a 32-bit integer (2,147,483,647).
//
// This test is to verify CPU implementation of the Gather operator doesn't overflow when calculating
// the output shape and generating the output tensor.
Expand All @@ -360,15 +354,15 @@ TEST(GatherOpTest, Gather_overflow_check) {
test.AddAttribute<int64_t>("axis", 1LL);

// Inputs
const std::vector<int64_t> data_dims{65537, 2};
const std::vector<int64_t> indices_dims{65537};
const std::vector<int64_t> data_dims{46341, 2};
const std::vector<int64_t> indices_dims{46341};
std::vector<uint8_t> data_values(static_cast<size_t>(data_dims[0] * data_dims[1]), 1);
std::vector<int64_t> indices_values(static_cast<size_t>(indices_dims[0]), 1);
std::vector<uint8_t> expected_output_values(static_cast<size_t>(65537) * static_cast<size_t>(65537), 1);
std::vector<uint8_t> expected_output_values(static_cast<size_t>(46341) * static_cast<size_t>(46341), 1);

test.AddInput<uint8_t>("data", {65537, 2}, data_values);
test.AddInput<int64_t>("indices", {65537}, indices_values);
test.AddOutput<uint8_t>("output", {65537, 65537}, expected_output_values);
test.AddInput<uint8_t>("data", {46341, 2}, data_values);
test.AddInput<int64_t>("indices", {46341}, indices_values);
test.AddOutput<uint8_t>("output", {46341, 46341}, expected_output_values);
Comment thread
adrianlizarraga marked this conversation as resolved.
Outdated

std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.emplace_back(DefaultCpuExecutionProvider());
Expand Down
Loading