aparapi仅能读取基本数据类型 及其一维数组
可以继承Kernel重写run方法
也可以用匿名内部类
调用Kernel.execute(int range),并且在方法内部通过getGlobalId()来获取唯一索引(0...range-1)
通过配置javac -g参数来显示代码调试信息
有四种执行模式
1.JTP Java thread pool 一个核心对应着一个线程
2.SEQ single sequential java loop 通过循环来串行执行
3.GPU 将Java字节码转化为OpenCL代码在GPU上执行
4.CPU 将Java字节码转化为
OpenCL代码在CPU上执行
如果OpenCL可用则默认使用GPU模式
否则使用JTP模式
通过Kernel.setExecutionMode()来设定执行模式
也可以设定启动参数来指定执行模式
-Dcom.amd.aparapi.ExecutionMode=JTP
通过Kernel.getExecutionMode()来获取实际执行模式
也可以设定启动参数来获取实际执行模式
-Dcom.amd.aparapi.enableExecutionModeReporting=true
其它可设定参数及默认值有
com.amd.aparapi.executionMode SEQ|JTP|CPU|GPU (GPU)
com.amd.aparapi.enableExecutionModeReporting true|false (false)
com.amd.aparapi.enableShowGeneratedOpenCL true|false (false)
com.amd.aparapi.logLevel FINEST|FINE|INFO|WARNING|SEVERE (WARNING)
com.amd.aparapi.enableProfiling true|false (false)
com.amd.aparapi.enableVerboseJNI true|false (false)
com.amd.aparapi.instructionListenerClass Name of a class implements Config.InstructionListener
举例:
-Dcom.amd.aparapi.executionMode=GPU
-Dcom.amd.aparapi.enableExecutionModeReporting=true
-Dcom.amd.aparapi.logLevel=FINE
-Dcom.amd.aparapi.enableShowGeneratedOpenCL=true
在for循环中多次执行核函数时,为了避免不必要的多次拷贝赋值,我们可以明确指出自己控制数据转移过程(支持链式调用)
final int hugeArray[] =new int[HUGE];
final boolean[] done = new boolean[false];
Kernel kernel = new Kernel(){
// reads and writes hugeArray
};
kernel.setExplicit(true); // we take control of all transfers
kernel.put(hugeArray).put(done);
while (!done[0]){
kernel.execute(range).get(done);
}
kernel.get(hugeArray);
一些可用的方法
getGlobalId() 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
getLocalId() 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
getGroupId()==0 getGroupId()==1
getNumGroups()==2
getGlobalSize()==16
getGroupSize()==8
for (int pass=0; pass<100; pass++){
kernel.execute(range);
}
可以被替换为
Kernel kernel = new Kernel(){
public void run(){
if (getPassId()%2==0){ // 通过getPassId()获取当前执行为第几次
// do this
}else{
// do that
}
}
};
kernel.execute(range, 100); // 指定当前核函数执行100次
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。