【问题标题】:Accessing variable by pointer in OpenCL kernel在 OpenCL 内核中通过指针访问变量
【发布时间】:2013-10-02 17:40:35
【问题描述】:

我正在 OpenCL 中编写一个光线追踪程序,我的内核中有一个函数 Quadratic,它接收 3 个浮点变量和两个指向浮点值的指针。

功能:

bool Quadratic(float A, float B, float C, float *t0, float *t1) {
    float discrim  = B * B - ( 4.0 * A * C );
    if (discrim <= 0.0) return false;
    float rootDiscrim = sqrtf(discrim);
    float q;
    if (B < 0) q = -0.5f * ( B - rootDiscrim);
    else q = -0.5f * ( B + rootDiscrim);
    *t0 = q / A;
    *t1 = C / q;
    float temp;
    return true;
}

调用函数:

float t0;
float t1;
if (Quadratic(A,  B,  C,  &t0,  &t1)) c[(i*dimy)+j] = t0;
else c[(i*dimy)+j] =  0.0;

产生以下错误:

pyopencl.RuntimeError: clBuildProgram failed: build program failure - 
Build on <pyopencl.Device 'ATI Radeon HD 6750M' on 'Apple' at 0x1021b00>:
Error returned by cvms_element_build_from_source

在试图找出问题所在时,我创建了以下似乎有效的测试函数:

bool TestFunc(float Y, float *x) {
    *x = Y;
    return true;
}

float x;
if (TestFunc(50.0, &x)) c[(i*dimy)+j] = x;

据我所知,这两个函数具有相同类型的输入和输出,任何帮助将不胜感激。

【问题讨论】:

  • 使用 clGetProgramBuildInfo() 获取错误的详细信息。这直接指向“sqrt() not defined”之类的问题。

标签: c opencl c99 pyopencl


【解决方案1】:

原来问题在于使用sqrtf。一旦更改为sqrt,它就可以完美运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多