tensorflow / tensorrt

TensorFlow/TensorRT integration
Apache License 2.0
736 stars 226 forks source link

example-cpp/mnist_demo build tf-trt example fails #323

Open IJunSang opened 2 years ago

IJunSang commented 2 years ago

Hello, I'm using 'nvcr.io/nvidia/tensorflow:22.07-tf2-py3' container.

When I try to build TF-TRT example, I get error message

root@196ef112f21c:/workspace/tensorrt/tftrt/examples-cpp/mnist_demo/build# make
[ 25%] Built target tf_symlinks
[ 50%] Building CXX object CMakeFiles/tf_trt_example.dir/main.cc.o
In file included from /usr/local/lib/python3.8/dist-packages/tensorflow/include/tensorflow/compiler/tf2tensorrt/trt_convert_api.h:25,
                 from /workspace/tensorrt/tftrt/examples-cpp/mnist_demo/main.cc:25:
/usr/local/lib/python3.8/dist-packages/tensorflow/include/tensorflow/compiler/tf2tensorrt/common/utils.h:42:10: fatal error: third_party/tensorrt/NvInfer.h: No such file or directory
   42 | #include "third_party/tensorrt/NvInfer.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/tf_trt_example.dir/build.make:63: CMakeFiles/tf_trt_example.dir/main.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/tf_trt_example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

so, I edited CMakeList.txt(line15, 47) file and /usr/local/lib/python3.8/dist-packages/tensorflow/include/tensorflow/compiler/tf2tensorrt/common/utils.h

from 
find_path(trt_include_path NAME NvInfer.h HINTS)
to 
find_path(trt_include_path NAME NvInfer.h HINTS /usr/local/cuda/targets/x86_64-linux/include)

from 
#include "third_party/tensorrt/NvInfer.h"
to
#include <NvInfer.h>

and added code at line 47

target_include_directories(tf_trt_example PRIVATE /usr/local/cuda/targets/x86_64-linux/include)

after change the code I faced error

