Skip to content

Commit

Permalink
Merge branch 'main' into xtensa-codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-johnson committed May 9, 2023
2 parents be1d051 + 53de4ce commit 2764a26
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/IROperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,8 +1943,17 @@ Expr cast(Type t, Expr a) {
if (a.type().is_scalar()) {
return Broadcast::make(cast(t.element_of(), std::move(a)), t.lanes());
} else if (const Broadcast *b = a.as<Broadcast>()) {
internal_assert(b->lanes == t.lanes());
return Broadcast::make(cast(t.element_of(), b->value), t.lanes());
if (b->lanes == t.lanes()) {
return Broadcast::make(cast(t.element_of(), b->value), t.lanes());
}
// else fall thru: we could have a situation like
//
// a=x3(ramp(x, y, 2)) # type=uint32x6
// t=uint1x6
//
// this should be legal to cast, but requiring b->lanes == t.lanes
// would make it fail. Just fall through and let the Cast IR node
// deal with possible errors. (https://github.com/halide/Halide/issues/7556)
}
}
return Cast::make(t, std::move(a));
Expand Down
1 change: 1 addition & 0 deletions src/runtime/vulkan_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ int VulkanMemoryAllocator::initialize(void *user_context,
block_allocator_config.maximum_block_count = cfg.maximum_block_count;
block_allocator_config.maximum_block_size = cfg.maximum_block_size;
block_allocator_config.minimum_block_size = cfg.minimum_block_size;
block_allocator_config.nearest_multiple = cfg.nearest_multiple;
block_allocator = BlockAllocator::create(user_context, block_allocator_config, allocators);
if (block_allocator == nullptr) {
error(user_context) << "VulkanMemoryAllocator: Failed to create BlockAllocator! Out of memory?!\n";
Expand Down
12 changes: 12 additions & 0 deletions test/correctness/cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ int main(int argc, char **argv) {
assert(float_expr.type() == Float(32));
assert(double_expr.type() == Float(64));

// Verify that broadcast-of-ramp works properly when cast
{
Type t = Int(32, 6);
Expr r = Halide::Internal::Ramp::make(3, 7, 2);
Expr b = Halide::Internal::Broadcast::make(r, 3);
assert(b.type() == t);

Type t_bool = UInt(1, 6);
Expr b_bool = cast(t_bool, b);
assert(b_bool.type() == t_bool);
}

printf("Success!\n");
return 0;
}
7 changes: 5 additions & 2 deletions test/fuzz/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ Expr random_expr(FuzzedDataProvider &fdp, Type t, int depth, bool overflow_undef

// Boolean operations -- both sides must be cast to booleans,
// and then we must cast the result back to 't'.
Expr a = cast<bool>(random_expr(fdp, t, depth, overflow_undef));
Expr b = cast<bool>(random_expr(fdp, t, depth, overflow_undef));
Expr a = random_expr(fdp, t, depth, overflow_undef);
Expr b = random_expr(fdp, t, depth, overflow_undef);
Type bool_with_lanes = Bool(t.lanes());
a = cast(bool_with_lanes, a);
b = cast(bool_with_lanes, b);
return cast(t, fdp.PickValueInArray(make_bin_op)(a, b));
}};
return fdp.PickValueInArray(operations)();
Expand Down

0 comments on commit 2764a26

Please sign in to comment.