Repository: microsoft/onnxruntime
File: onnxruntime/test/providers/cuda/cuda_mempool_arena_test.cc (C++)

Code before:
    return false;
  }

  // Check if the driver version supports the runtime version
  if (ort_cuda_rt_version >= 12000 && ort_cuda_driver_version < 12000) {
    return false;
  }

  if (ort_cuda_rt_version >= 13000 && ort_cuda_driver_version < 13000) {
    return false;
  }

  // Creating a cuda mempool in some pipelines fails with
  // CUDA failure 801: operation not supported ; GPU=0 ; hostname=af14bbb1c000000 ;
  // Even though CUDA version may be 12.8 possibly due to the driver.
  cudaMemPoolProps props{};
  // Pinned is not the same as pinned allocator, cudaMemLocationTypeDevice actually does not exist
  // even though is present in some internet docs.
  props.allocType = cudaMemAllocationTypePinned;
  props.handleTypes = cudaMemHandleTypeNone;        // local to process
  props.location.type = cudaMemLocationTypeDevice;  // Device memory
  props.location.id = 0;                            // test device 0
  cudaMemPool_t pool;
  auto cuda_error = cudaMemPoolCreate(&pool, &props);
  if (cuda_error != cudaSuccess) {
    ClearCudaError();
    return false;
  }
  ORT_IGNORE_RETURN_VALUE(cudaMemPoolDestroy(pool));

  return true;
}

static ::cudaStream_t NewCudaStream() {
  ::cudaStream_t s{};
  const cudaError_t st = ::cudaStreamCreate(&s);
  EXPECT_EQ(st, cudaSuccess);
  return s;
}

static void DestroyCudaStream(::cudaStream_t s) {
  if (s) EXPECT_EQ(cudaSuccess, ::cudaStreamDestroy(s));
}

static void TouchDevice(void* p, size_t bytes, ::cudaStream_t s, unsigned char value = 0xAB) {
  ASSERT_NE(p, nullptr);
  ASSERT_EQ(::cudaSuccess, ::cudaMemsetAsync(p, static_cast<int>(value), bytes, s));
}

// --------- Test parameters ---------


Review comment (bug):
Should we peek at the error before trying to create the mempool to check if there were issues from running other tests **before** trying to attempt mem pool creation and subsequently resetting the error if mempool creation failed? 

Code after:
    return false;
  }

  // Check if the driver version supports the runtime version
  if (ort_cuda_rt_version >= 12000 && ort_cuda_driver_version < 12000) {
    return false;
  }

  if (ort_cuda_rt_version >= 13000 && ort_cuda_driver_version < 13000) {
    return false;
  }

  // Creating a cuda mempool in some pipelines fails with
  // CUDA failure 801: operation not supported ; GPU=0 ; hostname=af14bbb1c000000 ;
  // Even though CUDA version may be 12.8 possibly due to the driver.
  cudaMemPoolProps props{};
  // Pinned is not the same as pinned allocator, cudaMemLocationTypeDevice actually does not exist
  // even though is present in some internet docs.
  props.allocType = cudaMemAllocationTypePinned;
  props.handleTypes = cudaMemHandleTypeNone;        // local to process
  props.location.type = cudaMemLocationTypeDevice;  // Device memory
  props.location.id = 0;                            // test device 0
  cudaMemPool_t pool;
  auto cuda_error = cudaMemPoolCreate(&pool, &props);
  if (cuda_error != cudaSuccess) {
    ClearCudaError();
    return false;
  }
  ORT_IGNORE_RETURN_VALUE(cudaMemPoolDestroy(pool));

  return true;
}

static ::cudaStream_t NewCudaStream() {
  ::cudaStream_t s{};
  const cudaError_t st = ::cudaStreamCreate(&s);
  EXPECT_EQ(st, cudaSuccess);
  return s;
}

static void DestroyCudaStream(::cudaStream_t s) {
  if (s) {
    EXPECT_EQ(cudaSuccess, ::cudaStreamDestroy(s));
  }
}

static void TouchDevice(void* p, size_t bytes, ::cudaStream_t s, unsigned char value = 0xAB) {
  ASSERT_NE(p, nullptr);
  ASSERT_EQ(::cudaSuccess, ::cudaMemsetAsync(p, static_cast<int>(value), bytes, s));
}