Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Dynamic subgraph accesses elements of empty vector #17987

@leezu

Description

@leezu

Description

Dynamic subgraph code accesses elements of empty vector, causing MXNet to abort.
The PR only passed CI because of the outdated toolchain used on CI. CI with updated toolchain (ie #17984) catches the bug.

Error Message

/usr/include/c++/7/bits/stl_vector.h:815: std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = mxnet:: Resource; _Alloc = std::allocator<mxnet::Resource>; std::vector<_Tp, _Alloc>::const_reference = const mxnet::Resource&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Asser tion '__builtin_expect(__n < this->size(), true)' failed.

To Reproduce

Compile MXNet with gcc7+ and _GLIBCXX_ASSERTIONS, for example via
CC=gcc-7 CXX=g++-7 cmake -GNinja -DUSE_CUDA=0 -DCMAKE_BUILD_TYPE=RelWithDebInfo ..; ninja.

Run python3 -m nose --verbose ../tests/python/unittest/test_extensions.py -m test_subgraph.
This will raise the error above.

OR apply the following simple patch

diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc
index 949a59406..2c17320f0 100644
--- a/src/c_api/c_api.cc
+++ b/src/c_api/c_api.cc
@@ -187,7 +187,7 @@ void CustomFComputeDispatcher(const std::string op_name,
   }

   // get memory resource and mxnet backend streams
-  const Resource &resource = ctx.requested[0];
+  const Resource &resource = ctx.requested.at(0);
   mshadow::Stream<mxnet::cpu> *cpu_stream = ctx.get_stream<mxnet::cpu>();
   mshadow::Stream<mxnet::gpu> *gpu_stream = ctx.get_stream<mxnet::gpu>();

and MXNet will always crash with vector: :_M_range_check: __n (which is 0) >= this->size() (which is 0) during the dynamic subgraph test.

cc @samskalicky @rondogency

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions