Skip to content

Commit

Permalink
[compute/cker] Add exception handling (#14208)
Browse files Browse the repository at this point in the history
This commit adds exception handling when input is odd number

ONE-DCO-1.0-Signed-off-by: youngsik kim <[email protected]>
  • Loading branch information
ys44kim authored Oct 15, 2024
1 parent 21496b0 commit 4a319d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compute/cker/include/cker/operation/RoPE.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ inline void RoPE(const RoPEMode mode, const Shape &input_shape, const T *input_d
const int32_t i2_n = MatchingDim(input_shape, 2, output_shape, 2);
const int32_t i3_n = MatchingDim(input_shape, 3, output_shape, 3);

if (i3_n % 2 != 0)
throw std::runtime_error("i3_n must be even number");

if (mode == RoPEMode::kGptNeox)
{
for (int32_t i0 = 0; i0 < i0_n; ++i0)
Expand Down
23 changes: 23 additions & 0 deletions compute/cker/src/RoPE.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,27 @@ TEST(CKer_Operation, neg_RoPE)
sin_table.data(), cos_table_shape, cos_table.data(),
ref_output_shape, output.data()));
}

// unsupported odd number
{
RoPEMode mode = RoPEMode::kGptNeox;

Shape input_shape{1, 1, 1, 3};
std::vector<float> input{0, 1.0, 2.0};

Shape sin_table_shape{1, 1, 1, 3};
std::vector<float> sin_table{0.5, 1.0, 1.0};
Shape cos_table_shape{1, 1, 1, 3};
std::vector<float> cos_table{1.0, 0.5, 0.5};

Shape ref_output_shape{1, 1, 1, 3};
std::vector<float> ref_output_data{-1.0, -2.5, 1.0};

Shape output_shape{1, 1, 1, 3};
std::vector<float> output(ref_output_data.size());

EXPECT_ANY_THROW(nnfw::cker::RoPE<float>(mode, input_shape, input.data(), sin_table_shape,
sin_table.data(), cos_table_shape, cos_table.data(),
ref_output_shape, output.data()));
}
}

0 comments on commit 4a319d0

Please sign in to comment.