首页 > 解决方案 > Halide:无法在生成器中打印 - “!function_takes_user_context(op->name)”

问题描述

当我尝试在生成器中 print() 表达式时,我无法构建:

Internal Error at /home/halidenightly/build_bot/worker/linux-64-gcc53-800/halide/src/CodeGen_OpenCL_Dev.cpp:229 triggered by user code at :
Condition failed: !function_takes_user_context(op->name):
Aborted (core dumped)

我不明白这个错误信息,它是什么?

编辑 1:我现在在下面包含了更完整的代码。

#include "Halide.h"

using namespace Halide;

class SimpleGenerator : public Generator<SimpleGenerator>{
public:

    Input<Buffer<uint8_t >> source{"src", 2};
    Input<Buffer<uint8_t >> reference{"ref", 2};
    Output<Buffer<uint8_t >> output{"out", 2};

    void generate(){
        intermediate(x, y) = print(source(x, y), "source at (", x,", ", y, ")") + print(reference(x, y));
        output(x, y) = intermediate(x, y);
    }

    void schedule(){
        Var xo("xo"), yo("yo"), xi("xi"), yi("yi");
        if (get_target().has_gpu_feature()) {
            std::cout << "Using GPU schedule\n";
            output.gpu_tile(x, y, xo, yo, xi, yi, 16, 16, TailStrategy::GuardWithIf);
        } else {
            std::cout << "Using CPU schedule\n";
        }
    }

private:
    Func intermediate{"intermediate"};
    Var x{"x"}, y{"y"};
};

HALIDE_REGISTER_GENERATOR(SimpleGenerator, simple_generator)

编辑2:我缩小了问题范围;尝试使用 OpenCL 以 GPU 为目标时会出现此问题。我记得在某处读到,在 GPU 上打印 Halide Exprs 是有问题的。有谁知道如何解决这个问题?

标签: halide

解决方案


你的语法似乎很好,就像教程中的一样 - 第4 课

Func f; f(x, y) = sin(x) + print(cos(y), "<- this is cos(", y, ") when x =", x);

您能否分享更多“最终”功能以获取更多上下文?也许它可能是在那之前的东西


推荐阅读