assert(cudaMalloc(&ptr_dev, 1024) == cudaSuccess) will causes ptr_dev==nullptr

My test code is as follows:

  float *ptr_dev;
  cudaMalloc(&ptr_dev, 1024);
  printf("ptr_dev: %p\n", ptr_dev);

  float *ptr_dev1;
  assert(cudaMalloc(&ptr_dev1, 1024) == cudaSuccess);
  printf("ptr_dev1: %p\n", ptr_dev1);

  float *ptr_dev2;
  assert(cudaSuccess == cudaMalloc(&ptr_dev2, 1024));
  printf("ptr_dev2: %p\n", ptr_dev2);

First, I run the code on Jetson AGX Xavier(Jetpack 4.4, gcc_version=7.5.0), and the output is :

ptr_dev: 0x2037ca000
ptr_dev1: (nil)
ptr_dev2: (nil)

Second, I run the code on Jetson Orin(Jetpack 5.0.1, gcc_version=9.4.0), and the output is:

ptr_dev: 0x205227000
ptr_dev1: 0x205227400
ptr_dev2: 0x205227800

Why assert causes cudaMalloc failed? Is this problem related to the GCC version?

I don’t get any null printouts with your code. My guess is it has something to do with the software stack on your AGX Xavier. I don’t know what exactly, and have no particular reason to attribute this to gcc version. Since the Jetpack 5.0.1 seems to be working as expected on the Jetson Orin, you might want to try updating the AGX Xavier to that Jetpack also.

You might also wish to ask on the Jetson AGX Xavier forum.

1 Like