内存释放接口返回成功 但是npu-smi查看界面上显存并未释放
收藏回复举报
内存释放接口返回成功 但是npu-smi查看界面上显存并未释放
t('forum.solved') 已解决
新人帖
发表于2025-04-07 11:03:10
0 查看

以下是测试的代码,调用hi_mpi_dvpp_malloc hi_mpi_dvpp_free 和aclrtMalloc aclrtFree两种都试过,如果申请的内存多一些可能会出现 npu-smi查看降低一部分显存的情况,并不是开辟多少实际销毁多少,这里测试是申请了32块1280*720*3/2大小的内存,测试多次,内存都没销毁,但是free接口又返回成功,请问是什么原因

 

int main() 

    aclInit(nullptr); 

    std::queue<void*> free_queue_; 

    aclrtContext aclContex_ = NULL; 

    aclError aclRet = aclrtCreateContext(&aclContex_, 0); 

    if (aclRet != ACL_SUCCESS) { 

        printf("aclrtCreateContext error\n"); 

        return -1; 

    } 

    // 媒体数据处理系统初始化 

    int ret = hi_mpi_sys_init(); 

    if (ret != HI_SUCCESS) { 

        printf("hi_mpi_sys_init error\n"); 

        aclrtDestroyContext(aclContex_); 

        return -1; 

    } 

    for (int i = 0; i < 32; ++i) { 

        void* pFrame = NULL; 

        //hi_mpi_dvpp_malloc(0, &pFrame, 1280*720*3/2); //aclrtMalloc 

        aclrtMalloc(&pFrame, 1280 * 720 * 3 / 2, ACL_MEM_MALLOC_HUGE_FIRST); 

 

        if (!pFrame) { 

            printf("alloc failed!!!!!!!!!!!!!!!!!!\n"); 

            continue; 

        } 

        free_queue_.push(pFrame); 

    } 

 

    for (int i = 0; i < 32; ++i) { 

        auto p = free_queue_.front(); 

        free_queue_.pop(); 

 

        auto ret = aclrtFree(p); 

        //auto ret = hi_mpi_dvpp_free(p); 

        if (ret) { 

            printf("dvpp free error:code==%#x\n", ret); 

        } 

        p = NULL; 

    } 

 

    cout << "Hello CMake." << endl; 

    while (1) 

    { 

        std::this_thread::sleep_for(std::chrono::seconds(3)); 

    } 

    return 0; 

我要发帖子