Memcpy and Unified Memory


I’m having a problem with migrating code that runs on a PC to the Jetson AGX Xavier ( running Tegra Linux ).

The software crashes ( seg fault ) when I run it on the Xavier, but it works on the PC.

I have tried to run the code in gdb and it turns out that it crashes the doing a memcpy.

memcpy(&buffer_[extra_buffer_index_],, sample.data_.size() * sizeof(int16_t));`

The buffer is allocated like this:

  cudaMallocManaged(reinterpret_cast<void**>(&buffer_), full_buffer_size_ * sizeof(int16_t));

So I’ve guessed that changeing the memcpy call to:

cudaMemcpy(&buffer_[extra_buffer_index_],, sample.data_.size() * sizeof(int16_t), cudaMemcpyDefault);

Now the code does not crash during the copying any more, however it crashes on other places in the code. The place in the code where the crash occurs is not always the same, but I have a feeling that it is related to reading/writing std::vector’s.

I have some questions regarding this that I was hoping that someone in this forum could help me with:

  1. I have suspicion that this problem is related to the Unified Memory on the Xavier, and does changing memcpy with cudaMemcpy fix this, and why did it work on the PC?
  2. Is it problematic to use std::vector on units with unified memory?
  3. Is there a way to disable the unified memory and have separate memories for GPU and CPU, so that the system would behave as on the PC?
  4. Does someone have some tips regarding debugging issues like this?

All help is highly appreciated, thanks!


1. The common cause is that Jetson doesn’t support concurrent access.
Is it possible that the buffer is accessed by other processors?

2. It should work.

3. No. CPU and GPU shared the same physical memory.

4. Please try to make sure there is no concurrent access to the buffer first.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.