简体   繁体   English

clCreateContextFromType在执行时以SEGFAULT结尾

[英]clCreateContextFromType ends up in a SEGFAULT while execution

I am trying to create an OpenCL context on the platform which is containing my graphics card. 我正在尝试在包含我的图形卡的平台上创建OpenCL上下文。 But when I call clCreateContextFromType() a SEGFAULT is thrown. 但是,当我调用clCreateContextFromType()将引发SEGFAULT。

int main(int argc, char** argv)
{
    /*
    ...
    */
    cl_platform_id* someValidPlatformId;
    //creating heap space using malloc to store all platform ids
    getCLPlatforms(someValidPlatformId);
    //error handling for getCLPLatforms()

    //OCLPlatform(cl_platform_id platform)
    OCLPLatform platform = OCLPlatform(someValidPlatformId[0]);
    //OCLContext::OCL_GPU_DEVICE == CL_DEVICE_TYPE_GPU
    OCLContext context = OCLContext(platform,OCLContext::OCL_GPU_DEVICE);

    /*
    ...
    */
}

cl_platform_id* getCLPlatforms(cl_platform_id* platforms)
{
    cl_int errNum;
    cl_uint numPlatforms;

    numPlatforms = (cl_uint) getCLPlatformsCount(); //returns the platform count 
                                                    //using clGetPlatformIDs() 
                                                    //as described in the Khronos API
    if(numPlatforms == 0)
        return NULL;

    errNum = clGetPlatformIDs(numPlatforms,platforms,NULL);
    if(errNum != CL_SUCCESS)
        return NULL;

    return platforms;
}

OCLContext::OCLContext(OCLPlatform platform,unsigned int type)
{
    this->initialize(platform,type);
}

void OCLContext::initialize(OCLPlatform platform,unsigned int type)
{
    cl_int errNum;

    cl_context_properties contextProperties[] =
    {
        CL_CONTEXT_PLATFORM,
        (cl_context_properties)platform.getPlatformId(),
        0
    };

    cout << "a" << endl;std::flush(cout);

    this->context = clCreateContextFromType(contextProperties,
                                           (cl_device_type)type,
                                           &pfn_notify,
                                           NULL,&errNum);
    if(errNum != CL_SUCCESS)
        throw OCLContextException();

    cout << "b" << endl;std::flush(cout);
    /*
    ...
    */
}

The given type is CL_DEVICE_TYPE_GPU and also the platform contained by the cl_context_properties array is valid. 给定的type为CL_DEVICE_TYPE_GPU, cl_context_properties数组包含的平台也有效。

To debug the error I implemented the following pfn_notify() function described by the Khronos API: 为了调试错误,我实现了Khronos API描述的以下pfn_notify()函数:

static void pfn_notify(const char* errinfo, 
                       const void* private_info,
                       size_t cb, void* user_data)
{
    fprintf(stderr, "OpenCL Error (via pfn_notify): %s\n", errinfo);
    flush(cout);
}

Here is the ouput schown by the shell: 这是外壳发出的输出:

$ ./OpenCLFramework.exe
a
Segmentation fault

The machine i am working with has the following properties: 我正在使用的机器具有以下属性:

  • Intel Core i5 2500 CPU 英特尔酷睿i5 2500 CPU
  • NVIDIA Geforce 210 GPU NVIDIA Geforce 210 GPU
  • OS: Windows 7 作业系统:Windows 7
  • AMD APP SDK 3.0 Beta AMD APP SDK 3.0 Beta
  • IDE: Eclipse with gdb IDE:具有gdb的Eclipse

It would be great if somebody knew an answer to this problem. 如果有人知道这个问题的答案,那就太好了。

The problem seems to be solved now. 该问题现在似乎已解决。

Injecting the a valid cl_platform_id throught gdb solved the SEGFAULT. 通过gdb注入有效的cl_platform_id解决SEGFAULT。 So I digged a little bit deeper and the issue for the error was that I saved the value as a standard primitive. 因此,我进行了更深入的研究,错误的原因是我将该值保存为标准原语。 When I called a function with this value casted to cl_platform_id some functions failed handling that. 当我使用将此值cl_platform_id转换为cl_platform_id函数cl_platform_id某些函数无法对其进行处理。 So it looks like it is a mingling of types what lead to this failure. 因此,导致失败的原因似乎是类型的混合。

Now I save the value as cl_platform_id and cast it to an primitive when needed and not vice versa. 现在,我将值另存为cl_platform_id并在需要时将其cl_platform_id转换为基元,反之亦然。

I thank you for your answers and apologize for the long radio silence for my part. 我感谢您的回答,并为电台长时间的沉默表示歉意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM