0

通过使用 Aparapi 的显式缓冲区管理,我遇到了一个问题。此后的代码显示我正在尝试管理多个 put/get 循环以从 GPU 刷新/取回数据。似乎第一个putget已经完成,但不是其他的。

import com.amd.aparapi

// Dummy test to reproduce explicit buffer management 
public class QuickTestExplicit extends Kernel
{
    private static final float DELTA = (float) 1E-5;
    // will be filled, put on GPU in each iterations
    private float[][] values;
    // will be filled with results, put in GPU once but retrieved several times
    private float[] currentRes;

    private void initData()
    {
        values = new float[2000][20];
        currentRes = new float[2000];
    }

    @Override
    public void run()
    {
        int id = getGlobalId();
        long accum = 0;
        // simple sum of elements
        for (int index = 0; index < 20; ++index)
        {
            accum += values[id][index];
        }
        currentRes[id] = accum;
    }

    public void process()
    {
        boolean passed = true;
        initData();

        if (isExplicit())
        {
            put(currentRes);
        }

        for (int row = 0; row < 2000; ++row)
        {
            for (int i = 0; i < values.length; ++i)
            {
                for (int depth = 0; depth < 20; ++depth)
                {
                    values[i][depth] = (float) row;
                }
            }

            if (isExplicit())
            {
                put(values);
            }

            execute(values.length);

            if (isExplicit())
            {
                get(currentRes);
            }

            // just check the success of the operation (for the example)
            passed = true;
            for (int currentIndexRes = 0; currentIndexRes < currentRes.length; ++currentIndexRes)
            {
                passed &= Math.abs(currentRes[currentIndexRes] - (row * 20.0)) < DELTA;
            }
            if (passed)
            {
                System.out.println("ROW " + row + " PASSED");
            }
            else
            {
                System.out.println("ROW " + row + " FAILED");
            }
        }
    }


    public static void main(String[] args)
    {
        QuickTestExplicit kern = new QuickTestExplicit();
        kern.setExecutionMode(EXECUTION_MODE.GPU);
        kern.setExplicit(true);
        kern.process();
    }
}

所以我的问题是:

  • 如何强制更新已放入 GPU 内存的大型缓冲区?
  • 为什么,当我使用隐式缓冲区管理运行这段代码时,会抛出 SIGSEV ?

我认为这不是与 GPU 内存容量相关的问题(在我的情况下为 2GB 内存,而应用程序只是放了 2000*20*4 + 2000*4 = 168KB)我使用的是 CUDA 架构。仅供参考,该程序在 JTP 模式下运行时通过。

提前致谢 !

编辑:我忘了提到我正在使用 svn/trunk/Downloads 中可用的“Aparapi_2014_04_29_Linux64”版本。
似乎使用 2D Java 原始数组时出现了问题。我使用 1D Java 原始数组重写了相同的算法,而且效果很好...有什么想法吗?

4

0 回答 0