Do we have to change CUDA API function according with CUDA Runtime Version?

I have been checked the sample codes of CUDA7.0.
I have one question to ask about bandwithTest code.

I found the code as blow in bandwithTest code.

//pinned memory mode - use special function to get OS-pinned memory
#if CUDART_VERSION >= 2020
checkCudaErrors(cudaHostAlloc((void **)&h_idata, memSize, (wc) ? cudaHostAllocWriteCombined :0));
checkCudaErrors(cudaHostAlloc((void **)&h_odata, memSize, (wc) ? cudaHostAllocWriteCombined :0));

#else
checkCudaErrors(cudaMallocHost((void **)&h_idata, memSize));
checkCudaErrors(cudaMallocHost((void **)&h_odata, memSize));

#endif

It seems like that we must change CUDA API function according with CUDART_VERSION.
if CUDART_VERSION >=2020 : We must use cudaHostAlloc()
if CUDART_VERSION < 2020 : We musr use cudaMallocHost()

Is it mandatory?

I’d really appriciate it if anyone will reply soon.

Regards,

The CUDART_VERSION of 2020 is really old. It is CUDA 2.2, which is from before 2010.

You can actually still use either cudaMallocHost or cudaHostAlloc. If you look in the cuda runtime API document, you will find both:

https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html#group__CUDART__MEMORY

cudaHostAlloc is the newer API and it replaces cudaMallocHost.

If you were running (compiling) on a system that only had CUDA 2.2 or older, then you would have to use cudaMallocHost. But that is a scenario you should never have to deal with - anyone using CUDA 2.2 should upgrade to a newer version immediately.