1
我想超載的renderScript內核:可以重載一個RenderScript內核嗎?
/* donothing.rs */
uchar4 __attribute__((kernel, overloadable)) root (uchar4 in) {
return in;
}
float4 __attribute__((kernel, overloadable)) root (float4 in) {
return in;
}
然而,這會產生相同名字的Java方法:
// ScriptC_donothing.java:95
public void forEach_root(Allocation ain, Allocation aout, Script.LaunchOptions sc) {
// check ain
if (!ain.getType().getElement().isCompatible(__U8_4)) {
throw new RSRuntimeException("Type mismatch with U8_4!");
}
...
// ScriptC_donothing.java:225
public void forEach_root(Allocation ain, Allocation aout, Script.LaunchOptions sc) {
// check ain
if (!ain.getType().getElement().isCompatible(__F32_4)) {
throw new RSRuntimeException("Type mismatch with F32_4!");
}
...
是否有寫的內核,使超載工作的方法嗎?我期望的用法是:
// DoNothingActivity.java
mInAllocation = Allocation.createFromBitmap(mRS, ...
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
mScript = new ScriptC_donothing(mRS);
mScript.forEach_root(mInAllocation, mOutAllocation);
// calls uchar4 kernel
關於用例,我的實際內核實現了[parallel reduction,](http://www.drdobbs.com/architecture-and-design/parallel-pattern-7-reduce/222000718),其中自動類型檢測會特別方便 - 現在我正在使用宏魔術來模擬模板編程。 – Kietz