diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index 83e6328bb..0288cd0cc 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -55,7 +55,7 @@ jobs: - name: codecov id: codecov continue-on-error: true - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build/lcov.info @@ -63,7 +63,7 @@ jobs: continue-on-error: true id: codecov-vlen256-retry-1 if: steps.codecov.outcome=='failure' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build/lcov.info @@ -71,7 +71,7 @@ jobs: continue-on-error: true id: codecov-vlen256-retry-2 if: steps.codecov-vlen256-retry-1.outcome=='failure' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build/lcov.info @@ -79,7 +79,7 @@ jobs: continue-on-error: true id: codecov-vlen256-retry-3 if: steps.codecov-vlen256-retry-2.outcome=='failure' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build/lcov.info @@ -87,7 +87,7 @@ jobs: continue-on-error: true id: codecov-vlen256-retry-4 if: steps.codecov-vlen256-retry-3.outcome=='failure' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build/lcov.info @@ -95,7 +95,7 @@ jobs: continue-on-error: true id: codecov-vlen256-retry-5 if: steps.codecov-vlen256-retry-4.outcome=='failure' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build/lcov.info @@ -140,7 +140,7 @@ jobs: lcov -r lcov.info '*/build-avx512-spr/*' -o lcov.info lcov --list lcov.info - name: codecov-avx512-spr - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: build-avx512-spr/lcov.info diff --git a/src/layer/loongarch/slice_loongarch.cpp b/src/layer/loongarch/slice_loongarch.cpp index 2da903253..de998bb26 100644 --- a/src/layer/loongarch/slice_loongarch.cpp +++ b/src/layer/loongarch/slice_loongarch.cpp @@ -142,6 +142,8 @@ int Slice_loongarch::forward(const std::vector& bottom_blobs, std::vector out_elempack) { convert_packing(bottom_blob, bottom_blob_unpacked, out_elempack, opt); + if (bottom_blob_unpacked.empty()) + return -100; } const float* ptr = bottom_blob_unpacked; @@ -304,6 +306,8 @@ int Slice_loongarch::forward(const std::vector& bottom_blobs, std::vector out_elempack) { convert_packing(bottom_blob, bottom_blob_unpacked, out_elempack, opt); + if (bottom_blob_unpacked.empty()) + return -100; } int p = 0; diff --git a/src/layer/mips/slice_mips.cpp b/src/layer/mips/slice_mips.cpp index dead2610b..46f4028e2 100644 --- a/src/layer/mips/slice_mips.cpp +++ b/src/layer/mips/slice_mips.cpp @@ -142,6 +142,8 @@ int Slice_mips::forward(const std::vector& bottom_blobs, std::vector& if (elempack > out_elempack) { convert_packing(bottom_blob, bottom_blob_unpacked, out_elempack, opt); + if (bottom_blob_unpacked.empty()) + return -100; } const float* ptr = bottom_blob_unpacked; @@ -304,6 +306,8 @@ int Slice_mips::forward(const std::vector& bottom_blobs, std::vector& if (elempack > out_elempack) { convert_packing(bottom_blob, bottom_blob_unpacked, out_elempack, opt); + if (bottom_blob_unpacked.empty()) + return -100; } int p = 0; diff --git a/tests/test_slice_oom.cpp b/tests/test_slice_oom.cpp new file mode 100644 index 000000000..62c717ba0 --- /dev/null +++ b/tests/test_slice_oom.cpp @@ -0,0 +1,164 @@ +// Tencent is pleased to support the open source community by making ncnn available. +// +// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#include "testutil.h" + +static ncnn::Mat IntArrayMat(int a0) +{ + ncnn::Mat m(1); + int* p = m; + p[0] = a0; + return m; +} + +static ncnn::Mat IntArrayMat(int a0, int a1) +{ + ncnn::Mat m(2); + int* p = m; + p[0] = a0; + p[1] = a1; + return m; +} + +static ncnn::Mat IntArrayMat(int a0, int a1, int a2) +{ + ncnn::Mat m(3); + int* p = m; + p[0] = a0; + p[1] = a1; + p[2] = a2; + return m; +} + +static ncnn::Mat IntArrayMat(int a0, int a1, int a2, int a3) +{ + ncnn::Mat m(4); + int* p = m; + p[0] = a0; + p[1] = a1; + p[2] = a2; + p[3] = a3; + return m; +} + +static void print_int_array(const ncnn::Mat& a) +{ + const int* pa = a; + + fprintf(stderr, "["); + for (int i = 0; i < a.w; i++) + { + fprintf(stderr, " %d", pa[i]); + } + fprintf(stderr, " ]"); +} + +static int test_slice_oom(const ncnn::Mat& a, const ncnn::Mat& slices, int axis) +{ + ncnn::ParamDict pd; + pd.set(0, slices); + pd.set(1, axis); + + std::vector weights(0); + + std::vector a0(1); + a0[0] = a; + + int ret = test_layer_oom("Slice", pd, weights, a0, slices.w); + if (ret != 0) + { + fprintf(stderr, "test_slice_oom failed a.dims=%d a=(%d %d %d %d)", a.dims, a.w, a.h, a.d, a.c); + fprintf(stderr, " slices="); + print_int_array(slices); + fprintf(stderr, " axis=%d\n", axis); + } + + return ret; +} + +static int test_slice_oom_indices(const ncnn::Mat& a, const ncnn::Mat& indices, int axis) +{ + ncnn::ParamDict pd; + pd.set(1, axis); + pd.set(2, indices); + + std::vector weights(0); + + std::vector a0(1); + a0[0] = a; + + int ret = test_layer_oom("Slice", pd, weights, a0, indices.w); + if (ret != 0) + { + fprintf(stderr, "test_slice_oom_indices failed a.dims=%d a=(%d %d %d %d)", a.dims, a.w, a.h, a.d, a.c); + fprintf(stderr, " indices="); + print_int_array(indices); + fprintf(stderr, " axis=%d\n", axis); + } + + return ret; +} + +static int test_slice_0() +{ + ncnn::Mat a = RandomMat(48, 48, 48, 48); + + return 0 + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 0) + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 1) + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 2) + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 3) + || test_slice_oom_indices(a, IntArrayMat(2, -24, -8), 0); +} + +static int test_slice_1() +{ + ncnn::Mat a = RandomMat(48, 48, 48); + + return 0 + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 0) + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 1) + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 2) + || test_slice_oom_indices(a, IntArrayMat(2, -24, -8), 0); +} + +static int test_slice_2() +{ + ncnn::Mat a = RandomMat(48, 48); + + return 0 + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 0) + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 1) + || test_slice_oom_indices(a, IntArrayMat(2, -24, -8), 0); +} + +static int test_slice_3() +{ + ncnn::Mat a = RandomMat(48); + + return 0 + || test_slice_oom(a, IntArrayMat(3, 12, 16, -233), 0) + || test_slice_oom_indices(a, IntArrayMat(2, -24, -8), 0); +} + +int main() +{ + SRAND(7767517); + + return 0 + || test_slice_0() + || test_slice_1() + || test_slice_2() + || test_slice_3(); +}