[ 25%] Built target tf_symlinks
[ 50%] Linking CXX executable tf_trt_example
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `LoadModel(std::string const&, tensorflow::SavedModelBundle*, std::vector<std::string, std::allocator<std::string> >*, std::vector<std::string, std::allocator<std::string> >*)':
main.cc:(.text+0x2d4): undefined reference to `tensorflow::LoadSavedModel(tensorflow::SessionOptions const&, tensorflow::RunOptions const&, std::string const&, std::unordered_set<std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::string> > const&, tensorflow::SavedModelBundle*)'
/usr/bin/ld: main.cc:(.text+0x4c6): undefined reference to `google::protobuf::Message::DebugString() const'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `LoadInputs(std::string const&, std::vector<std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >, std::allocator<std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> > > >*)':
main.cc:(.text+0x898): undefined reference to `tensorflow::TensorShapeRep::DebugString() const'
/usr/bin/ld: main.cc:(.text+0x9f1): undefined reference to `tensorflow::TensorShapeRep::DebugString() const'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `main':
main.cc:(.text+0xe04): undefined reference to `tensorflow::Flag::Flag(char const*, std::string*, std::string const&, bool*)'
/usr/bin/ld: main.cc:(.text+0xe64): undefined reference to `tensorflow::Flag::Flag(char const*, std::string*, std::string const&, bool*)'
/usr/bin/ld: main.cc:(.text+0xec4): undefined reference to `tensorflow::Flag::Flag(char const*, bool*, std::string const&, bool*)'
/usr/bin/ld: main.cc:(.text+0x102c): undefined reference to `tensorflow::Flags::Usage(std::string const&, std::vector<tensorflow::Flag, std::allocator<tensorflow::Flag> > const&)'
/usr/bin/ld: main.cc:(.text+0x138f): undefined reference to `tensorflow::tensorrt::ConvertAndBuild(tensorflow::GraphDef const&, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >, std::allocator<std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> > > > const&, tensorflow::tensorrt::TfTrtConversionParams const&)'
/usr/bin/ld: main.cc:(.text+0x1416): undefined reference to `tensorflow::tensorrt::ConvertAndBuild(tensorflow::SavedModelBundle*, std::string const&, std::vector<std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >, std::allocator<std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> > > > const&, tensorflow::tensorrt::TfTrtConversionParams const&)'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `google::protobuf::internal::GetEmptyStringAlreadyInited()':
main.cc:(.text._ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0xb): undefined reference to `google::protobuf::internal::fixed_address_empty_string'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `tensorflow::Status::error_message() const':
main.cc:(.text._ZNK10tensorflow6Status13error_messageEv[_ZNK10tensorflow6Status13error_messageEv]+0x21): undefined reference to `tensorflow::Status::empty_string()'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `std::string* tensorflow::internal::MakeCheckOpString<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)':
main.cc:(.text._ZN10tensorflow8internal17MakeCheckOpStringImmEEPSsRKT_RKT0_PKc[_ZN10tensorflow8internal17MakeCheckOpStringImmEEPSsRKT_RKT0_PKc]+0x7f): undefined reference to `tensorflow::internal::CheckOpMessageBuilder::NewString()'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `std::string* tensorflow::internal::MakeCheckOpString<long, int>(long const&, int const&, char const*)':
main.cc:(.text._ZN10tensorflow8internal17MakeCheckOpStringIliEEPSsRKT_RKT0_PKc[_ZN10tensorflow8internal17MakeCheckOpStringIliEEPSsRKT_RKT0_PKc]+0x7f): undefined reference to `tensorflow::internal::CheckOpMessageBuilder::NewString()'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `std::string* tensorflow::internal::MakeCheckOpString<long, long>(long const&, long const&, char const*)':
main.cc:(.text._ZN10tensorflow8internal17MakeCheckOpStringIllEEPSsRKT_RKT0_PKc[_ZN10tensorflow8internal17MakeCheckOpStringIllEEPSsRKT_RKT0_PKc]+0x7f): undefined reference to `tensorflow::internal::CheckOpMessageBuilder::NewString()'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/main.cc.o: in function `std::string* tensorflow::internal::MakeCheckOpString<int, long>(int const&, long const&, char const*)':
main.cc:(.text._ZN10tensorflow8internal17MakeCheckOpStringIilEEPSsRKT_RKT0_PKc[_ZN10tensorflow8internal17MakeCheckOpStringIilEEPSsRKT_RKT0_PKc]+0x7f): undefined reference to `tensorflow::internal::CheckOpMessageBuilder::NewString()'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/mnist.cc.o: in function `tensorflow::Status tensorflow::errors::NotFound<char const*, std::string, char const*, char*>(char const*, std::string, char const*, char*)':
mnist.cc:(.text._ZN10tensorflow6errors8NotFoundIJPKcSsS3_PcEEENS_6StatusEDpT_[_ZN10tensorflow6errors8NotFoundIJPKcSsS3_PcEEENS_6StatusEDpT_]+0x128): undefined reference to `tensorflow::strings::StrCat(tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/mnist.cc.o: in function `tensorflow::Status tensorflow::errors::FailedPrecondition<char const*, unsigned int, char const*>(char const*, unsigned int, char const*)':
mnist.cc:(.text._ZN10tensorflow6errors18FailedPreconditionIJPKcjS3_EEENS_6StatusEDpT_[_ZN10tensorflow6errors18FailedPreconditionIJPKcjS3_EEENS_6StatusEDpT_]+0xe4): undefined reference to `tensorflow::strings::StrCat(tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/mnist.cc.o: in function `tensorflow::Status tensorflow::errors::Internal<char const*>(char const*)':
mnist.cc:(.text._ZN10tensorflow6errors8InternalIJPKcEEENS_6StatusEDpT_[_ZN10tensorflow6errors8InternalIJPKcEEENS_6StatusEDpT_]+0x59): undefined reference to `tensorflow::strings::StrCat(tensorflow::strings::AlphaNum const&)'
/usr/bin/ld: CMakeFiles/tf_trt_example.dir/mnist.cc.o: in function `std::string tensorflow::strings::StrCat<>(tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)':
mnist.cc:(.text._ZN10tensorflow7strings6StrCatIJEEESsRKNS0_8AlphaNumES4_S4_S4_S4_DpRKT_[_ZN10tensorflow7strings6StrCatIJEEESsRKNS0_8AlphaNumES4_S4_S4_S4_DpRKT_]+0xe7): undefined reference to `tensorflow::strings::internal::CatPieces(std::initializer_list<absl::lts_20211102::string_view>)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/tf_trt_example.dir/build.make:99: tf_trt_example] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/tf_trt_example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

is there any solution can solve errors?

thanks.

ncomly-nvidia commented 2 years ago

CC: @DEKHTIARJonathan, @nvkevihu

nvkevihu commented 2 years ago

@IJunSang, please check that the CXX11_ABI flag is set to 1 on line 37 of CMakeLists.txt:

target_compile_options(tf_trt_example PRIVATE -D_GLIBCXX_USE_CXX11_ABI=1 -DGOOGLE_CUDA -DGOOGLE_TENSORRT)

The example should build without errors when using your workaround and the above CXX11_ABI value.

@tfeher could you help with the original compilation error? It doesn't seem like any of the changes between 22.06 and 22.07 should be causing this issue.