Is it possible to convert a host pointer to managed memory?

Hi,
I have a host pointer h_ptr which points to an array in ordinary host memory. The array does not fit into device memory.
I want to have read-only access to this array on both host and device. Unified Virtual Memory is supported.

Currently, I allocate a new array managed_ptr with cudaMallocManaged, copy the data from h_ptr to managed_ptr, free h_ptr and finally use cudaMemAdvice to set managed_ptr to cudaMemAdviseSetReadMostly.

However, this will fail if the size of the array exceeds the available free memory since a copy is made.

Is it possible to use cudaHostRegister or other another function to convert h_ptr into managed memory?

not possible

it’s unclear what you mean by “available free memory”, but if you are referring to host memory, then a possible workaround would be to use a managed allocation initially for h_ptr

another alternative is just to use host mapped memory, e.g. with cudaHostRegister

Thank you for your response. I rearranged my code to allocate h_ptr directly via cudaMallocManaged.