28 static constexpr int max_i32 = 0x7fffffff;
53 const std::vector<ImageParam>
image_params{
in_f32,
in_f64,
in_f16,
in_bf16,
in_i8,
in_u8,
in_i16,
in_u16,
in_i32,
in_u32,
in_i64,
in_u64};
54 const std::vector<Argument>
arg_types{
in_f32,
in_f64,
in_f16,
in_bf16,
in_i8,
in_u8,
in_i16,
in_u16,
in_i32,
in_u32,
in_i64,
in_u64};
115 virtual void compile_and_check(
Func error,
const std::string &op,
const std::string &name,
int vector_width, std::ostringstream &error_msg) {
116 std::string
fn_name =
"test_" + name;
120 std::map<OutputFileType, std::string> outputs = {
132 std::ostringstream msg;
133 msg << op <<
" did not generate for target=" <<
get_run_target().
to_string() <<
" vector_width=" << vector_width <<
". Instead we got:\n";
144 error_msg <<
"Failed: " << msg.str() <<
"\n";
153 while (*
p && *str && *
p == *str && *
p !=
'*') {
160 }
else if (*
p ==
'*') {
167 }
else if (*
p ==
' ') {
172 }
else if (*str ==
' ') {
198 std::ostringstream error_msg;
201 using Internal::IRVisitor::visit;
203 if (op->
call_type == Internal::Call::Halide) {
206 inline_reduction = f;
210 IRVisitor::visit(op);
241 .split(x,
xo,
xi, vector_width)
243 .vectorize(g.rvars()[0])
263 if (!buf.defined())
continue;
269 if (t ==
Float(32)) {
270 buf.as<
float>().for_each_value([&](
float &f) { f = (
rng() & 0xfff) / 8.0f - 0xff; });
271 }
else if (t ==
Float(64)) {
272 buf.as<
double>().for_each_value([&](
double &f) { f = (
rng() & 0xfff) / 8.0 - 0xff; });
273 }
else if (t ==
Float(16)) {
278 ptr != (
uint32_t *)buf.data() + buf.size_in_bytes() / 4;
293 error_msg <<
"The vector and scalar versions of " << name <<
" disagree. Maximum error: " << e <<
"\n";
301 error_msg <<
"Error assembly: \n";
304 error_msg <<
line <<
"\n";
311 return {op, error_msg.str()};
316 std::string name =
"op_" + op;
317 for (
size_t i = 0;
i < name.size();
i++) {
321 name +=
"_" + std::to_string(
tasks.size());
328 tasks.emplace_back(
Task{op, name, vector_width, e});
338 p.dim(0).set_min((
p.dim(0).min() / alignment) * alignment);
351 for (
size_t t = 0; t <
tasks.size(); t++) {
352 if (!
sharder.should_run(t))
continue;
353 const auto &task =
tasks.at(t);
354 auto result =
check_one(task.op, task.name, task.vector_width, task.expr);
356 const int spaces = std::max(1,
tabstop - (
int)result.op.size());
358 if (!result.error_msg.empty()) {
359 std::cerr << result.error_msg;
367 template<
typename SIMDOpCheckT>
370 std::cout <<
"host is: " << host <<
"\n";
373 std::cout <<
"simd_op_check test seed: " <<
seed <<
"\n";
376 if (!t.supported()) {
377 std::cout <<
"[SKIP] Unsupported target: " << t <<
"\n";
382 if (!t.supported()) {
383 std::cout <<
"Halide was compiled without support for " << t.to_string() <<
". Skipping.\n";
388 test.filter = argv[1];
391 if (
getenv(
"HL_SIMD_OP_CHECK_FILTER")) {
392 test.filter =
getenv(
"HL_SIMD_OP_CHECK_FILTER");
404 test.output_directory = argv[2];
407 bool success = test.test_all();
417 std::cout <<
"Success!\n";
void compile_to_assembly(const std::string &filename, const std::vector< Argument > &, const std::string &fn_name, const Target &target=get_target_from_environment())
Statically compile this function to text assembly equivalent to the object file generated by compile_...
void infer_input_bounds(const std::vector< int32_t > &sizes, const Target &target=get_jit_target_from_environment(), const ParamMap ¶m_map=ParamMap::empty_map())
For a given size of output, or a given output buffer, determine the bounds required of all unbound Im...
Func & compute_root()
Compute all of this function once ahead of time.
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target(), const ParamMap ¶m_map=ParamMap::empty_map())
Evaluate this function over some rectangular domain and return the resulting buffer or buffers.
void compile_to(const std::map< OutputFileType, std::string > &output_files, const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment())
Compile and generate multiple target files with single call.
Func & vectorize(const VarOrRVar &var)
Mark a dimension to be computed all-at-once as a single vector.
Func & bound(const Var &var, Expr min, Expr extent)
Statically declare that the range over which a function should be evaluated is given by the second an...
An Image parameter to a halide pipeline.
A reference-counted handle to Halide's internal representation of a function.
bool has_update_definition() const
Does this function have an update definition?
A base class for algorithms that need to recursively walk over the IR.
A multi-dimensional domain over which to iterate.
A reduction variable represents a single dimension of a reduction domain (RDom).
A Realization is a vector of references to existing Buffer objects.
virtual void compile_and_check(Func error, const std::string &op, const std::string &name, int vector_width, std::ostringstream &error_msg)
static constexpr int max_u8
const std::vector< Argument > arg_types
std::string output_directory
static constexpr int max_i32
virtual void setup_images()
virtual void add_tests()=0
bool wildcard_match(const std::string &p, const std::string &str) const
static constexpr int max_i8
static constexpr int max_u16
bool wildcard_search(const std::string &p, const std::string &str) const
bool wildcard_match(const char *p, const char *str) const
virtual ~SimdOpCheckTest()=default
SimdOpCheckTest(const Target t, int w, int h)
void check(std::string op, int vector_width, Expr e)
Target get_run_target() const
static int main(int argc, char **argv, const std::vector< Target > &targets_to_test)
const std::vector< ImageParam > image_params
static constexpr int max_i16
TestResult check_one(const std::string &op, const std::string &name, int vector_width, Expr e)
virtual bool can_run_code() const
std::vector< Task > tasks
A Halide variable, to be used when defining functions.
std::map< OutputFileType, const OutputInfo > get_output_info(const Target &target)
std::string get_test_tmp_dir()
Return the path to a directory that can be safely written to when running tests; the contents directo...
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Target get_host_target()
Return the target corresponding to the host machine.
Type BFloat(int bits, int lanes=1)
Construct a floating-point type in the bfloat format.
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Expr maximum(Expr, const std::string &s="maximum")
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Expr absd(Expr a, Expr b)
Return the absolute difference between two values.
void compile_standalone_runtime(const std::string &object_filename, const Target &t)
Create an object file containing the Halide runtime for a given target.
unsigned __INT32_TYPE__ uint32_t
char * getenv(const char *)
A fragment of Halide syntax.
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
HALIDE_ALWAYS_INLINE const Internal::BaseExprNode * get() const
Override get() to return a BaseExprNode * instead of an IRNode *.
void accept(IRVisitor *v) const
Dispatch to the correct visitor method for this node.
static bool can_jit_target(const Target &target)
If the given target can be executed via the wasm executor, return true.
A struct representing a target machine and os to generate code for.
enum Halide::Target::Arch arch
bool has_feature(Feature f) const
int bits
The bit-width of the target machine.
enum Halide::Target::OS os
std::string to_string() const
Convert the Target into a string form that can be reconstituted by merge_string(),...
Target without_feature(Feature f) const
Return a copy of the target with the given feature cleared.
Feature
Optional features a target can have.
Target with_feature(Feature f) const
Return a copy of the target with the given feature set.
Types in the halide type system.
int bytes() const
The number of bytes required to store a single scalar value of this type.
Expr max() const
Return an expression which is the maximum value of this type.
Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in s...