OpenCL clCreateCommandQueue内存泄漏

时间:2016-07-29 12:32:05

标签: c++ memory-leaks opencl gpgpu amd

在我的应用程序中,我有很多时间初始化OpenCL,这会导致内存泄漏。以下是导致泄漏的代码的一个小例子:

#include <iostream>
#include <CL/cl.h>

int main()
{
    cl_platform_id platform = 0;
    cl_int err = clGetPlatformIDs(1, &platform, NULL);
    if(err != CL_SUCCESS){ return 1; }

    cl_device_id device_id = 0;
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
    if(err != CL_SUCCESS){ return 2; }

    char buff[128];
    err = clGetDeviceInfo(device_id, CL_DEVICE_NAME, 128, buff, NULL);
    if(err != CL_SUCCESS){ return 3; }
    fprintf(stdout, "Device Name: %s\n", buff);

    while(true)
    {
        cl_context context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
        if(err != CL_SUCCESS)
            return 4;

        cl_command_queue command_queue = clCreateCommandQueue(context, device_id, 0, &err);
        if(err != CL_SUCCESS)
            return 5;

        clReleaseCommandQueue(command_queue);

        clReleaseContext(context);
    }

    return 0;
}

此代码是developer.apple.com示例的一部分。没有cl_command_queue初始化也不会导致泄漏。问题在哪里?

我的配置:Radeon R7 250,AMD APP SDK 3.0,Visual Studio 2010。

0 个答案:

没有答案