pytorch / TensorRT

PyTorch/TorchScript/FX compiler for NVIDIA GPUs using TensorRT
https://pytorch.org/TensorRT
BSD 3-Clause "New" or "Revised" License
2.47k stars 340 forks source link

Error when trying to build with compiled binaries #96

Closed tsaizhenling closed 4 years ago

tsaizhenling commented 4 years ago

I am building an application with TRTorch precompiled binaries, and I am able to compile full precision and half precision graphs successfully.

I run into build errors while trying to compile the int8 graph as long as I include this line

auto calibrator = trtorch::ptq::make_int8_calibrator(std::move(calibration_dataloader), calibration_cache_file, true);

the build error

In file included from /home/tsai/TRTorchSample/../trtorch/include/trtorch/trtorch.h:38,
                 from /home/tsai/TRTorchSample/main.cpp:4:
/home/tsai/TRTorchSample/../trtorch/include/trtorch/ptq.h: In instantiation of ‘trtorch::ptq::Int8Calibrator<Algorithm, DataLoaderUniquePtr>::Int8Calibrator(DataLoaderUniquePtr, const string&, bool) [with Algorithm = nvinfer1::IInt8EntropyCalibrator2; DataLoaderUniquePtr = std::unique_ptr<torch::data::StatelessDataLoader<torch::data::datasets::MapDataset<torch::data::datasets::MapDataset<datasets::CIFAR10, Resize>, torch::data::transforms::Normalize<> >, torch::data::samplers::RandomSampler>, std::default_delete<torch::data::StatelessDataLoader<torch::data::datasets::MapDataset<torch::data::datasets::MapDataset<datasets::CIFAR10, Resize>, torch::data::transforms::Normalize<> >, torch::data::samplers::RandomSampler> > >; std::string = std::__cxx11::basic_string<char>]’:
/home/tsai/TRTorchSample/../trtorch/include/trtorch/trtorch.h:430:12:   required from ‘trtorch::ptq::Int8Calibrator<Algorithm, DataLoader> trtorch::ptq::make_int8_calibrator(DataLoader, const string&, bool) [with Algorithm = nvinfer1::IInt8EntropyCalibrator2; DataLoader = std::unique_ptr<torch::data::StatelessDataLoader<torch::data::datasets::MapDataset<torch::data::datasets::MapDataset<datasets::CIFAR10, Resize>, torch::data::transforms::Normalize<> >, torch::data::samplers::RandomSampler>, std::default_delete<torch::data::StatelessDataLoader<torch::data::datasets::MapDataset<torch::data::datasets::MapDataset<datasets::CIFAR10, Resize>, torch::data::transforms::Normalize<> >, torch::data::samplers::RandomSampler> > >; std::string = std::__cxx11::basic_string<char>]’
/home/tsai/TRTorchSample/main.cpp:77:121:   required from here
/home/tsai/TRTorchSample/../trtorch/include/trtorch/ptq.h:55:13: error: no matching function for call to ‘std::vector<at::Tensor>::push_back(<unresolved overloaded function type>)’
   55 |             batched_data_.push_back(batch.data);
      |             ^~~~~~~~~~~~~
In file included from /usr/include/c++/9/vector:67,
                 from /home/tsai/libtorch/include/c10/util/StringUtil.h:11,
                 from /home/tsai/libtorch/include/c10/util/Exception.h:5,
                 from /home/tsai/libtorch/include/c10/core/Device.h:5,
                 from /home/tsai/libtorch/include/c10/core/Allocator.h:6,
                 from /home/tsai/libtorch/include/ATen/ATen.h:3,
                 from /home/tsai/libtorch/include/torch/csrc/api/include/torch/types.h:3,
                 from /home/tsai/libtorch/include/torch/script.h:3,
                 from /home/tsai/TRTorchSample/main.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = at::Tensor; _Alloc = std::allocator<at::Tensor>; std::vector<_Tp, _Alloc>::value_type = at::Tensor]’
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘const value_type&’ {aka ‘const at::Tensor&’}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = at::Tensor; _Alloc = std::allocator<at::Tensor>; std::vector<_Tp, _Alloc>::value_type = at::Tensor]’
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::vector<at::Tensor>::value_type&&’ {aka ‘at::Tensor&&’}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
make[2]: *** [CMakeFiles/TRTorchSample.dir/build.make:63: CMakeFiles/TRTorchSample.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/TRTorchSample.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(TRTorchSample)
enable_language(CUDA)

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
set(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda")
set(CUDA_INCLUDE_DIRS "/usr/local/cuda/include")

add_executable(TRTorchSample main.cpp cifar10.cpp cifar10.h)

target_link_libraries(TRTorchSample "${TORCH_LIBRARIES}")
target_link_libraries(TRTorchSample "${PROJECT_SOURCE_DIR}/../trtorch/lib/libtrtorch.so")
set_property(TARGET TRTorchSample PROPERTY CXX_STANDARD 14)

target_include_directories(TRTorchSample PUBLIC
    "${PROJECT_BINARY_DIR}"
    "${PROJECT_SOURCE_DIR}/../libtorch"
    "${PROJECT_SOURCE_DIR}/../trtorch/include"
    )
narendasan commented 4 years ago

This is an odd issue, my best guess at a solution is make sure you are including torch/torch.h and before trtorch.h (there is a fix for the ordering issue coming) since they aren't included for you in the header.

I am able to compile and run the PTQ application in the repo outside of the source tree with the following Makefile using binaries from the tarball

CXX=g++
ROOT=<PATH TO SOURCE>
TORCH_PATH=<PATH TO TORCH>
INCLUDE_DIRS= -I/usr/local/cuda/include -I$(TORCH_PATH)/include -I$(TORCH_PATH)/include/torch/csrc/api/include -I$(ROOT)/trtorch/include -I$(ROOT)/datasets -I$(ROOT)/benchmark
LIB_DIRS=-L$(ROOT)/trtorch/lib -L$(TORCH_PATH)/lib -L/usr/local/cuda/lib64
LIBS=-ltrtorch -ltorch -ltorch_global_deps -lc10 -lc10_cuda -ltorch_cpu -ltorch_cuda -lcudart
SRCS=main.cpp datasets/cifar10.cpp benchmark/benchmark.cpp

ptq:
    $(CXX) $(SRCS) $(INCLUDE_DIRS) $(LIB_DIRS) $(LIBS) -pthread
github-actions[bot] commented 4 years ago

This issue has not seen activity for 30 days, Remove stale label or comment or this will be closed in 5 days