我正在學習Aparapi(https://code.google.com/p/aparapi/)並且有一個包含樣本的奇怪行爲。 該示例是第一個「添加」。建立並執行它,沒問題。我還把以下代碼用於測試GPU是否真的使用了Aparapi添加樣本
if(!kernel.getExecutionMode().equals(Kernel.EXECUTION_MODE.GPU)){
System.out.println("Kernel did not execute on the GPU!");
}
它工作正常。 但是,如果我嘗試了數組的大小從512更改爲數字大於999(例如1000),我有以下的輸出:
!!!!!!! clEnqueueNDRangeKernel() failed invalid work group size
after clEnqueueNDRangeKernel, globalSize[0] = 1000, localSize[0] = 128
Apr 18, 2013 1:31:01 PM com.amd.aparapi.KernelRunner executeOpenCL
WARNING: ### CL exec seems to have failed. Trying to revert to Java ###
JTP
Kernel did not execute on the GPU!
這裏是我的代碼:
final int size = 1000;
final float[] a = new float[size];
final float[] b = new float[size];
for (int i = 0; i < size; i++) {
a[i] = (float)(Math.random()*100);
b[i] = (float)(Math.random()*100);
}
final float[] sum = new float[size];
Kernel kernel = new Kernel(){
@Override public void run() {
int gid = getGlobalId();
sum[gid] = a[gid] + b[gid];
}
};
Range range = Range.create(size);
kernel.execute(range);
System.out.println(kernel.getExecutionMode());
if (!kernel.getExecutionMode().equals(Kernel.EXECUTION_MODE.GPU)){
System.out.println("Kernel did not execute on the GPU!");
}
kernel.dispose();
}
我試圖使用指定
Range range = Range.create(size, 128);
大小的建議在Google組中,但沒有任何變化。
我目前正在使用Java 1.6.0_43的Mac OS X 10.8上運行。 Aparapi版本是最新的(2012-01-23)。
我錯過了什麼嗎?有任何想法嗎?
在此先感謝
感謝您的回答。我在Range.create()中丟棄了128,並且使用128的倍數作爲'size'變量,一切正常。 你說Aparapi在內部選擇組大小,它必須是範圍的一個因子。那麼爲什麼代碼工作選擇大小= 999?999%128 = 103,但它在GPU上執行沒有錯誤。我是否必須始終使用本地化的大小?我怎樣才能發現本地化的價值?非常感謝 – besil
只需使用Range.range(size)的單個arg版本即可。 Aparapi將爲您選擇最大的公因子。對於999這應該是像9 * 111。您選擇控制並強制Aparapi使用Range.range(X,128)工廠方法使用localsize 128。這裏,Aparapi'尊敬'你的請求,但OpenCL(正確)在運行時拒絕請求並且不能執行。請注意,在MacOSX上,存在關於設備(GPU)報告不正確的組大小的各種報告。我不確定你是否擊中了這個。我有Mac OSX,你的代碼對我來說工作得很好。 – gfrost