Obtain OpenACC free (or total) device memory

205 views Asked by At

I have a GPU code that, at each iteration, decides if the iteration can be offloaded to the accelerator. OpenACC come to be the best tool:

void module(struct my_aos *aos, int n_aos){

    int criteria = /* check either that n_aos is large enough and that aos[:n_aos] will fit the GPU */

    #pragma acc data copy(aos[0:n_aos]) if(criteria)
    #pragma acc parallel loop if(criteria)
    for(int i = 0; i < n_aos; i++){
        /* work on my_aos*/
    }

}

How can I decide in advance if aos[0:n_aos] will fit the GPU memory? Is there an openacc_get_free_device_memory() sort of function?

Other wise how can I start a device copy and get back to CPU-only run in case of out-of-memory failure?

1

There are 1 answers

1
Mat Colgrove On BEST ANSWER

See section "3.2.6 acc get property" section of the OpenACC standard. In particular the "acc_property_free_memory" property.

https://www.openacc.org/sites/default/files/inline-images/Specification/OpenACC-3.1-final.pdf