Java Aparabi多重put/get似乎没有效果
我在Aparabi中使用显式缓冲区管理时遇到了一个问题。 下面的代码显示,我正试图在一个循环中管理几个put/get,以刷新/从GPU获取数据。似乎第一个Java Aparabi多重put/get似乎没有效果,java,opencl,gpu,aparapi,Java,Opencl,Gpu,Aparapi,我在Aparabi中使用显式缓冲区管理时遇到了一个问题。 下面的代码显示,我正试图在一个循环中管理几个put/get,以刷新/从GPU获取数据。似乎第一个put和get都完成了,但其他的都没有完成 import com.amd.aparapi // Dummy test to reproduce explicit buffer management public class QuickTestExplicit extends Kernel { private static final
put
和get
都完成了,但其他的都没有完成
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();
}
}
import com.amd.aparapi
//复制显式缓冲区管理的虚拟测试
公共类QuickTestExplicit扩展内核
{
专用静态最终浮动增量=(浮动)1E-5;
//将被填充,在每次迭代中放在GPU上
私有浮动[][]值;
//将填充结果,放入GPU一次,但检索多次
私人股本;
私有void initData()
{
数值=新浮动[2000][20];
currentRes=新的浮动[2000];
}
@凌驾
公开募捐
{
int id=getGlobalId();
长累计=0;
//元素的简单和
对于(int索引=0;索引<20;++index)
{
累计+=值[id][索引];
}
currentRes[id]=累计值;
}
公共程序()
{
布尔传递=真;
initData();
if(isExplicit())
{
put(currentRes);
}
用于(int行=0;行<2000;++行)
{
对于(int i=0;i
因此,我的问题是:
- 如何强制更新已放入GPU内存中的大型缓冲区
- 为什么,当我使用隐式缓冲区管理运行这段代码时,会抛出一个SIGSEV
似乎在使用2D Java基元数组时出现了问题。我使用1D Java基元数组重写了相同的算法,效果非常好……有什么想法吗?2D数组是数组数组数组,不是Java的连续空间。在上传到GPU之前,可能需要2D到1D转换器。确切地说,但据我所知,Aparabi已经开发了oped支持在内核(和3D数组)中使用Java 2D数组。您的建议是有效的,但它只是绕过了真正的问题。。。