ermig1979 / Simd

C++ image processing and machine learning library with using of SIMD: SSE, AVX, AVX-512, AMX for x86/x64, NEON for ARM.
http://ermig1979.github.io/Simd
MIT License
2.06k stars 412 forks source link

Error: use of deleted function ‘std::unique_ptr' #139

Closed JopKnoppers closed 3 years ago

JopKnoppers commented 3 years ago

I have made a module using SIMD, this works fine when using just C++ (see makefile), this however generates the following error when compiling with cython for Python usage:

/usr/include/c++/6/bits/stl_algobase.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = const std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*; _OI = std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*]’:
/usr/include/c++/6/bits/stl_algobase.h:386:44:   required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*; _OI = std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*]’
/usr/include/c++/6/bits/stl_algobase.h:422:45:   required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*, std::vector<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >, std::allocator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> > > > >; _OI = __gnu_cxx::__normal_iterator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*, std::vector<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >, std::allocator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> > > > >]’
/usr/include/c++/6/bits/stl_algobase.h:455:8:   required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*, std::vector<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >, std::allocator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> > > > >; _OI = __gnu_cxx::__normal_iterator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >*, std::vector<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >, std::allocator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> > > > >]’
/usr/include/c++/6/bits/vector.tcc:206:31:   required from ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> >; _Alloc = std::allocator<std::unique_ptr<Simd::Detection<Simd::Allocator>::Level, std::default_delete<Simd::Detection<Simd::Allocator>::Level> > >]’
/var/www/eggway/egg_counter/GPU/Simd/src/Simd/SimdDetection.hpp:147:12:   required from here
/usr/include/c++/6/bits/stl_algobase.h:324:18: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>& std::unique_ptr<_Tp, _Dp>::operator=(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = Simd::Detection<Simd::Allocator>::Level; _Dp = std::default_delete<Simd::Detection<Simd::Allocator>::Level>]’
        *__result = *__first;

The makefile (makefile):

Detect: ctest.h ctest.cpp run.cpp
    g++ -pthread -o Detect run.cpp ctest.cpp -L/var/www/test/Simd/prj/cmake/ -I/var/www/test/Simd/src -lSimd -I/usr/local/include/opencv4 -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_imgproc -lopencv_highgui -lopencv_core
clean:
    rm Detect

I have the setup file (setup.py):

library_dirs = ['/var/www/test/Simd/prj/cmake/']
include_dirs = [numpy.get_include(), '/var/www/test/Simd/src', '/usr/local/include/opencv4']
args = ['-Wno-cpp']
files = ["ctest.cpp", "test.pyx"]
libraries = ['opencv_imgcodecs', 'opencv_objdetect', 'opencv_features2d', 'opencv_imgproc', 'opencv_highgui', 'opencv_core', ' Simd']

ext_modules = [Extension(
    "Test",
    files,
    language='c++',
    include_dirs=include_dirs,
    library_dirs=library_dirs,
    extra_compile_args=args,
    libraries=libraries
)]

It seems that this is a repro issue, but I could be wrong and just be doing something wrong. Any ideas?

JopKnoppers commented 3 years ago

typedef Simd::Detection<Simd::Allocator> Detection; is used.

JopKnoppers commented 3 years ago

Seems like SimdDetection 420 should be: typedef std::shared_ptr<Level> LevelPtr;, instead of typedef std::unique_ptr<Level> LevelPtr; please correct me if I missed something.

ermig1979 commented 3 years ago

I exchanged std::unique_ptr to std::shared_ptr in Simd::Detection.