了解OpenCL中的寄存器

时间:2012-07-16 14:48:15

标签: opencl gpgpu

我对OpenCL内核在内部使用寄存器感到有些困惑。我使用-cl-nv-verbose来捕获内核的寄存器用法。目前,我的内核正在为内核中的某些代码录制ptxas info: Used 4 registers。对于以下部分:

double a;
a = pow(2.0,2.0)
if (index != 0) {
}

使用的寄存器更改ptxas info: Used 6 registers。我知道if循环中没有任何内容。但如果我再次重组为:

double a;
if (index != 0) {
    a = pow(2.0,2.0)
}

这会将寄存器使用情况更改为ptxas info: Used 15 registers。我没有改变内核的工作组大小。也许答案在于查看ptx代码,但我不理解它(尽管如果需要我可以得到它)。我更感兴趣的是为什么寄存器使用只需移动一行代码就会跳转到两次。有任何想法吗? (索引是private

更新:PTX代码beforeafter

更新:内核代码:

__kernel void butterfC( __global double *sI,    
                        __global double *sJ,
                        __global double *sK,
                        const int zR, 
                        const int yR,   
                        const int xR,
                        unsigned int l1,
                        const int dir,
                        unsigned int type   ) 
{
    int idX = get_global_id(0);
    int idY = get_global_id(1);
    int idZ = get_global_id(2);

    int BASE = idZ*xR*yR;
    int STRIDE = 1;

    int powX = pow(4.0f,l1);
    int powXm1 = pow(4.0f,l1-1);

    int yIndex, kIndex;

    switch(type)
    {
        case 1: BASE += idY*xR; 
                yIndex  = idX / powXm1 * powX;
                kIndex  = (idX % powXm1) + yIndex;  
                break;
        case 2: BASE += idX; STRIDE = xR; 
                yIndex  = idY / powXm1 * powX;
                kIndex  = idY % powXm1 + yIndex;
                break;
        case 3: BASE = idY*xR + idX; STRIDE = xR * yR; 
                yIndex  = idZ / powXm1 * powX;
                kIndex  = idZ % powXm1 + yIndex;
                break; 
    }

    double a;   

    //a = pow(2.0,2.0);
    if (kIndex != 0) {
        a = pow(2.0,2.0);
        .... do stuff
    }
}

0 个答案:

没有答案