valgrind warning: Syscall param writev(vector[...]) points to uninitialised byte(s)

Ubuntu 16.04
TITAN Xp
Driver Version: 410.104
CUDA Version: 10.0
CUDNN Version: 7.3.1
TensorRT Version: 5.0.2

I modified sampleGoogleNet.cpp to write its engine to disk, using

void SampleGoogleNet::WriteToDisk(std::string const &filename) const {
  SampleUniquePtr<nvinfer1::IHostMemory> modelStream{mEngine->serialize()};

  std::ofstream s{filename, std::ios::binary};
  s.write(reinterpret_cast<char const *>(modelStream->data()),
          modelStream->size());
}

This resulted in warnings from valgrind 3.14.0:

==2842== Syscall param writev(vector[...]) points to uninitialised byte(s)
==2842==    at 0xD07DFFD: ??? (syscall-template.S:84)
==2842==    by 0xCA90ECF: std::__basic_file<char>::xsputn_2(char const*, long, char const*, long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==2842==    by 0xCACC37E: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==2842==    by 0xCAF0A91: std::ostream::write(char const*, long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==2842==    by 0x405024: SampleGoogleNet::WriteToDisk(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const (in /home/tom/Downloads/trt5/bin/sample_googlenet)
==2842==    by 0x405DF3: main (in /home/tom/Downloads/trt5/bin/sample_googlenet)
==2842==  Address 0x8101b3a8 is 872 bytes inside a block of size 46,411,280 alloc'd
==2842==    at 0x402EB4F: operator new[](unsigned long) (vg_replace_malloc.c:423)
==2842==    by 0x4C54009: nvinfer1::cudnn::serializeEngine(nvinfer1::rt::Engine const&) (in /usr/lib/x86_64-linux-gnu/libnvinfer.so.5.0.2)
==2842==    by 0x404F9E: SampleGoogleNet::WriteToDisk(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const (in /home/tom/Downloads/trt5/bin/sample_googlenet)
==2842==    by 0x405DF3: main (in /home/tom/Downloads/trt5/bin/sample_googlenet)
==2842==  Uninitialised value was created by a heap allocation
==2842==    at 0x402E462: operator new(unsigned long) (vg_replace_malloc.c:334)
==2842==    by 0x4C08F0E: nvinfer1::builder::buildGraph(nvinfer1::CudaEngineBuildConfig const&, nvinfer1::builder::Graph&, nvinfer1::Network const&) (in /usr/lib/x86_64-linux-gnu/libnvinfer.so.5.0.2)
==2842==    by 0x4C09F6E: nvinfer1::builder::buildEngine(nvinfer1::CudaEngineBuildConfig&, nvinfer1::rt::HardwareContext const&, nvinfer1::Network const&) (in /usr/lib/x86_64-linux-gnu/libnvinfer.so.5.0.2)
==2842==    by 0x4C78E0C: nvinfer1::builder::Builder::buildCudaEngine(nvinfer1::INetworkDefinition&) (in /usr/lib/x86_64-linux-gnu/libnvinfer.so.5.0.2)
==2842==    by 0x4051AC: SampleGoogleNet::build() (in /home/tom/Downloads/trt5/bin/sample_googlenet)
==2842==    by 0x405B9E: main (in /home/tom/Downloads/trt5/bin/sample_googlenet)

There is a good chance this warning is a false positive, due to things like padding, alignment, and legal (but maybe bad style) uninitialized values. However, without access to TensorRT sources, we users have no way to know. I’d be curious to hear nvidia’s thoughts on the matter. In the meantime, I’ll keep assuming this is benign, and add some valgrind supressions :).

Cheers,
Tom