【问题标题】:Can one overload a RenderScript kernel?可以重载 RenderScript 内核吗?
【发布时间】:2013-10-25 04:57:59
【问题描述】:

我想重载一个 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

【问题讨论】:

    标签: overloading renderscript


    【解决方案1】:

    目前无法重载内核名称。不过,我们正在投资一些方法来将更多类型信息与未来的分配相关联;我们会牢记这个用例。

    【讨论】:

    • 关于用例,我的实际内核实现了parallel reduction,,自动类型检测特别方便——现在我正在使用宏巫术来模拟模板编程。
    猜你喜欢
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2018-07-04
    相关资源
    最近更新 更多