显卡3050Ti(算力可以达到8.6 可查询)
cuda:11.0
由于cuda11.0不支持算力8.6的GPU 因此修改 ~/.bashrc中的信息
sudo ge
在cuda配置文件下面增加:
export TORCH_CUDA_ARCH_LIST="8.0"
然后:
source ~/.bashrc
参考
另一个办法,直接修改caffe中的cmake文件夹下面的cuda.cmake
修改cuda.cmake 文件内容
参考
# Function for selecting GPU arch flags for nvcc based on CUDA_ARCH_NAME
# Usage:
# caffe_select_nvcc_arch_flags(out_variable)
function(caffe_select_nvcc_arch_flags out_variable)
# List of arch names
set(__archs_names "Fermi" "Kepler" "Maxwell" "Pascal" "All" "Manual")
set(__archs_name_default "All")
if(NOT CMAKE_CROSSCOMPILING)
list(APPEND __archs_names "Auto")
set(__archs_name_default "Auto")
endif()
改为:
# Function for selecting GPU arch flags for nvcc based on CUDA_ARCH_NAME
# Usage:
# caffe_select_nvcc_arch_flags(out_variable)
function(caffe_select_nvcc_arch_flags out_variable)
# List of arch names
set(__archs_names "Ampere" "Kepler" "Maxwell" "Pascal" "All" "Manual")
set(__archs_name_default "All")
if(NOT CMAKE_CROSSCOMPILING)
list(APPEND __archs_names "Auto")
set(__archs_name_default "Auto")
endif()
# verify CUDA_ARCH_NAME value
if(NOT ";${__archs_names};" MATCHES ";${CUDA_ARCH_NAME};")
string(REPLACE ";" ", " __archs_names "${__archs_names}")
message(FATAL_ERROR "Only ${__archs_names} architeture names are supported.")
endif()
改为
# verify CUDA_ARCH_NAME value
if(NOT ";${__archs_names};" MATCHES ";${CUDA_ARCH_NAME};")
string(REPLACE ";" ", " __archs_names "${__archs_names}")
message(FATAL_ERROR "Only ${__archs_names} architeture names are supported.")
elseif(${CUDA_ARCH_NAME} STREQUAL "Ampere")
set(__cuda_arch_bin "86")
endif()
if(${CUDA_ARCH_NAME} STREQUAL "Fermi")
set(__cuda_arch_bin "20 21(20)")
elseif(${CUDA_ARCH_NAME} STREQUAL "Kepler")
set(__cuda_arch_bin "30 35")
elseif(${CUDA_ARCH_NAME} STREQUAL "Maxwell")
set(__cuda_arch_bin "50")
elseif(${CUDA_ARCH_NAME} STREQUAL "Pascal")
set(__cuda_arch_bin "60 61")
elseif(${CUDA_ARCH_NAME} STREQUAL "All")
set(__cuda_arch_bin ${Caffe_known_gpu_archs})
elseif(${CUDA_ARCH_NAME} STREQUAL "Auto")
caffe_detect_installed_gpus(__cuda_arch_bin)
else() # (${CUDA_ARCH_NAME} STREQUAL "Manual")
set(__cuda_arch_bin ${CUDA_ARCH_BIN})
endif()
改为
if(${CUDA_ARCH_NAME} STREQUAL "Fermi")
set(__cuda_arch_bin "20 21(20)")
elseif(${CUDA_ARCH_NAME} STREQUAL "Kepler")
set(__cuda_arch_bin "30 35")
elseif(${CUDA_ARCH_NAME} STREQUAL "Maxwell")
set(__cuda_arch_bin "50")
elseif(${CUDA_ARCH_NAME} STREQUAL "Pascal")
set(__cuda_arch_bin "60 61")
elseif(${CUDA_ARCH_NAME} STREQUAL "All")
set(__cuda_arch_bin ${Caffe_known_gpu_archs})
elseif(${CUDA_ARCH_NAME} STREQUAL "Auto")
#caffe_detect_installed_gpus(__cuda_arch_bin)
set(__cuda_arch_bin "60 61")
else() # (${CUDA_ARCH_NAME} STREQUAL "Manual")
set(__cuda_arch_bin ${CUDA_ARCH_BIN})
endif()
结果:
最后发现caffe使用的算力6.0的 之前的保存问题解决。
其实这样存在一个问题,最好是caffe的cuda.cmake 的算力与~/.bashrc中的设置算力保持一直,否则可能出现在抵用caffe框架时候 出现算力不匹配问题,例如:
Check failed: error == cudaSuccess (209 vs. 0) no kernel image is available
所以需要把:
if(${CUDA_ARCH_NAME} STREQUAL "Fermi")
set(__cuda_arch_bin "20 21(20)")
elseif(${CUDA_ARCH_NAME} STREQUAL "Kepler")
set(__cuda_arch_bin "30 35")
elseif(${CUDA_ARCH_NAME} STREQUAL "Maxwell")
set(__cuda_arch_bin "50")
elseif(${CUDA_ARCH_NAME} STREQUAL "Pascal")
set(__cuda_arch_bin "60 61")
elseif(${CUDA_ARCH_NAME} STREQUAL "All")
set(__cuda_arch_bin ${Caffe_known_gpu_archs})
elseif(${CUDA_ARCH_NAME} STREQUAL "Auto")
#caffe_detect_installed_gpus(__cuda_arch_bin)
set(__cuda_arch_bin "80")
else() # (${CUDA_ARCH_NAME} STREQUAL "Manual")
set(__cuda_arch_bin ${CUDA_ARCH_BIN})
endif()
/.bashrc中需要添加为:
export TORCH_CUDA_ARCH_LIST=“8.0”
这样编译,之后 GPU算力是一致的。
又出现新问题:
In file included from /usr/include/leveldb/iterator.h:20:0,
from /usr/include/leveldb/db.h:12,
from /home/ckq/gitproject/Semantic_SLAM/ORB_SLAM3/Thirdparty/caffe/include/caffe/util/db_leveldb.hpp:7,
from /home/ckq/gitproject/Semantic_SLAM/ORB_SLAM3/Thirdparty/caffe/src/caffe/util/db.cpp:2:
/usr/include/leveldb/status.h: At global scope:
/usr/include/leveldb/status.h:27:10: error: expected ‘;’ at end of member declaration
Status() noexcept : state_(nullptr) {}
^
/usr/include/leveldb/status.h:27:12: error: ‘noexcept’ does not name a type
Status() noexcept : state_(nullptr) {}
^
/usr/include/leveldb/status.h:27:12: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11
/usr/include/leveldb/status.h:33:16: error: expected ‘,’ or ‘...’ before ‘&&’ token
Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
^
/usr/include/leveldb/status.h:33:22: error: invalid constructor; you probably meant ‘leveldb::Status (const leveldb::Status&)’
Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
^
/usr/include/leveldb/status.h:33:22: error: expected ‘;’ at end of member declaration
/usr/include/leveldb/status.h:33:24: error: ‘noexcept’ does not name a type
Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
^
/usr/include/leveldb/status.h:33:24: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11
/usr/include/leveldb/status.h:34:27: error: expected ‘,’ or ‘...’ before ‘&&’ token
Status& operator=(Status&& rhs) noexcept;
^
/usr/include/leveldb/status.h:34:33: error: expected ‘;’ at end of member declaration
Status& operator=(Status&& rhs) noexcept;
^
/usr/include/leveldb/status.h:34:35: error: ‘noexcept’ does not name a type
Status& operator=(Status&& rhs) noexcept;
^
/usr/include/leveldb/status.h:34:35: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11
/usr/include/leveldb/status.h: In member function ‘bool leveldb::Status::ok() const’:
/usr/include/leveldb/status.h:57:39: error: ‘nullptr’ was not declared in this scope
bool ok() const { return (state_ == nullptr); }
(针对ubuntu)
打开caffe文件下的makefile
扎到ifeq ($(OSX), 1)
将
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++
改为
ifeq ($(LINUX), 1)
CXX ?= /usr/bin/g++ -std=c++11
如果是mac则改为:
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++ -std=c++11
参考
参考
如果是cmake编译 则修改 caffe中的cmakelist.txt中的
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()
改为:
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()
参考
如果还报错
问题出在gcc和g++版本问题上,说是 caffe是在gcc4.9版本上编译,大于4.9的版本会出现问题,因此要安装gcc 4.9 g++4.9版本
由于系统是ubuntu20.04 已经没有这个软件包,因此
需要修改源:
sudo gedit /etc/apt/sources.list
末尾添加:
deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe
sudo apt update
安装gcc 和g++
sudo apt install g++-4.9
sudo apt install gcc-4.9
最后涉及到多gcc g++版本的切换 :
设置gcc4.9 和g++的权重:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 25
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 25
切换:
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
报错:
89%] Linking CXX executable upgrade_net_proto_text
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `boost::re_detail_107500::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::GetTypeName() const'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::AssignDescriptors(std::string const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > > const&)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::DebugString() const'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::MessageLite::ParseFromString(std::string const&)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptor const*, int)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `boost::re_detail_107500::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::OnShutdownDestroyString(std::string const*)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `boost::re_detail_107500::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::fixed_address_empty_string'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `leveldb::Status::ToString() const'
/usr/bin/ld: ../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/CMakeFiles/upgrade_net_proto_text.dir/build.make:126: tools/upgrade_net_proto_text] Error 1
make[1]: *** [CMakeFiles/Makefile2:511: tools/CMakeFiles/upgrade_net_proto_text.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
下载protoc2.6.1版本
https://github.com/protocolbuffers/protobuf/releases/tag/v2.6.1
ubuntu安装caffe中涉及到protobuf
安装教程:
安装
安装完记得刷新
sudo ldconfig
报错:
fatal error: google/protobuf/arena.h: No such file or directory
说是3.3.0解决了该问题,卸载2.6.1
参考:https://blog.csdn.net/h799710/article/details/126762153
还是存在问题 貌似是 conda中的protobuf影响
在Gen6D中安装了 protobuf 3.20.3
卸载 pip uninstall protobuf
在dsp-slam中安装了protobuf 3.19.1
卸载 pip uninstall protobuf
报错来源:
https://www.ngui.cc/el/1135612.html?action=onClick
sudo apt-get remove libprotobuf-dev
sudo apt-get remove protobuf-compiler
sudo apt-get remove python-protobuf
sudo rm -rf /usr/local/bin/protoc
sudo rm -rf /usr/bin/protoc
sudo rm -rf /usr/local/include/google
sudo rm -rf /usr/local/include/protobuf*
sudo rm -rf /usr/include/google
sudo rm -rf /usr/include/protobuf*