-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure all Halide arithmetic scalar types can be named from the Generator interface. #7934
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "HalideBuffer.h" | ||
#include "HalideRuntime.h" | ||
|
||
#include <math.h> | ||
#include <stdio.h> | ||
|
||
#include "all_type_names.h" | ||
|
||
using namespace Halide::Runtime; | ||
|
||
const int kSize = 32; | ||
|
||
int main(int argc, char **argv) { | ||
int32_t result; | ||
|
||
Buffer<int8_t, 1> input_i8(kSize); | ||
Buffer<int16_t, 1> input_i16(kSize); | ||
Buffer<int32_t, 1> input_i32(kSize); | ||
Buffer<int64_t, 1> input_i64(kSize); | ||
Buffer<uint8_t, 1> input_u8(kSize); | ||
Buffer<uint16_t, 1> input_u16(kSize); | ||
Buffer<uint32_t, 1> input_u32(kSize); | ||
Buffer<uint64_t, 1> input_u64(kSize); | ||
Buffer<uint16_t, 1> input_f16(kSize); | ||
Buffer<float, 1> input_f32(kSize); | ||
Buffer<double, 1> input_f64(kSize); | ||
Buffer<uint16_t, 1> input_bf16(kSize); | ||
Buffer<double, 1> output(kSize); | ||
|
||
input_i8.fill(1); | ||
input_i16.fill(1); | ||
input_i32.fill(1); | ||
input_i64.fill(1); | ||
input_u8.fill(1); | ||
input_u16.fill(1); | ||
input_u32.fill(1); | ||
input_u64.fill(1); | ||
// Start with a u16 Buffer so it can be initialized then convert to float16. | ||
input_f16.fill(0x3C00); | ||
input_f16.raw_buffer()->type.code = halide_type_float; | ||
input_f32.fill(1.0f); | ||
input_f64.fill(1.0); | ||
// Start with a u16 Buffer so it can be initialized then convert to bfloat16. | ||
input_bf16.fill(0x3F80); | ||
input_bf16.raw_buffer()->type.code = halide_type_bfloat; | ||
|
||
result = all_type_names(input_i8, input_i16, input_i32, input_i64, | ||
input_u8, input_u16, input_u32, input_u64, | ||
input_f16, input_f32, input_f64, input_bf16, | ||
output); | ||
assert(result == 0); | ||
output.for_each_element([=](int x) { | ||
assert(output(x) == 10.0); | ||
}); | ||
|
||
printf("Success!\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "Halide.h" | ||
|
||
namespace { | ||
|
||
class AllTypeNamesGeneric : public Halide::Generator<AllTypeNamesGeneric> { | ||
public: | ||
Input<Func> input_i8{"input_i8", 1}; | ||
Input<Func> input_i16{"input_i16", 1}; | ||
Input<Func> input_i32{"input_i32", 1}; | ||
Input<Func> input_i64{"input_i64", 1}; | ||
Input<Func> input_u8{"input_u8", 1}; | ||
Input<Func> input_u16{"input_u16", 1}; | ||
Input<Func> input_u32{"input_u32", 1}; | ||
Input<Func> input_u64{"input_u64", 1}; | ||
Input<Func> input_f16{"input_f16", 1}; | ||
Input<Func> input_f32{"input_f32", 1}; | ||
Input<Func> input_f64{"input_f64", 1}; | ||
Input<Func> input_bf16{"input_bf16", 1}; | ||
Output<Func> output{"output", 1}; | ||
|
||
void generate() { | ||
Var x; | ||
|
||
// Don't use float16 and bfloat16 arguments as they do not compile with C++ code generation. | ||
output(x) = cast<double>(input_i8(x) + input_i16(x) + input_i32(x) + input_i64(x)) + | ||
cast<double>(input_u8(x) + input_u16(x) + input_u32(x) + input_u64(x)) + | ||
input_f32(x) + input_f64(x); | ||
|
||
// set estimates for the autoschedulers | ||
input_i8.set_estimates({{0, 32}}); | ||
input_i16.set_estimates({{0, 32}}); | ||
input_i32.set_estimates({{0, 32}}); | ||
input_i64.set_estimates({{0, 32}}); | ||
input_u8.set_estimates({{0, 32}}); | ||
input_u16.set_estimates({{0, 32}}); | ||
input_u32.set_estimates({{0, 32}}); | ||
input_u64.set_estimates({{0, 32}}); | ||
input_f16.set_estimates({{0, 32}}); | ||
input_f32.set_estimates({{0, 32}}); | ||
input_f64.set_estimates({{0, 32}}); | ||
input_bf16.set_estimates({{0, 32}}); | ||
output.set_estimates({{0, 32}}); | ||
|
||
if (!using_autoscheduler()) { | ||
output.vectorize(x, natural_vector_size<int64_t>()).compute_root(); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
HALIDE_REGISTER_GENERATOR(AllTypeNamesGeneric, all_type_names_generic) | ||
HALIDE_REGISTER_GENERATOR_ALIAS(all_type_names, all_type_names_generic, {{"input_i8.type", "int8"}, {"input_i16.type", "int16"}, {"input_i32.type", "int32"}, {"input_i64.type", "int64"}, {"input_u8.type", "uint8"}, {"input_u16.type", "uint16"}, {"input_u32.type", "uint32"}, {"input_u64.type", "uint64"}, {"input_f16.type", "float16"}, {"input_f32.type", "float32"}, {"input_f64.type", "float64"}, {"input_bf16.type", "bfloat16"}, {"output.type", "float64"}}) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: looooooong line is long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it very nicely formatted. The autoformat stuff said this is what it wants.