首页 > 解决方案 > 获取 OpenACC 空闲(或总)设备内存

问题描述

我有一个 GPU 代码,它在每次迭代时决定是否可以将迭代卸载到加速器。OpenACC 成为最好的工具:

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*/
    }

}

我如何提前决定是否aos[0:n_aos]适合 GPU 内存?有openacc_get_free_device_memory()某种功能吗?

否则,如果出现内存不足故障,我如何启动设备复制并返回仅 CPU 运行?

标签: nvccopenaccpgipgi-accelerator

解决方案


请参阅 OpenACC 标准的“3.2.6 acc get property”部分。特别是“acc_property_free_memory”属性。

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


推荐阅读