When using float16 and a metal backend, I'm getting runtime errors that complains calls to min/max/select are ambiguous because METAL_FUNC with both half and float signatures exist.
This error is triggered if the computation involves both half and float, even when explicit cast is used before calling the functions min/max/select.
Here is a minimum example that exposed this error for min and select. I'm using Mac M2 with target=host-metal, and I'm building Halide from top of tree.
// f16_bug_generator.cpp
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
class F16BugGenerator : public Halide::Generator<F16BugGenerator> {
public:
Input<Buffer<>> input{"input", 2};
Output<Buffer<>> output{"output", 2};
Var x, y;
void generate() {
Expr val = cast(output.type(), input(x, y) + 1.f);
Expr clamp_val = clamp(val, cast(output.type(), 0), cast(output.type(), 1));
output(x, y) = cast(output.type(), select(clamp_val > 1, cast<float>(abs(clamp_val)), cast<float>(fast_pow(clamp_val, 1.f / 2.2f))));
if (get_target().has_gpu_feature()) {
printf("GPU schedule\n");
Var xi, xo, yi, yo;
output.compute_root()
.gpu_tile(x, y, xo, yo, xi, yi, 8, 32);
}
}
};
HALIDE_REGISTER_GENERATOR(F16BugGenerator, f16_bug_generator)
When using float16 and a metal backend, I'm getting runtime errors that complains calls to min/max/select are ambiguous because METAL_FUNC with both half and float signatures exist.
This error is triggered if the computation involves both half and float, even when explicit cast is used before calling the functions min/max/select.
Here is a minimum example that exposed this error for min and select. I'm using Mac M2 with
target=host-metal
, and I'm building Halide from top of tree.Error message: