php 递归函数 segfault,clCreateContextFromType在执行时以SEGFAULT结尾(clCreateContextFromType ends up in a SEGFAU...

clCreateContextFromType在执行时以SEGFAULT结尾(clCreateContextFromType ends up in a SEGFAULT while execution)

我试图在包含我的图形卡的平台上创建一个OpenCL上下文。 但是当我调用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);

/*

...

*/

}

给定type为CL_DEVICE_TYPE_GPU, cl_context_properties数组包含的平台也有效。

为了调试错误,我实现了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);

}

这是shell的输出:

$ ./OpenCLFramework.exe

a

Segmentation fault

我正在使用的机器具有以下属性:

英特尔酷睿i5 2500 CPU

NVIDIA Geforce 210 GPU

操作系统:Windows 7

AMD APP SDK 3.0 Beta

IDE:带有gdb的Eclipse

如果有人知道这个问题的答案,那就太好了。

I am trying to create an OpenCL context on the platform which is containing my graphics card. But when I call clCreateContextFromType() a SEGFAULT is thrown.

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.

To debug the error I implemented the following pfn_notify() function described by the Khronos API:

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

NVIDIA Geforce 210 GPU

OS: Windows 7

AMD APP SDK 3.0 Beta

IDE: Eclipse with gdb

It would be great if somebody knew an answer to this problem.

原文:https://stackoverflow.com/questions/29537906

更新时间:2020-01-01 11:11

最满意答案

这个问题现在似乎已经解决了。

通过gdb注入有效的cl_platform_id解决了SEGFAULT。 所以我更深入地挖掘了错误的问题是我将值保存为标准基元。 当我调用一个函数时,这个值被转换为cl_platform_id有些函数处理失败了。 所以看起来它是混合导致这种失败的类型。

现在我将值保存为cl_platform_id并在需要时将其转换为基元,反之亦然。

我感谢你的回答,并为我的长期无线电沉默道歉。

The problem seems to be solved now.

Injecting the a valid cl_platform_id throught gdb solved the 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. 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.

I thank you for your answers and apologize for the long radio silence for my part.

2015-10-05

相关问答

此代码适用于我: #include

#include

#include

#include "itkImage.h"

#include "itkImageFileReader.h"

#include "itkImageFileWriter.h"

#include "itkRGBPixel.h"

int main(int argc, char** argv)

{

std::string input = "/home/doriad/tem

...

clCreateCommandQueueWithProperties被添加到OpenCL 2.0中。 您不应该将它与平台和低于版本2.0的设备(例如日志中显示的1.1和1.2)一起使用。 clCreateCommandQueueWithProperties got added in OpenCL 2.0. You should not use it with platforms and devices that are less than version 2.0 (such as 1.1 and

...

if((strm = opendir(dir) == NULL))

括号嵌套错误。 它应该是: if((strm = opendir(dir)) == NULL)

if((strm = opendir(dir) == NULL))

The parentheses are nested wrong. It should be: if((strm = opendir(dir)) == NULL)

这个问题现在似乎已经解决了。 通过gdb注入有效的cl_platform_id解决了SEGFAULT。 所以我更深入地挖掘了错误的问题是我将值保存为标准基元。 当我调用一个函数时,这个值被转换为cl_platform_id有些函数处理失败了。 所以看起来它是混合导致这种失败的类型。 现在我将值保存为cl_platform_id并在需要时将其转换为基元,反之亦然。 我感谢你的回答,并为我的长期无线电沉默道歉。 The problem seems to be solved now. Injecting

...

好吧,我仍然不知道为什么会修复它 - 但是seg错误是由我改变了在链接命令中指定目标文件的顺序引起的。 但是在使用这些函数的文件之前指定将函数指针加载到OpenGL的目标文件会使一切正常工作。 Okay, I still don't really know why this fixes it - but the seg fault was caused by me changing the order the object files were specified in the linking c

...

raspberry pi通过特定于供应商的库为OpenGL ES 1.x / 2.x提供硬件支持 - 但桌面GL没有。 立即模式( glBegin/glEnd ) 从未出现在GLES中。 你必须使用顶点数组。 但是,矩阵堆栈在GLES1.x中可用。 你必须使用egl来获得一个加速的上下文。 从好的方面来说,RPi上的GL不需要X11,所以你可以直接在控制台上安装GL覆盖,非常酷。 官方RPi固件附带了hello_triangle演示,它演示了如何获得有效的上下文,源代码可以在/opt/vc/src

...

您没有初始化Library变量:请参阅FT_LIBRARY文档 。 你应该使用FT_Init_FreeType : FT_Init_FreeType 在FT_FREETYPE_H(freetype / freetype.h)中定义。 FT_EXPORT(FT_Error)FT_Init_FreeType(FT_Library * alibrary); 初始化一个新的FreeType库对象。 由此函数注册的模块集在构建时确定。 output alibrary新库对象的句柄。 返回FreeType错误

...

您需要初始化Coord::children的元素。 它们不能保证为NULL,因此在populateTree() ,当您对每个子进行空测试时,您将获得非空子项,尽管它们不会指向有效的Coord 。 当它们从队列中弹出,并且您在无效的Coord上调用getValidMoves()时,您将获得seg-fault。 将Coord构造函数更改为: Coord::Coord(int xPos, int yPos) : Loc(xPos, yPos)

{

std::fill( children, chi

...

分段错误来自多个线程同时更新pos的值,因此将其设置为某个值,将com + pos转换为指向com的已分配内存之外或之前的指针。 并行化这种循环的正确方法是将私有字符串中的值连接起来,然后以有序的方式连接私有字符串: char com[255];

int pos = 0;

#pragma omp parallel

{

char mycom[255];

int mypos = 0;

#pragma omp for schedule(static) nowait

for (

...

int* num;

*num = atoi(argv[0]);

取消引用未初始化的指针 - 未定义的行为。 将其更改为 int num;

num = atoi(argv[0]);

要么 int *num = malloc(sizeof(int));

*num = atoi(argv[0]);

int* num;

*num = atoi(argv[0]);

dereferencing a uninitialised pointer - undefined behaviour. Change

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值