Renderscript挂起设备

时间:2015-05-25 13:43:30

标签: renderscript

我在Android中使用Renderscript实现了FFT算法的一部分,当我运行代码时,我的应用程序被挂起了。我想一次处理来自real和img分配的512个值。内核将使用提供的大小为512的虚拟分配执行512次。

这是我的java代码

uploadFileToUrl

这是我的Renderscript代码

RenderScript rs = RenderScript.create(WajinViewerApplication
            .getApplication());
    ScriptC_fft scriptC_fft = new ScriptC_fft(rs);

    float inReal[] = new float[512 * 512];
    float inImg[] = new float[512 * 512];
    int k = 0;
    for (int i = 0; i < 512; i++) {
        for (int j = 0; j < 512; j++) {
            // copy values from complex 2d array to 1d array
            inReal[k] = data[i][j].real;
            inImg[k] = data[i][j].imaginary;
            k++;
        }
    }

    Allocation realAllocation = Allocation.createSized(rs, Element.F32(rs),
            512 * 512);
    Allocation imgAllocation = Allocation.createSized(rs, Element.F32(rs),
            512 * 512);
    realAllocation.copyFrom(inReal);
    imgAllocation.copyFrom(inImg);


    scriptC_fft.set_real(realAllocation);
    scriptC_fft.set_img(imgAllocation);

    Allocation inAllocation = Allocation.createSized(rs, Element.U16(rs),
            512);
    Allocation outAllocation = Allocation.createTyped(rs,
            inAllocation.getType());
    inAllocation.copyFrom(new short[512]);

    // set direction
    if (direction == Direction.Forward) {
        scriptC_fft.set_is_forward(true);
    } else {
        scriptC_fft.set_is_forward(false);
    }

    scriptC_fft.set_len(512);
    scriptC_fft.set_levels(Integer.numberOfLeadingZeros(512));

    scriptC_fft.forEach_root(inAllocation, outAllocation);
    outAllocation.copyTo(new short[512]);

    float outReal[] = new float[512 * 512];
    float outImg[] = new float[512 * 512];

    scriptC_fft.get_real().copyTo(outReal);
    scriptC_fft.get_img().copyTo(outImg);

    k = 0;
    for (int i = 0; i < 512; i++) {
        for (int j = 0; j < 512; j++) {
            // copy values from complex 1d array to 2d array
            data[i][j].real = outReal[k];
            data[i][j].imaginary = outImg[k];
            k++;
        }
    }

    rs.destroy();

0 个答案:

没有答案